| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843 |
- /*
- * MbedTLS Source Code Library Header
- */
- #include "me.h"
- #if ME_COM_MBEDTLS
- #if defined(MBEDTLS_CONFIG_FILE)
- #include MBEDTLS_CONFIG_FILE
- #endif
- /********* Start of file library/common.h ************/
- /**
- * \file common.h
- *
- * \brief Utility macros for internal use in the library
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_LIBRARY_COMMON_H
- #define MBEDTLS_LIBRARY_COMMON_H
- #if defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stdint.h>
- /** Helper to define a function as static except when building invasive tests.
- *
- * If a function is only used inside its own source file and should be
- * declared `static` to allow the compiler to optimize for code size,
- * but that function has unit tests, define it with
- * ```
- * MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... }
- * ```
- * and declare it in a header in the `library/` directory with
- * ```
- * #if defined(MBEDTLS_TEST_HOOKS)
- * int mbedtls_foo(...);
- * #endif
- * ```
- */
- #if defined(MBEDTLS_TEST_HOOKS)
- #define MBEDTLS_STATIC_TESTABLE
- #else
- #define MBEDTLS_STATIC_TESTABLE static
- #endif
- /** Byte Reading Macros
- *
- * Given a multi-byte integer \p x, MBEDTLS_BYTE_n retrieves the n-th
- * byte from x, where byte 0 is the least significant byte.
- */
- #define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) )
- #define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) )
- #define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) )
- #define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
- #define MBEDTLS_BYTE_4( x ) ( (uint8_t) ( ( ( x ) >> 32 ) & 0xff ) )
- #define MBEDTLS_BYTE_5( x ) ( (uint8_t) ( ( ( x ) >> 40 ) & 0xff ) )
- #define MBEDTLS_BYTE_6( x ) ( (uint8_t) ( ( ( x ) >> 48 ) & 0xff ) )
- #define MBEDTLS_BYTE_7( x ) ( (uint8_t) ( ( ( x ) >> 56 ) & 0xff ) )
- /**
- * Get the unsigned 32 bits integer corresponding to four bytes in
- * big-endian order (MSB first).
- *
- * \param data Base address of the memory to get the four bytes from.
- * \param offset Offset from \p base of the first and most significant
- * byte of the four bytes to build the 32 bits unsigned
- * integer from.
- */
- #ifndef MBEDTLS_GET_UINT32_BE
- #define MBEDTLS_GET_UINT32_BE( data , offset ) \
- ( \
- ( (uint32_t) ( data )[( offset ) ] << 24 ) \
- | ( (uint32_t) ( data )[( offset ) + 1] << 16 ) \
- | ( (uint32_t) ( data )[( offset ) + 2] << 8 ) \
- | ( (uint32_t) ( data )[( offset ) + 3] ) \
- )
- #endif
- /**
- * Put in memory a 32 bits unsigned integer in big-endian order.
- *
- * \param n 32 bits unsigned integer to put in memory.
- * \param data Base address of the memory where to put the 32
- * bits unsigned integer in.
- * \param offset Offset from \p base where to put the most significant
- * byte of the 32 bits unsigned integer \p n.
- */
- #ifndef MBEDTLS_PUT_UINT32_BE
- #define MBEDTLS_PUT_UINT32_BE( n, data, offset ) \
- { \
- ( data )[( offset ) ] = MBEDTLS_BYTE_3( n ); \
- ( data )[( offset ) + 1] = MBEDTLS_BYTE_2( n ); \
- ( data )[( offset ) + 2] = MBEDTLS_BYTE_1( n ); \
- ( data )[( offset ) + 3] = MBEDTLS_BYTE_0( n ); \
- }
- #endif
- /**
- * Get the unsigned 32 bits integer corresponding to four bytes in
- * little-endian order (LSB first).
- *
- * \param data Base address of the memory to get the four bytes from.
- * \param offset Offset from \p base of the first and least significant
- * byte of the four bytes to build the 32 bits unsigned
- * integer from.
- */
- #ifndef MBEDTLS_GET_UINT32_LE
- #define MBEDTLS_GET_UINT32_LE( data, offset ) \
- ( \
- ( (uint32_t) ( data )[( offset ) ] ) \
- | ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \
- | ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \
- | ( (uint32_t) ( data )[( offset ) + 3] << 24 ) \
- )
- #endif
- /**
- * Put in memory a 32 bits unsigned integer in little-endian order.
- *
- * \param n 32 bits unsigned integer to put in memory.
- * \param data Base address of the memory where to put the 32
- * bits unsigned integer in.
- * \param offset Offset from \p base where to put the least significant
- * byte of the 32 bits unsigned integer \p n.
- */
- #ifndef MBEDTLS_PUT_UINT32_LE
- #define MBEDTLS_PUT_UINT32_LE( n, data, offset ) \
- { \
- ( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \
- ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
- ( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \
- ( data )[( offset ) + 3] = MBEDTLS_BYTE_3( n ); \
- }
- #endif
- /**
- * Get the unsigned 16 bits integer corresponding to two bytes in
- * little-endian order (LSB first).
- *
- * \param data Base address of the memory to get the two bytes from.
- * \param offset Offset from \p base of the first and least significant
- * byte of the two bytes to build the 16 bits unsigned
- * integer from.
- */
- #ifndef MBEDTLS_GET_UINT16_LE
- #define MBEDTLS_GET_UINT16_LE( data, offset ) \
- ( \
- ( (uint16_t) ( data )[( offset ) ] ) \
- | ( (uint16_t) ( data )[( offset ) + 1] << 8 ) \
- )
- #endif
- /**
- * Put in memory a 16 bits unsigned integer in little-endian order.
- *
- * \param n 16 bits unsigned integer to put in memory.
- * \param data Base address of the memory where to put the 16
- * bits unsigned integer in.
- * \param offset Offset from \p base where to put the least significant
- * byte of the 16 bits unsigned integer \p n.
- */
- #ifndef MBEDTLS_PUT_UINT16_LE
- #define MBEDTLS_PUT_UINT16_LE( n, data, offset ) \
- { \
- ( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \
- ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
- }
- #endif
- /**
- * Get the unsigned 16 bits integer corresponding to two bytes in
- * big-endian order (MSB first).
- *
- * \param data Base address of the memory to get the two bytes from.
- * \param offset Offset from \p base of the first and most significant
- * byte of the two bytes to build the 16 bits unsigned
- * integer from.
- */
- #ifndef MBEDTLS_GET_UINT16_BE
- #define MBEDTLS_GET_UINT16_BE( data, offset ) \
- ( \
- ( (uint16_t) ( data )[( offset ) ] << 8 ) \
- | ( (uint16_t) ( data )[( offset ) + 1] ) \
- )
- #endif
- /**
- * Put in memory a 16 bits unsigned integer in big-endian order.
- *
- * \param n 16 bits unsigned integer to put in memory.
- * \param data Base address of the memory where to put the 16
- * bits unsigned integer in.
- * \param offset Offset from \p base where to put the most significant
- * byte of the 16 bits unsigned integer \p n.
- */
- #ifndef MBEDTLS_PUT_UINT16_BE
- #define MBEDTLS_PUT_UINT16_BE( n, data, offset ) \
- { \
- ( data )[( offset ) ] = MBEDTLS_BYTE_1( n ); \
- ( data )[( offset ) + 1] = MBEDTLS_BYTE_0( n ); \
- }
- #endif
- /**
- * Get the unsigned 64 bits integer corresponding to eight bytes in
- * big-endian order (MSB first).
- *
- * \param data Base address of the memory to get the eight bytes from.
- * \param offset Offset from \p base of the first and most significant
- * byte of the eight bytes to build the 64 bits unsigned
- * integer from.
- */
- #ifndef MBEDTLS_GET_UINT64_BE
- #define MBEDTLS_GET_UINT64_BE( data, offset ) \
- ( \
- ( (uint64_t) ( data )[( offset ) ] << 56 ) \
- | ( (uint64_t) ( data )[( offset ) + 1] << 48 ) \
- | ( (uint64_t) ( data )[( offset ) + 2] << 40 ) \
- | ( (uint64_t) ( data )[( offset ) + 3] << 32 ) \
- | ( (uint64_t) ( data )[( offset ) + 4] << 24 ) \
- | ( (uint64_t) ( data )[( offset ) + 5] << 16 ) \
- | ( (uint64_t) ( data )[( offset ) + 6] << 8 ) \
- | ( (uint64_t) ( data )[( offset ) + 7] ) \
- )
- #endif
- /**
- * Put in memory a 64 bits unsigned integer in big-endian order.
- *
- * \param n 64 bits unsigned integer to put in memory.
- * \param data Base address of the memory where to put the 64
- * bits unsigned integer in.
- * \param offset Offset from \p base where to put the most significant
- * byte of the 64 bits unsigned integer \p n.
- */
- #ifndef MBEDTLS_PUT_UINT64_BE
- #define MBEDTLS_PUT_UINT64_BE( n, data, offset ) \
- { \
- ( data )[( offset ) ] = MBEDTLS_BYTE_7( n ); \
- ( data )[( offset ) + 1] = MBEDTLS_BYTE_6( n ); \
- ( data )[( offset ) + 2] = MBEDTLS_BYTE_5( n ); \
- ( data )[( offset ) + 3] = MBEDTLS_BYTE_4( n ); \
- ( data )[( offset ) + 4] = MBEDTLS_BYTE_3( n ); \
- ( data )[( offset ) + 5] = MBEDTLS_BYTE_2( n ); \
- ( data )[( offset ) + 6] = MBEDTLS_BYTE_1( n ); \
- ( data )[( offset ) + 7] = MBEDTLS_BYTE_0( n ); \
- }
- #endif
- /**
- * Get the unsigned 64 bits integer corresponding to eight bytes in
- * little-endian order (LSB first).
- *
- * \param data Base address of the memory to get the eight bytes from.
- * \param offset Offset from \p base of the first and least significant
- * byte of the eight bytes to build the 64 bits unsigned
- * integer from.
- */
- #ifndef MBEDTLS_GET_UINT64_LE
- #define MBEDTLS_GET_UINT64_LE( data, offset ) \
- ( \
- ( (uint64_t) ( data )[( offset ) + 7] << 56 ) \
- | ( (uint64_t) ( data )[( offset ) + 6] << 48 ) \
- | ( (uint64_t) ( data )[( offset ) + 5] << 40 ) \
- | ( (uint64_t) ( data )[( offset ) + 4] << 32 ) \
- | ( (uint64_t) ( data )[( offset ) + 3] << 24 ) \
- | ( (uint64_t) ( data )[( offset ) + 2] << 16 ) \
- | ( (uint64_t) ( data )[( offset ) + 1] << 8 ) \
- | ( (uint64_t) ( data )[( offset ) ] ) \
- )
- #endif
- /**
- * Put in memory a 64 bits unsigned integer in little-endian order.
- *
- * \param n 64 bits unsigned integer to put in memory.
- * \param data Base address of the memory where to put the 64
- * bits unsigned integer in.
- * \param offset Offset from \p base where to put the least significant
- * byte of the 64 bits unsigned integer \p n.
- */
- #ifndef MBEDTLS_PUT_UINT64_LE
- #define MBEDTLS_PUT_UINT64_LE( n, data, offset ) \
- { \
- ( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \
- ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
- ( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \
- ( data )[( offset ) + 3] = MBEDTLS_BYTE_3( n ); \
- ( data )[( offset ) + 4] = MBEDTLS_BYTE_4( n ); \
- ( data )[( offset ) + 5] = MBEDTLS_BYTE_5( n ); \
- ( data )[( offset ) + 6] = MBEDTLS_BYTE_6( n ); \
- ( data )[( offset ) + 7] = MBEDTLS_BYTE_7( n ); \
- }
- #endif
- #endif /* MBEDTLS_LIBRARY_COMMON_H */
- /********* Start of file include/mbedtls/config.h ************/
- /**
- * \file config.h
- *
- * \brief Configuration options (set of defines)
- *
- * This set of compile-time options may be used to enable
- * or disable features selectively, and reduce the global
- * memory footprint.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CONFIG_H
- #define MBEDTLS_CONFIG_H
- #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
- #define _CRT_SECURE_NO_DEPRECATE 1
- #endif
- /**
- * \name SECTION: System support
- *
- * This section sets system specific settings.
- * \{
- */
- /**
- * \def MBEDTLS_HAVE_ASM
- *
- * The compiler has support for asm().
- *
- * Requires support for asm() in compiler.
- *
- * Used in:
- * library/aria.c
- * library/timing.c
- * include/mbedtls/bn_mul.h
- *
- * Required by:
- * MBEDTLS_AESNI_C
- * MBEDTLS_PADLOCK_C
- *
- * Comment to disable the use of assembly code.
- */
- #define MBEDTLS_HAVE_ASM
- /**
- * \def MBEDTLS_NO_UDBL_DIVISION
- *
- * The platform lacks support for double-width integer division (64-bit
- * division on a 32-bit platform, 128-bit division on a 64-bit platform).
- *
- * Used in:
- * include/mbedtls/bignum.h
- * library/bignum.c
- *
- * The bignum code uses double-width division to speed up some operations.
- * Double-width division is often implemented in software that needs to
- * be linked with the program. The presence of a double-width integer
- * type is usually detected automatically through preprocessor macros,
- * but the automatic detection cannot know whether the code needs to
- * and can be linked with an implementation of division for that type.
- * By default division is assumed to be usable if the type is present.
- * Uncomment this option to prevent the use of double-width division.
- *
- * Note that division for the native integer type is always required.
- * Furthermore, a 64-bit type is always required even on a 32-bit
- * platform, but it need not support multiplication or division. In some
- * cases it is also desirable to disable some double-width operations. For
- * example, if double-width division is implemented in software, disabling
- * it can reduce code size in some embedded targets.
- */
- //#define MBEDTLS_NO_UDBL_DIVISION
- /**
- * \def MBEDTLS_NO_64BIT_MULTIPLICATION
- *
- * The platform lacks support for 32x32 -> 64-bit multiplication.
- *
- * Used in:
- * library/poly1305.c
- *
- * Some parts of the library may use multiplication of two unsigned 32-bit
- * operands with a 64-bit result in order to speed up computations. On some
- * platforms, this is not available in hardware and has to be implemented in
- * software, usually in a library provided by the toolchain.
- *
- * Sometimes it is not desirable to have to link to that library. This option
- * removes the dependency of that library on platforms that lack a hardware
- * 64-bit multiplier by embedding a software implementation in Mbed TLS.
- *
- * Note that depending on the compiler, this may decrease performance compared
- * to using the library function provided by the toolchain.
- */
- //#define MBEDTLS_NO_64BIT_MULTIPLICATION
- /**
- * \def MBEDTLS_HAVE_SSE2
- *
- * CPU supports SSE2 instruction set.
- *
- * Uncomment if the CPU supports SSE2 (IA-32 specific).
- */
- //#define MBEDTLS_HAVE_SSE2
- /**
- * \def MBEDTLS_HAVE_TIME
- *
- * System has time.h and time().
- * The time does not need to be correct, only time differences are used,
- * by contrast with MBEDTLS_HAVE_TIME_DATE
- *
- * Defining MBEDTLS_HAVE_TIME allows you to specify MBEDTLS_PLATFORM_TIME_ALT,
- * MBEDTLS_PLATFORM_TIME_MACRO, MBEDTLS_PLATFORM_TIME_TYPE_MACRO and
- * MBEDTLS_PLATFORM_STD_TIME.
- *
- * Comment if your system does not support time functions
- */
- #define MBEDTLS_HAVE_TIME
- /**
- * \def MBEDTLS_HAVE_TIME_DATE
- *
- * System has time.h, time(), and an implementation for
- * mbedtls_platform_gmtime_r() (see below).
- * The time needs to be correct (not necessarily very accurate, but at least
- * the date should be correct). This is used to verify the validity period of
- * X.509 certificates.
- *
- * Comment if your system does not have a correct clock.
- *
- * \note mbedtls_platform_gmtime_r() is an abstraction in platform_util.h that
- * behaves similarly to the gmtime_r() function from the C standard. Refer to
- * the documentation for mbedtls_platform_gmtime_r() for more information.
- *
- * \note It is possible to configure an implementation for
- * mbedtls_platform_gmtime_r() at compile-time by using the macro
- * MBEDTLS_PLATFORM_GMTIME_R_ALT.
- */
- #define MBEDTLS_HAVE_TIME_DATE
- /**
- * \def MBEDTLS_PLATFORM_MEMORY
- *
- * Enable the memory allocation layer.
- *
- * By default mbed TLS uses the system-provided calloc() and free().
- * This allows different allocators (self-implemented or provided) to be
- * provided to the platform abstraction layer.
- *
- * Enabling MBEDTLS_PLATFORM_MEMORY without the
- * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
- * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
- * free() function pointer at runtime.
- *
- * Enabling MBEDTLS_PLATFORM_MEMORY and specifying
- * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
- * alternate function at compile time.
- *
- * Requires: MBEDTLS_PLATFORM_C
- *
- * Enable this layer to allow use of alternative memory allocators.
- */
- //#define MBEDTLS_PLATFORM_MEMORY
- /**
- * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
- *
- * Do not assign standard functions in the platform layer (e.g. calloc() to
- * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF)
- *
- * This makes sure there are no linking errors on platforms that do not support
- * these functions. You will HAVE to provide alternatives, either at runtime
- * via the platform_set_xxx() functions or at compile time by setting
- * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a
- * MBEDTLS_PLATFORM_XXX_MACRO.
- *
- * Requires: MBEDTLS_PLATFORM_C
- *
- * Uncomment to prevent default assignment of standard functions in the
- * platform layer.
- */
- //#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
- /**
- * \def MBEDTLS_PLATFORM_EXIT_ALT
- *
- * MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let mbed TLS support the
- * function in the platform abstraction layer.
- *
- * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will
- * provide a function "mbedtls_platform_set_printf()" that allows you to set an
- * alternative printf function pointer.
- *
- * All these define require MBEDTLS_PLATFORM_C to be defined!
- *
- * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows;
- * it will be enabled automatically by check_config.h
- *
- * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as
- * MBEDTLS_PLATFORM_XXX_MACRO!
- *
- * Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME
- *
- * Uncomment a macro to enable alternate implementation of specific base
- * platform function
- */
- //#define MBEDTLS_PLATFORM_EXIT_ALT
- //#define MBEDTLS_PLATFORM_TIME_ALT
- //#define MBEDTLS_PLATFORM_FPRINTF_ALT
- //#define MBEDTLS_PLATFORM_PRINTF_ALT
- //#define MBEDTLS_PLATFORM_SNPRINTF_ALT
- //#define MBEDTLS_PLATFORM_VSNPRINTF_ALT
- //#define MBEDTLS_PLATFORM_NV_SEED_ALT
- //#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
- /**
- * \def MBEDTLS_DEPRECATED_WARNING
- *
- * Mark deprecated functions and features so that they generate a warning if
- * used. Functionality deprecated in one version will usually be removed in the
- * next version. You can enable this to help you prepare the transition to a
- * new major version by making sure your code is not using this functionality.
- *
- * This only works with GCC and Clang. With other compilers, you may want to
- * use MBEDTLS_DEPRECATED_REMOVED
- *
- * Uncomment to get warnings on using deprecated functions and features.
- */
- //#define MBEDTLS_DEPRECATED_WARNING
- /**
- * \def MBEDTLS_DEPRECATED_REMOVED
- *
- * Remove deprecated functions and features so that they generate an error if
- * used. Functionality deprecated in one version will usually be removed in the
- * next version. You can enable this to help you prepare the transition to a
- * new major version by making sure your code is not using this functionality.
- *
- * Uncomment to get errors on using deprecated functions and features.
- */
- //#define MBEDTLS_DEPRECATED_REMOVED
- /**
- * \def MBEDTLS_CHECK_PARAMS
- *
- * This configuration option controls whether the library validates more of
- * the parameters passed to it.
- *
- * When this flag is not defined, the library only attempts to validate an
- * input parameter if: (1) they may come from the outside world (such as the
- * network, the filesystem, etc.) or (2) not validating them could result in
- * internal memory errors such as overflowing a buffer controlled by the
- * library. On the other hand, it doesn't attempt to validate parameters whose
- * values are fully controlled by the application (such as pointers).
- *
- * When this flag is defined, the library additionally attempts to validate
- * parameters that are fully controlled by the application, and should always
- * be valid if the application code is fully correct and trusted.
- *
- * For example, when a function accepts as input a pointer to a buffer that may
- * contain untrusted data, and its documentation mentions that this pointer
- * must not be NULL:
- * - The pointer is checked to be non-NULL only if this option is enabled.
- * - The content of the buffer is always validated.
- *
- * When this flag is defined, if a library function receives a parameter that
- * is invalid:
- * 1. The function will invoke the macro MBEDTLS_PARAM_FAILED().
- * 2. If MBEDTLS_PARAM_FAILED() did not terminate the program, the function
- * will immediately return. If the function returns an Mbed TLS error code,
- * the error code in this case is MBEDTLS_ERR_xxx_BAD_INPUT_DATA.
- *
- * When defining this flag, you also need to arrange a definition for
- * MBEDTLS_PARAM_FAILED(). You can do this by any of the following methods:
- * - By default, the library defines MBEDTLS_PARAM_FAILED() to call a
- * function mbedtls_param_failed(), but the library does not define this
- * function. If you do not make any other arrangements, you must provide
- * the function mbedtls_param_failed() in your application.
- * See `platform_util.h` for its prototype.
- * - If you enable the macro #MBEDTLS_CHECK_PARAMS_ASSERT, then the
- * library defines MBEDTLS_PARAM_FAILED(\c cond) to be `assert(cond)`.
- * You can still supply an alternative definition of
- * MBEDTLS_PARAM_FAILED(), which may call `assert`.
- * - If you define a macro MBEDTLS_PARAM_FAILED() before including `config.h`
- * or you uncomment the definition of MBEDTLS_PARAM_FAILED() in `config.h`,
- * the library will call the macro that you defined and will not supply
- * its own version. Note that if MBEDTLS_PARAM_FAILED() calls `assert`,
- * you need to enable #MBEDTLS_CHECK_PARAMS_ASSERT so that library source
- * files include `<assert.h>`.
- *
- * Uncomment to enable validation of application-controlled parameters.
- */
- //#define MBEDTLS_CHECK_PARAMS
- /**
- * \def MBEDTLS_CHECK_PARAMS_ASSERT
- *
- * Allow MBEDTLS_PARAM_FAILED() to call `assert`, and make it default to
- * `assert`. This macro is only used if #MBEDTLS_CHECK_PARAMS is defined.
- *
- * If this macro is not defined, then MBEDTLS_PARAM_FAILED() defaults to
- * calling a function mbedtls_param_failed(). See the documentation of
- * #MBEDTLS_CHECK_PARAMS for details.
- *
- * Uncomment to allow MBEDTLS_PARAM_FAILED() to call `assert`.
- */
- //#define MBEDTLS_CHECK_PARAMS_ASSERT
- /* \} name SECTION: System support */
- /**
- * \name SECTION: mbed TLS feature support
- *
- * This section sets support for features that are or are not needed
- * within the modules that are enabled.
- * \{
- */
- /**
- * \def MBEDTLS_TIMING_ALT
- *
- * Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(),
- * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay()
- *
- * Only works if you have MBEDTLS_TIMING_C enabled.
- *
- * You will need to provide a header "timing_alt.h" and an implementation at
- * compile time.
- */
- //#define MBEDTLS_TIMING_ALT
- /**
- * \def MBEDTLS_AES_ALT
- *
- * MBEDTLS__MODULE_NAME__ALT: Uncomment a macro to let mbed TLS use your
- * alternate core implementation of a symmetric crypto, an arithmetic or hash
- * module (e.g. platform specific assembly optimized implementations). Keep
- * in mind that the function prototypes should remain the same.
- *
- * This replaces the whole module. If you only want to replace one of the
- * functions, use one of the MBEDTLS__FUNCTION_NAME__ALT flags.
- *
- * Example: In case you uncomment MBEDTLS_AES_ALT, mbed TLS will no longer
- * provide the "struct mbedtls_aes_context" definition and omit the base
- * function declarations and implementations. "aes_alt.h" will be included from
- * "aes.h" to include the new function definitions.
- *
- * Uncomment a macro to enable alternate implementation of the corresponding
- * module.
- *
- * \warning MD2, MD4, MD5, ARC4, DES and SHA-1 are considered weak and their
- * use constitutes a security risk. If possible, we recommend
- * avoiding dependencies on them, and considering stronger message
- * digests and ciphers instead.
- *
- */
- //#define MBEDTLS_AES_ALT
- //#define MBEDTLS_ARC4_ALT
- //#define MBEDTLS_ARIA_ALT
- //#define MBEDTLS_BLOWFISH_ALT
- //#define MBEDTLS_CAMELLIA_ALT
- //#define MBEDTLS_CCM_ALT
- //#define MBEDTLS_CHACHA20_ALT
- //#define MBEDTLS_CHACHAPOLY_ALT
- //#define MBEDTLS_CMAC_ALT
- //#define MBEDTLS_DES_ALT
- //#define MBEDTLS_DHM_ALT
- //#define MBEDTLS_ECJPAKE_ALT
- //#define MBEDTLS_GCM_ALT
- //#define MBEDTLS_NIST_KW_ALT
- //#define MBEDTLS_MD2_ALT
- //#define MBEDTLS_MD4_ALT
- //#define MBEDTLS_MD5_ALT
- //#define MBEDTLS_POLY1305_ALT
- //#define MBEDTLS_RIPEMD160_ALT
- //#define MBEDTLS_RSA_ALT
- //#define MBEDTLS_SHA1_ALT
- //#define MBEDTLS_SHA256_ALT
- //#define MBEDTLS_SHA512_ALT
- //#define MBEDTLS_XTEA_ALT
- /*
- * When replacing the elliptic curve module, pleace consider, that it is
- * implemented with two .c files:
- * - ecp.c
- * - ecp_curves.c
- * You can replace them very much like all the other MBEDTLS__MODULE_NAME__ALT
- * macros as described above. The only difference is that you have to make sure
- * that you provide functionality for both .c files.
- */
- //#define MBEDTLS_ECP_ALT
- /**
- * \def MBEDTLS_MD2_PROCESS_ALT
- *
- * MBEDTLS__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use you
- * alternate core implementation of symmetric crypto or hash function. Keep in
- * mind that function prototypes should remain the same.
- *
- * This replaces only one function. The header file from mbed TLS is still
- * used, in contrast to the MBEDTLS__MODULE_NAME__ALT flags.
- *
- * Example: In case you uncomment MBEDTLS_SHA256_PROCESS_ALT, mbed TLS will
- * no longer provide the mbedtls_sha1_process() function, but it will still provide
- * the other function (using your mbedtls_sha1_process() function) and the definition
- * of mbedtls_sha1_context, so your implementation of mbedtls_sha1_process must be compatible
- * with this definition.
- *
- * \note Because of a signature change, the core AES encryption and decryption routines are
- * currently named mbedtls_aes_internal_encrypt and mbedtls_aes_internal_decrypt,
- * respectively. When setting up alternative implementations, these functions should
- * be overridden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt
- * must stay untouched.
- *
- * \note If you use the AES_xxx_ALT macros, then it is recommended to also set
- * MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES
- * tables.
- *
- * Uncomment a macro to enable alternate implementation of the corresponding
- * function.
- *
- * \warning MD2, MD4, MD5, DES and SHA-1 are considered weak and their use
- * constitutes a security risk. If possible, we recommend avoiding
- * dependencies on them, and considering stronger message digests
- * and ciphers instead.
- *
- * \warning If both MBEDTLS_ECDSA_SIGN_ALT and MBEDTLS_ECDSA_DETERMINISTIC are
- * enabled, then the deterministic ECDH signature functions pass the
- * the static HMAC-DRBG as RNG to mbedtls_ecdsa_sign(). Therefore
- * alternative implementations should use the RNG only for generating
- * the ephemeral key and nothing else. If this is not possible, then
- * MBEDTLS_ECDSA_DETERMINISTIC should be disabled and an alternative
- * implementation should be provided for mbedtls_ecdsa_sign_det_ext()
- * (and for mbedtls_ecdsa_sign_det() too if backward compatibility is
- * desirable).
- *
- */
- //#define MBEDTLS_MD2_PROCESS_ALT
- //#define MBEDTLS_MD4_PROCESS_ALT
- //#define MBEDTLS_MD5_PROCESS_ALT
- //#define MBEDTLS_RIPEMD160_PROCESS_ALT
- //#define MBEDTLS_SHA1_PROCESS_ALT
- //#define MBEDTLS_SHA256_PROCESS_ALT
- //#define MBEDTLS_SHA512_PROCESS_ALT
- //#define MBEDTLS_DES_SETKEY_ALT
- //#define MBEDTLS_DES_CRYPT_ECB_ALT
- //#define MBEDTLS_DES3_CRYPT_ECB_ALT
- //#define MBEDTLS_AES_SETKEY_ENC_ALT
- //#define MBEDTLS_AES_SETKEY_DEC_ALT
- //#define MBEDTLS_AES_ENCRYPT_ALT
- //#define MBEDTLS_AES_DECRYPT_ALT
- //#define MBEDTLS_ECDH_GEN_PUBLIC_ALT
- //#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT
- //#define MBEDTLS_ECDSA_VERIFY_ALT
- //#define MBEDTLS_ECDSA_SIGN_ALT
- //#define MBEDTLS_ECDSA_GENKEY_ALT
- /**
- * \def MBEDTLS_ECP_INTERNAL_ALT
- *
- * Expose a part of the internal interface of the Elliptic Curve Point module.
- *
- * MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use your
- * alternative core implementation of elliptic curve arithmetic. Keep in mind
- * that function prototypes should remain the same.
- *
- * This partially replaces one function. The header file from mbed TLS is still
- * used, in contrast to the MBEDTLS_ECP_ALT flag. The original implementation
- * is still present and it is used for group structures not supported by the
- * alternative.
- *
- * The original implementation can in addition be removed by setting the
- * MBEDTLS_ECP_NO_FALLBACK option, in which case any function for which the
- * corresponding MBEDTLS_ECP__FUNCTION_NAME__ALT macro is defined will not be
- * able to fallback to curves not supported by the alternative implementation.
- *
- * Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT
- * and implementing the following functions:
- * unsigned char mbedtls_internal_ecp_grp_capable(
- * const mbedtls_ecp_group *grp )
- * int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp )
- * void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp )
- * The mbedtls_internal_ecp_grp_capable function should return 1 if the
- * replacement functions implement arithmetic for the given group and 0
- * otherwise.
- * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_free are
- * called before and after each point operation and provide an opportunity to
- * implement optimized set up and tear down instructions.
- *
- * Example: In case you set MBEDTLS_ECP_INTERNAL_ALT and
- * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac()
- * function, but will use your mbedtls_internal_ecp_double_jac() if the group
- * for the operation is supported by your implementation (i.e. your
- * mbedtls_internal_ecp_grp_capable() function returns 1 for this group). If the
- * group is not supported by your implementation, then the original mbed TLS
- * implementation of ecp_double_jac() is used instead, unless this fallback
- * behaviour is disabled by setting MBEDTLS_ECP_NO_FALLBACK (in which case
- * ecp_double_jac() will return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE).
- *
- * The function prototypes and the definition of mbedtls_ecp_group and
- * mbedtls_ecp_point will not change based on MBEDTLS_ECP_INTERNAL_ALT, so your
- * implementation of mbedtls_internal_ecp__function_name__ must be compatible
- * with their definitions.
- *
- * Uncomment a macro to enable alternate implementation of the corresponding
- * function.
- */
- /* Required for all the functions in this section */
- //#define MBEDTLS_ECP_INTERNAL_ALT
- /* Turn off software fallback for curves not supported in hardware */
- //#define MBEDTLS_ECP_NO_FALLBACK
- /* Support for Weierstrass curves with Jacobi representation */
- //#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT
- //#define MBEDTLS_ECP_ADD_MIXED_ALT
- //#define MBEDTLS_ECP_DOUBLE_JAC_ALT
- //#define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT
- //#define MBEDTLS_ECP_NORMALIZE_JAC_ALT
- /* Support for curves with Montgomery arithmetic */
- //#define MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT
- //#define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT
- //#define MBEDTLS_ECP_NORMALIZE_MXZ_ALT
- /**
- * \def MBEDTLS_TEST_NULL_ENTROPY
- *
- * Enables testing and use of mbed TLS without any configured entropy sources.
- * This permits use of the library on platforms before an entropy source has
- * been integrated (see for example the MBEDTLS_ENTROPY_HARDWARE_ALT or the
- * MBEDTLS_ENTROPY_NV_SEED switches).
- *
- * WARNING! This switch MUST be disabled in production builds, and is suitable
- * only for development.
- * Enabling the switch negates any security provided by the library.
- *
- * Requires MBEDTLS_ENTROPY_C, MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
- *
- */
- //#define MBEDTLS_TEST_NULL_ENTROPY
- /**
- * \def MBEDTLS_ENTROPY_HARDWARE_ALT
- *
- * Uncomment this macro to let mbed TLS use your own implementation of a
- * hardware entropy collector.
- *
- * Your function must be called \c mbedtls_hardware_poll(), have the same
- * prototype as declared in entropy_poll.h, and accept NULL as first argument.
- *
- * Uncomment to use your own hardware entropy collector.
- */
- //#define MBEDTLS_ENTROPY_HARDWARE_ALT
- /**
- * \def MBEDTLS_AES_ROM_TABLES
- *
- * Use precomputed AES tables stored in ROM.
- *
- * Uncomment this macro to use precomputed AES tables stored in ROM.
- * Comment this macro to generate AES tables in RAM at runtime.
- *
- * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb
- * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the
- * initialization time before the first AES operation can be performed.
- * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c
- * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded
- * performance if ROM access is slower than RAM access.
- *
- * This option is independent of \c MBEDTLS_AES_FEWER_TABLES.
- *
- */
- //#define MBEDTLS_AES_ROM_TABLES
- /**
- * \def MBEDTLS_AES_FEWER_TABLES
- *
- * Use less ROM/RAM for AES tables.
- *
- * Uncommenting this macro omits 75% of the AES tables from
- * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES)
- * by computing their values on the fly during operations
- * (the tables are entry-wise rotations of one another).
- *
- * Tradeoff: Uncommenting this reduces the RAM / ROM footprint
- * by ~6kb but at the cost of more arithmetic operations during
- * runtime. Specifically, one has to compare 4 accesses within
- * different tables to 4 accesses with additional arithmetic
- * operations within the same table. The performance gain/loss
- * depends on the system and memory details.
- *
- * This option is independent of \c MBEDTLS_AES_ROM_TABLES.
- *
- */
- //#define MBEDTLS_AES_FEWER_TABLES
- /**
- * \def MBEDTLS_CAMELLIA_SMALL_MEMORY
- *
- * Use less ROM for the Camellia implementation (saves about 768 bytes).
- *
- * Uncomment this macro to use less memory for Camellia.
- */
- //#define MBEDTLS_CAMELLIA_SMALL_MEMORY
- /**
- * \def MBEDTLS_CHECK_RETURN_WARNING
- *
- * If this macro is defined, emit a compile-time warning if application code
- * calls a function without checking its return value, but the return value
- * should generally be checked in portable applications.
- *
- * This is only supported on platforms where #MBEDTLS_CHECK_RETURN is
- * implemented. Otherwise this option has no effect.
- *
- * Uncomment to get warnings on using fallible functions without checking
- * their return value.
- *
- * \note This feature is a work in progress.
- * Warnings will be added to more functions in the future.
- *
- * \note A few functions are considered critical, and ignoring the return
- * value of these functions will trigger a warning even if this
- * macro is not defined. To completely disable return value check
- * warnings, define #MBEDTLS_CHECK_RETURN with an empty expansion.
- */
- //#define MBEDTLS_CHECK_RETURN_WARNING
- /**
- * \def MBEDTLS_CIPHER_MODE_CBC
- *
- * Enable Cipher Block Chaining mode (CBC) for symmetric ciphers.
- */
- #define MBEDTLS_CIPHER_MODE_CBC
- /**
- * \def MBEDTLS_CIPHER_MODE_CFB
- *
- * Enable Cipher Feedback mode (CFB) for symmetric ciphers.
- */
- #define MBEDTLS_CIPHER_MODE_CFB
- /**
- * \def MBEDTLS_CIPHER_MODE_CTR
- *
- * Enable Counter Block Cipher mode (CTR) for symmetric ciphers.
- */
- #define MBEDTLS_CIPHER_MODE_CTR
- /**
- * \def MBEDTLS_CIPHER_MODE_OFB
- *
- * Enable Output Feedback mode (OFB) for symmetric ciphers.
- */
- #define MBEDTLS_CIPHER_MODE_OFB
- /**
- * \def MBEDTLS_CIPHER_MODE_XTS
- *
- * Enable Xor-encrypt-xor with ciphertext stealing mode (XTS) for AES.
- */
- #define MBEDTLS_CIPHER_MODE_XTS
- /**
- * \def MBEDTLS_CIPHER_NULL_CIPHER
- *
- * Enable NULL cipher.
- * Warning: Only do so when you know what you are doing. This allows for
- * encryption or channels without any security!
- *
- * Requires MBEDTLS_ENABLE_WEAK_CIPHERSUITES as well to enable
- * the following ciphersuites:
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA
- * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384
- * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256
- * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA
- * MBEDTLS_TLS_RSA_WITH_NULL_SHA256
- * MBEDTLS_TLS_RSA_WITH_NULL_SHA
- * MBEDTLS_TLS_RSA_WITH_NULL_MD5
- * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA
- * MBEDTLS_TLS_PSK_WITH_NULL_SHA384
- * MBEDTLS_TLS_PSK_WITH_NULL_SHA256
- * MBEDTLS_TLS_PSK_WITH_NULL_SHA
- *
- * Uncomment this macro to enable the NULL cipher and ciphersuites
- */
- //#define MBEDTLS_CIPHER_NULL_CIPHER
- /**
- * \def MBEDTLS_CIPHER_PADDING_PKCS7
- *
- * MBEDTLS_CIPHER_PADDING_XXX: Uncomment or comment macros to add support for
- * specific padding modes in the cipher layer with cipher modes that support
- * padding (e.g. CBC)
- *
- * If you disable all padding modes, only full blocks can be used with CBC.
- *
- * Enable padding modes in the cipher layer.
- */
- #define MBEDTLS_CIPHER_PADDING_PKCS7
- #define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
- #define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
- #define MBEDTLS_CIPHER_PADDING_ZEROS
- /** \def MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
- *
- * Uncomment this macro to use a 128-bit key in the CTR_DRBG module.
- * By default, CTR_DRBG uses a 256-bit key.
- */
- //#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
- /**
- * \def MBEDTLS_ENABLE_WEAK_CIPHERSUITES
- *
- * Enable weak ciphersuites in SSL / TLS.
- * Warning: Only do so when you know what you are doing. This allows for
- * channels with virtually no security at all!
- *
- * This enables the following ciphersuites:
- * MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA
- *
- * Uncomment this macro to enable weak ciphersuites
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers instead.
- */
- //#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES
- /**
- * \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES
- *
- * Remove RC4 ciphersuites by default in SSL / TLS.
- * This flag removes the ciphersuites based on RC4 from the default list as
- * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible to
- * enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including them
- * explicitly.
- *
- * Uncomment this macro to remove RC4 ciphersuites by default.
- */
- #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
- /**
- * \def MBEDTLS_REMOVE_3DES_CIPHERSUITES
- *
- * Remove 3DES ciphersuites by default in SSL / TLS.
- * This flag removes the ciphersuites based on 3DES from the default list as
- * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible
- * to enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including
- * them explicitly.
- *
- * A man-in-the-browser attacker can recover authentication tokens sent through
- * a TLS connection using a 3DES based cipher suite (see "On the Practical
- * (In-)Security of 64-bit Block Ciphers" by Karthikeyan Bhargavan and Gaëtan
- * Leurent, see https://sweet32.info/SWEET32_CCS16.pdf). If this attack falls
- * in your threat model or you are unsure, then you should keep this option
- * enabled to remove 3DES based cipher suites.
- *
- * Comment this macro to keep 3DES in the default ciphersuite list.
- */
- #define MBEDTLS_REMOVE_3DES_CIPHERSUITES
- /**
- * \def MBEDTLS_ECP_DP_SECP192R1_ENABLED
- *
- * MBEDTLS_ECP_XXXX_ENABLED: Enables specific curves within the Elliptic Curve
- * module. By default all supported curves are enabled.
- *
- * Comment macros to disable the curve and functions for it
- */
- /* Short Weierstrass curves (supporting ECP, ECDH, ECDSA) */
- #define MBEDTLS_ECP_DP_SECP192R1_ENABLED
- #define MBEDTLS_ECP_DP_SECP224R1_ENABLED
- #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
- #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
- #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
- #define MBEDTLS_ECP_DP_SECP192K1_ENABLED
- #define MBEDTLS_ECP_DP_SECP224K1_ENABLED
- #define MBEDTLS_ECP_DP_SECP256K1_ENABLED
- #define MBEDTLS_ECP_DP_BP256R1_ENABLED
- #define MBEDTLS_ECP_DP_BP384R1_ENABLED
- #define MBEDTLS_ECP_DP_BP512R1_ENABLED
- /* Montgomery curves (supporting ECP) */
- #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
- #define MBEDTLS_ECP_DP_CURVE448_ENABLED
- /**
- * \def MBEDTLS_ECP_NIST_OPTIM
- *
- * Enable specific 'modulo p' routines for each NIST prime.
- * Depending on the prime and architecture, makes operations 4 to 8 times
- * faster on the corresponding curve.
- *
- * Comment this macro to disable NIST curves optimisation.
- */
- #define MBEDTLS_ECP_NIST_OPTIM
- /**
- * \def MBEDTLS_ECP_NO_INTERNAL_RNG
- *
- * When this option is disabled, mbedtls_ecp_mul() will make use of an
- * internal RNG when called with a NULL \c f_rng argument, in order to protect
- * against some side-channel attacks.
- *
- * This protection introduces a dependency of the ECP module on one of the
- * DRBG modules. For very constrained implementations that don't require this
- * protection (for example, because you're only doing signature verification,
- * so not manipulating any secret, or because local/physical side-channel
- * attacks are outside your threat model), it might be desirable to get rid of
- * that dependency.
- *
- * \warning Enabling this option makes some uses of ECP vulnerable to some
- * side-channel attacks. Only enable it if you know that's not a problem for
- * your use case.
- *
- * Uncomment this macro to disable some counter-measures in ECP.
- */
- //#define MBEDTLS_ECP_NO_INTERNAL_RNG
- /**
- * \def MBEDTLS_ECP_RESTARTABLE
- *
- * Enable "non-blocking" ECC operations that can return early and be resumed.
- *
- * This allows various functions to pause by returning
- * #MBEDTLS_ERR_ECP_IN_PROGRESS (or, for functions in the SSL module,
- * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) and then be called later again in
- * order to further progress and eventually complete their operation. This is
- * controlled through mbedtls_ecp_set_max_ops() which limits the maximum
- * number of ECC operations a function may perform before pausing; see
- * mbedtls_ecp_set_max_ops() for more information.
- *
- * This is useful in non-threaded environments if you want to avoid blocking
- * for too long on ECC (and, hence, X.509 or SSL/TLS) operations.
- *
- * Uncomment this macro to enable restartable ECC computations.
- *
- * \note This option only works with the default software implementation of
- * elliptic curve functionality. It is incompatible with
- * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT, MBEDTLS_ECDSA_XXX_ALT
- * and MBEDTLS_ECDH_LEGACY_CONTEXT.
- */
- //#define MBEDTLS_ECP_RESTARTABLE
- /**
- * \def MBEDTLS_ECDH_LEGACY_CONTEXT
- *
- * Use a backward compatible ECDH context.
- *
- * Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context
- * defined in `ecdh.h`). For most applications, the choice of format makes
- * no difference, since all library functions can work with either format,
- * except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE.
- * The new format used when this option is disabled is smaller
- * (56 bytes on a 32-bit platform). In future versions of the library, it
- * will support alternative implementations of ECDH operations.
- * The new format is incompatible with applications that access
- * context fields directly and with restartable ECP operations.
- *
- * Define this macro if you enable MBEDTLS_ECP_RESTARTABLE or if you
- * want to access ECDH context fields directly. Otherwise you should
- * comment out this macro definition.
- *
- * This option has no effect if #MBEDTLS_ECDH_C is not enabled.
- *
- * \note This configuration option is experimental. Future versions of the
- * library may modify the way the ECDH context layout is configured
- * and may modify the layout of the new context type.
- */
- #define MBEDTLS_ECDH_LEGACY_CONTEXT
- /**
- * \def MBEDTLS_ECDSA_DETERMINISTIC
- *
- * Enable deterministic ECDSA (RFC 6979).
- * Standard ECDSA is "fragile" in the sense that lack of entropy when signing
- * may result in a compromise of the long-term signing key. This is avoided by
- * the deterministic variant.
- *
- * Requires: MBEDTLS_HMAC_DRBG_C, MBEDTLS_ECDSA_C
- *
- * Comment this macro to disable deterministic ECDSA.
- */
- #define MBEDTLS_ECDSA_DETERMINISTIC
- /**
- * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
- *
- * Enable the PSK based ciphersuite modes in SSL / TLS.
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
- */
- #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
- *
- * Enable the DHE-PSK based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_DHM_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
- *
- * \warning Using DHE constitutes a security risk as it
- * is not possible to validate custom DH parameters.
- * If possible, it is recommended users should consider
- * preferring other methods of key exchange.
- * See dhm.h for more details.
- *
- */
- #define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
- *
- * Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_ECDH_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
- */
- #define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
- *
- * Enable the RSA-PSK based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
- * MBEDTLS_X509_CRT_PARSE_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
- */
- #define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
- *
- * Enable the RSA-only based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
- * MBEDTLS_X509_CRT_PARSE_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
- */
- #define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
- *
- * Enable the DHE-RSA based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_DHM_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
- * MBEDTLS_X509_CRT_PARSE_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
- *
- * \warning Using DHE constitutes a security risk as it
- * is not possible to validate custom DH parameters.
- * If possible, it is recommended users should consider
- * preferring other methods of key exchange.
- * See dhm.h for more details.
- *
- */
- #define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
- *
- * Enable the ECDHE-RSA based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
- * MBEDTLS_X509_CRT_PARSE_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
- */
- #define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
- *
- * Enable the ECDHE-ECDSA based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C,
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
- */
- #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
- *
- * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
- */
- #define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
- *
- * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS.
- *
- * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_X509_CRT_PARSE_C
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384
- */
- #define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
- /**
- * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
- *
- * Enable the ECJPAKE based ciphersuite modes in SSL / TLS.
- *
- * \warning This is currently experimental. EC J-PAKE support is based on the
- * Thread v1.0.0 specification; incompatible changes to the specification
- * might still happen. For this reason, this is disabled by default.
- *
- * Requires: MBEDTLS_ECJPAKE_C
- * MBEDTLS_SHA256_C
- * MBEDTLS_ECP_DP_SECP256R1_ENABLED
- *
- * This enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
- */
- //#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
- /**
- * \def MBEDTLS_PK_PARSE_EC_EXTENDED
- *
- * Enhance support for reading EC keys using variants of SEC1 not allowed by
- * RFC 5915 and RFC 5480.
- *
- * Currently this means parsing the SpecifiedECDomain choice of EC
- * parameters (only known groups are supported, not arbitrary domains, to
- * avoid validation issues).
- *
- * Disable if you only need to support RFC 5915 + 5480 key formats.
- */
- #define MBEDTLS_PK_PARSE_EC_EXTENDED
- /**
- * \def MBEDTLS_ERROR_STRERROR_DUMMY
- *
- * Enable a dummy error function to make use of mbedtls_strerror() in
- * third party libraries easier when MBEDTLS_ERROR_C is disabled
- * (no effect when MBEDTLS_ERROR_C is enabled).
- *
- * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're
- * not using mbedtls_strerror() or error_strerror() in your application.
- *
- * Disable if you run into name conflicts and want to really remove the
- * mbedtls_strerror()
- */
- #define MBEDTLS_ERROR_STRERROR_DUMMY
- /**
- * \def MBEDTLS_GENPRIME
- *
- * Enable the prime-number generation code.
- *
- * Requires: MBEDTLS_BIGNUM_C
- */
- #define MBEDTLS_GENPRIME
- /**
- * \def MBEDTLS_FS_IO
- *
- * Enable functions that use the filesystem.
- */
- #define MBEDTLS_FS_IO
- /**
- * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
- *
- * Do not add default entropy sources. These are the platform specific,
- * mbedtls_timing_hardclock and HAVEGE based poll functions.
- *
- * This is useful to have more control over the added entropy sources in an
- * application.
- *
- * Uncomment this macro to prevent loading of default entropy functions.
- */
- //#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
- /**
- * \def MBEDTLS_NO_PLATFORM_ENTROPY
- *
- * Do not use built-in platform entropy functions.
- * This is useful if your platform does not support
- * standards like the /dev/urandom or Windows CryptoAPI.
- *
- * Uncomment this macro to disable the built-in platform entropy functions.
- */
- //#define MBEDTLS_NO_PLATFORM_ENTROPY
- /**
- * \def MBEDTLS_ENTROPY_FORCE_SHA256
- *
- * Force the entropy accumulator to use a SHA-256 accumulator instead of the
- * default SHA-512 based one (if both are available).
- *
- * Requires: MBEDTLS_SHA256_C
- *
- * On 32-bit systems SHA-256 can be much faster than SHA-512. Use this option
- * if you have performance concerns.
- *
- * This option is only useful if both MBEDTLS_SHA256_C and
- * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used.
- */
- //#define MBEDTLS_ENTROPY_FORCE_SHA256
- /**
- * \def MBEDTLS_ENTROPY_NV_SEED
- *
- * Enable the non-volatile (NV) seed file-based entropy source.
- * (Also enables the NV seed read/write functions in the platform layer)
- *
- * This is crucial (if not required) on systems that do not have a
- * cryptographic entropy source (in hardware or kernel) available.
- *
- * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C
- *
- * \note The read/write functions that are used by the entropy source are
- * determined in the platform layer, and can be modified at runtime and/or
- * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used.
- *
- * \note If you use the default implementation functions that read a seedfile
- * with regular fopen(), please make sure you make a seedfile with the
- * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at
- * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from
- * and written to or you will get an entropy source error! The default
- * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE
- * bytes from the file.
- *
- * \note The entropy collector will write to the seed file before entropy is
- * given to an external source, to update it.
- */
- //#define MBEDTLS_ENTROPY_NV_SEED
- /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
- *
- * Enable key identifiers that encode a key owner identifier.
- *
- * The owner of a key is identified by a value of type ::mbedtls_key_owner_id_t
- * which is currently hard-coded to be int32_t.
- *
- * Note that this option is meant for internal use only and may be removed
- * without notice. It is incompatible with MBEDTLS_USE_PSA_CRYPTO.
- */
- //#define MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
- /**
- * \def MBEDTLS_MEMORY_DEBUG
- *
- * Enable debugging of buffer allocator memory issues. Automatically prints
- * (to stderr) all (fatal) messages on memory allocation issues. Enables
- * function for 'debug output' of allocated memory.
- *
- * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
- *
- * Uncomment this macro to let the buffer allocator print out error messages.
- */
- //#define MBEDTLS_MEMORY_DEBUG
- /**
- * \def MBEDTLS_MEMORY_BACKTRACE
- *
- * Include backtrace information with each allocated block.
- *
- * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
- * GLIBC-compatible backtrace() an backtrace_symbols() support
- *
- * Uncomment this macro to include backtrace information
- */
- //#define MBEDTLS_MEMORY_BACKTRACE
- /**
- * \def MBEDTLS_PK_RSA_ALT_SUPPORT
- *
- * Support external private RSA keys (eg from a HSM) in the PK layer.
- *
- * Comment this macro to disable support for external private RSA keys.
- */
- #define MBEDTLS_PK_RSA_ALT_SUPPORT
- /**
- * \def MBEDTLS_PKCS1_V15
- *
- * Enable support for PKCS#1 v1.5 encoding.
- *
- * Requires: MBEDTLS_RSA_C
- *
- * This enables support for PKCS#1 v1.5 operations.
- */
- #define MBEDTLS_PKCS1_V15
- /**
- * \def MBEDTLS_PKCS1_V21
- *
- * Enable support for PKCS#1 v2.1 encoding.
- *
- * Requires: MBEDTLS_MD_C, MBEDTLS_RSA_C
- *
- * This enables support for RSAES-OAEP and RSASSA-PSS operations.
- */
- #define MBEDTLS_PKCS1_V21
- /** \def MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
- *
- * Enable support for platform built-in keys. If you enable this feature,
- * you must implement the function mbedtls_psa_platform_get_builtin_key().
- * See the documentation of that function for more information.
- *
- * Built-in keys are typically derived from a hardware unique key or
- * stored in a secure element.
- *
- * Requires: MBEDTLS_PSA_CRYPTO_C.
- *
- * \warning This interface is experimental and may change or be removed
- * without notice.
- */
- //#define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
- /** \def MBEDTLS_PSA_CRYPTO_CLIENT
- *
- * Enable support for PSA crypto client.
- *
- * \note This option allows to include the code necessary for a PSA
- * crypto client when the PSA crypto implementation is not included in
- * the library (MBEDTLS_PSA_CRYPTO_C disabled). The code included is the
- * code to set and get PSA key attributes.
- * The development of PSA drivers partially relying on the library to
- * fulfill the hardware gaps is another possible usage of this option.
- *
- * \warning This interface is experimental and may change or be removed
- * without notice.
- */
- //#define MBEDTLS_PSA_CRYPTO_CLIENT
- /** \def MBEDTLS_PSA_CRYPTO_DRIVERS
- *
- * Enable support for the experimental PSA crypto driver interface.
- *
- * Requires: MBEDTLS_PSA_CRYPTO_C
- *
- * \warning This interface is experimental and may change or be removed
- * without notice.
- */
- //#define MBEDTLS_PSA_CRYPTO_DRIVERS
- /** \def MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
- *
- * Make the PSA Crypto module use an external random generator provided
- * by a driver, instead of Mbed TLS's entropy and DRBG modules.
- *
- * \note This random generator must deliver random numbers with cryptographic
- * quality and high performance. It must supply unpredictable numbers
- * with a uniform distribution. The implementation of this function
- * is responsible for ensuring that the random generator is seeded
- * with sufficient entropy. If you have a hardware TRNG which is slow
- * or delivers non-uniform output, declare it as an entropy source
- * with mbedtls_entropy_add_source() instead of enabling this option.
- *
- * If you enable this option, you must configure the type
- * ::mbedtls_psa_external_random_context_t in psa/crypto_platform.h
- * and define a function called mbedtls_psa_external_get_random()
- * with the following prototype:
- * ```
- * psa_status_t mbedtls_psa_external_get_random(
- * mbedtls_psa_external_random_context_t *context,
- * uint8_t *output, size_t output_size, size_t *output_length);
- * );
- * ```
- * The \c context value is initialized to 0 before the first call.
- * The function must fill the \c output buffer with \p output_size bytes
- * of random data and set \c *output_length to \p output_size.
- *
- * Requires: MBEDTLS_PSA_CRYPTO_C
- *
- * \warning If you enable this option, code that uses the PSA cryptography
- * interface will not use any of the entropy sources set up for
- * the entropy module, nor the NV seed that MBEDTLS_ENTROPY_NV_SEED
- * enables.
- *
- * \note This option is experimental and may be removed without notice.
- */
- //#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
- /**
- * \def MBEDTLS_PSA_CRYPTO_SPM
- *
- * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is built for SPM (Secure
- * Partition Manager) integration which separates the code into two parts: a
- * NSPE (Non-Secure Process Environment) and an SPE (Secure Process
- * Environment).
- *
- * Module: library/psa_crypto.c
- * Requires: MBEDTLS_PSA_CRYPTO_C
- *
- */
- //#define MBEDTLS_PSA_CRYPTO_SPM
- /**
- * \def MBEDTLS_PSA_INJECT_ENTROPY
- *
- * Enable support for entropy injection at first boot. This feature is
- * required on systems that do not have a built-in entropy source (TRNG).
- * This feature is currently not supported on systems that have a built-in
- * entropy source.
- *
- * Requires: MBEDTLS_PSA_CRYPTO_STORAGE_C, MBEDTLS_ENTROPY_NV_SEED
- *
- */
- //#define MBEDTLS_PSA_INJECT_ENTROPY
- /**
- * \def MBEDTLS_RSA_NO_CRT
- *
- * Do not use the Chinese Remainder Theorem
- * for the RSA private operation.
- *
- * Uncomment this macro to disable the use of CRT in RSA.
- *
- */
- //#define MBEDTLS_RSA_NO_CRT
- /**
- * \def MBEDTLS_SELF_TEST
- *
- * Enable the checkup functions (*_self_test).
- */
- #define MBEDTLS_SELF_TEST
- /**
- * \def MBEDTLS_SHA256_SMALLER
- *
- * Enable an implementation of SHA-256 that has lower ROM footprint but also
- * lower performance.
- *
- * The default implementation is meant to be a reasonnable compromise between
- * performance and size. This version optimizes more aggressively for size at
- * the expense of performance. Eg on Cortex-M4 it reduces the size of
- * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about
- * 30%.
- *
- * Uncomment to enable the smaller implementation of SHA256.
- */
- //#define MBEDTLS_SHA256_SMALLER
- /**
- * \def MBEDTLS_SHA512_SMALLER
- *
- * Enable an implementation of SHA-512 that has lower ROM footprint but also
- * lower performance.
- *
- * Uncomment to enable the smaller implementation of SHA512.
- */
- //#define MBEDTLS_SHA512_SMALLER
- /**
- * \def MBEDTLS_SHA512_NO_SHA384
- *
- * Disable the SHA-384 option of the SHA-512 module. Use this to save some
- * code size on devices that don't use SHA-384.
- *
- * Requires: MBEDTLS_SHA512_C
- *
- * Uncomment to disable SHA-384
- */
- //#define MBEDTLS_SHA512_NO_SHA384
- /**
- * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES
- *
- * Enable sending of alert messages in case of encountered errors as per RFC.
- * If you choose not to send the alert messages, mbed TLS can still communicate
- * with other servers, only debugging of failures is harder.
- *
- * The advantage of not sending alert messages, is that no information is given
- * about reasons for failures thus preventing adversaries of gaining intel.
- *
- * Enable sending of all alert messages
- */
- #define MBEDTLS_SSL_ALL_ALERT_MESSAGES
- /**
- * \def MBEDTLS_SSL_RECORD_CHECKING
- *
- * Enable the function mbedtls_ssl_check_record() which can be used to check
- * the validity and authenticity of an incoming record, to verify that it has
- * not been seen before. These checks are performed without modifying the
- * externally visible state of the SSL context.
- *
- * See mbedtls_ssl_check_record() for more information.
- *
- * Uncomment to enable support for record checking.
- */
- #define MBEDTLS_SSL_RECORD_CHECKING
- /**
- * \def MBEDTLS_SSL_DTLS_CONNECTION_ID
- *
- * Enable support for the DTLS Connection ID extension
- * (version draft-ietf-tls-dtls-connection-id-05,
- * https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05)
- * which allows to identify DTLS connections across changes
- * in the underlying transport.
- *
- * Setting this option enables the SSL APIs `mbedtls_ssl_set_cid()`,
- * `mbedtls_ssl_get_peer_cid()` and `mbedtls_ssl_conf_cid()`.
- * See the corresponding documentation for more information.
- *
- * \warning The Connection ID extension is still in draft state.
- * We make no stability promises for the availability
- * or the shape of the API controlled by this option.
- *
- * The maximum lengths of outgoing and incoming CIDs can be configured
- * through the options
- * - MBEDTLS_SSL_CID_OUT_LEN_MAX
- * - MBEDTLS_SSL_CID_IN_LEN_MAX.
- *
- * Requires: MBEDTLS_SSL_PROTO_DTLS
- *
- * Uncomment to enable the Connection ID extension.
- */
- //#define MBEDTLS_SSL_DTLS_CONNECTION_ID
- /**
- * \def MBEDTLS_SSL_ASYNC_PRIVATE
- *
- * Enable asynchronous external private key operations in SSL. This allows
- * you to configure an SSL connection to call an external cryptographic
- * module to perform private key operations instead of performing the
- * operation inside the library.
- *
- */
- //#define MBEDTLS_SSL_ASYNC_PRIVATE
- /**
- * \def MBEDTLS_SSL_CONTEXT_SERIALIZATION
- *
- * Enable serialization of the TLS context structures, through use of the
- * functions mbedtls_ssl_context_save() and mbedtls_ssl_context_load().
- *
- * This pair of functions allows one side of a connection to serialize the
- * context associated with the connection, then free or re-use that context
- * while the serialized state is persisted elsewhere, and finally deserialize
- * that state to a live context for resuming read/write operations on the
- * connection. From a protocol perspective, the state of the connection is
- * unaffected, in particular this is entirely transparent to the peer.
- *
- * Note: this is distinct from TLS session resumption, which is part of the
- * protocol and fully visible by the peer. TLS session resumption enables
- * establishing new connections associated to a saved session with shorter,
- * lighter handshakes, while context serialization is a local optimization in
- * handling a single, potentially long-lived connection.
- *
- * Enabling these APIs makes some SSL structures larger, as 64 extra bytes are
- * saved after the handshake to allow for more efficient serialization, so if
- * you don't need this feature you'll save RAM by disabling it.
- *
- * Comment to disable the context serialization APIs.
- */
- #define MBEDTLS_SSL_CONTEXT_SERIALIZATION
- /**
- * \def MBEDTLS_SSL_DEBUG_ALL
- *
- * Enable the debug messages in SSL module for all issues.
- * Debug messages have been disabled in some places to prevent timing
- * attacks due to (unbalanced) debugging function calls.
- *
- * If you need all error reporting you should enable this during debugging,
- * but remove this for production servers that should log as well.
- *
- * Uncomment this macro to report all debug messages on errors introducing
- * a timing side-channel.
- *
- */
- //#define MBEDTLS_SSL_DEBUG_ALL
- /** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC
- *
- * Enable support for Encrypt-then-MAC, RFC 7366.
- *
- * This allows peers that both support it to use a more robust protection for
- * ciphersuites using CBC, providing deep resistance against timing attacks
- * on the padding or underlying cipher.
- *
- * This only affects CBC ciphersuites, and is useless if none is defined.
- *
- * Requires: MBEDTLS_SSL_PROTO_TLS1 or
- * MBEDTLS_SSL_PROTO_TLS1_1 or
- * MBEDTLS_SSL_PROTO_TLS1_2
- *
- * Comment this macro to disable support for Encrypt-then-MAC
- */
- #define MBEDTLS_SSL_ENCRYPT_THEN_MAC
- /** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET
- *
- * Enable support for RFC 7627: Session Hash and Extended Master Secret
- * Extension.
- *
- * This was introduced as "the proper fix" to the Triple Handshake familiy of
- * attacks, but it is recommended to always use it (even if you disable
- * renegotiation), since it actually fixes a more fundamental issue in the
- * original SSL/TLS design, and has implications beyond Triple Handshake.
- *
- * Requires: MBEDTLS_SSL_PROTO_TLS1 or
- * MBEDTLS_SSL_PROTO_TLS1_1 or
- * MBEDTLS_SSL_PROTO_TLS1_2
- *
- * Comment this macro to disable support for Extended Master Secret.
- */
- #define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
- /**
- * \def MBEDTLS_SSL_FALLBACK_SCSV
- *
- * Enable support for RFC 7507: Fallback Signaling Cipher Suite Value (SCSV)
- * for Preventing Protocol Downgrade Attacks.
- *
- * For servers, it is recommended to always enable this, unless you support
- * only one version of TLS, or know for sure that none of your clients
- * implements a fallback strategy.
- *
- * For clients, you only need this if you're using a fallback strategy, which
- * is not recommended in the first place, unless you absolutely need it to
- * interoperate with buggy (version-intolerant) servers.
- *
- * Comment this macro to disable support for FALLBACK_SCSV
- */
- #define MBEDTLS_SSL_FALLBACK_SCSV
- /**
- * \def MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
- *
- * This option controls the availability of the API mbedtls_ssl_get_peer_cert()
- * giving access to the peer's certificate after completion of the handshake.
- *
- * Unless you need mbedtls_ssl_peer_cert() in your application, it is
- * recommended to disable this option for reduced RAM usage.
- *
- * \note If this option is disabled, mbedtls_ssl_get_peer_cert() is still
- * defined, but always returns \c NULL.
- *
- * \note This option has no influence on the protection against the
- * triple handshake attack. Even if it is disabled, Mbed TLS will
- * still ensure that certificates do not change during renegotiation,
- * for exaple by keeping a hash of the peer's certificate.
- *
- * Comment this macro to disable storing the peer's certificate
- * after the handshake.
- */
- #define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
- /**
- * \def MBEDTLS_SSL_HW_RECORD_ACCEL
- *
- * Enable hooking functions in SSL module for hardware acceleration of
- * individual records.
- *
- * \deprecated This option is deprecated and will be removed in a future
- * version of Mbed TLS.
- *
- * Uncomment this macro to enable hooking functions.
- */
- //#define MBEDTLS_SSL_HW_RECORD_ACCEL
- /**
- * \def MBEDTLS_SSL_CBC_RECORD_SPLITTING
- *
- * Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0.
- *
- * This is a countermeasure to the BEAST attack, which also minimizes the risk
- * of interoperability issues compared to sending 0-length records.
- *
- * Comment this macro to disable 1/n-1 record splitting.
- */
- #define MBEDTLS_SSL_CBC_RECORD_SPLITTING
- /**
- * \def MBEDTLS_SSL_RENEGOTIATION
- *
- * Enable support for TLS renegotiation.
- *
- * The two main uses of renegotiation are (1) refresh keys on long-lived
- * connections and (2) client authentication after the initial handshake.
- * If you don't need renegotiation, it's probably better to disable it, since
- * it has been associated with security issues in the past and is easy to
- * misuse/misunderstand.
- *
- * Comment this to disable support for renegotiation.
- *
- * \note Even if this option is disabled, both client and server are aware
- * of the Renegotiation Indication Extension (RFC 5746) used to
- * prevent the SSL renegotiation attack (see RFC 5746 Sect. 1).
- * (See \c mbedtls_ssl_conf_legacy_renegotiation for the
- * configuration of this extension).
- *
- */
- #define MBEDTLS_SSL_RENEGOTIATION
- /**
- * \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
- *
- * Enable support for receiving and parsing SSLv2 Client Hello messages for the
- * SSL Server module (MBEDTLS_SSL_SRV_C).
- *
- * \deprecated This option is deprecated and will be removed in a future
- * version of Mbed TLS.
- *
- * Uncomment this macro to enable support for SSLv2 Client Hello messages.
- */
- //#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
- /**
- * \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
- *
- * Pick the ciphersuite according to the client's preferences rather than ours
- * in the SSL Server module (MBEDTLS_SSL_SRV_C).
- *
- * Uncomment this macro to respect client's ciphersuite order
- */
- //#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
- /**
- * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
- *
- * Enable support for RFC 6066 max_fragment_length extension in SSL.
- *
- * Comment this macro to disable support for the max_fragment_length extension
- */
- #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
- /**
- * \def MBEDTLS_SSL_PROTO_SSL3
- *
- * Enable support for SSL 3.0.
- *
- * Requires: MBEDTLS_MD5_C
- * MBEDTLS_SHA1_C
- *
- * \deprecated This option is deprecated and will be removed in a future
- * version of Mbed TLS.
- *
- * Comment this macro to disable support for SSL 3.0
- */
- //#define MBEDTLS_SSL_PROTO_SSL3
- /**
- * \def MBEDTLS_SSL_PROTO_TLS1
- *
- * Enable support for TLS 1.0.
- *
- * Requires: MBEDTLS_MD5_C
- * MBEDTLS_SHA1_C
- *
- * Comment this macro to disable support for TLS 1.0
- */
- #define MBEDTLS_SSL_PROTO_TLS1
- /**
- * \def MBEDTLS_SSL_PROTO_TLS1_1
- *
- * Enable support for TLS 1.1 (and DTLS 1.0 if DTLS is enabled).
- *
- * Requires: MBEDTLS_MD5_C
- * MBEDTLS_SHA1_C
- *
- * Comment this macro to disable support for TLS 1.1 / DTLS 1.0
- */
- #define MBEDTLS_SSL_PROTO_TLS1_1
- /**
- * \def MBEDTLS_SSL_PROTO_TLS1_2
- *
- * Enable support for TLS 1.2 (and DTLS 1.2 if DTLS is enabled).
- *
- * Requires: MBEDTLS_SHA1_C or MBEDTLS_SHA256_C or MBEDTLS_SHA512_C
- * (Depends on ciphersuites)
- *
- * Comment this macro to disable support for TLS 1.2 / DTLS 1.2
- */
- #define MBEDTLS_SSL_PROTO_TLS1_2
- /**
- * \def MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
- *
- * This macro is used to selectively enable experimental parts
- * of the code that contribute to the ongoing development of
- * the prototype TLS 1.3 and DTLS 1.3 implementation, and provide
- * no other purpose.
- *
- * \warning TLS 1.3 and DTLS 1.3 aren't yet supported in Mbed TLS,
- * and no feature exposed through this macro is part of the
- * public API. In particular, features under the control
- * of this macro are experimental and don't come with any
- * stability guarantees.
- *
- * Uncomment this macro to enable experimental and partial
- * functionality specific to TLS 1.3.
- */
- //#define MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
- /**
- * \def MBEDTLS_SSL_PROTO_DTLS
- *
- * Enable support for DTLS (all available versions).
- *
- * Enable this and MBEDTLS_SSL_PROTO_TLS1_1 to enable DTLS 1.0,
- * and/or this and MBEDTLS_SSL_PROTO_TLS1_2 to enable DTLS 1.2.
- *
- * Requires: MBEDTLS_SSL_PROTO_TLS1_1
- * or MBEDTLS_SSL_PROTO_TLS1_2
- *
- * Comment this macro to disable support for DTLS
- */
- #define MBEDTLS_SSL_PROTO_DTLS
- /**
- * \def MBEDTLS_SSL_ALPN
- *
- * Enable support for RFC 7301 Application Layer Protocol Negotiation.
- *
- * Comment this macro to disable support for ALPN.
- */
- #define MBEDTLS_SSL_ALPN
- /**
- * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY
- *
- * Enable support for the anti-replay mechanism in DTLS.
- *
- * Requires: MBEDTLS_SSL_TLS_C
- * MBEDTLS_SSL_PROTO_DTLS
- *
- * \warning Disabling this is often a security risk!
- * See mbedtls_ssl_conf_dtls_anti_replay() for details.
- *
- * Comment this to disable anti-replay in DTLS.
- */
- #define MBEDTLS_SSL_DTLS_ANTI_REPLAY
- /**
- * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY
- *
- * Enable support for HelloVerifyRequest on DTLS servers.
- *
- * This feature is highly recommended to prevent DTLS servers being used as
- * amplifiers in DoS attacks against other hosts. It should always be enabled
- * unless you know for sure amplification cannot be a problem in the
- * environment in which your server operates.
- *
- * \warning Disabling this can ba a security risk! (see above)
- *
- * Requires: MBEDTLS_SSL_PROTO_DTLS
- *
- * Comment this to disable support for HelloVerifyRequest.
- */
- #define MBEDTLS_SSL_DTLS_HELLO_VERIFY
- /**
- * \def MBEDTLS_SSL_DTLS_SRTP
- *
- * Enable support for negotiation of DTLS-SRTP (RFC 5764)
- * through the use_srtp extension.
- *
- * \note This feature provides the minimum functionality required
- * to negotiate the use of DTLS-SRTP and to allow the derivation of
- * the associated SRTP packet protection key material.
- * In particular, the SRTP packet protection itself, as well as the
- * demultiplexing of RTP and DTLS packets at the datagram layer
- * (see Section 5 of RFC 5764), are not handled by this feature.
- * Instead, after successful completion of a handshake negotiating
- * the use of DTLS-SRTP, the extended key exporter API
- * mbedtls_ssl_conf_export_keys_ext_cb() should be used to implement
- * the key exporter described in Section 4.2 of RFC 5764 and RFC 5705
- * (this is implemented in the SSL example programs).
- * The resulting key should then be passed to an SRTP stack.
- *
- * Setting this option enables the runtime API
- * mbedtls_ssl_conf_dtls_srtp_protection_profiles()
- * through which the supported DTLS-SRTP protection
- * profiles can be configured. You must call this API at
- * runtime if you wish to negotiate the use of DTLS-SRTP.
- *
- * Requires: MBEDTLS_SSL_PROTO_DTLS
- *
- * Uncomment this to enable support for use_srtp extension.
- */
- //#define MBEDTLS_SSL_DTLS_SRTP
- /**
- * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
- *
- * Enable server-side support for clients that reconnect from the same port.
- *
- * Some clients unexpectedly close the connection and try to reconnect using the
- * same source port. This needs special support from the server to handle the
- * new connection securely, as described in section 4.2.8 of RFC 6347. This
- * flag enables that support.
- *
- * Requires: MBEDTLS_SSL_DTLS_HELLO_VERIFY
- *
- * Comment this to disable support for clients reusing the source port.
- */
- #define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
- /**
- * \def MBEDTLS_SSL_DTLS_BADMAC_LIMIT
- *
- * Enable support for a limit of records with bad MAC.
- *
- * See mbedtls_ssl_conf_dtls_badmac_limit().
- *
- * Requires: MBEDTLS_SSL_PROTO_DTLS
- */
- #define MBEDTLS_SSL_DTLS_BADMAC_LIMIT
- /**
- * \def MBEDTLS_SSL_SESSION_TICKETS
- *
- * Enable support for RFC 5077 session tickets in SSL.
- * Client-side, provides full support for session tickets (maintenance of a
- * session store remains the responsibility of the application, though).
- * Server-side, you also need to provide callbacks for writing and parsing
- * tickets, including authenticated encryption and key management. Example
- * callbacks are provided by MBEDTLS_SSL_TICKET_C.
- *
- * Comment this macro to disable support for SSL session tickets
- */
- #define MBEDTLS_SSL_SESSION_TICKETS
- /**
- * \def MBEDTLS_SSL_EXPORT_KEYS
- *
- * Enable support for exporting key block and master secret.
- * This is required for certain users of TLS, e.g. EAP-TLS.
- *
- * Comment this macro to disable support for key export
- */
- #define MBEDTLS_SSL_EXPORT_KEYS
- /**
- * \def MBEDTLS_SSL_SERVER_NAME_INDICATION
- *
- * Enable support for RFC 6066 server name indication (SNI) in SSL.
- *
- * Requires: MBEDTLS_X509_CRT_PARSE_C
- *
- * Comment this macro to disable support for server name indication in SSL
- */
- #define MBEDTLS_SSL_SERVER_NAME_INDICATION
- /**
- * \def MBEDTLS_SSL_TRUNCATED_HMAC
- *
- * Enable support for RFC 6066 truncated HMAC in SSL.
- *
- * Comment this macro to disable support for truncated HMAC in SSL
- */
- #define MBEDTLS_SSL_TRUNCATED_HMAC
- /**
- * \def MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
- *
- * Fallback to old (pre-2.7), non-conforming implementation of the truncated
- * HMAC extension which also truncates the HMAC key. Note that this option is
- * only meant for a transitory upgrade period and will be removed in a future
- * version of the library.
- *
- * \warning The old implementation is non-compliant and has a security weakness
- * (2^80 brute force attack on the HMAC key used for a single,
- * uninterrupted connection). This should only be enabled temporarily
- * when (1) the use of truncated HMAC is essential in order to save
- * bandwidth, and (2) the peer is an Mbed TLS stack that doesn't use
- * the fixed implementation yet (pre-2.7).
- *
- * \deprecated This option is deprecated and will be removed in a
- * future version of Mbed TLS.
- *
- * Uncomment to fallback to old, non-compliant truncated HMAC implementation.
- *
- * Requires: MBEDTLS_SSL_TRUNCATED_HMAC
- */
- //#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
- /**
- * \def MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
- *
- * When this option is enabled, the SSL buffer will be resized automatically
- * based on the negotiated maximum fragment length in each direction.
- *
- * Requires: MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
- */
- //#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
- /**
- * \def MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
- *
- * Enable testing of the constant-flow nature of some sensitive functions with
- * clang's MemorySanitizer. This causes some existing tests to also test
- * this non-functional property of the code under test.
- *
- * This setting requires compiling with clang -fsanitize=memory. The test
- * suites can then be run normally.
- *
- * \warning This macro is only used for extended testing; it is not considered
- * part of the library's API, so it may change or disappear at any time.
- *
- * Uncomment to enable testing of the constant-flow nature of selected code.
- */
- //#define MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
- /**
- * \def MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
- *
- * Enable testing of the constant-flow nature of some sensitive functions with
- * valgrind's memcheck tool. This causes some existing tests to also test
- * this non-functional property of the code under test.
- *
- * This setting requires valgrind headers for building, and is only useful for
- * testing if the tests suites are run with valgrind's memcheck. This can be
- * done for an individual test suite with 'valgrind ./test_suite_xxx', or when
- * using CMake, this can be done for all test suites with 'make memcheck'.
- *
- * \warning This macro is only used for extended testing; it is not considered
- * part of the library's API, so it may change or disappear at any time.
- *
- * Uncomment to enable testing of the constant-flow nature of selected code.
- */
- //#define MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
- /**
- * \def MBEDTLS_TEST_HOOKS
- *
- * Enable features for invasive testing such as introspection functions and
- * hooks for fault injection. This enables additional unit tests.
- *
- * Merely enabling this feature should not change the behavior of the product.
- * It only adds new code, and new branching points where the default behavior
- * is the same as when this feature is disabled.
- * However, this feature increases the attack surface: there is an added
- * risk of vulnerabilities, and more gadgets that can make exploits easier.
- * Therefore this feature must never be enabled in production.
- *
- * See `docs/architecture/testing/mbed-crypto-invasive-testing.md` for more
- * information.
- *
- * Uncomment to enable invasive tests.
- */
- //#define MBEDTLS_TEST_HOOKS
- /**
- * \def MBEDTLS_THREADING_ALT
- *
- * Provide your own alternate threading implementation.
- *
- * Requires: MBEDTLS_THREADING_C
- *
- * Uncomment this to allow your own alternate threading implementation.
- */
- //#define MBEDTLS_THREADING_ALT
- /**
- * \def MBEDTLS_THREADING_PTHREAD
- *
- * Enable the pthread wrapper layer for the threading layer.
- *
- * Requires: MBEDTLS_THREADING_C
- *
- * Uncomment this to enable pthread mutexes.
- */
- //#define MBEDTLS_THREADING_PTHREAD
- /**
- * \def MBEDTLS_USE_PSA_CRYPTO
- *
- * Make the X.509 and TLS library use PSA for cryptographic operations, and
- * enable new APIs for using keys handled by PSA Crypto.
- *
- * \note Development of this option is currently in progress, and parts of Mbed
- * TLS's X.509 and TLS modules are not ported to PSA yet. However, these parts
- * will still continue to work as usual, so enabling this option should not
- * break backwards compatibility.
- *
- * \note See docs/use-psa-crypto.md for a complete description of what this
- * option currently does, and of parts that are not affected by it so far.
- *
- * \warning This option enables new Mbed TLS APIs which are currently
- * considered experimental and may change in incompatible ways at any time.
- * That is, the APIs enabled by this option are not covered by the usual
- * promises of API stability.
- *
- * Requires: MBEDTLS_PSA_CRYPTO_C.
- *
- * Uncomment this to enable internal use of PSA Crypto and new associated APIs.
- */
- //#define MBEDTLS_USE_PSA_CRYPTO
- /**
- * \def MBEDTLS_PSA_CRYPTO_CONFIG
- *
- * This setting allows support for cryptographic mechanisms through the PSA
- * API to be configured separately from support through the mbedtls API.
- *
- * Uncomment this to enable use of PSA Crypto configuration settings which
- * can be found in include/psa/crypto_config.h.
- *
- * If you enable this option and write your own configuration file, you must
- * include mbedtls/config_psa.h in your configuration file. The default
- * provided mbedtls/config.h contains the necessary inclusion.
- *
- * This feature is still experimental and is not ready for production since
- * it is not completed.
- */
- //#define MBEDTLS_PSA_CRYPTO_CONFIG
- /**
- * \def MBEDTLS_VERSION_FEATURES
- *
- * Allow run-time checking of compile-time enabled features. Thus allowing users
- * to check at run-time if the library is for instance compiled with threading
- * support via mbedtls_version_check_feature().
- *
- * Requires: MBEDTLS_VERSION_C
- *
- * Comment this to disable run-time checking and save ROM space
- */
- #define MBEDTLS_VERSION_FEATURES
- /**
- * \def MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
- *
- * If set, the X509 parser will not break-off when parsing an X509 certificate
- * and encountering an extension in a v1 or v2 certificate.
- *
- * Uncomment to prevent an error.
- */
- //#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
- /**
- * \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
- *
- * If set, the X509 parser will not break-off when parsing an X509 certificate
- * and encountering an unknown critical extension.
- *
- * \warning Depending on your PKI use, enabling this can be a security risk!
- *
- * Uncomment to prevent an error.
- */
- //#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
- /**
- * \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
- *
- * If set, this enables the X.509 API `mbedtls_x509_crt_verify_with_ca_cb()`
- * and the SSL API `mbedtls_ssl_conf_ca_cb()` which allow users to configure
- * the set of trusted certificates through a callback instead of a linked
- * list.
- *
- * This is useful for example in environments where a large number of trusted
- * certificates is present and storing them in a linked list isn't efficient
- * enough, or when the set of trusted certificates changes frequently.
- *
- * See the documentation of `mbedtls_x509_crt_verify_with_ca_cb()` and
- * `mbedtls_ssl_conf_ca_cb()` for more information.
- *
- * Uncomment to enable trusted certificate callbacks.
- */
- //#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
- /**
- * \def MBEDTLS_X509_CHECK_KEY_USAGE
- *
- * Enable verification of the keyUsage extension (CA and leaf certificates).
- *
- * Disabling this avoids problems with mis-issued and/or misused
- * (intermediate) CA and leaf certificates.
- *
- * \warning Depending on your PKI use, disabling this can be a security risk!
- *
- * Comment to skip keyUsage checking for both CA and leaf certificates.
- */
- #define MBEDTLS_X509_CHECK_KEY_USAGE
- /**
- * \def MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
- *
- * Enable verification of the extendedKeyUsage extension (leaf certificates).
- *
- * Disabling this avoids problems with mis-issued and/or misused certificates.
- *
- * \warning Depending on your PKI use, disabling this can be a security risk!
- *
- * Comment to skip extendedKeyUsage checking for certificates.
- */
- #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
- /**
- * \def MBEDTLS_X509_RSASSA_PSS_SUPPORT
- *
- * Enable parsing and verification of X.509 certificates, CRLs and CSRS
- * signed with RSASSA-PSS (aka PKCS#1 v2.1).
- *
- * Comment this macro to disallow using RSASSA-PSS in certificates.
- */
- #define MBEDTLS_X509_RSASSA_PSS_SUPPORT
- /**
- * \def MBEDTLS_ZLIB_SUPPORT
- *
- * If set, the SSL/TLS module uses ZLIB to support compression and
- * decompression of packet data.
- *
- * \warning TLS-level compression MAY REDUCE SECURITY! See for example the
- * CRIME attack. Before enabling this option, you should examine with care if
- * CRIME or similar exploits may be applicable to your use case.
- *
- * \note Currently compression can't be used with DTLS.
- *
- * \deprecated This feature is deprecated and will be removed
- * in the next major revision of the library.
- *
- * Used in: library/ssl_tls.c
- * library/ssl_cli.c
- * library/ssl_srv.c
- *
- * This feature requires zlib library and headers to be present.
- *
- * Uncomment to enable use of ZLIB
- */
- //#define MBEDTLS_ZLIB_SUPPORT
- /* \} name SECTION: mbed TLS feature support */
- /**
- * \name SECTION: mbed TLS modules
- *
- * This section enables or disables entire modules in mbed TLS
- * \{
- */
- /**
- * \def MBEDTLS_AESNI_C
- *
- * Enable AES-NI support on x86-64.
- *
- * Module: library/aesni.c
- * Caller: library/aes.c
- *
- * Requires: MBEDTLS_HAVE_ASM
- *
- * This modules adds support for the AES-NI instructions on x86-64
- */
- #define MBEDTLS_AESNI_C
- /**
- * \def MBEDTLS_AES_C
- *
- * Enable the AES block cipher.
- *
- * Module: library/aes.c
- * Caller: library/cipher.c
- * library/pem.c
- * library/ctr_drbg.c
- *
- * This module enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA
- * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
- * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
- * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
- * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
- * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
- * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
- *
- * PEM_PARSE uses AES for decrypting encrypted keys.
- */
- #define MBEDTLS_AES_C
- /**
- * \def MBEDTLS_ARC4_C
- *
- * Enable the ARCFOUR stream cipher.
- *
- * Module: library/arc4.c
- * Caller: library/cipher.c
- *
- * This module enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
- * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
- * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
- * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
- * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. If possible, we recommend avoidng dependencies on
- * it, and considering stronger ciphers instead.
- *
- */
- #define MBEDTLS_ARC4_C
- /**
- * \def MBEDTLS_ASN1_PARSE_C
- *
- * Enable the generic ASN1 parser.
- *
- * Module: library/asn1.c
- * Caller: library/x509.c
- * library/dhm.c
- * library/pkcs12.c
- * library/pkcs5.c
- * library/pkparse.c
- */
- #define MBEDTLS_ASN1_PARSE_C
- /**
- * \def MBEDTLS_ASN1_WRITE_C
- *
- * Enable the generic ASN1 writer.
- *
- * Module: library/asn1write.c
- * Caller: library/ecdsa.c
- * library/pkwrite.c
- * library/x509_create.c
- * library/x509write_crt.c
- * library/x509write_csr.c
- */
- #define MBEDTLS_ASN1_WRITE_C
- /**
- * \def MBEDTLS_BASE64_C
- *
- * Enable the Base64 module.
- *
- * Module: library/base64.c
- * Caller: library/pem.c
- *
- * This module is required for PEM support (required by X.509).
- */
- #define MBEDTLS_BASE64_C
- /**
- * \def MBEDTLS_BIGNUM_C
- *
- * Enable the multi-precision integer library.
- *
- * Module: library/bignum.c
- * Caller: library/dhm.c
- * library/ecp.c
- * library/ecdsa.c
- * library/rsa.c
- * library/rsa_internal.c
- * library/ssl_tls.c
- *
- * This module is required for RSA, DHM and ECC (ECDH, ECDSA) support.
- */
- #define MBEDTLS_BIGNUM_C
- /**
- * \def MBEDTLS_BLOWFISH_C
- *
- * Enable the Blowfish block cipher.
- *
- * Module: library/blowfish.c
- */
- #define MBEDTLS_BLOWFISH_C
- /**
- * \def MBEDTLS_CAMELLIA_C
- *
- * Enable the Camellia block cipher.
- *
- * Module: library/camellia.c
- * Caller: library/cipher.c
- *
- * This module enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
- * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
- */
- #define MBEDTLS_CAMELLIA_C
- /**
- * \def MBEDTLS_ARIA_C
- *
- * Enable the ARIA block cipher.
- *
- * Module: library/aria.c
- * Caller: library/cipher.c
- *
- * This module enables the following ciphersuites (if other requisites are
- * enabled as well):
- *
- * MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384
- * MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256
- * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384
- * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256
- * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384
- */
- //#define MBEDTLS_ARIA_C
- /**
- * \def MBEDTLS_CCM_C
- *
- * Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher.
- *
- * Module: library/ccm.c
- *
- * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C
- *
- * This module enables the AES-CCM ciphersuites, if other requisites are
- * enabled as well.
- */
- #define MBEDTLS_CCM_C
- /**
- * \def MBEDTLS_CERTS_C
- *
- * Enable the test certificates.
- *
- * Module: library/certs.c
- * Caller:
- *
- * This module is used for testing (ssl_client/server).
- */
- #define MBEDTLS_CERTS_C
- /**
- * \def MBEDTLS_CHACHA20_C
- *
- * Enable the ChaCha20 stream cipher.
- *
- * Module: library/chacha20.c
- */
- #define MBEDTLS_CHACHA20_C
- /**
- * \def MBEDTLS_CHACHAPOLY_C
- *
- * Enable the ChaCha20-Poly1305 AEAD algorithm.
- *
- * Module: library/chachapoly.c
- *
- * This module requires: MBEDTLS_CHACHA20_C, MBEDTLS_POLY1305_C
- */
- #define MBEDTLS_CHACHAPOLY_C
- /**
- * \def MBEDTLS_CIPHER_C
- *
- * Enable the generic cipher layer.
- *
- * Module: library/cipher.c
- * Caller: library/ssl_tls.c
- *
- * Uncomment to enable generic cipher wrappers.
- */
- #define MBEDTLS_CIPHER_C
- /**
- * \def MBEDTLS_CMAC_C
- *
- * Enable the CMAC (Cipher-based Message Authentication Code) mode for block
- * ciphers.
- *
- * \note When #MBEDTLS_CMAC_ALT is active, meaning that the underlying
- * implementation of the CMAC algorithm is provided by an alternate
- * implementation, that alternate implementation may opt to not support
- * AES-192 or 3DES as underlying block ciphers for the CMAC operation.
- *
- * Module: library/cmac.c
- *
- * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
- *
- */
- //#define MBEDTLS_CMAC_C
- /**
- * \def MBEDTLS_CTR_DRBG_C
- *
- * Enable the CTR_DRBG AES-based random generator.
- * The CTR_DRBG generator uses AES-256 by default.
- * To use AES-128 instead, enable \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY above.
- *
- * \note To achieve a 256-bit security strength with CTR_DRBG,
- * you must use AES-256 *and* use sufficient entropy.
- * See ctr_drbg.h for more details.
- *
- * Module: library/ctr_drbg.c
- * Caller:
- *
- * Requires: MBEDTLS_AES_C
- *
- * This module provides the CTR_DRBG AES random number generator.
- */
- #define MBEDTLS_CTR_DRBG_C
- /**
- * \def MBEDTLS_DEBUG_C
- *
- * Enable the debug functions.
- *
- * Module: library/debug.c
- * Caller: library/ssl_cli.c
- * library/ssl_srv.c
- * library/ssl_tls.c
- *
- * This module provides debugging functions.
- */
- #define MBEDTLS_DEBUG_C
- /**
- * \def MBEDTLS_DES_C
- *
- * Enable the DES block cipher.
- *
- * Module: library/des.c
- * Caller: library/pem.c
- * library/cipher.c
- *
- * This module enables the following ciphersuites (if other requisites are
- * enabled as well):
- * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
- * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
- *
- * PEM_PARSE uses DES/3DES for decrypting encrypted keys.
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers instead.
- */
- #define MBEDTLS_DES_C
- /**
- * \def MBEDTLS_DHM_C
- *
- * Enable the Diffie-Hellman-Merkle module.
- *
- * Module: library/dhm.c
- * Caller: library/ssl_cli.c
- * library/ssl_srv.c
- *
- * This module is used by the following key exchanges:
- * DHE-RSA, DHE-PSK
- *
- * \warning Using DHE constitutes a security risk as it
- * is not possible to validate custom DH parameters.
- * If possible, it is recommended users should consider
- * preferring other methods of key exchange.
- * See dhm.h for more details.
- *
- */
- #define MBEDTLS_DHM_C
- /**
- * \def MBEDTLS_ECDH_C
- *
- * Enable the elliptic curve Diffie-Hellman library.
- *
- * Module: library/ecdh.c
- * Caller: library/ssl_cli.c
- * library/ssl_srv.c
- *
- * This module is used by the following key exchanges:
- * ECDHE-ECDSA, ECDHE-RSA, DHE-PSK
- *
- * Requires: MBEDTLS_ECP_C
- */
- #define MBEDTLS_ECDH_C
- /**
- * \def MBEDTLS_ECDSA_C
- *
- * Enable the elliptic curve DSA library.
- *
- * Module: library/ecdsa.c
- * Caller:
- *
- * This module is used by the following key exchanges:
- * ECDHE-ECDSA
- *
- * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C,
- * and at least one MBEDTLS_ECP_DP_XXX_ENABLED for a
- * short Weierstrass curve.
- */
- #define MBEDTLS_ECDSA_C
- /**
- * \def MBEDTLS_ECJPAKE_C
- *
- * Enable the elliptic curve J-PAKE library.
- *
- * \warning This is currently experimental. EC J-PAKE support is based on the
- * Thread v1.0.0 specification; incompatible changes to the specification
- * might still happen. For this reason, this is disabled by default.
- *
- * Module: library/ecjpake.c
- * Caller:
- *
- * This module is used by the following key exchanges:
- * ECJPAKE
- *
- * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C
- */
- //#define MBEDTLS_ECJPAKE_C
- /**
- * \def MBEDTLS_ECP_C
- *
- * Enable the elliptic curve over GF(p) library.
- *
- * Module: library/ecp.c
- * Caller: library/ecdh.c
- * library/ecdsa.c
- * library/ecjpake.c
- *
- * Requires: MBEDTLS_BIGNUM_C and at least one MBEDTLS_ECP_DP_XXX_ENABLED
- */
- #define MBEDTLS_ECP_C
- /**
- * \def MBEDTLS_ENTROPY_C
- *
- * Enable the platform-specific entropy code.
- *
- * Module: library/entropy.c
- * Caller:
- *
- * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C
- *
- * This module provides a generic entropy pool
- */
- #define MBEDTLS_ENTROPY_C
- /**
- * \def MBEDTLS_ERROR_C
- *
- * Enable error code to error string conversion.
- *
- * Module: library/error.c
- * Caller:
- *
- * This module enables mbedtls_strerror().
- */
- #define MBEDTLS_ERROR_C
- /**
- * \def MBEDTLS_GCM_C
- *
- * Enable the Galois/Counter Mode (GCM).
- *
- * Module: library/gcm.c
- *
- * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C or MBEDTLS_ARIA_C
- *
- * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other
- * requisites are enabled as well.
- */
- #define MBEDTLS_GCM_C
- /**
- * \def MBEDTLS_HAVEGE_C
- *
- * Enable the HAVEGE random generator.
- *
- * Warning: the HAVEGE random generator is not suitable for virtualized
- * environments
- *
- * Warning: the HAVEGE random generator is dependent on timing and specific
- * processor traits. It is therefore not advised to use HAVEGE as
- * your applications primary random generator or primary entropy pool
- * input. As a secondary input to your entropy pool, it IS able add
- * the (limited) extra entropy it provides.
- *
- * Module: library/havege.c
- * Caller:
- *
- * Requires: MBEDTLS_TIMING_C
- *
- * Uncomment to enable the HAVEGE random generator.
- */
- //#define MBEDTLS_HAVEGE_C
- /**
- * \def MBEDTLS_HKDF_C
- *
- * Enable the HKDF algorithm (RFC 5869).
- *
- * Module: library/hkdf.c
- * Caller:
- *
- * Requires: MBEDTLS_MD_C
- *
- * This module adds support for the Hashed Message Authentication Code
- * (HMAC)-based key derivation function (HKDF).
- */
- #define MBEDTLS_HKDF_C
- /**
- * \def MBEDTLS_HMAC_DRBG_C
- *
- * Enable the HMAC_DRBG random generator.
- *
- * Module: library/hmac_drbg.c
- * Caller:
- *
- * Requires: MBEDTLS_MD_C
- *
- * Uncomment to enable the HMAC_DRBG random number geerator.
- */
- #define MBEDTLS_HMAC_DRBG_C
- /**
- * \def MBEDTLS_NIST_KW_C
- *
- * Enable the Key Wrapping mode for 128-bit block ciphers,
- * as defined in NIST SP 800-38F. Only KW and KWP modes
- * are supported. At the moment, only AES is approved by NIST.
- *
- * Module: library/nist_kw.c
- *
- * Requires: MBEDTLS_AES_C and MBEDTLS_CIPHER_C
- */
- //#define MBEDTLS_NIST_KW_C
- /**
- * \def MBEDTLS_MD_C
- *
- * Enable the generic message digest layer.
- *
- * Module: library/md.c
- * Caller:
- *
- * Uncomment to enable generic message digest wrappers.
- */
- #define MBEDTLS_MD_C
- /**
- * \def MBEDTLS_MD2_C
- *
- * Enable the MD2 hash algorithm.
- *
- * Module: library/md2.c
- * Caller:
- *
- * Uncomment to enable support for (rare) MD2-signed X.509 certs.
- *
- * \warning MD2 is considered a weak message digest and its use constitutes a
- * security risk. If possible, we recommend avoiding dependencies on
- * it, and considering stronger message digests instead.
- *
- */
- //#define MBEDTLS_MD2_C
- /**
- * \def MBEDTLS_MD4_C
- *
- * Enable the MD4 hash algorithm.
- *
- * Module: library/md4.c
- * Caller:
- *
- * Uncomment to enable support for (rare) MD4-signed X.509 certs.
- *
- * \warning MD4 is considered a weak message digest and its use constitutes a
- * security risk. If possible, we recommend avoiding dependencies on
- * it, and considering stronger message digests instead.
- *
- */
- //#define MBEDTLS_MD4_C
- /**
- * \def MBEDTLS_MD5_C
- *
- * Enable the MD5 hash algorithm.
- *
- * Module: library/md5.c
- * Caller: library/md.c
- * library/pem.c
- * library/ssl_tls.c
- *
- * This module is required for SSL/TLS up to version 1.1, and for TLS 1.2
- * depending on the handshake parameters. Further, it is used for checking
- * MD5-signed certificates, and for PBKDF1 when decrypting PEM-encoded
- * encrypted keys.
- *
- * \warning MD5 is considered a weak message digest and its use constitutes a
- * security risk. If possible, we recommend avoiding dependencies on
- * it, and considering stronger message digests instead.
- *
- */
- #define MBEDTLS_MD5_C
- /**
- * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C
- *
- * Enable the buffer allocator implementation that makes use of a (stack)
- * based buffer to 'allocate' dynamic memory. (replaces calloc() and free()
- * calls)
- *
- * Module: library/memory_buffer_alloc.c
- *
- * Requires: MBEDTLS_PLATFORM_C
- * MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS)
- *
- * Enable this module to enable the buffer memory allocator.
- */
- //#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
- /**
- * \def MBEDTLS_NET_C
- *
- * Enable the TCP and UDP over IPv6/IPv4 networking routines.
- *
- * \note This module only works on POSIX/Unix (including Linux, BSD and OS X)
- * and Windows. For other platforms, you'll want to disable it, and write your
- * own networking callbacks to be passed to \c mbedtls_ssl_set_bio().
- *
- * \note See also our Knowledge Base article about porting to a new
- * environment:
- * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
- *
- * Module: library/net_sockets.c
- *
- * This module provides networking routines.
- */
- #define MBEDTLS_NET_C
- /**
- * \def MBEDTLS_OID_C
- *
- * Enable the OID database.
- *
- * Module: library/oid.c
- * Caller: library/asn1write.c
- * library/pkcs5.c
- * library/pkparse.c
- * library/pkwrite.c
- * library/rsa.c
- * library/x509.c
- * library/x509_create.c
- * library/x509_crl.c
- * library/x509_crt.c
- * library/x509_csr.c
- * library/x509write_crt.c
- * library/x509write_csr.c
- *
- * This modules translates between OIDs and internal values.
- */
- #define MBEDTLS_OID_C
- /**
- * \def MBEDTLS_PADLOCK_C
- *
- * Enable VIA Padlock support on x86.
- *
- * Module: library/padlock.c
- * Caller: library/aes.c
- *
- * Requires: MBEDTLS_HAVE_ASM
- *
- * This modules adds support for the VIA PadLock on x86.
- */
- #define MBEDTLS_PADLOCK_C
- /**
- * \def MBEDTLS_PEM_PARSE_C
- *
- * Enable PEM decoding / parsing.
- *
- * Module: library/pem.c
- * Caller: library/dhm.c
- * library/pkparse.c
- * library/x509_crl.c
- * library/x509_crt.c
- * library/x509_csr.c
- *
- * Requires: MBEDTLS_BASE64_C
- *
- * This modules adds support for decoding / parsing PEM files.
- */
- #define MBEDTLS_PEM_PARSE_C
- /**
- * \def MBEDTLS_PEM_WRITE_C
- *
- * Enable PEM encoding / writing.
- *
- * Module: library/pem.c
- * Caller: library/pkwrite.c
- * library/x509write_crt.c
- * library/x509write_csr.c
- *
- * Requires: MBEDTLS_BASE64_C
- *
- * This modules adds support for encoding / writing PEM files.
- */
- #define MBEDTLS_PEM_WRITE_C
- /**
- * \def MBEDTLS_PK_C
- *
- * Enable the generic public (asymetric) key layer.
- *
- * Module: library/pk.c
- * Caller: library/ssl_tls.c
- * library/ssl_cli.c
- * library/ssl_srv.c
- *
- * Requires: MBEDTLS_RSA_C or MBEDTLS_ECP_C
- *
- * Uncomment to enable generic public key wrappers.
- */
- #define MBEDTLS_PK_C
- /**
- * \def MBEDTLS_PK_PARSE_C
- *
- * Enable the generic public (asymetric) key parser.
- *
- * Module: library/pkparse.c
- * Caller: library/x509_crt.c
- * library/x509_csr.c
- *
- * Requires: MBEDTLS_PK_C
- *
- * Uncomment to enable generic public key parse functions.
- */
- #define MBEDTLS_PK_PARSE_C
- /**
- * \def MBEDTLS_PK_WRITE_C
- *
- * Enable the generic public (asymetric) key writer.
- *
- * Module: library/pkwrite.c
- * Caller: library/x509write.c
- *
- * Requires: MBEDTLS_PK_C
- *
- * Uncomment to enable generic public key write functions.
- */
- #define MBEDTLS_PK_WRITE_C
- /**
- * \def MBEDTLS_PKCS5_C
- *
- * Enable PKCS#5 functions.
- *
- * Module: library/pkcs5.c
- *
- * Requires: MBEDTLS_MD_C
- *
- * This module adds support for the PKCS#5 functions.
- */
- #define MBEDTLS_PKCS5_C
- /**
- * \def MBEDTLS_PKCS11_C
- *
- * Enable wrapper for PKCS#11 smartcard support via the pkcs11-helper library.
- *
- * \deprecated This option is deprecated and will be removed in a future
- * version of Mbed TLS.
- *
- * Module: library/pkcs11.c
- * Caller: library/pk.c
- *
- * Requires: MBEDTLS_PK_C
- *
- * This module enables SSL/TLS PKCS #11 smartcard support.
- * Requires the presence of the PKCS#11 helper library (libpkcs11-helper)
- */
- //#define MBEDTLS_PKCS11_C
- /**
- * \def MBEDTLS_PKCS12_C
- *
- * Enable PKCS#12 PBE functions.
- * Adds algorithms for parsing PKCS#8 encrypted private keys
- *
- * Module: library/pkcs12.c
- * Caller: library/pkparse.c
- *
- * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_CIPHER_C, MBEDTLS_MD_C
- * Can use: MBEDTLS_ARC4_C
- *
- * This module enables PKCS#12 functions.
- */
- #define MBEDTLS_PKCS12_C
- /**
- * \def MBEDTLS_PLATFORM_C
- *
- * Enable the platform abstraction layer that allows you to re-assign
- * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit().
- *
- * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT
- * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
- * above to be specified at runtime or compile time respectively.
- *
- * \note This abstraction layer must be enabled on Windows (including MSYS2)
- * as other module rely on it for a fixed snprintf implementation.
- *
- * Module: library/platform.c
- * Caller: Most other .c files
- *
- * This module enables abstraction of common (libc) functions.
- */
- #define MBEDTLS_PLATFORM_C
- /**
- * \def MBEDTLS_POLY1305_C
- *
- * Enable the Poly1305 MAC algorithm.
- *
- * Module: library/poly1305.c
- * Caller: library/chachapoly.c
- */
- #define MBEDTLS_POLY1305_C
- /**
- * \def MBEDTLS_PSA_CRYPTO_C
- *
- * Enable the Platform Security Architecture cryptography API.
- *
- * Module: library/psa_crypto.c
- *
- * Requires: either MBEDTLS_CTR_DRBG_C and MBEDTLS_ENTROPY_C,
- * or MBEDTLS_HMAC_DRBG_C and MBEDTLS_ENTROPY_C,
- * or MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG.
- *
- */
- #define MBEDTLS_PSA_CRYPTO_C
- /**
- * \def MBEDTLS_PSA_CRYPTO_SE_C
- *
- * Enable secure element support in the Platform Security Architecture
- * cryptography API.
- *
- * \warning This feature is not yet suitable for production. It is provided
- * for API evaluation and testing purposes only.
- *
- * Module: library/psa_crypto_se.c
- *
- * Requires: MBEDTLS_PSA_CRYPTO_C, MBEDTLS_PSA_CRYPTO_STORAGE_C
- *
- */
- //#define MBEDTLS_PSA_CRYPTO_SE_C
- /**
- * \def MBEDTLS_PSA_CRYPTO_STORAGE_C
- *
- * Enable the Platform Security Architecture persistent key storage.
- *
- * Module: library/psa_crypto_storage.c
- *
- * Requires: MBEDTLS_PSA_CRYPTO_C,
- * either MBEDTLS_PSA_ITS_FILE_C or a native implementation of
- * the PSA ITS interface
- */
- #define MBEDTLS_PSA_CRYPTO_STORAGE_C
- /**
- * \def MBEDTLS_PSA_ITS_FILE_C
- *
- * Enable the emulation of the Platform Security Architecture
- * Internal Trusted Storage (PSA ITS) over files.
- *
- * Module: library/psa_its_file.c
- *
- * Requires: MBEDTLS_FS_IO
- */
- #define MBEDTLS_PSA_ITS_FILE_C
- /**
- * \def MBEDTLS_RIPEMD160_C
- *
- * Enable the RIPEMD-160 hash algorithm.
- *
- * Module: library/ripemd160.c
- * Caller: library/md.c
- *
- */
- #define MBEDTLS_RIPEMD160_C
- /**
- * \def MBEDTLS_RSA_C
- *
- * Enable the RSA public-key cryptosystem.
- *
- * Module: library/rsa.c
- * library/rsa_internal.c
- * Caller: library/ssl_cli.c
- * library/ssl_srv.c
- * library/ssl_tls.c
- * library/x509.c
- *
- * This module is used by the following key exchanges:
- * RSA, DHE-RSA, ECDHE-RSA, RSA-PSK
- *
- * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C
- */
- #define MBEDTLS_RSA_C
- /**
- * \def MBEDTLS_SHA1_C
- *
- * Enable the SHA1 cryptographic hash algorithm.
- *
- * Module: library/sha1.c
- * Caller: library/md.c
- * library/ssl_cli.c
- * library/ssl_srv.c
- * library/ssl_tls.c
- * library/x509write_crt.c
- *
- * This module is required for SSL/TLS up to version 1.1, for TLS 1.2
- * depending on the handshake parameters, and for SHA1-signed certificates.
- *
- * \warning SHA-1 is considered a weak message digest and its use constitutes
- * a security risk. If possible, we recommend avoiding dependencies
- * on it, and considering stronger message digests instead.
- *
- */
- #define MBEDTLS_SHA1_C
- /**
- * \def MBEDTLS_SHA256_C
- *
- * Enable the SHA-224 and SHA-256 cryptographic hash algorithms.
- *
- * Module: library/sha256.c
- * Caller: library/entropy.c
- * library/md.c
- * library/ssl_cli.c
- * library/ssl_srv.c
- * library/ssl_tls.c
- *
- * This module adds support for SHA-224 and SHA-256.
- * This module is required for the SSL/TLS 1.2 PRF function.
- */
- #define MBEDTLS_SHA256_C
- /**
- * \def MBEDTLS_SHA512_C
- *
- * Enable the SHA-384 and SHA-512 cryptographic hash algorithms.
- *
- * Module: library/sha512.c
- * Caller: library/entropy.c
- * library/md.c
- * library/ssl_cli.c
- * library/ssl_srv.c
- *
- * This module adds support for SHA-384 and SHA-512.
- */
- #define MBEDTLS_SHA512_C
- /**
- * \def MBEDTLS_SSL_CACHE_C
- *
- * Enable simple SSL cache implementation.
- *
- * Module: library/ssl_cache.c
- * Caller:
- *
- * Requires: MBEDTLS_SSL_CACHE_C
- */
- #define MBEDTLS_SSL_CACHE_C
- /**
- * \def MBEDTLS_SSL_COOKIE_C
- *
- * Enable basic implementation of DTLS cookies for hello verification.
- *
- * Module: library/ssl_cookie.c
- * Caller:
- */
- #define MBEDTLS_SSL_COOKIE_C
- /**
- * \def MBEDTLS_SSL_TICKET_C
- *
- * Enable an implementation of TLS server-side callbacks for session tickets.
- *
- * Module: library/ssl_ticket.c
- * Caller:
- *
- * Requires: MBEDTLS_CIPHER_C
- */
- #define MBEDTLS_SSL_TICKET_C
- /**
- * \def MBEDTLS_SSL_CLI_C
- *
- * Enable the SSL/TLS client code.
- *
- * Module: library/ssl_cli.c
- * Caller:
- *
- * Requires: MBEDTLS_SSL_TLS_C
- *
- * This module is required for SSL/TLS client support.
- */
- #define MBEDTLS_SSL_CLI_C
- /**
- * \def MBEDTLS_SSL_SRV_C
- *
- * Enable the SSL/TLS server code.
- *
- * Module: library/ssl_srv.c
- * Caller:
- *
- * Requires: MBEDTLS_SSL_TLS_C
- *
- * This module is required for SSL/TLS server support.
- */
- #define MBEDTLS_SSL_SRV_C
- /**
- * \def MBEDTLS_SSL_TLS_C
- *
- * Enable the generic SSL/TLS code.
- *
- * Module: library/ssl_tls.c
- * Caller: library/ssl_cli.c
- * library/ssl_srv.c
- *
- * Requires: MBEDTLS_CIPHER_C, MBEDTLS_MD_C
- * and at least one of the MBEDTLS_SSL_PROTO_XXX defines
- *
- * This module is required for SSL/TLS.
- */
- #define MBEDTLS_SSL_TLS_C
- /**
- * \def MBEDTLS_THREADING_C
- *
- * Enable the threading abstraction layer.
- * By default mbed TLS assumes it is used in a non-threaded environment or that
- * contexts are not shared between threads. If you do intend to use contexts
- * between threads, you will need to enable this layer to prevent race
- * conditions. See also our Knowledge Base article about threading:
- * https://tls.mbed.org/kb/development/thread-safety-and-multi-threading
- *
- * Module: library/threading.c
- *
- * This allows different threading implementations (self-implemented or
- * provided).
- *
- * You will have to enable either MBEDTLS_THREADING_ALT or
- * MBEDTLS_THREADING_PTHREAD.
- *
- * Enable this layer to allow use of mutexes within mbed TLS
- */
- //#define MBEDTLS_THREADING_C
- /**
- * \def MBEDTLS_TIMING_C
- *
- * Enable the semi-portable timing interface.
- *
- * \note The provided implementation only works on POSIX/Unix (including Linux,
- * BSD and OS X) and Windows. On other platforms, you can either disable that
- * module and provide your own implementations of the callbacks needed by
- * \c mbedtls_ssl_set_timer_cb() for DTLS, or leave it enabled and provide
- * your own implementation of the whole module by setting
- * \c MBEDTLS_TIMING_ALT in the current file.
- *
- * \note See also our Knowledge Base article about porting to a new
- * environment:
- * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
- *
- * Module: library/timing.c
- * Caller: library/havege.c
- *
- * This module is used by the HAVEGE random number generator.
- */
- #define MBEDTLS_TIMING_C
- /**
- * \def MBEDTLS_VERSION_C
- *
- * Enable run-time version information.
- *
- * Module: library/version.c
- *
- * This module provides run-time version information.
- */
- #define MBEDTLS_VERSION_C
- /**
- * \def MBEDTLS_X509_USE_C
- *
- * Enable X.509 core for using certificates.
- *
- * Module: library/x509.c
- * Caller: library/x509_crl.c
- * library/x509_crt.c
- * library/x509_csr.c
- *
- * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C,
- * MBEDTLS_PK_PARSE_C
- *
- * This module is required for the X.509 parsing modules.
- */
- #define MBEDTLS_X509_USE_C
- /**
- * \def MBEDTLS_X509_CRT_PARSE_C
- *
- * Enable X.509 certificate parsing.
- *
- * Module: library/x509_crt.c
- * Caller: library/ssl_cli.c
- * library/ssl_srv.c
- * library/ssl_tls.c
- *
- * Requires: MBEDTLS_X509_USE_C
- *
- * This module is required for X.509 certificate parsing.
- */
- #define MBEDTLS_X509_CRT_PARSE_C
- /**
- * \def MBEDTLS_X509_CRL_PARSE_C
- *
- * Enable X.509 CRL parsing.
- *
- * Module: library/x509_crl.c
- * Caller: library/x509_crt.c
- *
- * Requires: MBEDTLS_X509_USE_C
- *
- * This module is required for X.509 CRL parsing.
- */
- #define MBEDTLS_X509_CRL_PARSE_C
- /**
- * \def MBEDTLS_X509_CSR_PARSE_C
- *
- * Enable X.509 Certificate Signing Request (CSR) parsing.
- *
- * Module: library/x509_csr.c
- * Caller: library/x509_crt_write.c
- *
- * Requires: MBEDTLS_X509_USE_C
- *
- * This module is used for reading X.509 certificate request.
- */
- #define MBEDTLS_X509_CSR_PARSE_C
- /**
- * \def MBEDTLS_X509_CREATE_C
- *
- * Enable X.509 core for creating certificates.
- *
- * Module: library/x509_create.c
- *
- * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_WRITE_C
- *
- * This module is the basis for creating X.509 certificates and CSRs.
- */
- #define MBEDTLS_X509_CREATE_C
- /**
- * \def MBEDTLS_X509_CRT_WRITE_C
- *
- * Enable creating X.509 certificates.
- *
- * Module: library/x509_crt_write.c
- *
- * Requires: MBEDTLS_X509_CREATE_C
- *
- * This module is required for X.509 certificate creation.
- */
- #define MBEDTLS_X509_CRT_WRITE_C
- /**
- * \def MBEDTLS_X509_CSR_WRITE_C
- *
- * Enable creating X.509 Certificate Signing Requests (CSR).
- *
- * Module: library/x509_csr_write.c
- *
- * Requires: MBEDTLS_X509_CREATE_C
- *
- * This module is required for X.509 certificate request writing.
- */
- #define MBEDTLS_X509_CSR_WRITE_C
- /**
- * \def MBEDTLS_XTEA_C
- *
- * Enable the XTEA block cipher.
- *
- * Module: library/xtea.c
- * Caller:
- */
- #define MBEDTLS_XTEA_C
- /* \} name SECTION: mbed TLS modules */
- /**
- * \name SECTION: Module configuration options
- *
- * This section allows for the setting of module specific sizes and
- * configuration options. The default values are already present in the
- * relevant header files and should suffice for the regular use cases.
- *
- * Our advice is to enable options and change their values here
- * only if you have a good reason and know the consequences.
- *
- * Please check the respective header file for documentation on these
- * parameters (to prevent duplicate documentation).
- * \{
- */
- /* MPI / BIGNUM options */
- //#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum window size used. */
- //#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
- /* CTR_DRBG options */
- //#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */
- //#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
- //#define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
- //#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
- //#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
- /* HMAC_DRBG options */
- //#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
- //#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
- //#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
- //#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
- /* ECP options */
- //#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups. Normally determined automatically from the configured curves. */
- //#define MBEDTLS_ECP_WINDOW_SIZE 4 /**< Maximum window size used */
- //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
- /* Entropy options */
- //#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
- //#define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
- //#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Default minimum number of bytes required for the hardware entropy source mbedtls_hardware_poll() before entropy is released */
- /* Memory buffer allocator options */
- //#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
- /* Platform options */
- //#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. */
- //#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
- //#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
- /* Note: your snprintf must correctly zero-terminate the buffer! */
- //#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
- //#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" /**< Seed file to read/write with default implementation */
- /* To Use Function Macros MBEDTLS_PLATFORM_C must be enabled */
- /* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */
- //#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, can be undefined */
- //#define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */
- //#define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */
- //#define MBEDTLS_PLATFORM_TIME_MACRO time /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
- //#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
- //#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */
- //#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */
- /* Note: your snprintf must correctly zero-terminate the buffer! */
- //#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */
- //#define MBEDTLS_PLATFORM_VSNPRINTF_MACRO vsnprintf /**< Default vsnprintf macro to use, can be undefined */
- //#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
- //#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
- /**
- * \brief This macro is invoked by the library when an invalid parameter
- * is detected that is only checked with #MBEDTLS_CHECK_PARAMS
- * (see the documentation of that option for context).
- *
- * When you leave this undefined here, the library provides
- * a default definition. If the macro #MBEDTLS_CHECK_PARAMS_ASSERT
- * is defined, the default definition is `assert(cond)`,
- * otherwise the default definition calls a function
- * mbedtls_param_failed(). This function is declared in
- * `platform_util.h` for the benefit of the library, but
- * you need to define in your application.
- *
- * When you define this here, this replaces the default
- * definition in platform_util.h (which no longer declares the
- * function mbedtls_param_failed()) and it is your responsibility
- * to make sure this macro expands to something suitable (in
- * particular, that all the necessary declarations are visible
- * from within the library - you can ensure that by providing
- * them in this file next to the macro definition).
- * If you define this macro to call `assert`, also define
- * #MBEDTLS_CHECK_PARAMS_ASSERT so that library source files
- * include `<assert.h>`.
- *
- * Note that you may define this macro to expand to nothing, in
- * which case you don't have to worry about declarations or
- * definitions. However, you will then be notified about invalid
- * parameters only in non-void functions, and void function will
- * just silently return early on invalid parameters, which
- * partially negates the benefits of enabling
- * #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged.
- *
- * \param cond The expression that should evaluate to true, but doesn't.
- */
- //#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
- /** \def MBEDTLS_CHECK_RETURN
- *
- * This macro is used at the beginning of the declaration of a function
- * to indicate that its return value should be checked. It should
- * instruct the compiler to emit a warning or an error if the function
- * is called without checking its return value.
- *
- * There is a default implementation for popular compilers in platform_util.h.
- * You can override the default implementation by defining your own here.
- *
- * If the implementation here is empty, this will effectively disable the
- * checking of functions' return values.
- */
- //#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__))
- /** \def MBEDTLS_IGNORE_RETURN
- *
- * This macro requires one argument, which should be a C function call.
- * If that function call would cause a #MBEDTLS_CHECK_RETURN warning, this
- * warning is suppressed.
- */
- //#define MBEDTLS_IGNORE_RETURN( result ) ((void) !(result))
- /* PSA options */
- /**
- * Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the
- * PSA crypto subsystem.
- *
- * If this option is unset:
- * - If CTR_DRBG is available, the PSA subsystem uses it rather than HMAC_DRBG.
- * - Otherwise, the PSA subsystem uses HMAC_DRBG with either
- * #MBEDTLS_MD_SHA512 or #MBEDTLS_MD_SHA256 based on availability and
- * on unspecified heuristics.
- */
- //#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256
- /** \def MBEDTLS_PSA_KEY_SLOT_COUNT
- * Restrict the PSA library to supporting a maximum amount of simultaneously
- * loaded keys. A loaded key is a key stored by the PSA Crypto core as a
- * volatile key, or a persistent key which is loaded temporarily by the
- * library as part of a crypto operation in flight.
- *
- * If this option is unset, the library will fall back to a default value of
- * 32 keys.
- */
- //#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
- /* SSL Cache options */
- //#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */
- //#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */
- /* SSL options */
- /** \def MBEDTLS_SSL_MAX_CONTENT_LEN
- *
- * Maximum length (in bytes) of incoming and outgoing plaintext fragments.
- *
- * This determines the size of both the incoming and outgoing TLS I/O buffers
- * in such a way that both are capable of holding the specified amount of
- * plaintext data, regardless of the protection mechanism used.
- *
- * To configure incoming and outgoing I/O buffers separately, use
- * #MBEDTLS_SSL_IN_CONTENT_LEN and #MBEDTLS_SSL_OUT_CONTENT_LEN,
- * which overwrite the value set by this option.
- *
- * \note When using a value less than the default of 16KB on the client, it is
- * recommended to use the Maximum Fragment Length (MFL) extension to
- * inform the server about this limitation. On the server, there
- * is no supported, standardized way of informing the client about
- * restriction on the maximum size of incoming messages, and unless
- * the limitation has been communicated by other means, it is recommended
- * to only change the outgoing buffer size #MBEDTLS_SSL_OUT_CONTENT_LEN
- * while keeping the default value of 16KB for the incoming buffer.
- *
- * Uncomment to set the maximum plaintext size of both
- * incoming and outgoing I/O buffers.
- */
- //#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384
- /** \def MBEDTLS_SSL_IN_CONTENT_LEN
- *
- * Maximum length (in bytes) of incoming plaintext fragments.
- *
- * This determines the size of the incoming TLS I/O buffer in such a way
- * that it is capable of holding the specified amount of plaintext data,
- * regardless of the protection mechanism used.
- *
- * If this option is undefined, it inherits its value from
- * #MBEDTLS_SSL_MAX_CONTENT_LEN.
- *
- * \note When using a value less than the default of 16KB on the client, it is
- * recommended to use the Maximum Fragment Length (MFL) extension to
- * inform the server about this limitation. On the server, there
- * is no supported, standardized way of informing the client about
- * restriction on the maximum size of incoming messages, and unless
- * the limitation has been communicated by other means, it is recommended
- * to only change the outgoing buffer size #MBEDTLS_SSL_OUT_CONTENT_LEN
- * while keeping the default value of 16KB for the incoming buffer.
- *
- * Uncomment to set the maximum plaintext size of the incoming I/O buffer
- * independently of the outgoing I/O buffer.
- */
- //#define MBEDTLS_SSL_IN_CONTENT_LEN 16384
- /** \def MBEDTLS_SSL_CID_IN_LEN_MAX
- *
- * The maximum length of CIDs used for incoming DTLS messages.
- *
- */
- //#define MBEDTLS_SSL_CID_IN_LEN_MAX 32
- /** \def MBEDTLS_SSL_CID_OUT_LEN_MAX
- *
- * The maximum length of CIDs used for outgoing DTLS messages.
- *
- */
- //#define MBEDTLS_SSL_CID_OUT_LEN_MAX 32
- /** \def MBEDTLS_SSL_CID_PADDING_GRANULARITY
- *
- * This option controls the use of record plaintext padding
- * when using the Connection ID extension in DTLS 1.2.
- *
- * The padding will always be chosen so that the length of the
- * padded plaintext is a multiple of the value of this option.
- *
- * Note: A value of \c 1 means that no padding will be used
- * for outgoing records.
- *
- * Note: On systems lacking division instructions,
- * a power of two should be preferred.
- *
- */
- //#define MBEDTLS_SSL_CID_PADDING_GRANULARITY 16
- /** \def MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY
- *
- * This option controls the use of record plaintext padding
- * in TLS 1.3.
- *
- * The padding will always be chosen so that the length of the
- * padded plaintext is a multiple of the value of this option.
- *
- * Note: A value of \c 1 means that no padding will be used
- * for outgoing records.
- *
- * Note: On systems lacking division instructions,
- * a power of two should be preferred.
- */
- //#define MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY 1
- /** \def MBEDTLS_SSL_OUT_CONTENT_LEN
- *
- * Maximum length (in bytes) of outgoing plaintext fragments.
- *
- * This determines the size of the outgoing TLS I/O buffer in such a way
- * that it is capable of holding the specified amount of plaintext data,
- * regardless of the protection mechanism used.
- *
- * If this option undefined, it inherits its value from
- * #MBEDTLS_SSL_MAX_CONTENT_LEN.
- *
- * It is possible to save RAM by setting a smaller outward buffer, while keeping
- * the default inward 16384 byte buffer to conform to the TLS specification.
- *
- * The minimum required outward buffer size is determined by the handshake
- * protocol's usage. Handshaking will fail if the outward buffer is too small.
- * The specific size requirement depends on the configured ciphers and any
- * certificate data which is sent during the handshake.
- *
- * Uncomment to set the maximum plaintext size of the outgoing I/O buffer
- * independently of the incoming I/O buffer.
- */
- //#define MBEDTLS_SSL_OUT_CONTENT_LEN 16384
- /** \def MBEDTLS_SSL_DTLS_MAX_BUFFERING
- *
- * Maximum number of heap-allocated bytes for the purpose of
- * DTLS handshake message reassembly and future message buffering.
- *
- * This should be at least 9/8 * MBEDTLS_SSL_IN_CONTENT_LEN
- * to account for a reassembled handshake message of maximum size,
- * together with its reassembly bitmap.
- *
- * A value of 2 * MBEDTLS_SSL_IN_CONTENT_LEN (32768 by default)
- * should be sufficient for all practical situations as it allows
- * to reassembly a large handshake message (such as a certificate)
- * while buffering multiple smaller handshake messages.
- *
- */
- //#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
- //#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
- //#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */
- //#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
- /** \def MBEDTLS_TLS_EXT_CID
- *
- * At the time of writing, the CID extension has not been assigned its
- * final value. Set this configuration option to make Mbed TLS use a
- * different value.
- *
- * A future minor revision of Mbed TLS may change the default value of
- * this option to match evolving standards and usage.
- */
- //#define MBEDTLS_TLS_EXT_CID 254
- /**
- * Complete list of ciphersuites to use, in order of preference.
- *
- * \warning No dependency checking is done on that field! This option can only
- * be used to restrict the set of available ciphersuites. It is your
- * responsibility to make sure the needed modules are active.
- *
- * Use this to save a few hundred bytes of ROM (default ordering of all
- * available ciphersuites) and a few to a few hundred bytes of RAM.
- *
- * The value below is only an example, not the default.
- */
- //#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- /* X509 options */
- //#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */
- //#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum length of a path/filename string in bytes including the null terminator character ('\0'). */
- /**
- * Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake
- * signature and ciphersuite selection. Without this build-time option, SHA-1
- * support must be activated explicitly through mbedtls_ssl_conf_sig_hashes.
- * The use of SHA-1 in TLS <= 1.1 and in HMAC-SHA-1 is always allowed by
- * default. At the time of writing, there is no practical attack on the use
- * of SHA-1 in handshake signatures, hence this option is turned on by default
- * to preserve compatibility with existing peers, but the general
- * warning applies nonetheless:
- *
- * \warning SHA-1 is considered a weak message digest and its use constitutes
- * a security risk. If possible, we recommend avoiding dependencies
- * on it, and considering stronger message digests instead.
- *
- */
- //#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE
- /**
- * Uncomment the macro to let mbed TLS use your alternate implementation of
- * mbedtls_platform_zeroize(). This replaces the default implementation in
- * platform_util.c.
- *
- * mbedtls_platform_zeroize() is a widely used function across the library to
- * zero a block of memory. The implementation is expected to be secure in the
- * sense that it has been written to prevent the compiler from removing calls
- * to mbedtls_platform_zeroize() as part of redundant code elimination
- * optimizations. However, it is difficult to guarantee that calls to
- * mbedtls_platform_zeroize() will not be optimized by the compiler as older
- * versions of the C language standards do not provide a secure implementation
- * of memset(). Therefore, MBEDTLS_PLATFORM_ZEROIZE_ALT enables users to
- * configure their own implementation of mbedtls_platform_zeroize(), for
- * example by using directives specific to their compiler, features from newer
- * C standards (e.g using memset_s() in C11) or calling a secure memset() from
- * their system (e.g explicit_bzero() in BSD).
- */
- //#define MBEDTLS_PLATFORM_ZEROIZE_ALT
- /**
- * Uncomment the macro to let Mbed TLS use your alternate implementation of
- * mbedtls_platform_gmtime_r(). This replaces the default implementation in
- * platform_util.c.
- *
- * gmtime() is not a thread-safe function as defined in the C standard. The
- * library will try to use safer implementations of this function, such as
- * gmtime_r() when available. However, if Mbed TLS cannot identify the target
- * system, the implementation of mbedtls_platform_gmtime_r() will default to
- * using the standard gmtime(). In this case, calls from the library to
- * gmtime() will be guarded by the global mutex mbedtls_threading_gmtime_mutex
- * if MBEDTLS_THREADING_C is enabled. We recommend that calls from outside the
- * library are also guarded with this mutex to avoid race conditions. However,
- * if the macro MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, Mbed TLS will
- * unconditionally use the implementation for mbedtls_platform_gmtime_r()
- * supplied at compile time.
- */
- //#define MBEDTLS_PLATFORM_GMTIME_R_ALT
- /**
- * Enable the verified implementations of ECDH primitives from Project Everest
- * (currently only Curve25519). This feature changes the layout of ECDH
- * contexts and therefore is a compatibility break for applications that access
- * fields of a mbedtls_ecdh_context structure directly. See also
- * MBEDTLS_ECDH_LEGACY_CONTEXT in include/mbedtls/ecdh.h.
- */
- //#define MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
- /* \} name SECTION: Customisation configuration options */
- /* Target and application specific configurations
- *
- * Allow user to override any previous default.
- *
- */
- #if defined(MBEDTLS_USER_CONFIG_FILE)
- #include MBEDTLS_USER_CONFIG_FILE
- #endif
- #if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
- #endif
- #endif /* MBEDTLS_CONFIG_H */
- /********* Start of file include/mbedtls/check_config.h ************/
- /**
- * \file check_config.h
- *
- * \brief Consistency checks for configuration options
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /*
- * It is recommended to include this file from your config.h
- * in order to catch dependency issues early.
- */
- #ifndef MBEDTLS_CHECK_CONFIG_H
- #define MBEDTLS_CHECK_CONFIG_H
- /*
- * We assume CHAR_BIT is 8 in many places. In practice, this is true on our
- * target platforms, so not an issue, but let's just be extra sure.
- */
- #include <limits.h>
- #if CHAR_BIT != 8
- #error "mbed TLS requires a platform with 8-bit chars"
- #endif
- #if defined(_WIN32)
- #if !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_C is required on Windows"
- #endif
- /* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as
- * it would confuse config.py. */
- #if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
- !defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
- #define MBEDTLS_PLATFORM_SNPRINTF_ALT
- #endif
- #if !defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) && \
- !defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO)
- #define MBEDTLS_PLATFORM_VSNPRINTF_ALT
- #endif
- #endif /* _WIN32 */
- #if defined(TARGET_LIKE_MBED) && defined(MBEDTLS_NET_C)
- #error "The NET module is not available for mbed OS - please use the network functions provided by Mbed OS"
- #endif
- #if defined(MBEDTLS_DEPRECATED_WARNING) && \
- !defined(__GNUC__) && !defined(__clang__)
- #error "MBEDTLS_DEPRECATED_WARNING only works with GCC and Clang"
- #endif
- #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_HAVE_TIME)
- #error "MBEDTLS_HAVE_TIME_DATE without MBEDTLS_HAVE_TIME does not make sense"
- #endif
- #if defined(MBEDTLS_AESNI_C) && !defined(MBEDTLS_HAVE_ASM)
- #error "MBEDTLS_AESNI_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C)
- #error "MBEDTLS_CTR_DRBG_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_DHM_C) && !defined(MBEDTLS_BIGNUM_C)
- #error "MBEDTLS_DHM_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT) && !defined(MBEDTLS_SSL_TRUNCATED_HMAC)
- #error "MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_CMAC_C) && \
- !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C)
- #error "MBEDTLS_CMAC_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_NIST_KW_C) && \
- ( !defined(MBEDTLS_AES_C) || !defined(MBEDTLS_CIPHER_C) )
- #error "MBEDTLS_NIST_KW_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
- #error "MBEDTLS_ECDH_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECDSA_C) && \
- ( !defined(MBEDTLS_ECP_C) || \
- !( defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) ) || \
- !defined(MBEDTLS_ASN1_PARSE_C) || \
- !defined(MBEDTLS_ASN1_WRITE_C) )
- #error "MBEDTLS_ECDSA_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECJPAKE_C) && \
- ( !defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_MD_C) )
- #error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_RESTARTABLE) && \
- ( defined(MBEDTLS_USE_PSA_CRYPTO) || \
- defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \
- defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) || \
- defined(MBEDTLS_ECDSA_SIGN_ALT) || \
- defined(MBEDTLS_ECDSA_VERIFY_ALT) || \
- defined(MBEDTLS_ECDSA_GENKEY_ALT) || \
- defined(MBEDTLS_ECP_INTERNAL_ALT) || \
- defined(MBEDTLS_ECP_ALT) )
- #error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative or PSA-based ECP implementation"
- #endif
- #if defined(MBEDTLS_ECP_RESTARTABLE) && \
- ! defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
- #error "MBEDTLS_ECP_RESTARTABLE defined, but not MBEDTLS_ECDH_LEGACY_CONTEXT"
- #endif
- #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) && \
- defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
- #error "MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED defined, but MBEDTLS_ECDH_LEGACY_CONTEXT not disabled"
- #endif
- #if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
- #error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_C) && ( !defined(MBEDTLS_BIGNUM_C) || ( \
- !defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) && \
- !defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) ) )
- #error "MBEDTLS_ECP_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_C) && !( \
- defined(MBEDTLS_ECP_ALT) || \
- defined(MBEDTLS_CTR_DRBG_C) || \
- defined(MBEDTLS_HMAC_DRBG_C) || \
- defined(MBEDTLS_ECP_NO_INTERNAL_RNG))
- #error "MBEDTLS_ECP_C requires a DRBG module unless MBEDTLS_ECP_NO_INTERNAL_RNG is defined or an alternative implementation is used"
- #endif
- #if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_ASN1_PARSE_C)
- #error "MBEDTLS_PK_PARSE_C defined, but not all prerequesites"
- #endif
- #if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \
- !defined(MBEDTLS_SHA256_C))
- #error "MBEDTLS_ENTROPY_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && \
- defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64)
- #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
- #endif
- #if defined(MBEDTLS_ENTROPY_C) && \
- ( !defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256) ) \
- && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32)
- #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
- #endif
- #if defined(MBEDTLS_ENTROPY_C) && \
- defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_SHA256_C)
- #error "MBEDTLS_ENTROPY_FORCE_SHA256 defined, but not all prerequisites"
- #endif
- #if defined(__has_feature)
- #if __has_feature(memory_sanitizer)
- #define MBEDTLS_HAS_MEMSAN
- #endif
- #endif
- #if defined(MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN) && !defined(MBEDTLS_HAS_MEMSAN)
- #error "MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN requires building with MemorySanitizer"
- #endif
- #undef MBEDTLS_HAS_MEMSAN
- #if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
- ( !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) )
- #error "MBEDTLS_TEST_NULL_ENTROPY defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
- ( defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
- defined(MBEDTLS_HAVEGE_C) )
- #error "MBEDTLS_TEST_NULL_ENTROPY defined, but entropy sources too"
- #endif
- #if defined(MBEDTLS_GCM_C) && ( \
- !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) && !defined(MBEDTLS_ARIA_C) )
- #error "MBEDTLS_GCM_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_RANDOMIZE_JAC_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_ADD_MIXED_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_DOUBLE_JAC_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_NORMALIZE_JAC_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_RANDOMIZE_MXZ_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ECP_NO_FALLBACK) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
- #error "MBEDTLS_ECP_NO_FALLBACK defined, but no alternative implementation enabled"
- #endif
- #if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C)
- #error "MBEDTLS_HAVEGE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_HKDF_C) && !defined(MBEDTLS_MD_C)
- #error "MBEDTLS_HKDF_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_HMAC_DRBG_C) && !defined(MBEDTLS_MD_C)
- #error "MBEDTLS_HMAC_DRBG_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \
- ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) )
- #error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
- ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) )
- #error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) && !defined(MBEDTLS_DHM_C)
- #error "MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \
- !defined(MBEDTLS_ECDH_C)
- #error "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
- ( !defined(MBEDTLS_DHM_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
- #error "MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
- ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
- #error "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \
- ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \
- !defined(MBEDTLS_X509_CRT_PARSE_C) )
- #error "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) && \
- ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
- !defined(MBEDTLS_PKCS1_V15) )
- #error "MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
- ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
- !defined(MBEDTLS_PKCS1_V15) )
- #error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
- ( !defined(MBEDTLS_ECJPAKE_C) || !defined(MBEDTLS_SHA256_C) || \
- !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) )
- #error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
- !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) && \
- ( !defined(MBEDTLS_SHA256_C) && \
- !defined(MBEDTLS_SHA512_C) && \
- !defined(MBEDTLS_SHA1_C) )
- #error "!MBEDTLS_SSL_KEEP_PEER_CERTIFICATE requires MBEDTLS_SHA512_C, MBEDTLS_SHA256_C or MBEDTLS_SHA1_C"
- #endif
- #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
- #error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_MEMORY_BACKTRACE) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
- #error "MBEDTLS_MEMORY_BACKTRACE defined, but not all prerequesites"
- #endif
- #if defined(MBEDTLS_MEMORY_DEBUG) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
- #error "MBEDTLS_MEMORY_DEBUG defined, but not all prerequesites"
- #endif
- #if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM)
- #error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PEM_PARSE_C) && !defined(MBEDTLS_BASE64_C)
- #error "MBEDTLS_PEM_PARSE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PEM_WRITE_C) && !defined(MBEDTLS_BASE64_C)
- #error "MBEDTLS_PEM_WRITE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PK_C) && \
- ( !defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_C) )
- #error "MBEDTLS_PK_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_PK_C)
- #error "MBEDTLS_PK_PARSE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PK_WRITE_C) && !defined(MBEDTLS_PK_C)
- #error "MBEDTLS_PK_WRITE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PKCS11_C) && !defined(MBEDTLS_PK_C)
- #error "MBEDTLS_PKCS11_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PKCS11_C)
- #if defined(MBEDTLS_DEPRECATED_REMOVED)
- #error "MBEDTLS_PKCS11_C is deprecated and will be removed in a future version of Mbed TLS"
- #elif defined(MBEDTLS_DEPRECATED_WARNING)
- #warning "MBEDTLS_PKCS11_C is deprecated and will be removed in a future version of Mbed TLS"
- #endif
- #endif /* MBEDTLS_PKCS11_C */
- #if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_EXIT) ||\
- defined(MBEDTLS_PLATFORM_EXIT_ALT) )
- #error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_TIME_ALT) &&\
- ( !defined(MBEDTLS_PLATFORM_C) ||\
- !defined(MBEDTLS_HAVE_TIME) )
- #error "MBEDTLS_PLATFORM_TIME_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) ||\
- !defined(MBEDTLS_HAVE_TIME) )
- #error "MBEDTLS_PLATFORM_TIME_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) ||\
- !defined(MBEDTLS_HAVE_TIME) )
- #error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
- defined(MBEDTLS_PLATFORM_TIME_ALT) )
- #error "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
- defined(MBEDTLS_PLATFORM_TIME_ALT) )
- #error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_FPRINTF) ||\
- defined(MBEDTLS_PLATFORM_FPRINTF_ALT) )
- #error "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
- #error "MBEDTLS_PLATFORM_FREE_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
- defined(MBEDTLS_PLATFORM_STD_FREE)
- #error "MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_STD_FREE cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && !defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
- #error "MBEDTLS_PLATFORM_CALLOC_MACRO must be defined if MBEDTLS_PLATFORM_FREE_MACRO is"
- #endif
- #if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
- #error "MBEDTLS_PLATFORM_CALLOC_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
- defined(MBEDTLS_PLATFORM_STD_CALLOC)
- #error "MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_STD_CALLOC cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && !defined(MBEDTLS_PLATFORM_FREE_MACRO)
- #error "MBEDTLS_PLATFORM_FREE_MACRO must be defined if MBEDTLS_PLATFORM_CALLOC_MACRO is"
- #endif
- #if defined(MBEDTLS_PLATFORM_MEMORY) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_MEMORY defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_PRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_PRINTF) ||\
- defined(MBEDTLS_PLATFORM_PRINTF_ALT) )
- #error "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
- #error "MBEDTLS_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_SNPRINTF) ||\
- defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) )
- #error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\
- !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
- #error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
- #error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY)
- #error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_EXIT) &&\
- !defined(MBEDTLS_PLATFORM_EXIT_ALT)
- #error "MBEDTLS_PLATFORM_STD_EXIT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_TIME) &&\
- ( !defined(MBEDTLS_PLATFORM_TIME_ALT) ||\
- !defined(MBEDTLS_HAVE_TIME) )
- #error "MBEDTLS_PLATFORM_STD_TIME defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_FPRINTF) &&\
- !defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
- #error "MBEDTLS_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_PRINTF) &&\
- !defined(MBEDTLS_PLATFORM_PRINTF_ALT)
- #error "MBEDTLS_PLATFORM_STD_PRINTF defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_SNPRINTF) &&\
- !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
- #error "MBEDTLS_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_ENTROPY_NV_SEED) &&\
- ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_ENTROPY_C) )
- #error "MBEDTLS_ENTROPY_NV_SEED defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) &&\
- !defined(MBEDTLS_ENTROPY_NV_SEED)
- #error "MBEDTLS_PLATFORM_NV_SEED_ALT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) &&\
- !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
- #error "MBEDTLS_PLATFORM_STD_NV_SEED_READ defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) &&\
- !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
- #error "MBEDTLS_PLATFORM_STD_NV_SEED_WRITE defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) ||\
- defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
- #error "MBEDTLS_PLATFORM_NV_SEED_READ_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_READ cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) &&\
- ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) ||\
- defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
- #error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously"
- #endif
- #if defined(MBEDTLS_PSA_CRYPTO_C) && \
- !( ( ( defined(MBEDTLS_CTR_DRBG_C) || defined(MBEDTLS_HMAC_DRBG_C) ) && \
- defined(MBEDTLS_ENTROPY_C) ) || \
- defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) )
- #error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites (missing RNG)"
- #endif
- #if defined(MBEDTLS_PSA_CRYPTO_SPM) && !defined(MBEDTLS_PSA_CRYPTO_C)
- #error "MBEDTLS_PSA_CRYPTO_SPM defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PSA_CRYPTO_SE_C) && \
- ! ( defined(MBEDTLS_PSA_CRYPTO_C) && \
- defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) )
- #error "MBEDTLS_PSA_CRYPTO_SE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) && \
- ! defined(MBEDTLS_PSA_CRYPTO_C)
- #error "MBEDTLS_PSA_CRYPTO_STORAGE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \
- !( defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) && \
- defined(MBEDTLS_ENTROPY_NV_SEED) )
- #error "MBEDTLS_PSA_INJECT_ENTROPY defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \
- !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES)
- #error "MBEDTLS_PSA_INJECT_ENTROPY is not compatible with actual entropy sources"
- #endif
- #if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \
- defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
- #error "MBEDTLS_PSA_INJECT_ENTROPY is not compatible with MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG"
- #endif
- #if defined(MBEDTLS_PSA_ITS_FILE_C) && \
- !defined(MBEDTLS_FS_IO)
- #error "MBEDTLS_PSA_ITS_FILE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) && \
- defined(MBEDTLS_USE_PSA_CRYPTO)
- #error "MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER defined, but it cannot coexist with MBEDTLS_USE_PSA_CRYPTO."
- #endif
- #if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
- !defined(MBEDTLS_OID_C) )
- #error "MBEDTLS_RSA_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_PKCS1_V21) && \
- !defined(MBEDTLS_PKCS1_V15) )
- #error "MBEDTLS_RSA_C defined, but none of the PKCS1 versions enabled"
- #endif
- #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) && \
- ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_PKCS1_V21) )
- #error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SHA512_NO_SHA384) && !defined(MBEDTLS_SHA512_C)
- #error "MBEDTLS_SHA512_NO_SHA384 defined without MBEDTLS_SHA512_C"
- #endif
- #if defined(MBEDTLS_SSL_PROTO_SSL3) && ( !defined(MBEDTLS_MD5_C) || \
- !defined(MBEDTLS_SHA1_C) )
- #error "MBEDTLS_SSL_PROTO_SSL3 defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_PROTO_TLS1) && ( !defined(MBEDTLS_MD5_C) || \
- !defined(MBEDTLS_SHA1_C) )
- #error "MBEDTLS_SSL_PROTO_TLS1 defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_PROTO_TLS1_1) && ( !defined(MBEDTLS_MD5_C) || \
- !defined(MBEDTLS_SHA1_C) )
- #error "MBEDTLS_SSL_PROTO_TLS1_1 defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && ( !defined(MBEDTLS_SHA1_C) && \
- !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) )
- #error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL) && ( !defined(MBEDTLS_HKDF_C) && \
- !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) )
- #error "MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL defined, but not all prerequisites"
- #endif
- #if (defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
- defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2)) && \
- !(defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) )
- #error "One or more versions of the TLS protocol are enabled " \
- "but no key exchange methods defined with MBEDTLS_KEY_EXCHANGE_xxxx"
- #endif
- #if defined(MBEDTLS_SSL_PROTO_DTLS) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1_2)
- #error "MBEDTLS_SSL_PROTO_DTLS defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_CLI_C) && !defined(MBEDTLS_SSL_TLS_C)
- #error "MBEDTLS_SSL_CLI_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_TLS_C) && ( !defined(MBEDTLS_CIPHER_C) || \
- !defined(MBEDTLS_MD_C) )
- #error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_SRV_C) && !defined(MBEDTLS_SSL_TLS_C)
- #error "MBEDTLS_SSL_SRV_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_TLS_C) && (!defined(MBEDTLS_SSL_PROTO_SSL3) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1) && !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1_2))
- #error "MBEDTLS_SSL_TLS_C defined, but no protocols are active"
- #endif
- #if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
- defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1))
- #error "Illegal protocol selection"
- #endif
- #if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_TLS1) && \
- defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1))
- #error "Illegal protocol selection"
- #endif
- #if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
- defined(MBEDTLS_SSL_PROTO_TLS1_2) && (!defined(MBEDTLS_SSL_PROTO_TLS1) || \
- !defined(MBEDTLS_SSL_PROTO_TLS1_1)))
- #error "Illegal protocol selection"
- #endif
- #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && !defined(MBEDTLS_SSL_PROTO_DTLS)
- #error "MBEDTLS_SSL_DTLS_HELLO_VERIFY defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE) && \
- !defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
- #error "MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) && \
- ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
- #error "MBEDTLS_SSL_DTLS_ANTI_REPLAY defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
- ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
- #error "MBEDTLS_SSL_DTLS_CONNECTION_ID defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
- defined(MBEDTLS_SSL_CID_IN_LEN_MAX) && \
- MBEDTLS_SSL_CID_IN_LEN_MAX > 255
- #error "MBEDTLS_SSL_CID_IN_LEN_MAX too large (max 255)"
- #endif
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
- defined(MBEDTLS_SSL_CID_OUT_LEN_MAX) && \
- MBEDTLS_SSL_CID_OUT_LEN_MAX > 255
- #error "MBEDTLS_SSL_CID_OUT_LEN_MAX too large (max 255)"
- #endif
- #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) && \
- ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
- #error "MBEDTLS_SSL_DTLS_BADMAC_LIMIT defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1_2)
- #error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites"
- #endif
- #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
- !defined(MBEDTLS_SSL_PROTO_TLS1_2)
- #error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites"
- #endif
- #if defined(MBEDTLS_SSL_TICKET_C) && !defined(MBEDTLS_CIPHER_C)
- #error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) && \
- !defined(MBEDTLS_SSL_PROTO_SSL3) && !defined(MBEDTLS_SSL_PROTO_TLS1)
- #error "MBEDTLS_SSL_CBC_RECORD_SPLITTING defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \
- !defined(MBEDTLS_X509_CRT_PARSE_C)
- #error "MBEDTLS_SSL_SERVER_NAME_INDICATION defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_THREADING_PTHREAD)
- #if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
- #error "MBEDTLS_THREADING_PTHREAD defined, but not all prerequisites"
- #endif
- #define MBEDTLS_THREADING_IMPL
- #endif
- #if defined(MBEDTLS_THREADING_ALT)
- #if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
- #error "MBEDTLS_THREADING_ALT defined, but not all prerequisites"
- #endif
- #define MBEDTLS_THREADING_IMPL
- #endif
- #if defined(MBEDTLS_THREADING_C) && !defined(MBEDTLS_THREADING_IMPL)
- #error "MBEDTLS_THREADING_C defined, single threading implementation required"
- #endif
- #undef MBEDTLS_THREADING_IMPL
- #if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_PSA_CRYPTO_C)
- #error "MBEDTLS_USE_PSA_CRYPTO defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C)
- #error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_X509_USE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
- !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \
- !defined(MBEDTLS_PK_PARSE_C) )
- #error "MBEDTLS_X509_USE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_X509_CREATE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
- !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || \
- !defined(MBEDTLS_PK_WRITE_C) )
- #error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_CERTS_C) && !defined(MBEDTLS_X509_USE_C)
- #error "MBEDTLS_CERTS_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_X509_CRT_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
- #error "MBEDTLS_X509_CRT_PARSE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_X509_CRL_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
- #error "MBEDTLS_X509_CRL_PARSE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_X509_CSR_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
- #error "MBEDTLS_X509_CSR_PARSE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_X509_CRT_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
- #error "MBEDTLS_X509_CRT_WRITE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_X509_CSR_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
- #error "MBEDTLS_X509_CSR_WRITE_C defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64)
- #error "MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 cannot be defined simultaneously"
- #endif /* MBEDTLS_HAVE_INT32 && MBEDTLS_HAVE_INT64 */
- #if ( defined(MBEDTLS_HAVE_INT32) || defined(MBEDTLS_HAVE_INT64) ) && \
- defined(MBEDTLS_HAVE_ASM)
- #error "MBEDTLS_HAVE_INT32/MBEDTLS_HAVE_INT64 and MBEDTLS_HAVE_ASM cannot be defined simultaneously"
- #endif /* (MBEDTLS_HAVE_INT32 || MBEDTLS_HAVE_INT64) && MBEDTLS_HAVE_ASM */
- #if defined(MBEDTLS_SSL_PROTO_SSL3)
- #if defined(MBEDTLS_DEPRECATED_REMOVED)
- #error "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS"
- #elif defined(MBEDTLS_DEPRECATED_WARNING)
- #warning "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS"
- #endif
- #endif /* MBEDTLS_SSL_PROTO_SSL3 */
- #if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
- #if defined(MBEDTLS_DEPRECATED_REMOVED)
- #error "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS"
- #elif defined(MBEDTLS_DEPRECATED_WARNING)
- #warning "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS"
- #endif
- #endif /* MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */
- #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
- #if defined(MBEDTLS_DEPRECATED_REMOVED)
- #error "MBEDTLS_SSL_HW_RECORD_ACCEL is deprecated and will be removed in a future version of Mbed TLS"
- #elif defined(MBEDTLS_DEPRECATED_WARNING)
- #warning "MBEDTLS_SSL_HW_RECORD_ACCEL is deprecated and will be removed in a future version of Mbed TLS"
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
- #if defined(MBEDTLS_SSL_DTLS_SRTP) && ( !defined(MBEDTLS_SSL_PROTO_DTLS) )
- #error "MBEDTLS_SSL_DTLS_SRTP defined, but not all prerequisites"
- #endif
- #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) && ( !defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) )
- #error "MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH defined, but not all prerequisites"
- #endif
- /*
- * Avoid warning from -pedantic. This is a convenient place for this
- * workaround since this is included by every single file before the
- * #if defined(MBEDTLS_xxx_C) that results in empty translation units.
- */
- typedef int mbedtls_iso_c_forbids_empty_translation_units;
- #endif /* MBEDTLS_CHECK_CONFIG_H */
- /********* Start of file include/mbedtls/platform.h ************/
- /**
- * \file platform.h
- *
- * \brief This file contains the definitions and functions of the
- * Mbed TLS platform abstraction layer.
- *
- * The platform abstraction layer removes the need for the library
- * to directly link to standard C library functions or operating
- * system services, making the library easier to port and embed.
- * Application developers and users of the library can provide their own
- * implementations of these functions, or implementations specific to
- * their platform, which can be statically linked to the library or
- * dynamically configured at runtime.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PLATFORM_H
- #define MBEDTLS_PLATFORM_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_HAVE_TIME)
- #endif
- /** Hardware accelerator failed */
- #define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070
- /** The requested feature is not supported by the platform */
- #define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- /* The older Microsoft Windows common runtime provides non-conforming
- * implementations of some standard library functions, including snprintf
- * and vsnprintf. This affects MSVC and MinGW builds.
- */
- #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER <= 1900)
- #define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF
- #define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF
- #endif
- #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
- #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF)
- #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */
- #else
- #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */
- #endif
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_VSNPRINTF)
- #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF)
- #define MBEDTLS_PLATFORM_STD_VSNPRINTF mbedtls_platform_win32_vsnprintf /**< The default \c vsnprintf function to use. */
- #else
- #define MBEDTLS_PLATFORM_STD_VSNPRINTF vsnprintf /**< The default \c vsnprintf function to use. */
- #endif
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
- #define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
- #define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
- #define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_FREE)
- #define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
- #define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_TIME)
- #define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
- #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< The default exit value to use. */
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
- #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< The default exit value to use. */
- #endif
- #if defined(MBEDTLS_FS_IO)
- #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
- #define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
- #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
- #endif
- #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
- #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
- #endif
- #endif /* MBEDTLS_FS_IO */
- #else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
- #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
- #include MBEDTLS_PLATFORM_STD_MEM_HDR
- #endif
- #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
- /* \} name SECTION: Module settings */
- /*
- * The function pointers for calloc and free.
- */
- #if defined(MBEDTLS_PLATFORM_MEMORY)
- #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
- defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
- #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
- #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
- #else
- /* For size_t */
- #include <stddef.h>
- extern void *mbedtls_calloc( size_t n, size_t size );
- extern void mbedtls_free( void *ptr );
- /**
- * \brief This function dynamically sets the memory-management
- * functions used by the library, during runtime.
- *
- * \param calloc_func The \c calloc function implementation.
- * \param free_func The \c free function implementation.
- *
- * \return \c 0.
- */
- int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
- void (*free_func)( void * ) );
- #endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
- #else /* !MBEDTLS_PLATFORM_MEMORY */
- #define mbedtls_free free
- #define mbedtls_calloc calloc
- #endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
- /*
- * The function pointers for fprintf
- */
- #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
- /* We need FILE * */
- #include <stdio.h>
- extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
- /**
- * \brief This function dynamically configures the fprintf
- * function that is called when the
- * mbedtls_fprintf() function is invoked by the library.
- *
- * \param fprintf_func The \c fprintf function implementation.
- *
- * \return \c 0.
- */
- int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
- ... ) );
- #else
- #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
- #define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
- #else
- #define mbedtls_fprintf fprintf
- #endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
- #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
- /*
- * The function pointers for printf
- */
- #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
- extern int (*mbedtls_printf)( const char *format, ... );
- /**
- * \brief This function dynamically configures the snprintf
- * function that is called when the mbedtls_snprintf()
- * function is invoked by the library.
- *
- * \param printf_func The \c printf function implementation.
- *
- * \return \c 0 on success.
- */
- int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
- #else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
- #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
- #define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
- #else
- #define mbedtls_printf printf
- #endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
- #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
- /*
- * The function pointers for snprintf
- *
- * The snprintf implementation should conform to C99:
- * - it *must* always correctly zero-terminate the buffer
- * (except when n == 0, then it must leave the buffer untouched)
- * - however it is acceptable to return -1 instead of the required length when
- * the destination buffer is too short.
- */
- #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF)
- /* For Windows (inc. MSYS2), we provide our own fixed implementation */
- int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
- #endif
- #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
- extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
- /**
- * \brief This function allows configuring a custom
- * \c snprintf function pointer.
- *
- * \param snprintf_func The \c snprintf function implementation.
- *
- * \return \c 0 on success.
- */
- int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
- const char * format, ... ) );
- #else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
- #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
- #define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
- #else
- #define mbedtls_snprintf MBEDTLS_PLATFORM_STD_SNPRINTF
- #endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
- #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
- /*
- * The function pointers for vsnprintf
- *
- * The vsnprintf implementation should conform to C99:
- * - it *must* always correctly zero-terminate the buffer
- * (except when n == 0, then it must leave the buffer untouched)
- * - however it is acceptable to return -1 instead of the required length when
- * the destination buffer is too short.
- */
- #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF)
- #include <stdarg.h>
- /* For Older Windows (inc. MSYS2), we provide our own fixed implementation */
- int mbedtls_platform_win32_vsnprintf( char *s, size_t n, const char *fmt, va_list arg );
- #endif
- #if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT)
- #include <stdarg.h>
- extern int (*mbedtls_vsnprintf)( char * s, size_t n, const char * format, va_list arg );
- /**
- * \brief Set your own snprintf function pointer
- *
- * \param vsnprintf_func The \c vsnprintf function implementation
- *
- * \return \c 0
- */
- int mbedtls_platform_set_vsnprintf( int (*vsnprintf_func)( char * s, size_t n,
- const char * format, va_list arg ) );
- #else /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */
- #if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO)
- #define mbedtls_vsnprintf MBEDTLS_PLATFORM_VSNPRINTF_MACRO
- #else
- #define mbedtls_vsnprintf vsnprintf
- #endif /* MBEDTLS_PLATFORM_VSNPRINTF_MACRO */
- #endif /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */
- /*
- * The function pointers for exit
- */
- #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
- extern void (*mbedtls_exit)( int status );
- /**
- * \brief This function dynamically configures the exit
- * function that is called when the mbedtls_exit()
- * function is invoked by the library.
- *
- * \param exit_func The \c exit function implementation.
- *
- * \return \c 0 on success.
- */
- int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
- #else
- #if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
- #define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
- #else
- #define mbedtls_exit exit
- #endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
- #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
- /*
- * The default exit values
- */
- #if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
- #define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
- #else
- #define MBEDTLS_EXIT_SUCCESS 0
- #endif
- #if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
- #define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
- #else
- #define MBEDTLS_EXIT_FAILURE 1
- #endif
- /*
- * The function pointers for reading from and writing a seed file to
- * Non-Volatile storage (NV) in a platform-independent way
- *
- * Only enabled when the NV seed entropy source is enabled
- */
- #if defined(MBEDTLS_ENTROPY_NV_SEED)
- #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
- /* Internal standard platform definitions */
- int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
- int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
- #endif
- #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
- extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
- extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
- /**
- * \brief This function allows configuring custom seed file writing and
- * reading functions.
- *
- * \param nv_seed_read_func The seed reading function implementation.
- * \param nv_seed_write_func The seed writing function implementation.
- *
- * \return \c 0 on success.
- */
- int mbedtls_platform_set_nv_seed(
- int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
- int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
- );
- #else
- #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
- defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
- #define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
- #define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
- #else
- #define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
- #define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
- #endif
- #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
- #endif /* MBEDTLS_ENTROPY_NV_SEED */
- #if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
- /**
- * \brief The platform context structure.
- *
- * \note This structure may be used to assist platform-specific
- * setup or teardown operations.
- */
- typedef struct mbedtls_platform_context
- {
- char dummy; /**< A placeholder member, as empty structs are not portable. */
- }
- mbedtls_platform_context;
- #else
- #endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
- /**
- * \brief This function performs any platform-specific initialization
- * operations.
- *
- * \note This function should be called before any other library functions.
- *
- * Its implementation is platform-specific, and unless
- * platform-specific code is provided, it does nothing.
- *
- * \note The usage and necessity of this function is dependent on the platform.
- *
- * \param ctx The platform context.
- *
- * \return \c 0 on success.
- */
- int mbedtls_platform_setup( mbedtls_platform_context *ctx );
- /**
- * \brief This function performs any platform teardown operations.
- *
- * \note This function should be called after every other Mbed TLS module
- * has been correctly freed using the appropriate free function.
- *
- * Its implementation is platform-specific, and unless
- * platform-specific code is provided, it does nothing.
- *
- * \note The usage and necessity of this function is dependent on the platform.
- *
- * \param ctx The platform context.
- *
- */
- void mbedtls_platform_teardown( mbedtls_platform_context *ctx );
- #ifdef __cplusplus
- }
- #endif
- #endif /* platform.h */
- /********* Start of file include/mbedtls/platform_time.h ************/
- /**
- * \file platform_time.h
- *
- * \brief mbed TLS Platform time abstraction
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PLATFORM_TIME_H
- #define MBEDTLS_PLATFORM_TIME_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- /*
- * The time_t datatype
- */
- #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
- typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
- #else
- /* For time_t */
- #include <time.h>
- typedef time_t mbedtls_time_t;
- #endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
- /*
- * The function pointers for time
- */
- #if defined(MBEDTLS_PLATFORM_TIME_ALT)
- extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time );
- /**
- * \brief Set your own time function pointer
- *
- * \param time_func the time function implementation
- *
- * \return 0
- */
- int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time ) );
- #else
- #if defined(MBEDTLS_PLATFORM_TIME_MACRO)
- #define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO
- #else
- #define mbedtls_time time
- #endif /* MBEDTLS_PLATFORM_TIME_MACRO */
- #endif /* MBEDTLS_PLATFORM_TIME_ALT */
- #ifdef __cplusplus
- }
- #endif
- #endif /* platform_time.h */
- /********* Start of file include/mbedtls/platform_util.h ************/
- /**
- * \file platform_util.h
- *
- * \brief Common and shared functions used by multiple modules in the Mbed TLS
- * library.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PLATFORM_UTIL_H
- #define MBEDTLS_PLATFORM_UTIL_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #if defined(MBEDTLS_HAVE_TIME_DATE)
- #include <time.h>
- #endif /* MBEDTLS_HAVE_TIME_DATE */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(MBEDTLS_CHECK_PARAMS)
- #if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
- /* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
- * (which is what our config.h suggests). */
- #include <assert.h>
- #endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
- #if defined(MBEDTLS_PARAM_FAILED)
- /** An alternative definition of MBEDTLS_PARAM_FAILED has been set in config.h.
- *
- * This flag can be used to check whether it is safe to assume that
- * MBEDTLS_PARAM_FAILED() will expand to a call to mbedtls_param_failed().
- */
- #define MBEDTLS_PARAM_FAILED_ALT
- #elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
- #define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
- #define MBEDTLS_PARAM_FAILED_ALT
- #else /* MBEDTLS_PARAM_FAILED */
- #define MBEDTLS_PARAM_FAILED( cond ) \
- mbedtls_param_failed( #cond, __FILE__, __LINE__ )
- /**
- * \brief User supplied callback function for parameter validation failure.
- * See #MBEDTLS_CHECK_PARAMS for context.
- *
- * This function will be called unless an alternative treatement
- * is defined through the #MBEDTLS_PARAM_FAILED macro.
- *
- * This function can return, and the operation will be aborted, or
- * alternatively, through use of setjmp()/longjmp() can resume
- * execution in the application code.
- *
- * \param failure_condition The assertion that didn't hold.
- * \param file The file where the assertion failed.
- * \param line The line in the file where the assertion failed.
- */
- void mbedtls_param_failed( const char *failure_condition,
- const char *file,
- int line );
- #endif /* MBEDTLS_PARAM_FAILED */
- /* Internal macro meant to be called only from within the library. */
- #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
- do { \
- if( !(cond) ) \
- { \
- MBEDTLS_PARAM_FAILED( cond ); \
- return( ret ); \
- } \
- } while( 0 )
- /* Internal macro meant to be called only from within the library. */
- #define MBEDTLS_INTERNAL_VALIDATE( cond ) \
- do { \
- if( !(cond) ) \
- { \
- MBEDTLS_PARAM_FAILED( cond ); \
- return; \
- } \
- } while( 0 )
- #else /* MBEDTLS_CHECK_PARAMS */
- /* Internal macros meant to be called only from within the library. */
- #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
- #define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
- #endif /* MBEDTLS_CHECK_PARAMS */
- /* Internal helper macros for deprecating API constants. */
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- /* Deliberately don't (yet) export MBEDTLS_DEPRECATED here
- * to avoid conflict with other headers which define and use
- * it, too. We might want to move all these definitions here at
- * some point for uniformity. */
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_string_constant_t;
- #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \
- ( (mbedtls_deprecated_string_constant_t) ( VAL ) )
- MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
- #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) \
- ( (mbedtls_deprecated_numeric_constant_t) ( VAL ) )
- #undef MBEDTLS_DEPRECATED
- #else /* MBEDTLS_DEPRECATED_WARNING */
- #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL
- #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) VAL
- #endif /* MBEDTLS_DEPRECATED_WARNING */
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- /* Implementation of the check-return facility.
- * See the user documentation in config.h.
- *
- * Do not use this macro directly to annotate function: instead,
- * use one of MBEDTLS_CHECK_RETURN_CRITICAL or MBEDTLS_CHECK_RETURN_TYPICAL
- * depending on how important it is to check the return value.
- */
- #if !defined(MBEDTLS_CHECK_RETURN)
- #if defined(__GNUC__)
- #define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__))
- #elif defined(_MSC_VER) && _MSC_VER >= 1700
- #include <sal.h>
- #define MBEDTLS_CHECK_RETURN _Check_return_
- #else
- #define MBEDTLS_CHECK_RETURN
- #endif
- #endif
- /** Critical-failure function
- *
- * This macro appearing at the beginning of the declaration of a function
- * indicates that its return value should be checked in all applications.
- * Omitting the check is very likely to indicate a bug in the application
- * and will result in a compile-time warning if #MBEDTLS_CHECK_RETURN
- * is implemented for the compiler in use.
- *
- * \note The use of this macro is a work in progress.
- * This macro may be added to more functions in the future.
- * Such an extension is not considered an API break, provided that
- * there are near-unavoidable circumstances under which the function
- * can fail. For example, signature/MAC/AEAD verification functions,
- * and functions that require a random generator, are considered
- * return-check-critical.
- */
- #define MBEDTLS_CHECK_RETURN_CRITICAL MBEDTLS_CHECK_RETURN
- /** Ordinary-failure function
- *
- * This macro appearing at the beginning of the declaration of a function
- * indicates that its return value should be generally be checked in portable
- * applications. Omitting the check will result in a compile-time warning if
- * #MBEDTLS_CHECK_RETURN is implemented for the compiler in use and
- * #MBEDTLS_CHECK_RETURN_WARNING is enabled in the compile-time configuration.
- *
- * You can use #MBEDTLS_IGNORE_RETURN to explicitly ignore the return value
- * of a function that is annotated with #MBEDTLS_CHECK_RETURN.
- *
- * \note The use of this macro is a work in progress.
- * This macro will be added to more functions in the future.
- * Eventually this should appear before most functions returning
- * an error code (as \c int in the \c mbedtls_xxx API or
- * as ::psa_status_t in the \c psa_xxx API).
- */
- #if defined(MBEDTLS_CHECK_RETURN_WARNING)
- #define MBEDTLS_CHECK_RETURN_TYPICAL MBEDTLS_CHECK_RETURN
- #else
- #define MBEDTLS_CHECK_RETURN_TYPICAL
- #endif
- /** Benign-failure function
- *
- * This macro appearing at the beginning of the declaration of a function
- * indicates that it is rarely useful to check its return value.
- *
- * This macro has an empty expansion. It exists for documentation purposes:
- * a #MBEDTLS_CHECK_RETURN_OPTIONAL annotation indicates that the function
- * has been analyzed for return-check usefuless, whereas the lack of
- * an annotation indicates that the function has not been analyzed and its
- * return-check usefulness is unknown.
- */
- #define MBEDTLS_CHECK_RETURN_OPTIONAL
- /** \def MBEDTLS_IGNORE_RETURN
- *
- * Call this macro with one argument, a function call, to suppress a warning
- * from #MBEDTLS_CHECK_RETURN due to that function call.
- */
- #if !defined(MBEDTLS_IGNORE_RETURN)
- /* GCC doesn't silence the warning with just (void)(result).
- * (void)!(result) is known to work up at least up to GCC 10, as well
- * as with Clang and MSVC.
- *
- * https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Non_002dbugs.html
- * https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result
- * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34
- */
- #define MBEDTLS_IGNORE_RETURN(result) ( (void) !( result ) )
- #endif
- /**
- * \brief Securely zeroize a buffer
- *
- * The function is meant to wipe the data contained in a buffer so
- * that it can no longer be recovered even if the program memory
- * is later compromised. Call this function on sensitive data
- * stored on the stack before returning from a function, and on
- * sensitive data stored on the heap before freeing the heap
- * object.
- *
- * It is extremely difficult to guarantee that calls to
- * mbedtls_platform_zeroize() are not removed by aggressive
- * compiler optimizations in a portable way. For this reason, Mbed
- * TLS provides the configuration option
- * MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure
- * mbedtls_platform_zeroize() to use a suitable implementation for
- * their platform and needs
- *
- * \param buf Buffer to be zeroized
- * \param len Length of the buffer in bytes
- *
- */
- void mbedtls_platform_zeroize( void *buf, size_t len );
- #if defined(MBEDTLS_HAVE_TIME_DATE)
- /**
- * \brief Platform-specific implementation of gmtime_r()
- *
- * The function is a thread-safe abstraction that behaves
- * similarly to the gmtime_r() function from Unix/POSIX.
- *
- * Mbed TLS will try to identify the underlying platform and
- * make use of an appropriate underlying implementation (e.g.
- * gmtime_r() for POSIX and gmtime_s() for Windows). If this is
- * not possible, then gmtime() will be used. In this case, calls
- * from the library to gmtime() will be guarded by the mutex
- * mbedtls_threading_gmtime_mutex if MBEDTLS_THREADING_C is
- * enabled. It is recommended that calls from outside the library
- * are also guarded by this mutex.
- *
- * If MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, then Mbed TLS will
- * unconditionally use the alternative implementation for
- * mbedtls_platform_gmtime_r() supplied by the user at compile time.
- *
- * \param tt Pointer to an object containing time (in seconds) since the
- * epoch to be converted
- * \param tm_buf Pointer to an object where the results will be stored
- *
- * \return Pointer to an object of type struct tm on success, otherwise
- * NULL
- */
- struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
- struct tm *tm_buf );
- #endif /* MBEDTLS_HAVE_TIME_DATE */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_PLATFORM_UTIL_H */
- /********* Start of file include/mbedtls/threading.h ************/
- /**
- * \file threading.h
- *
- * \brief Threading abstraction layer
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_THREADING_H
- #define MBEDTLS_THREADING_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stdlib.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /* MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE is deprecated and should not be
- * used. */
- /** The selected feature is not available. */
- #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C
- /** Locking / unlocking / free failed with error code. */
- #define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E
- #if defined(MBEDTLS_THREADING_PTHREAD)
- #include <pthread.h>
- typedef struct mbedtls_threading_mutex_t
- {
- pthread_mutex_t mutex;
- /* is_valid is 0 after a failed init or a free, and nonzero after a
- * successful init. This field is not considered part of the public
- * API of Mbed TLS and may change without notice. */
- char is_valid;
- } mbedtls_threading_mutex_t;
- #endif
- #if defined(MBEDTLS_THREADING_ALT)
- /* You should define the mbedtls_threading_mutex_t type in your header */
- /**
- * \brief Set your alternate threading implementation function
- * pointers and initialize global mutexes. If used, this
- * function must be called once in the main thread before any
- * other mbed TLS function is called, and
- * mbedtls_threading_free_alt() must be called once in the main
- * thread after all other mbed TLS functions.
- *
- * \note mutex_init() and mutex_free() don't return a status code.
- * If mutex_init() fails, it should leave its argument (the
- * mutex) in a state such that mutex_lock() will fail when
- * called with this argument.
- *
- * \param mutex_init the init function implementation
- * \param mutex_free the free function implementation
- * \param mutex_lock the lock function implementation
- * \param mutex_unlock the unlock function implementation
- */
- void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
- void (*mutex_free)( mbedtls_threading_mutex_t * ),
- int (*mutex_lock)( mbedtls_threading_mutex_t * ),
- int (*mutex_unlock)( mbedtls_threading_mutex_t * ) );
- /**
- * \brief Free global mutexes.
- */
- void mbedtls_threading_free_alt( void );
- #endif /* MBEDTLS_THREADING_ALT */
- #if defined(MBEDTLS_THREADING_C)
- /*
- * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
- *
- * All these functions are expected to work or the result will be undefined.
- */
- extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex );
- extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex );
- extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex );
- extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
- /*
- * Global mutexes
- */
- #if defined(MBEDTLS_FS_IO)
- extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
- #endif
- #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
- /* This mutex may or may not be used in the default definition of
- * mbedtls_platform_gmtime_r(), but in order to determine that,
- * we need to check POSIX features, hence modify _POSIX_C_SOURCE.
- * With the current approach, this declaration is orphaned, lacking
- * an accompanying definition, in case mbedtls_platform_gmtime_r()
- * doesn't need it, but that's not a problem. */
- extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
- #endif /* MBEDTLS_HAVE_TIME_DATE && !MBEDTLS_PLATFORM_GMTIME_R_ALT */
- #endif /* MBEDTLS_THREADING_C */
- #ifdef __cplusplus
- }
- #endif
- #endif /* threading.h */
- /********* Start of file include/mbedtls/bignum.h ************/
- /**
- * \file bignum.h
- *
- * \brief Multi-precision integer library
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_BIGNUM_H
- #define MBEDTLS_BIGNUM_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- #if defined(MBEDTLS_FS_IO)
- #include <stdio.h>
- #endif
- /** An error occurred while reading from or writing to a file. */
- #define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004
- /** There is an invalid character in the digit string. */
- #define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006
- /** The buffer is too small to write to. */
- #define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008
- /** The input arguments are negative or result in illegal output. */
- #define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A
- /** The input argument for division is zero, which is not allowed. */
- #define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C
- /** The input arguments are not acceptable. */
- #define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E
- /** Memory allocation failed. */
- #define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010
- #define MBEDTLS_MPI_CHK(f) \
- do \
- { \
- if( ( ret = (f) ) != 0 ) \
- goto cleanup; \
- } while( 0 )
- /*
- * Maximum size MPIs are allowed to grow to in number of limbs.
- */
- #define MBEDTLS_MPI_MAX_LIMBS 10000
- #if !defined(MBEDTLS_MPI_WINDOW_SIZE)
- /*
- * Maximum window size used for modular exponentiation. Default: 6
- * Minimum value: 1. Maximum value: 6.
- *
- * Result is an array of ( 2 ** MBEDTLS_MPI_WINDOW_SIZE ) MPIs used
- * for the sliding window calculation. (So 64 by default)
- *
- * Reduction in size, reduces speed.
- */
- #define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum window size used. */
- #endif /* !MBEDTLS_MPI_WINDOW_SIZE */
- #if !defined(MBEDTLS_MPI_MAX_SIZE)
- /*
- * Maximum size of MPIs allowed in bits and bytes for user-MPIs.
- * ( Default: 512 bytes => 4096 bits, Maximum tested: 2048 bytes => 16384 bits )
- *
- * Note: Calculations can temporarily result in larger MPIs. So the number
- * of limbs required (MBEDTLS_MPI_MAX_LIMBS) is higher.
- */
- #define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
- #endif /* !MBEDTLS_MPI_MAX_SIZE */
- #define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */
- /*
- * When reading from files with mbedtls_mpi_read_file() and writing to files with
- * mbedtls_mpi_write_file() the buffer should have space
- * for a (short) label, the MPI (in the provided radix), the newline
- * characters and the '\0'.
- *
- * By default we assume at least a 10 char label, a minimum radix of 10
- * (decimal) and a maximum of 4096 bit numbers (1234 decimal chars).
- * Autosized at compile time for at least a 10 char label, a minimum radix
- * of 10 (decimal) for a number of MBEDTLS_MPI_MAX_BITS size.
- *
- * This used to be statically sized to 1250 for a maximum of 4096 bit
- * numbers (1234 decimal chars).
- *
- * Calculate using the formula:
- * MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) +
- * LabelSize + 6
- */
- #define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS )
- #define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332
- #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 )
- /*
- * Define the base integer type, architecture-wise.
- *
- * 32 or 64-bit integer types can be forced regardless of the underlying
- * architecture by defining MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64
- * respectively and undefining MBEDTLS_HAVE_ASM.
- *
- * Double-width integers (e.g. 128-bit in 64-bit architectures) can be
- * disabled by defining MBEDTLS_NO_UDBL_DIVISION.
- */
- #if !defined(MBEDTLS_HAVE_INT32)
- #if defined(_MSC_VER) && defined(_M_AMD64)
- /* Always choose 64-bit when using MSC */
- #if !defined(MBEDTLS_HAVE_INT64)
- #define MBEDTLS_HAVE_INT64
- #endif /* !MBEDTLS_HAVE_INT64 */
- typedef int64_t mbedtls_mpi_sint;
- typedef uint64_t mbedtls_mpi_uint;
- #elif defined(__GNUC__) && ( \
- defined(__amd64__) || defined(__x86_64__) || \
- defined(__ppc64__) || defined(__powerpc64__) || \
- defined(__ia64__) || defined(__alpha__) || \
- ( defined(__sparc__) && defined(__arch64__) ) || \
- defined(__s390x__) || defined(__mips64) || \
- defined(__aarch64__) )
- #if !defined(MBEDTLS_HAVE_INT64)
- #define MBEDTLS_HAVE_INT64
- #endif /* MBEDTLS_HAVE_INT64 */
- typedef int64_t mbedtls_mpi_sint;
- typedef uint64_t mbedtls_mpi_uint;
- #if !defined(MBEDTLS_NO_UDBL_DIVISION)
- /* mbedtls_t_udbl defined as 128-bit unsigned int */
- typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
- #define MBEDTLS_HAVE_UDBL
- #endif /* !MBEDTLS_NO_UDBL_DIVISION */
- #elif defined(__ARMCC_VERSION) && defined(__aarch64__)
- /*
- * __ARMCC_VERSION is defined for both armcc and armclang and
- * __aarch64__ is only defined by armclang when compiling 64-bit code
- */
- #if !defined(MBEDTLS_HAVE_INT64)
- #define MBEDTLS_HAVE_INT64
- #endif /* !MBEDTLS_HAVE_INT64 */
- typedef int64_t mbedtls_mpi_sint;
- typedef uint64_t mbedtls_mpi_uint;
- #if !defined(MBEDTLS_NO_UDBL_DIVISION)
- /* mbedtls_t_udbl defined as 128-bit unsigned int */
- typedef __uint128_t mbedtls_t_udbl;
- #define MBEDTLS_HAVE_UDBL
- #endif /* !MBEDTLS_NO_UDBL_DIVISION */
- #elif defined(MBEDTLS_HAVE_INT64)
- /* Force 64-bit integers with unknown compiler */
- typedef int64_t mbedtls_mpi_sint;
- typedef uint64_t mbedtls_mpi_uint;
- #endif
- #endif /* !MBEDTLS_HAVE_INT32 */
- #if !defined(MBEDTLS_HAVE_INT64)
- /* Default to 32-bit compilation */
- #if !defined(MBEDTLS_HAVE_INT32)
- #define MBEDTLS_HAVE_INT32
- #endif /* !MBEDTLS_HAVE_INT32 */
- typedef int32_t mbedtls_mpi_sint;
- typedef uint32_t mbedtls_mpi_uint;
- #if !defined(MBEDTLS_NO_UDBL_DIVISION)
- typedef uint64_t mbedtls_t_udbl;
- #define MBEDTLS_HAVE_UDBL
- #endif /* !MBEDTLS_NO_UDBL_DIVISION */
- #endif /* !MBEDTLS_HAVE_INT64 */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief MPI structure
- */
- typedef struct mbedtls_mpi
- {
- int s; /*!< Sign: -1 if the mpi is negative, 1 otherwise */
- size_t n; /*!< total # of limbs */
- mbedtls_mpi_uint *p; /*!< pointer to limbs */
- }
- mbedtls_mpi;
- /**
- * \brief Initialize an MPI context.
- *
- * This makes the MPI ready to be set or freed,
- * but does not define a value for the MPI.
- *
- * \param X The MPI context to initialize. This must not be \c NULL.
- */
- void mbedtls_mpi_init( mbedtls_mpi *X );
- /**
- * \brief This function frees the components of an MPI context.
- *
- * \param X The MPI context to be cleared. This may be \c NULL,
- * in which case this function is a no-op. If it is
- * not \c NULL, it must point to an initialized MPI.
- */
- void mbedtls_mpi_free( mbedtls_mpi *X );
- /**
- * \brief Enlarge an MPI to the specified number of limbs.
- *
- * \note This function does nothing if the MPI is
- * already large enough.
- *
- * \param X The MPI to grow. It must be initialized.
- * \param nblimbs The target number of limbs.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs );
- /**
- * \brief This function resizes an MPI downwards, keeping at least the
- * specified number of limbs.
- *
- * If \c X is smaller than \c nblimbs, it is resized up
- * instead.
- *
- * \param X The MPI to shrink. This must point to an initialized MPI.
- * \param nblimbs The minimum number of limbs to keep.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
- * (this can only happen when resizing up).
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs );
- /**
- * \brief Make a copy of an MPI.
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param Y The source MPI. This must point to an initialized MPI.
- *
- * \note The limb-buffer in the destination MPI is enlarged
- * if necessary to hold the value in the source MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y );
- /**
- * \brief Swap the contents of two MPIs.
- *
- * \param X The first MPI. It must be initialized.
- * \param Y The second MPI. It must be initialized.
- */
- void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
- /**
- * \brief Perform a safe conditional copy of MPI which doesn't
- * reveal whether the condition was true or not.
- *
- * \param X The MPI to conditionally assign to. This must point
- * to an initialized MPI.
- * \param Y The MPI to be assigned from. This must point to an
- * initialized MPI.
- * \param assign The condition deciding whether to perform the
- * assignment or not. Possible values:
- * * \c 1: Perform the assignment `X = Y`.
- * * \c 0: Keep the original value of \p X.
- *
- * \note This function is equivalent to
- * `if( assign ) mbedtls_mpi_copy( X, Y );`
- * except that it avoids leaking any information about whether
- * the assignment was done or not (the above code may leak
- * information through branch prediction and/or memory access
- * patterns analysis).
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign );
- /**
- * \brief Perform a safe conditional swap which doesn't
- * reveal whether the condition was true or not.
- *
- * \param X The first MPI. This must be initialized.
- * \param Y The second MPI. This must be initialized.
- * \param assign The condition deciding whether to perform
- * the swap or not. Possible values:
- * * \c 1: Swap the values of \p X and \p Y.
- * * \c 0: Keep the original values of \p X and \p Y.
- *
- * \note This function is equivalent to
- * if( assign ) mbedtls_mpi_swap( X, Y );
- * except that it avoids leaking any information about whether
- * the assignment was done or not (the above code may leak
- * information through branch prediction and/or memory access
- * patterns analysis).
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on other kinds of failure.
- *
- */
- int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign );
- /**
- * \brief Store integer value in MPI.
- *
- * \param X The MPI to set. This must be initialized.
- * \param z The value to use.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z );
- /**
- * \brief Get a specific bit from an MPI.
- *
- * \param X The MPI to query. This must be initialized.
- * \param pos Zero-based index of the bit to query.
- *
- * \return \c 0 or \c 1 on success, depending on whether bit \c pos
- * of \c X is unset or set.
- * \return A negative error code on failure.
- */
- int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos );
- /**
- * \brief Modify a specific bit in an MPI.
- *
- * \note This function will grow the target MPI if necessary to set a
- * bit to \c 1 in a not yet existing limb. It will not grow if
- * the bit should be set to \c 0.
- *
- * \param X The MPI to modify. This must be initialized.
- * \param pos Zero-based index of the bit to modify.
- * \param val The desired value of bit \c pos: \c 0 or \c 1.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val );
- /**
- * \brief Return the number of bits of value \c 0 before the
- * least significant bit of value \c 1.
- *
- * \note This is the same as the zero-based index of
- * the least significant bit of value \c 1.
- *
- * \param X The MPI to query.
- *
- * \return The number of bits of value \c 0 before the least significant
- * bit of value \c 1 in \p X.
- */
- size_t mbedtls_mpi_lsb( const mbedtls_mpi *X );
- /**
- * \brief Return the number of bits up to and including the most
- * significant bit of value \c 1.
- *
- * * \note This is same as the one-based index of the most
- * significant bit of value \c 1.
- *
- * \param X The MPI to query. This must point to an initialized MPI.
- *
- * \return The number of bits up to and including the most
- * significant bit of value \c 1.
- */
- size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X );
- /**
- * \brief Return the total size of an MPI value in bytes.
- *
- * \param X The MPI to use. This must point to an initialized MPI.
- *
- * \note The value returned by this function may be less than
- * the number of bytes used to store \p X internally.
- * This happens if and only if there are trailing bytes
- * of value zero.
- *
- * \return The least number of bytes capable of storing
- * the absolute value of \p X.
- */
- size_t mbedtls_mpi_size( const mbedtls_mpi *X );
- /**
- * \brief Import an MPI from an ASCII string.
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param radix The numeric base of the input string.
- * \param s Null-terminated string buffer.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s );
- /**
- * \brief Export an MPI to an ASCII string.
- *
- * \param X The source MPI. This must point to an initialized MPI.
- * \param radix The numeric base of the output string.
- * \param buf The buffer to write the string to. This must be writable
- * buffer of length \p buflen Bytes.
- * \param buflen The available size in Bytes of \p buf.
- * \param olen The address at which to store the length of the string
- * written, including the final \c NULL byte. This must
- * not be \c NULL.
- *
- * \note You can call this function with `buflen == 0` to obtain the
- * minimum required buffer size in `*olen`.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the target buffer \p buf
- * is too small to hold the value of \p X in the desired base.
- * In this case, `*olen` is nonetheless updated to contain the
- * size of \p buf required for a successful call.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
- char *buf, size_t buflen, size_t *olen );
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief Read an MPI from a line in an opened file.
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param radix The numeric base of the string representation used
- * in the source line.
- * \param fin The input file handle to use. This must not be \c NULL.
- *
- * \note On success, this function advances the file stream
- * to the end of the current line or to EOF.
- *
- * The function returns \c 0 on an empty line.
- *
- * Leading whitespaces are ignored, as is a
- * '0x' prefix for radix \c 16.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the file read buffer
- * is too small.
- * \return Another negative error code on failure.
- */
- int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
- /**
- * \brief Export an MPI into an opened file.
- *
- * \param p A string prefix to emit prior to the MPI data.
- * For example, this might be a label, or "0x" when
- * printing in base \c 16. This may be \c NULL if no prefix
- * is needed.
- * \param X The source MPI. This must point to an initialized MPI.
- * \param radix The numeric base to be used in the emitted string.
- * \param fout The output file handle. This may be \c NULL, in which case
- * the output is written to \c stdout.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X,
- int radix, FILE *fout );
- #endif /* MBEDTLS_FS_IO */
- /**
- * \brief Import an MPI from unsigned big endian binary data.
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param buf The input buffer. This must be a readable buffer of length
- * \p buflen Bytes.
- * \param buflen The length of the input buffer \p p in Bytes.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf,
- size_t buflen );
- /**
- * \brief Import X from unsigned binary data, little endian
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param buf The input buffer. This must be a readable buffer of length
- * \p buflen Bytes.
- * \param buflen The length of the input buffer \p p in Bytes.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_read_binary_le( mbedtls_mpi *X,
- const unsigned char *buf, size_t buflen );
- /**
- * \brief Export X into unsigned binary data, big endian.
- * Always fills the whole buffer, which will start with zeros
- * if the number is smaller.
- *
- * \param X The source MPI. This must point to an initialized MPI.
- * \param buf The output buffer. This must be a writable buffer of length
- * \p buflen Bytes.
- * \param buflen The size of the output buffer \p buf in Bytes.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't
- * large enough to hold the value of \p X.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf,
- size_t buflen );
- /**
- * \brief Export X into unsigned binary data, little endian.
- * Always fills the whole buffer, which will end with zeros
- * if the number is smaller.
- *
- * \param X The source MPI. This must point to an initialized MPI.
- * \param buf The output buffer. This must be a writable buffer of length
- * \p buflen Bytes.
- * \param buflen The size of the output buffer \p buf in Bytes.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't
- * large enough to hold the value of \p X.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X,
- unsigned char *buf, size_t buflen );
- /**
- * \brief Perform a left-shift on an MPI: X <<= count
- *
- * \param X The MPI to shift. This must point to an initialized MPI.
- * \param count The number of bits to shift by.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count );
- /**
- * \brief Perform a right-shift on an MPI: X >>= count
- *
- * \param X The MPI to shift. This must point to an initialized MPI.
- * \param count The number of bits to shift by.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count );
- /**
- * \brief Compare the absolute values of two MPIs.
- *
- * \param X The left-hand MPI. This must point to an initialized MPI.
- * \param Y The right-hand MPI. This must point to an initialized MPI.
- *
- * \return \c 1 if `|X|` is greater than `|Y|`.
- * \return \c -1 if `|X|` is lesser than `|Y|`.
- * \return \c 0 if `|X|` is equal to `|Y|`.
- */
- int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
- /**
- * \brief Compare two MPIs.
- *
- * \param X The left-hand MPI. This must point to an initialized MPI.
- * \param Y The right-hand MPI. This must point to an initialized MPI.
- *
- * \return \c 1 if \p X is greater than \p Y.
- * \return \c -1 if \p X is lesser than \p Y.
- * \return \c 0 if \p X is equal to \p Y.
- */
- int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
- /**
- * \brief Check if an MPI is less than the other in constant time.
- *
- * \param X The left-hand MPI. This must point to an initialized MPI
- * with the same allocated length as Y.
- * \param Y The right-hand MPI. This must point to an initialized MPI
- * with the same allocated length as X.
- * \param ret The result of the comparison:
- * \c 1 if \p X is less than \p Y.
- * \c 0 if \p X is greater than or equal to \p Y.
- *
- * \return 0 on success.
- * \return MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the allocated length of
- * the two input MPIs is not the same.
- */
- int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y,
- unsigned *ret );
- /**
- * \brief Compare an MPI with an integer.
- *
- * \param X The left-hand MPI. This must point to an initialized MPI.
- * \param z The integer value to compare \p X to.
- *
- * \return \c 1 if \p X is greater than \p z.
- * \return \c -1 if \p X is lesser than \p z.
- * \return \c 0 if \p X is equal to \p z.
- */
- int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z );
- /**
- * \brief Perform an unsigned addition of MPIs: X = |A| + |B|
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The first summand. This must point to an initialized MPI.
- * \param B The second summand. This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Perform an unsigned subtraction of MPIs: X = |A| - |B|
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The minuend. This must point to an initialized MPI.
- * \param B The subtrahend. This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p B is greater than \p A.
- * \return Another negative error code on different kinds of failure.
- *
- */
- int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Perform a signed addition of MPIs: X = A + B
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The first summand. This must point to an initialized MPI.
- * \param B The second summand. This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Perform a signed subtraction of MPIs: X = A - B
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The minuend. This must point to an initialized MPI.
- * \param B The subtrahend. This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Perform a signed addition of an MPI and an integer: X = A + b
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The first summand. This must point to an initialized MPI.
- * \param b The second summand.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A,
- mbedtls_mpi_sint b );
- /**
- * \brief Perform a signed subtraction of an MPI and an integer:
- * X = A - b
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The minuend. This must point to an initialized MPI.
- * \param b The subtrahend.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A,
- mbedtls_mpi_sint b );
- /**
- * \brief Perform a multiplication of two MPIs: X = A * B
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The first factor. This must point to an initialized MPI.
- * \param B The second factor. This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- *
- */
- int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Perform a multiplication of an MPI with an unsigned integer:
- * X = A * b
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The first factor. This must point to an initialized MPI.
- * \param b The second factor.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- *
- */
- int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A,
- mbedtls_mpi_uint b );
- /**
- * \brief Perform a division with remainder of two MPIs:
- * A = Q * B + R
- *
- * \param Q The destination MPI for the quotient.
- * This may be \c NULL if the value of the
- * quotient is not needed.
- * \param R The destination MPI for the remainder value.
- * This may be \c NULL if the value of the
- * remainder is not needed.
- * \param A The dividend. This must point to an initialized MPi.
- * \param B The divisor. This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p B equals zero.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Perform a division with remainder of an MPI by an integer:
- * A = Q * b + R
- *
- * \param Q The destination MPI for the quotient.
- * This may be \c NULL if the value of the
- * quotient is not needed.
- * \param R The destination MPI for the remainder value.
- * This may be \c NULL if the value of the
- * remainder is not needed.
- * \param A The dividend. This must point to an initialized MPi.
- * \param b The divisor.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p b equals zero.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
- mbedtls_mpi_sint b );
- /**
- * \brief Perform a modular reduction. R = A mod B
- *
- * \param R The destination MPI for the residue value.
- * This must point to an initialized MPI.
- * \param A The MPI to compute the residue of.
- * This must point to an initialized MPI.
- * \param B The base of the modular reduction.
- * This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p B equals zero.
- * \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p B is negative.
- * \return Another negative error code on different kinds of failure.
- *
- */
- int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Perform a modular reduction with respect to an integer.
- * r = A mod b
- *
- * \param r The address at which to store the residue.
- * This must not be \c NULL.
- * \param A The MPI to compute the residue of.
- * This must point to an initialized MPi.
- * \param b The integer base of the modular reduction.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p b equals zero.
- * \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p b is negative.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A,
- mbedtls_mpi_sint b );
- /**
- * \brief Perform a sliding-window exponentiation: X = A^E mod N
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The base of the exponentiation.
- * This must point to an initialized MPI.
- * \param E The exponent MPI. This must point to an initialized MPI.
- * \param N The base for the modular reduction. This must point to an
- * initialized MPI.
- * \param prec_RR A helper MPI depending solely on \p N which can be used to
- * speed-up multiple modular exponentiations for the same value
- * of \p N. This may be \c NULL. If it is not \c NULL, it must
- * point to an initialized MPI. If it hasn't been used after
- * the call to mbedtls_mpi_init(), this function will compute
- * the helper value and store it in \p prec_RR for reuse on
- * subsequent calls to this function. Otherwise, the function
- * will assume that \p prec_RR holds the helper value set by a
- * previous call to mbedtls_mpi_exp_mod(), and reuse it.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \c N is negative or
- * even, or if \c E is negative.
- * \return Another negative error code on different kinds of failures.
- *
- */
- int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
- const mbedtls_mpi *E, const mbedtls_mpi *N,
- mbedtls_mpi *prec_RR );
- /**
- * \brief Fill an MPI with a number of random bytes.
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param size The number of random bytes to generate.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng doesn't need a context argument.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on failure.
- *
- * \note The bytes obtained from the RNG are interpreted
- * as a big-endian representation of an MPI; this can
- * be relevant in applications like deterministic ECDSA.
- */
- int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /** Generate a random number uniformly in a range.
- *
- * This function generates a random number between \p min inclusive and
- * \p N exclusive.
- *
- * The procedure complies with RFC 6979 §3.3 (deterministic ECDSA)
- * when the RNG is a suitably parametrized instance of HMAC_DRBG
- * and \p min is \c 1.
- *
- * \note There are `N - min` possible outputs. The lower bound
- * \p min can be reached, but the upper bound \p N cannot.
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param min The minimum value to return.
- * It must be nonnegative.
- * \param N The upper bound of the range, exclusive.
- * In other words, this is one plus the maximum value to return.
- * \p N must be strictly larger than \p min.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p min or \p N is invalid
- * or if they are incompatible.
- * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if the implementation was
- * unable to find a suitable value within a limited number
- * of attempts. This has a negligible probability if \p N
- * is significantly larger than \p min, which is the case
- * for all usual cryptographic applications.
- * \return Another negative error code on failure.
- */
- int mbedtls_mpi_random( mbedtls_mpi *X,
- mbedtls_mpi_sint min,
- const mbedtls_mpi *N,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief Compute the greatest common divisor: G = gcd(A, B)
- *
- * \param G The destination MPI. This must point to an initialized MPI.
- * \param A The first operand. This must point to an initialized MPI.
- * \param B The second operand. This must point to an initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A,
- const mbedtls_mpi *B );
- /**
- * \brief Compute the modular inverse: X = A^-1 mod N
- *
- * \param X The destination MPI. This must point to an initialized MPI.
- * \param A The MPI to calculate the modular inverse of. This must point
- * to an initialized MPI.
- * \param N The base of the modular inversion. This must point to an
- * initialized MPI.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p N is less than
- * or equal to one.
- * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p has no modular inverse
- * with respect to \p N.
- */
- int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
- const mbedtls_mpi *N );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief Perform a Miller-Rabin primality test with error
- * probability of 2<sup>-80</sup>.
- *
- * \deprecated Superseded by mbedtls_mpi_is_prime_ext() which allows
- * specifying the number of Miller-Rabin rounds.
- *
- * \param X The MPI to check for primality.
- * This must point to an initialized MPI.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng.
- * This may be \c NULL if \p f_rng doesn't use a
- * context parameter.
- *
- * \return \c 0 if successful, i.e. \p X is probably prime.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime.
- * \return Another negative error code on other kinds of failure.
- */
- MBEDTLS_DEPRECATED int mbedtls_mpi_is_prime( const mbedtls_mpi *X,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief Miller-Rabin primality test.
- *
- * \warning If \p X is potentially generated by an adversary, for example
- * when validating cryptographic parameters that you didn't
- * generate yourself and that are supposed to be prime, then
- * \p rounds should be at least the half of the security
- * strength of the cryptographic algorithm. On the other hand,
- * if \p X is chosen uniformly or non-adversially (as is the
- * case when mbedtls_mpi_gen_prime calls this function), then
- * \p rounds can be much lower.
- *
- * \param X The MPI to check for primality.
- * This must point to an initialized MPI.
- * \param rounds The number of bases to perform the Miller-Rabin primality
- * test for. The probability of returning 0 on a composite is
- * at most 2<sup>-2*\p rounds</sup>.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng.
- * This may be \c NULL if \p f_rng doesn't use
- * a context parameter.
- *
- * \return \c 0 if successful, i.e. \p X is probably prime.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief Flags for mbedtls_mpi_gen_prime()
- *
- * Each of these flags is a constraint on the result X returned by
- * mbedtls_mpi_gen_prime().
- */
- typedef enum {
- MBEDTLS_MPI_GEN_PRIME_FLAG_DH = 0x0001, /**< (X-1)/2 is prime too */
- MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR = 0x0002, /**< lower error rate from 2<sup>-80</sup> to 2<sup>-128</sup> */
- } mbedtls_mpi_gen_prime_flag_t;
- /**
- * \brief Generate a prime number.
- *
- * \param X The destination MPI to store the generated prime in.
- * This must point to an initialized MPi.
- * \param nbits The required size of the destination MPI in bits.
- * This must be between \c 3 and #MBEDTLS_MPI_MAX_BITS.
- * \param flags A mask of flags of type #mbedtls_mpi_gen_prime_flag_t.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng.
- * This may be \c NULL if \p f_rng doesn't use
- * a context parameter.
- *
- * \return \c 0 if successful, in which case \p X holds a
- * probably prime number.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
- * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `nbits` is not between
- * \c 3 and #MBEDTLS_MPI_MAX_BITS.
- */
- int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- int mbedtls_mpi_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* bignum.h */
- /********* Start of file include/mbedtls/constant_time.h ************/
- /**
- * Constant-time functions
- *
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CONSTANT_TIME_H
- #define MBEDTLS_CONSTANT_TIME_H
- #include <stddef.h>
- /** Constant-time buffer comparison without branches.
- *
- * This is equivalent to the standard memcmp function, but is likely to be
- * compiled to code using bitwise operation rather than a branch.
- *
- * This function can be used to write constant-time code by replacing branches
- * with bit operations using masks.
- *
- * \param a Pointer to the first buffer.
- * \param b Pointer to the second buffer.
- * \param n The number of bytes to compare in the buffer.
- *
- * \return Zero if the content of the two buffer is the same,
- * otherwise non-zero.
- */
- int mbedtls_ct_memcmp( const void *a,
- const void *b,
- size_t n );
- #endif /* MBEDTLS_CONSTANT_TIME_H */
- /********* Start of file library/constant_time_internal.h ************/
- /**
- * Constant-time functions
- *
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CONSTANT_TIME_INTERNAL_H
- #define MBEDTLS_CONSTANT_TIME_INTERNAL_H
- #if defined(MBEDTLS_BIGNUM_C)
- #endif
- #if defined(MBEDTLS_SSL_TLS_C)
- #endif
- #include <stddef.h>
- /** Turn a value into a mask:
- * - if \p value == 0, return the all-bits 0 mask, aka 0
- * - otherwise, return the all-bits 1 mask, aka (unsigned) -1
- *
- * This function can be used to write constant-time code by replacing branches
- * with bit operations using masks.
- *
- * \param value The value to analyze.
- *
- * \return Zero if \p value is zero, otherwise all-bits-one.
- */
- unsigned mbedtls_ct_uint_mask( unsigned value );
- #if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC)
- /** Turn a value into a mask:
- * - if \p value == 0, return the all-bits 0 mask, aka 0
- * - otherwise, return the all-bits 1 mask, aka (size_t) -1
- *
- * This function can be used to write constant-time code by replacing branches
- * with bit operations using masks.
- *
- * \param value The value to analyze.
- *
- * \return Zero if \p value is zero, otherwise all-bits-one.
- */
- size_t mbedtls_ct_size_mask( size_t value );
- #endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */
- #if defined(MBEDTLS_BIGNUM_C)
- /** Turn a value into a mask:
- * - if \p value == 0, return the all-bits 0 mask, aka 0
- * - otherwise, return the all-bits 1 mask, aka (mbedtls_mpi_uint) -1
- *
- * This function can be used to write constant-time code by replacing branches
- * with bit operations using masks.
- *
- * \param value The value to analyze.
- *
- * \return Zero if \p value is zero, otherwise all-bits-one.
- */
- mbedtls_mpi_uint mbedtls_ct_mpi_uint_mask( mbedtls_mpi_uint value );
- #endif /* MBEDTLS_BIGNUM_C */
- #if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC)
- /** Constant-flow mask generation for "greater or equal" comparison:
- * - if \p x >= \p y, return all-bits 1, that is (size_t) -1
- * - otherwise, return all bits 0, that is 0
- *
- * This function can be used to write constant-time code by replacing branches
- * with bit operations using masks.
- *
- * \param x The first value to analyze.
- * \param y The second value to analyze.
- *
- * \return All-bits-one if \p x is greater or equal than \p y,
- * otherwise zero.
- */
- size_t mbedtls_ct_size_mask_ge( size_t x,
- size_t y );
- #endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */
- /** Constant-flow boolean "equal" comparison:
- * return x == y
- *
- * This is equivalent to \p x == \p y, but is likely to be compiled
- * to code using bitwise operation rather than a branch.
- *
- * \param x The first value to analyze.
- * \param y The second value to analyze.
- *
- * \return 1 if \p x equals to \p y, otherwise 0.
- */
- unsigned mbedtls_ct_size_bool_eq( size_t x,
- size_t y );
- #if defined(MBEDTLS_BIGNUM_C)
- /** Decide if an integer is less than the other, without branches.
- *
- * This is equivalent to \p x < \p y, but is likely to be compiled
- * to code using bitwise operation rather than a branch.
- *
- * \param x The first value to analyze.
- * \param y The second value to analyze.
- *
- * \return 1 if \p x is less than \p y, otherwise 0.
- */
- unsigned mbedtls_ct_mpi_uint_lt( const mbedtls_mpi_uint x,
- const mbedtls_mpi_uint y );
- #endif /* MBEDTLS_BIGNUM_C */
- /** Choose between two integer values without branches.
- *
- * This is equivalent to `condition ? if1 : if0`, but is likely to be compiled
- * to code using bitwise operation rather than a branch.
- *
- * \param condition Condition to test.
- * \param if1 Value to use if \p condition is nonzero.
- * \param if0 Value to use if \p condition is zero.
- *
- * \return \c if1 if \p condition is nonzero, otherwise \c if0.
- */
- unsigned mbedtls_ct_uint_if( unsigned condition,
- unsigned if1,
- unsigned if0 );
- #if defined(MBEDTLS_BIGNUM_C)
- /** Conditionally assign a value without branches.
- *
- * This is equivalent to `if ( condition ) dest = src`, but is likely
- * to be compiled to code using bitwise operation rather than a branch.
- *
- * \param n \p dest and \p src must be arrays of limbs of size n.
- * \param dest The MPI to conditionally assign to. This must point
- * to an initialized MPI.
- * \param src The MPI to be assigned from. This must point to an
- * initialized MPI.
- * \param condition Condition to test, must be 0 or 1.
- */
- void mbedtls_ct_mpi_uint_cond_assign( size_t n,
- mbedtls_mpi_uint *dest,
- const mbedtls_mpi_uint *src,
- unsigned char condition );
- #endif /* MBEDTLS_BIGNUM_C */
- #if defined(MBEDTLS_BASE64_C)
- /** Given a value in the range 0..63, return the corresponding Base64 digit.
- *
- * The implementation assumes that letters are consecutive (e.g. ASCII
- * but not EBCDIC).
- *
- * \param value A value in the range 0..63.
- *
- * \return A base64 digit converted from \p value.
- */
- unsigned char mbedtls_ct_base64_enc_char( unsigned char value );
- /** Given a Base64 digit, return its value.
- *
- * If c is not a Base64 digit ('A'..'Z', 'a'..'z', '0'..'9', '+' or '/'),
- * return -1.
- *
- * The implementation assumes that letters are consecutive (e.g. ASCII
- * but not EBCDIC).
- *
- * \param c A base64 digit.
- *
- * \return The value of the base64 digit \p c.
- */
- signed char mbedtls_ct_base64_dec_value( unsigned char c );
- #endif /* MBEDTLS_BASE64_C */
- #if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC)
- /** Conditional memcpy without branches.
- *
- * This is equivalent to `if ( c1 == c2 ) memcpy(dest, src, len)`, but is likely
- * to be compiled to code using bitwise operation rather than a branch.
- *
- * \param dest The pointer to conditionally copy to.
- * \param src The pointer to copy from. Shouldn't overlap with \p dest.
- * \param len The number of bytes to copy.
- * \param c1 The first value to analyze in the condition.
- * \param c2 The second value to analyze in the condition.
- */
- void mbedtls_ct_memcpy_if_eq( unsigned char *dest,
- const unsigned char *src,
- size_t len,
- size_t c1, size_t c2 );
- /** Copy data from a secret position with constant flow.
- *
- * This function copies \p len bytes from \p src_base + \p offset_secret to \p
- * dst, with a code flow and memory access pattern that does not depend on \p
- * offset_secret, but only on \p offset_min, \p offset_max and \p len.
- * Functionally equivalent to `memcpy(dst, src + offset_secret, len)`.
- *
- * \param dest The destination buffer. This must point to a writable
- * buffer of at least \p len bytes.
- * \param src The base of the source buffer. This must point to a
- * readable buffer of at least \p offset_max + \p len
- * bytes. Shouldn't overlap with \p dest.
- * \param offset The offset in the source buffer from which to copy.
- * This must be no less than \p offset_min and no greater
- * than \p offset_max.
- * \param offset_min The minimal value of \p offset.
- * \param offset_max The maximal value of \p offset.
- * \param len The number of bytes to copy.
- */
- void mbedtls_ct_memcpy_offset( unsigned char *dest,
- const unsigned char *src,
- size_t offset,
- size_t offset_min,
- size_t offset_max,
- size_t len );
- /** Compute the HMAC of variable-length data with constant flow.
- *
- * This function computes the HMAC of the concatenation of \p add_data and \p
- * data, and does with a code flow and memory access pattern that does not
- * depend on \p data_len_secret, but only on \p min_data_len and \p
- * max_data_len. In particular, this function always reads exactly \p
- * max_data_len bytes from \p data.
- *
- * \param ctx The HMAC context. It must have keys configured
- * with mbedtls_md_hmac_starts() and use one of the
- * following hashes: SHA-384, SHA-256, SHA-1 or MD-5.
- * It is reset using mbedtls_md_hmac_reset() after
- * the computation is complete to prepare for the
- * next computation.
- * \param add_data The first part of the message whose HMAC is being
- * calculated. This must point to a readable buffer
- * of \p add_data_len bytes.
- * \param add_data_len The length of \p add_data in bytes.
- * \param data The buffer containing the second part of the
- * message. This must point to a readable buffer
- * of \p max_data_len bytes.
- * \param data_len_secret The length of the data to process in \p data.
- * This must be no less than \p min_data_len and no
- * greater than \p max_data_len.
- * \param min_data_len The minimal length of the second part of the
- * message, read from \p data.
- * \param max_data_len The maximal length of the second part of the
- * message, read from \p data.
- * \param output The HMAC will be written here. This must point to
- * a writable buffer of sufficient size to hold the
- * HMAC value.
- *
- * \retval 0 on success.
- * \retval #MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED
- * The hardware accelerator failed.
- */
- int mbedtls_ct_hmac( mbedtls_md_context_t *ctx,
- const unsigned char *add_data,
- size_t add_data_len,
- const unsigned char *data,
- size_t data_len_secret,
- size_t min_data_len,
- size_t max_data_len,
- unsigned char *output );
- #endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */
- #if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT)
- /** This function performs the unpadding part of a PKCS#1 v1.5 decryption
- * operation (EME-PKCS1-v1_5 decoding).
- *
- * \note The return value from this function is a sensitive value
- * (this is unusual). #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE shouldn't happen
- * in a well-written application, but 0 vs #MBEDTLS_ERR_RSA_INVALID_PADDING
- * is often a situation that an attacker can provoke and leaking which
- * one is the result is precisely the information the attacker wants.
- *
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
- * \param input The input buffer which is the payload inside PKCS#1v1.5
- * encryption padding, called the "encoded message EM"
- * by the terminology.
- * \param ilen The length of the payload in the \p input buffer.
- * \param output The buffer for the payload, called "message M" by the
- * PKCS#1 terminology. This must be a writable buffer of
- * length \p output_max_len bytes.
- * \param olen The address at which to store the length of
- * the payload. This must not be \c NULL.
- * \param output_max_len The length in bytes of the output buffer \p output.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE
- * The output buffer is too small for the unpadded payload.
- * \return #MBEDTLS_ERR_RSA_INVALID_PADDING
- * The input doesn't contain properly formatted padding.
- */
- int mbedtls_ct_rsaes_pkcs1_v15_unpadding( int mode,
- unsigned char *input,
- size_t ilen,
- unsigned char *output,
- size_t output_max_len,
- size_t *olen );
- #endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */
- #endif /* MBEDTLS_CONSTANT_TIME_INTERNAL_H */
- /********* Start of file include/mbedtls/net.h ************/
- /**
- * \file net.h
- *
- * \brief Deprecated header file that includes net_sockets.h
- *
- * \deprecated Superseded by mbedtls/net_sockets.h
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #warning "Deprecated header file: Superseded by mbedtls/net_sockets.h"
- #endif /* MBEDTLS_DEPRECATED_WARNING */
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /********* Start of file include/mbedtls/net_sockets.h ************/
- /**
- * \file net_sockets.h
- *
- * \brief Network sockets abstraction layer to integrate Mbed TLS into a
- * BSD-style sockets API.
- *
- * The network sockets module provides an example integration of the
- * Mbed TLS library into a BSD sockets implementation. The module is
- * intended to be an example of how Mbed TLS can be integrated into a
- * networking stack, as well as to be Mbed TLS's network integration
- * for its supported platforms.
- *
- * The module is intended only to be used with the Mbed TLS library and
- * is not intended to be used by third party application software
- * directly.
- *
- * The supported platforms are as follows:
- * * Microsoft Windows and Windows CE
- * * POSIX/Unix platforms including Linux, OS X
- *
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_NET_SOCKETS_H
- #define MBEDTLS_NET_SOCKETS_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /** Failed to open a socket. */
- #define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042
- /** The connection to the given server / port failed. */
- #define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044
- /** Binding of the socket failed. */
- #define MBEDTLS_ERR_NET_BIND_FAILED -0x0046
- /** Could not listen on the socket. */
- #define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048
- /** Could not accept the incoming connection. */
- #define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A
- /** Reading information from the socket failed. */
- #define MBEDTLS_ERR_NET_RECV_FAILED -0x004C
- /** Sending information through the socket failed. */
- #define MBEDTLS_ERR_NET_SEND_FAILED -0x004E
- /** Connection was reset by peer. */
- #define MBEDTLS_ERR_NET_CONN_RESET -0x0050
- /** Failed to get an IP address for the given hostname. */
- #define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052
- /** Buffer is too small to hold the data. */
- #define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043
- /** The context is invalid, eg because it was free()ed. */
- #define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045
- /** Polling the net context failed. */
- #define MBEDTLS_ERR_NET_POLL_FAILED -0x0047
- /** Input invalid. */
- #define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049
- #define MBEDTLS_NET_LISTEN_BACKLOG 10 /**< The backlog that listen() should use. */
- #define MBEDTLS_NET_PROTO_TCP 0 /**< The TCP transport protocol */
- #define MBEDTLS_NET_PROTO_UDP 1 /**< The UDP transport protocol */
- #define MBEDTLS_NET_POLL_READ 1 /**< Used in \c mbedtls_net_poll to check for pending data */
- #define MBEDTLS_NET_POLL_WRITE 2 /**< Used in \c mbedtls_net_poll to check if write possible */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Wrapper type for sockets.
- *
- * Currently backed by just a file descriptor, but might be more in the future
- * (eg two file descriptors for combined IPv4 + IPv6 support, or additional
- * structures for hand-made UDP demultiplexing).
- */
- typedef struct mbedtls_net_context
- {
- int fd; /**< The underlying file descriptor */
- }
- mbedtls_net_context;
- /**
- * \brief Initialize a context
- * Just makes the context ready to be used or freed safely.
- *
- * \param ctx Context to initialize
- */
- void mbedtls_net_init( mbedtls_net_context *ctx );
- /**
- * \brief Initiate a connection with host:port in the given protocol
- *
- * \param ctx Socket to use
- * \param host Host to connect to
- * \param port Port to connect to
- * \param proto Protocol: MBEDTLS_NET_PROTO_TCP or MBEDTLS_NET_PROTO_UDP
- *
- * \return 0 if successful, or one of:
- * MBEDTLS_ERR_NET_SOCKET_FAILED,
- * MBEDTLS_ERR_NET_UNKNOWN_HOST,
- * MBEDTLS_ERR_NET_CONNECT_FAILED
- *
- * \note Sets the socket in connected mode even with UDP.
- */
- int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto );
- /**
- * \brief Create a receiving socket on bind_ip:port in the chosen
- * protocol. If bind_ip == NULL, all interfaces are bound.
- *
- * \param ctx Socket to use
- * \param bind_ip IP to bind to, can be NULL
- * \param port Port number to use
- * \param proto Protocol: MBEDTLS_NET_PROTO_TCP or MBEDTLS_NET_PROTO_UDP
- *
- * \return 0 if successful, or one of:
- * MBEDTLS_ERR_NET_SOCKET_FAILED,
- * MBEDTLS_ERR_NET_UNKNOWN_HOST,
- * MBEDTLS_ERR_NET_BIND_FAILED,
- * MBEDTLS_ERR_NET_LISTEN_FAILED
- *
- * \note Regardless of the protocol, opens the sockets and binds it.
- * In addition, make the socket listening if protocol is TCP.
- */
- int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto );
- /**
- * \brief Accept a connection from a remote client
- *
- * \param bind_ctx Relevant socket
- * \param client_ctx Will contain the connected client socket
- * \param client_ip Will contain the client IP address, can be NULL
- * \param buf_size Size of the client_ip buffer
- * \param ip_len Will receive the size of the client IP written,
- * can be NULL if client_ip is null
- *
- * \return 0 if successful, or
- * MBEDTLS_ERR_NET_SOCKET_FAILED,
- * MBEDTLS_ERR_NET_BIND_FAILED,
- * MBEDTLS_ERR_NET_ACCEPT_FAILED, or
- * MBEDTLS_ERR_NET_BUFFER_TOO_SMALL if buf_size is too small,
- * MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to
- * non-blocking and accept() would block.
- */
- int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
- mbedtls_net_context *client_ctx,
- void *client_ip, size_t buf_size, size_t *ip_len );
- /**
- * \brief Check and wait for the context to be ready for read/write
- *
- * \note The current implementation of this function uses
- * select() and returns an error if the file descriptor
- * is \c FD_SETSIZE or greater.
- *
- * \param ctx Socket to check
- * \param rw Bitflag composed of MBEDTLS_NET_POLL_READ and
- * MBEDTLS_NET_POLL_WRITE specifying the events
- * to wait for:
- * - If MBEDTLS_NET_POLL_READ is set, the function
- * will return as soon as the net context is available
- * for reading.
- * - If MBEDTLS_NET_POLL_WRITE is set, the function
- * will return as soon as the net context is available
- * for writing.
- * \param timeout Maximal amount of time to wait before returning,
- * in milliseconds. If \c timeout is zero, the
- * function returns immediately. If \c timeout is
- * -1u, the function blocks potentially indefinitely.
- *
- * \return Bitmask composed of MBEDTLS_NET_POLL_READ/WRITE
- * on success or timeout, or a negative return code otherwise.
- */
- int mbedtls_net_poll( mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout );
- /**
- * \brief Set the socket blocking
- *
- * \param ctx Socket to set
- *
- * \return 0 if successful, or a non-zero error code
- */
- int mbedtls_net_set_block( mbedtls_net_context *ctx );
- /**
- * \brief Set the socket non-blocking
- *
- * \param ctx Socket to set
- *
- * \return 0 if successful, or a non-zero error code
- */
- int mbedtls_net_set_nonblock( mbedtls_net_context *ctx );
- /**
- * \brief Portable usleep helper
- *
- * \param usec Amount of microseconds to sleep
- *
- * \note Real amount of time slept will not be less than
- * select()'s timeout granularity (typically, 10ms).
- */
- void mbedtls_net_usleep( unsigned long usec );
- /**
- * \brief Read at most 'len' characters. If no error occurs,
- * the actual amount read is returned.
- *
- * \param ctx Socket
- * \param buf The buffer to write to
- * \param len Maximum length of the buffer
- *
- * \return the number of bytes received,
- * or a non-zero error code; with a non-blocking socket,
- * MBEDTLS_ERR_SSL_WANT_READ indicates read() would block.
- */
- int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len );
- /**
- * \brief Write at most 'len' characters. If no error occurs,
- * the actual amount read is returned.
- *
- * \param ctx Socket
- * \param buf The buffer to read from
- * \param len The length of the buffer
- *
- * \return the number of bytes sent,
- * or a non-zero error code; with a non-blocking socket,
- * MBEDTLS_ERR_SSL_WANT_WRITE indicates write() would block.
- */
- int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );
- /**
- * \brief Read at most 'len' characters, blocking for at most
- * 'timeout' seconds. If no error occurs, the actual amount
- * read is returned.
- *
- * \note The current implementation of this function uses
- * select() and returns an error if the file descriptor
- * is \c FD_SETSIZE or greater.
- *
- * \param ctx Socket
- * \param buf The buffer to write to
- * \param len Maximum length of the buffer
- * \param timeout Maximum number of milliseconds to wait for data
- * 0 means no timeout (wait forever)
- *
- * \return The number of bytes received if successful.
- * MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out.
- * MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
- * Another negative error code (MBEDTLS_ERR_NET_xxx)
- * for other failures.
- *
- * \note This function will block (until data becomes available or
- * timeout is reached) even if the socket is set to
- * non-blocking. Handling timeouts with non-blocking reads
- * requires a different strategy.
- */
- int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
- uint32_t timeout );
- /**
- * \brief Closes down the connection and free associated data
- *
- * \param ctx The context to close
- */
- void mbedtls_net_close( mbedtls_net_context *ctx );
- /**
- * \brief Gracefully shutdown the connection and free associated data
- *
- * \param ctx The context to free
- */
- void mbedtls_net_free( mbedtls_net_context *ctx );
- #ifdef __cplusplus
- }
- #endif
- #endif /* net_sockets.h */
- /********* Start of file include/mbedtls/dhm.h ************/
- /**
- * \file dhm.h
- *
- * \brief This file contains Diffie-Hellman-Merkle (DHM) key exchange
- * definitions and functions.
- *
- * Diffie-Hellman-Merkle (DHM) key exchange is defined in
- * <em>RFC-2631: Diffie-Hellman Key Agreement Method</em> and
- * <em>Public-Key Cryptography Standards (PKCS) #3: Diffie
- * Hellman Key Agreement Standard</em>.
- *
- * <em>RFC-3526: More Modular Exponential (MODP) Diffie-Hellman groups for
- * Internet Key Exchange (IKE)</em> defines a number of standardized
- * Diffie-Hellman groups for IKE.
- *
- * <em>RFC-5114: Additional Diffie-Hellman Groups for Use with IETF
- * Standards</em> defines a number of standardized Diffie-Hellman
- * groups that can be used.
- *
- * \warning The security of the DHM key exchange relies on the proper choice
- * of prime modulus - optimally, it should be a safe prime. The usage
- * of non-safe primes both decreases the difficulty of the underlying
- * discrete logarithm problem and can lead to small subgroup attacks
- * leaking private exponent bits when invalid public keys are used
- * and not detected. This is especially relevant if the same DHM
- * parameters are reused for multiple key exchanges as in static DHM,
- * while the criticality of small-subgroup attacks is lower for
- * ephemeral DHM.
- *
- * \warning For performance reasons, the code does neither perform primality
- * nor safe primality tests, nor the expensive checks for invalid
- * subgroups. Moreover, even if these were performed, non-standardized
- * primes cannot be trusted because of the possibility of backdoors
- * that can't be effectively checked for.
- *
- * \warning Diffie-Hellman-Merkle is therefore a security risk when not using
- * standardized primes generated using a trustworthy ("nothing up
- * my sleeve") method, such as the RFC 3526 / 7919 primes. In the TLS
- * protocol, DH parameters need to be negotiated, so using the default
- * primes systematically is not always an option. If possible, use
- * Elliptic Curve Diffie-Hellman (ECDH), which has better performance,
- * and for which the TLS protocol mandates the use of standard
- * parameters.
- *
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_DHM_H
- #define MBEDTLS_DHM_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /*
- * DHM Error codes
- */
- /** Bad input parameters. */
- #define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080
- /** Reading of the DHM parameters failed. */
- #define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100
- /** Making of the DHM parameters failed. */
- #define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180
- /** Reading of the public values failed. */
- #define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200
- /** Making of the public value failed. */
- #define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280
- /** Calculation of the DHM secret failed. */
- #define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300
- /** The ASN.1 data is not formatted correctly. */
- #define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380
- /** Allocation of memory failed. */
- #define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400
- /** Read or write of file failed. */
- #define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480
- /* MBEDTLS_ERR_DHM_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** DHM hardware accelerator failed. */
- #define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500
- /** Setting the modulus and generator failed. */
- #define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_DHM_ALT)
- /**
- * \brief The DHM context structure.
- */
- typedef struct mbedtls_dhm_context
- {
- size_t len; /*!< The size of \p P in Bytes. */
- mbedtls_mpi P; /*!< The prime modulus. */
- mbedtls_mpi G; /*!< The generator. */
- mbedtls_mpi X; /*!< Our secret value. */
- mbedtls_mpi GX; /*!< Our public key = \c G^X mod \c P. */
- mbedtls_mpi GY; /*!< The public key of the peer = \c G^Y mod \c P. */
- mbedtls_mpi K; /*!< The shared secret = \c G^(XY) mod \c P. */
- mbedtls_mpi RP; /*!< The cached value = \c R^2 mod \c P. */
- mbedtls_mpi Vi; /*!< The blinding value. */
- mbedtls_mpi Vf; /*!< The unblinding value. */
- mbedtls_mpi pX; /*!< The previous \c X. */
- }
- mbedtls_dhm_context;
- #else /* MBEDTLS_DHM_ALT */
- #endif /* MBEDTLS_DHM_ALT */
- /**
- * \brief This function initializes the DHM context.
- *
- * \param ctx The DHM context to initialize.
- */
- void mbedtls_dhm_init( mbedtls_dhm_context *ctx );
- /**
- * \brief This function parses the DHM parameters in a
- * TLS ServerKeyExchange handshake message
- * (DHM modulus, generator, and public key).
- *
- * \note In a TLS handshake, this is the how the client
- * sets up its DHM context from the server's public
- * DHM key material.
- *
- * \param ctx The DHM context to use. This must be initialized.
- * \param p On input, *p must be the start of the input buffer.
- * On output, *p is updated to point to the end of the data
- * that has been read. On success, this is the first byte
- * past the end of the ServerKeyExchange parameters.
- * On error, this is the point at which an error has been
- * detected, which is usually not useful except to debug
- * failures.
- * \param end The end of the input buffer.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure.
- */
- int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx,
- unsigned char **p,
- const unsigned char *end );
- /**
- * \brief This function generates a DHM key pair and exports its
- * public part together with the DHM parameters in the format
- * used in a TLS ServerKeyExchange handshake message.
- *
- * \note This function assumes that the DHM parameters \c ctx->P
- * and \c ctx->G have already been properly set. For that, use
- * mbedtls_dhm_set_group() below in conjunction with
- * mbedtls_mpi_read_binary() and mbedtls_mpi_read_string().
- *
- * \note In a TLS handshake, this is the how the server generates
- * and exports its DHM key material.
- *
- * \param ctx The DHM context to use. This must be initialized
- * and have the DHM parameters set. It may or may not
- * already have imported the peer's public key.
- * \param x_size The private key size in Bytes.
- * \param olen The address at which to store the number of Bytes
- * written on success. This must not be \c NULL.
- * \param output The destination buffer. This must be a writable buffer of
- * sufficient size to hold the reduced binary presentation of
- * the modulus, the generator and the public key, each wrapped
- * with a 2-byte length field. It is the responsibility of the
- * caller to ensure that enough space is available. Refer to
- * mbedtls_mpi_size() to computing the byte-size of an MPI.
- * \param f_rng The RNG function. Must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng doesn't need a context parameter.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure.
- */
- int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
- unsigned char *output, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function sets the prime modulus and generator.
- *
- * \note This function can be used to set \c ctx->P, \c ctx->G
- * in preparation for mbedtls_dhm_make_params().
- *
- * \param ctx The DHM context to configure. This must be initialized.
- * \param P The MPI holding the DHM prime modulus. This must be
- * an initialized MPI.
- * \param G The MPI holding the DHM generator. This must be an
- * initialized MPI.
- *
- * \return \c 0 if successful.
- * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure.
- */
- int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx,
- const mbedtls_mpi *P,
- const mbedtls_mpi *G );
- /**
- * \brief This function imports the raw public value of the peer.
- *
- * \note In a TLS handshake, this is the how the server imports
- * the Client's public DHM key.
- *
- * \param ctx The DHM context to use. This must be initialized and have
- * its DHM parameters set, e.g. via mbedtls_dhm_set_group().
- * It may or may not already have generated its own private key.
- * \param input The input buffer containing the \c G^Y value of the peer.
- * This must be a readable buffer of size \p ilen Bytes.
- * \param ilen The size of the input buffer \p input in Bytes.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure.
- */
- int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx,
- const unsigned char *input, size_t ilen );
- /**
- * \brief This function creates a DHM key pair and exports
- * the raw public key in big-endian format.
- *
- * \note The destination buffer is always fully written
- * so as to contain a big-endian representation of G^X mod P.
- * If it is larger than \c ctx->len, it is padded accordingly
- * with zero-bytes at the beginning.
- *
- * \param ctx The DHM context to use. This must be initialized and
- * have the DHM parameters set. It may or may not already
- * have imported the peer's public key.
- * \param x_size The private key size in Bytes.
- * \param output The destination buffer. This must be a writable buffer of
- * size \p olen Bytes.
- * \param olen The length of the destination buffer. This must be at least
- * equal to `ctx->len` (the size of \c P).
- * \param f_rng The RNG function. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
- * if \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure.
- */
- int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size,
- unsigned char *output, size_t olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function derives and exports the shared secret
- * \c (G^Y)^X mod \c P.
- *
- * \note If \p f_rng is not \c NULL, it is used to blind the input as
- * a countermeasure against timing attacks. Blinding is used
- * only if our private key \c X is re-used, and not used
- * otherwise. We recommend always passing a non-NULL
- * \p f_rng argument.
- *
- * \param ctx The DHM context to use. This must be initialized
- * and have its own private key generated and the peer's
- * public key imported.
- * \param output The buffer to write the generated shared key to. This
- * must be a writable buffer of size \p output_size Bytes.
- * \param output_size The size of the destination buffer. This must be at
- * least the size of \c ctx->len (the size of \c P).
- * \param olen On exit, holds the actual number of Bytes written.
- * \param f_rng The RNG function, for blinding purposes. This may
- * b \c NULL if blinding isn't needed.
- * \param p_rng The RNG context. This may be \c NULL if \p f_rng
- * doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure.
- */
- int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx,
- unsigned char *output, size_t output_size, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function frees and clears the components
- * of a DHM context.
- *
- * \param ctx The DHM context to free and clear. This may be \c NULL,
- * in which case this function is a no-op. If it is not \c NULL,
- * it must point to an initialized DHM context.
- */
- void mbedtls_dhm_free( mbedtls_dhm_context *ctx );
- #if defined(MBEDTLS_ASN1_PARSE_C)
- /**
- * \brief This function parses DHM parameters in PEM or DER format.
- *
- * \param dhm The DHM context to import the DHM parameters into.
- * This must be initialized.
- * \param dhmin The input buffer. This must be a readable buffer of
- * length \p dhminlen Bytes.
- * \param dhminlen The size of the input buffer \p dhmin, including the
- * terminating \c NULL Byte for PEM data.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_DHM_XXX or \c MBEDTLS_ERR_PEM_XXX error
- * code on failure.
- */
- int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin,
- size_t dhminlen );
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief This function loads and parses DHM parameters from a file.
- *
- * \param dhm The DHM context to load the parameters to.
- * This must be initialized.
- * \param path The filename to read the DHM parameters from.
- * This must not be \c NULL.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_DHM_XXX or \c MBEDTLS_ERR_PEM_XXX
- * error code on failure.
- */
- int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
- #endif /* MBEDTLS_FS_IO */
- #endif /* MBEDTLS_ASN1_PARSE_C */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The DMH checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_dhm_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- /**
- * RFC 3526, RFC 5114 and RFC 7919 standardize a number of
- * Diffie-Hellman groups, some of which are included here
- * for use within the SSL/TLS module and the user's convenience
- * when configuring the Diffie-Hellman parameters by hand
- * through \c mbedtls_ssl_conf_dh_param.
- *
- * The following lists the source of the above groups in the standards:
- * - RFC 5114 section 2.2: 2048-bit MODP Group with 224-bit Prime Order Subgroup
- * - RFC 3526 section 3: 2048-bit MODP Group
- * - RFC 3526 section 4: 3072-bit MODP Group
- * - RFC 3526 section 5: 4096-bit MODP Group
- * - RFC 7919 section A.1: ffdhe2048
- * - RFC 7919 section A.2: ffdhe3072
- * - RFC 7919 section A.3: ffdhe4096
- * - RFC 7919 section A.4: ffdhe6144
- * - RFC 7919 section A.5: ffdhe8192
- *
- * The constants with suffix "_p" denote the chosen prime moduli, while
- * the constants with suffix "_g" denote the chosen generator
- * of the associated prime field.
- *
- * The constants further suffixed with "_bin" are provided in binary format,
- * while all other constants represent null-terminated strings holding the
- * hexadecimal presentation of the respective numbers.
- *
- * The primes from RFC 3526 and RFC 7919 have been generating by the following
- * trust-worthy procedure:
- * - Fix N in { 2048, 3072, 4096, 6144, 8192 } and consider the N-bit number
- * the first and last 64 bits are all 1, and the remaining N - 128 bits of
- * which are 0x7ff...ff.
- * - Add the smallest multiple of the first N - 129 bits of the binary expansion
- * of pi (for RFC 5236) or e (for RFC 7919) to this intermediate bit-string
- * such that the resulting integer is a safe-prime.
- * - The result is the respective RFC 3526 / 7919 prime, and the corresponding
- * generator is always chosen to be 2 (which is a square for these prime,
- * hence the corresponding subgroup has order (p-1)/2 and avoids leaking a
- * bit in the private exponent).
- *
- */
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- /**
- * \warning The origin of the primes in RFC 5114 is not documented and
- * their use therefore constitutes a security risk!
- *
- * \deprecated The hex-encoded primes from RFC 5114 are deprecated and are
- * likely to be removed in a future version of the library without
- * replacement.
- */
- /**
- * The hexadecimal presentation of the prime underlying the
- * 2048-bit MODP Group with 224-bit Prime Order Subgroup, as defined
- * in <em>RFC-5114: Additional Diffie-Hellman Groups for Use with
- * IETF Standards</em>.
- */
- #define MBEDTLS_DHM_RFC5114_MODP_2048_P \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( \
- "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" \
- "B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" \
- "EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" \
- "9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" \
- "C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" \
- "B3BF8A317091883681286130BC8985DB1602E714415D9330" \
- "278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" \
- "CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" \
- "BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" \
- "C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" \
- "CF9DE5384E71B81C0AC4DFFE0C10E64F" )
- /**
- * The hexadecimal presentation of the chosen generator of the 2048-bit MODP
- * Group with 224-bit Prime Order Subgroup, as defined in <em>RFC-5114:
- * Additional Diffie-Hellman Groups for Use with IETF Standards</em>.
- */
- #define MBEDTLS_DHM_RFC5114_MODP_2048_G \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( \
- "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF" \
- "74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA" \
- "AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7" \
- "C17669101999024AF4D027275AC1348BB8A762D0521BC98A" \
- "E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE" \
- "F180EB34118E98D119529A45D6F834566E3025E316A330EF" \
- "BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB" \
- "10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381" \
- "B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269" \
- "EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179" \
- "81BC087F2A7065B384B890D3191F2BFA" )
- /**
- * The hexadecimal presentation of the prime underlying the 2048-bit MODP
- * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
- * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
- *
- * \deprecated The hex-encoded primes from RFC 3625 are deprecated and
- * superseded by the corresponding macros providing them as
- * binary constants. Their hex-encoded constants are likely
- * to be removed in a future version of the library.
- *
- */
- #define MBEDTLS_DHM_RFC3526_MODP_2048_P \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( \
- "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
- "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
- "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
- "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
- "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
- "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
- "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
- "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
- "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
- "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
- "15728E5A8AACAA68FFFFFFFFFFFFFFFF" )
- /**
- * The hexadecimal presentation of the chosen generator of the 2048-bit MODP
- * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
- * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
- */
- #define MBEDTLS_DHM_RFC3526_MODP_2048_G \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
- /**
- * The hexadecimal presentation of the prime underlying the 3072-bit MODP
- * Group, as defined in <em>RFC-3072: More Modular Exponential (MODP)
- * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
- */
- #define MBEDTLS_DHM_RFC3526_MODP_3072_P \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( \
- "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
- "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
- "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
- "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
- "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
- "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
- "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
- "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
- "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
- "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
- "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
- "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
- "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
- "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
- "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
- "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF" )
- /**
- * The hexadecimal presentation of the chosen generator of the 3072-bit MODP
- * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
- * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
- */
- #define MBEDTLS_DHM_RFC3526_MODP_3072_G \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
- /**
- * The hexadecimal presentation of the prime underlying the 4096-bit MODP
- * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
- * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
- */
- #define MBEDTLS_DHM_RFC3526_MODP_4096_P \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( \
- "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
- "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
- "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
- "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
- "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
- "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
- "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
- "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
- "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
- "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
- "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
- "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
- "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
- "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
- "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
- "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
- "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
- "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
- "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
- "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
- "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \
- "FFFFFFFFFFFFFFFF" )
- /**
- * The hexadecimal presentation of the chosen generator of the 4096-bit MODP
- * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
- * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
- */
- #define MBEDTLS_DHM_RFC3526_MODP_4096_G \
- MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- /*
- * Trustworthy DHM parameters in binary form
- */
- #define MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
- 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
- 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
- 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
- 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
- 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
- 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
- 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
- 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
- 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
- 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
- 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
- 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
- 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
- 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
- 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
- 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
- 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
- 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
- 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
- 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
- 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
- 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
- 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
- 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
- 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
- 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
- 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
- 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
- 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
- #define MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN { 0x02 }
- #define MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
- 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
- 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
- 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
- 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
- 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
- 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
- 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
- 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
- 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
- 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
- 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
- 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
- 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
- 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
- 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
- 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
- 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
- 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
- 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
- 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
- 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
- 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
- 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
- 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
- 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
- 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
- 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
- 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
- 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, \
- 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \
- 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, \
- 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, \
- 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, \
- 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, \
- 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, \
- 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, \
- 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, \
- 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, \
- 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, \
- 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, \
- 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, \
- 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, \
- 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, \
- 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, \
- 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
- #define MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN { 0x02 }
- #define MBEDTLS_DHM_RFC3526_MODP_4096_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
- 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
- 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
- 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
- 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
- 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
- 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
- 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
- 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
- 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
- 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
- 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
- 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
- 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
- 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
- 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
- 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
- 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
- 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
- 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
- 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
- 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
- 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
- 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
- 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
- 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
- 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
- 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
- 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
- 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, \
- 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \
- 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, \
- 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, \
- 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, \
- 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, \
- 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, \
- 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, \
- 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, \
- 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, \
- 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, \
- 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, \
- 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, \
- 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, \
- 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, \
- 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, \
- 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, \
- 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, \
- 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, \
- 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C, \
- 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, \
- 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, \
- 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, \
- 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, \
- 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, \
- 0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2, \
- 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, \
- 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, \
- 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, \
- 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, \
- 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, \
- 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F, \
- 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
- #define MBEDTLS_DHM_RFC3526_MODP_4096_G_BIN { 0x02 }
- #define MBEDTLS_DHM_RFC7919_FFDHE2048_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
- 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
- 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
- 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
- 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
- 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
- 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
- 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
- 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
- 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
- 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
- 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
- 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
- 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
- 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
- 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
- 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
- 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
- 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
- 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
- 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
- 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
- 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
- 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
- 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
- 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
- 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
- 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
- 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
- 0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }
- #define MBEDTLS_DHM_RFC7919_FFDHE2048_G_BIN { 0x02 }
- #define MBEDTLS_DHM_RFC7919_FFDHE3072_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
- 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
- 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
- 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
- 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
- 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
- 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
- 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
- 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
- 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
- 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
- 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
- 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
- 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
- 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
- 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
- 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
- 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
- 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
- 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
- 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
- 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
- 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
- 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
- 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
- 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
- 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
- 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
- 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
- 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
- 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
- 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
- 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
- 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
- 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
- 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
- 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
- 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
- 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
- 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
- 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
- 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
- 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
- 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
- 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
- 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, 0x37, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
- #define MBEDTLS_DHM_RFC7919_FFDHE3072_G_BIN { 0x02 }
- #define MBEDTLS_DHM_RFC7919_FFDHE4096_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
- 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
- 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
- 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
- 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
- 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
- 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
- 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
- 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
- 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
- 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
- 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
- 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
- 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
- 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
- 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
- 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
- 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
- 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
- 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
- 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
- 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
- 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
- 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
- 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
- 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
- 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
- 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
- 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
- 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
- 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
- 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
- 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
- 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
- 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
- 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
- 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
- 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
- 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
- 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
- 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
- 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
- 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
- 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
- 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
- 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
- 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
- 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
- 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
- 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
- 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
- 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
- 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
- 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
- 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
- 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
- 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
- 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
- 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
- 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
- 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
- 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
- #define MBEDTLS_DHM_RFC7919_FFDHE4096_G_BIN { 0x02 }
- #define MBEDTLS_DHM_RFC7919_FFDHE6144_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
- 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
- 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
- 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
- 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
- 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
- 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
- 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
- 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
- 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
- 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
- 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
- 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
- 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
- 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
- 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
- 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
- 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
- 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
- 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
- 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
- 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
- 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
- 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
- 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
- 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
- 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
- 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
- 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
- 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
- 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
- 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
- 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
- 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
- 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
- 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
- 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
- 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
- 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
- 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
- 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
- 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
- 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
- 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
- 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
- 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
- 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
- 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
- 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
- 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
- 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
- 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
- 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
- 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
- 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
- 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
- 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
- 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
- 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
- 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
- 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
- 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, \
- 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, \
- 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, \
- 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \
- 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, \
- 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, \
- 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, \
- 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, \
- 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, \
- 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, \
- 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, \
- 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, \
- 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, \
- 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, \
- 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, \
- 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, \
- 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, \
- 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, \
- 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, \
- 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, \
- 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \
- 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, \
- 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, \
- 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, \
- 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, \
- 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, \
- 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, \
- 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, \
- 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, \
- 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, \
- 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, \
- 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, \
- 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
- #define MBEDTLS_DHM_RFC7919_FFDHE6144_G_BIN { 0x02 }
- #define MBEDTLS_DHM_RFC7919_FFDHE8192_P_BIN { \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
- 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
- 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
- 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
- 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
- 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
- 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
- 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
- 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
- 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
- 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
- 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
- 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
- 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
- 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
- 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
- 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
- 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
- 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
- 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
- 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
- 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
- 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
- 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
- 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
- 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
- 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
- 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
- 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
- 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
- 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
- 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
- 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
- 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
- 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
- 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
- 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
- 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
- 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
- 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
- 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
- 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
- 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
- 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
- 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
- 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
- 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
- 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
- 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
- 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
- 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
- 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
- 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
- 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
- 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
- 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
- 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
- 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
- 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
- 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
- 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
- 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
- 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, \
- 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, \
- 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, \
- 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \
- 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, \
- 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, \
- 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, \
- 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, \
- 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, \
- 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, \
- 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, \
- 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, \
- 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, \
- 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, \
- 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, \
- 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, \
- 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, \
- 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, \
- 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, \
- 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, \
- 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \
- 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, \
- 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, \
- 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, \
- 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, \
- 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, \
- 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, \
- 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, \
- 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, \
- 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, \
- 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, \
- 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, \
- 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, \
- 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38, \
- 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64, \
- 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43, \
- 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, \
- 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, \
- 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, \
- 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65, \
- 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, \
- 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, \
- 0x54, 0x50, 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82, \
- 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, \
- 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51, \
- 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22, \
- 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74, \
- 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, \
- 0x1C, 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C, \
- 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, \
- 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, 0x7B, \
- 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, \
- 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0, \
- 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31, \
- 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, \
- 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, \
- 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E, \
- 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, \
- 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, \
- 0x2F, 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, \
- 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, \
- 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, 0x3D, \
- 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, \
- 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C, \
- 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C, \
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
- #define MBEDTLS_DHM_RFC7919_FFDHE8192_G_BIN { 0x02 }
- #endif /* dhm.h */
- /********* Start of file include/mbedtls/error.h ************/
- /**
- * \file error.h
- *
- * \brief Error to string translation
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ERROR_H
- #define MBEDTLS_ERROR_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
- #define inline __inline
- #endif
- /**
- * Error code layout.
- *
- * Currently we try to keep all error codes within the negative space of 16
- * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
- * addition we'd like to give two layers of information on the error if
- * possible.
- *
- * For that purpose the error codes are segmented in the following manner:
- *
- * 16 bit error code bit-segmentation
- *
- * 1 bit - Unused (sign bit)
- * 3 bits - High level module ID
- * 5 bits - Module-dependent error code
- * 7 bits - Low level module errors
- *
- * For historical reasons, low-level error codes are divided in even and odd,
- * even codes were assigned first, and -1 is reserved for other errors.
- *
- * Low-level module errors (0x0002-0x007E, 0x0001-0x007F)
- *
- * Module Nr Codes assigned
- * ERROR 2 0x006E 0x0001
- * MPI 7 0x0002-0x0010
- * GCM 3 0x0012-0x0014 0x0013-0x0013
- * BLOWFISH 3 0x0016-0x0018 0x0017-0x0017
- * THREADING 3 0x001A-0x001E
- * AES 5 0x0020-0x0022 0x0021-0x0025
- * CAMELLIA 3 0x0024-0x0026 0x0027-0x0027
- * XTEA 2 0x0028-0x0028 0x0029-0x0029
- * BASE64 2 0x002A-0x002C
- * OID 1 0x002E-0x002E 0x000B-0x000B
- * PADLOCK 1 0x0030-0x0030
- * DES 2 0x0032-0x0032 0x0033-0x0033
- * CTR_DBRG 4 0x0034-0x003A
- * ENTROPY 3 0x003C-0x0040 0x003D-0x003F
- * NET 13 0x0042-0x0052 0x0043-0x0049
- * ARIA 4 0x0058-0x005E
- * ASN1 7 0x0060-0x006C
- * CMAC 1 0x007A-0x007A
- * PBKDF2 1 0x007C-0x007C
- * HMAC_DRBG 4 0x0003-0x0009
- * CCM 3 0x000D-0x0011
- * ARC4 1 0x0019-0x0019
- * MD2 1 0x002B-0x002B
- * MD4 1 0x002D-0x002D
- * MD5 1 0x002F-0x002F
- * RIPEMD160 1 0x0031-0x0031
- * SHA1 1 0x0035-0x0035 0x0073-0x0073
- * SHA256 1 0x0037-0x0037 0x0074-0x0074
- * SHA512 1 0x0039-0x0039 0x0075-0x0075
- * CHACHA20 3 0x0051-0x0055
- * POLY1305 3 0x0057-0x005B
- * CHACHAPOLY 2 0x0054-0x0056
- * PLATFORM 2 0x0070-0x0072
- *
- * High-level module nr (3 bits - 0x0...-0x7...)
- * Name ID Nr of Errors
- * PEM 1 9
- * PKCS#12 1 4 (Started from top)
- * X509 2 20
- * PKCS5 2 4 (Started from top)
- * DHM 3 11
- * PK 3 15 (Started from top)
- * RSA 4 11
- * ECP 4 10 (Started from top)
- * MD 5 5
- * HKDF 5 1 (Started from top)
- * SSL 5 2 (Started from 0x5F00)
- * CIPHER 6 8 (Started from 0x6080)
- * SSL 6 24 (Started from top, plus 0x6000)
- * SSL 7 32
- *
- * Module dependent error code (5 bits 0x.00.-0x.F8.)
- */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /** Generic error */
- #define MBEDTLS_ERR_ERROR_GENERIC_ERROR -0x0001
- /** This is a bug in the library */
- #define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
- /**
- * \brief Combines a high-level and low-level error code together.
- *
- * Wrapper macro for mbedtls_error_add(). See that function for
- * more details.
- */
- #define MBEDTLS_ERROR_ADD( high, low ) \
- mbedtls_error_add( high, low, __FILE__, __LINE__ )
- #if defined(MBEDTLS_TEST_HOOKS)
- /**
- * \brief Testing hook called before adding/combining two error codes together.
- * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS.
- */
- extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int );
- #endif
- /**
- * \brief Combines a high-level and low-level error code together.
- *
- * This function can be called directly however it is usually
- * called via the #MBEDTLS_ERROR_ADD macro.
- *
- * While a value of zero is not a negative error code, it is still an
- * error code (that denotes success) and can be combined with both a
- * negative error code or another value of zero.
- *
- * \note When invasive testing is enabled via #MBEDTLS_TEST_HOOKS, also try to
- * call \link mbedtls_test_hook_error_add \endlink.
- *
- * \param high high-level error code. See error.h for more details.
- * \param low low-level error code. See error.h for more details.
- * \param file file where this error code addition occurred.
- * \param line line where this error code addition occurred.
- */
- static inline int mbedtls_error_add( int high, int low,
- const char *file, int line )
- {
- #if defined(MBEDTLS_TEST_HOOKS)
- if( *mbedtls_test_hook_error_add != NULL )
- ( *mbedtls_test_hook_error_add )( high, low, file, line );
- #endif
- (void)file;
- (void)line;
- return( high + low );
- }
- /**
- * \brief Translate a mbed TLS error code into a string representation,
- * Result is truncated if necessary and always includes a terminating
- * null byte.
- *
- * \param errnum error code
- * \param buffer buffer to place representation in
- * \param buflen length of the buffer
- */
- void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
- /**
- * \brief Translate the high-level part of an Mbed TLS error code into a string
- * representation.
- *
- * This function returns a const pointer to an un-modifiable string. The caller
- * must not try to modify the string. It is intended to be used mostly for
- * logging purposes.
- *
- * \param error_code error code
- *
- * \return The string representation of the error code, or \c NULL if the error
- * code is unknown.
- */
- const char * mbedtls_high_level_strerr( int error_code );
- /**
- * \brief Translate the low-level part of an Mbed TLS error code into a string
- * representation.
- *
- * This function returns a const pointer to an un-modifiable string. The caller
- * must not try to modify the string. It is intended to be used mostly for
- * logging purposes.
- *
- * \param error_code error code
- *
- * \return The string representation of the error code, or \c NULL if the error
- * code is unknown.
- */
- const char * mbedtls_low_level_strerr( int error_code );
- #ifdef __cplusplus
- }
- #endif
- #endif /* error.h */
- /********* Start of file include/mbedtls/md.h ************/
- /**
- * \file md.h
- *
- * \brief This file contains the generic message-digest wrapper.
- *
- * \author Adriaan de Jong <dejong@fox-it.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_MD_H
- #define MBEDTLS_MD_H
- #include <stddef.h>
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /** The selected feature is not available. */
- #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
- /** Failed to allocate memory. */
- #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
- /** Opening or reading of file failed. */
- #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
- /* MBEDTLS_ERR_MD_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** MD hardware accelerator failed. */
- #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Supported message digests.
- *
- * \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and
- * their use constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- typedef enum {
- MBEDTLS_MD_NONE=0, /**< None. */
- MBEDTLS_MD_MD2, /**< The MD2 message digest. */
- MBEDTLS_MD_MD4, /**< The MD4 message digest. */
- MBEDTLS_MD_MD5, /**< The MD5 message digest. */
- MBEDTLS_MD_SHA1, /**< The SHA-1 message digest. */
- MBEDTLS_MD_SHA224, /**< The SHA-224 message digest. */
- MBEDTLS_MD_SHA256, /**< The SHA-256 message digest. */
- MBEDTLS_MD_SHA384, /**< The SHA-384 message digest. */
- MBEDTLS_MD_SHA512, /**< The SHA-512 message digest. */
- MBEDTLS_MD_RIPEMD160, /**< The RIPEMD-160 message digest. */
- } mbedtls_md_type_t;
- #if defined(MBEDTLS_SHA512_C)
- #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
- #else
- #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
- #endif
- #if defined(MBEDTLS_SHA512_C)
- #define MBEDTLS_MD_MAX_BLOCK_SIZE 128
- #else
- #define MBEDTLS_MD_MAX_BLOCK_SIZE 64
- #endif
- /**
- * Opaque struct defined in md_internal.h.
- */
- typedef struct mbedtls_md_info_t mbedtls_md_info_t;
- /**
- * The generic message-digest context.
- */
- typedef struct mbedtls_md_context_t
- {
- /** Information about the associated message digest. */
- const mbedtls_md_info_t *md_info;
- /** The digest-specific context. */
- void *md_ctx;
- /** The HMAC part of the context. */
- void *hmac_ctx;
- } mbedtls_md_context_t;
- /**
- * \brief This function returns the list of digests supported by the
- * generic digest module.
- *
- * \note The list starts with the strongest available hashes.
- *
- * \return A statically allocated array of digests. Each element
- * in the returned list is an integer belonging to the
- * message-digest enumeration #mbedtls_md_type_t.
- * The last entry is 0.
- */
- const int *mbedtls_md_list( void );
- /**
- * \brief This function returns the message-digest information
- * associated with the given digest name.
- *
- * \param md_name The name of the digest to search for.
- *
- * \return The message-digest information associated with \p md_name.
- * \return NULL if the associated message-digest information is not found.
- */
- const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
- /**
- * \brief This function returns the message-digest information
- * associated with the given digest type.
- *
- * \param md_type The type of digest to search for.
- *
- * \return The message-digest information associated with \p md_type.
- * \return NULL if the associated message-digest information is not found.
- */
- const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
- /**
- * \brief This function initializes a message-digest context without
- * binding it to a particular message-digest algorithm.
- *
- * This function should always be called first. It prepares the
- * context for mbedtls_md_setup() for binding it to a
- * message-digest algorithm.
- */
- void mbedtls_md_init( mbedtls_md_context_t *ctx );
- /**
- * \brief This function clears the internal structure of \p ctx and
- * frees any embedded internal structure, but does not free
- * \p ctx itself.
- *
- * If you have called mbedtls_md_setup() on \p ctx, you must
- * call mbedtls_md_free() when you are no longer using the
- * context.
- * Calling this function if you have previously
- * called mbedtls_md_init() and nothing else is optional.
- * You must not call this function if you have not called
- * mbedtls_md_init().
- */
- void mbedtls_md_free( mbedtls_md_context_t *ctx );
- #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function selects the message digest algorithm to use,
- * and allocates internal structures.
- *
- * It should be called after mbedtls_md_init() or mbedtls_md_free().
- * Makes it necessary to call mbedtls_md_free() later.
- *
- * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
- *
- * \param ctx The context to set up.
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- * \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure.
- */
- int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
- #undef MBEDTLS_DEPRECATED
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief This function selects the message digest algorithm to use,
- * and allocates internal structures.
- *
- * It should be called after mbedtls_md_init() or
- * mbedtls_md_free(). Makes it necessary to call
- * mbedtls_md_free() later.
- *
- * \param ctx The context to set up.
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- * \param hmac Defines if HMAC is used. 0: HMAC is not used (saves some memory),
- * or non-zero: HMAC is used with this context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- * \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
- /**
- * \brief This function clones the state of an message-digest
- * context.
- *
- * \note You must call mbedtls_md_setup() on \c dst before calling
- * this function.
- *
- * \note The two contexts must have the same type,
- * for example, both are SHA-256.
- *
- * \warning This function clones the message-digest state, not the
- * HMAC state.
- *
- * \param dst The destination context.
- * \param src The context to be cloned.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_clone( mbedtls_md_context_t *dst,
- const mbedtls_md_context_t *src );
- /**
- * \brief This function extracts the message-digest size from the
- * message-digest information structure.
- *
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- *
- * \return The size of the message-digest output in Bytes.
- */
- unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
- /**
- * \brief This function extracts the message-digest type from the
- * message-digest information structure.
- *
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- *
- * \return The type of the message digest.
- */
- mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
- /**
- * \brief This function extracts the message-digest name from the
- * message-digest information structure.
- *
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- *
- * \return The name of the message digest.
- */
- const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
- /**
- * \brief This function starts a message-digest computation.
- *
- * You must call this function after setting up the context
- * with mbedtls_md_setup(), and before passing data with
- * mbedtls_md_update().
- *
- * \param ctx The generic message-digest context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_starts( mbedtls_md_context_t *ctx );
- /**
- * \brief This function feeds an input buffer into an ongoing
- * message-digest computation.
- *
- * You must call mbedtls_md_starts() before calling this
- * function. You may call this function multiple times.
- * Afterwards, call mbedtls_md_finish().
- *
- * \param ctx The generic message-digest context.
- * \param input The buffer holding the input data.
- * \param ilen The length of the input data.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
- /**
- * \brief This function finishes the digest operation,
- * and writes the result to the output buffer.
- *
- * Call this function after a call to mbedtls_md_starts(),
- * followed by any number of calls to mbedtls_md_update().
- * Afterwards, you may either clear the context with
- * mbedtls_md_free(), or call mbedtls_md_starts() to reuse
- * the context for another digest operation with the same
- * algorithm.
- *
- * \param ctx The generic message-digest context.
- * \param output The buffer for the generic message-digest checksum result.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
- /**
- * \brief This function calculates the message-digest of a buffer,
- * with respect to a configurable message-digest algorithm
- * in a single call.
- *
- * The result is calculated as
- * Output = message_digest(input buffer).
- *
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- * \param input The buffer holding the data.
- * \param ilen The length of the input data.
- * \param output The generic message-digest checksum result.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
- unsigned char *output );
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief This function calculates the message-digest checksum
- * result of the contents of the provided file.
- *
- * The result is calculated as
- * Output = message_digest(file contents).
- *
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- * \param path The input file name.
- * \param output The generic message-digest checksum result.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_FILE_IO_ERROR on an I/O error accessing
- * the file pointed by \p path.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
- unsigned char *output );
- #endif /* MBEDTLS_FS_IO */
- /**
- * \brief This function sets the HMAC key and prepares to
- * authenticate a new message.
- *
- * Call this function after mbedtls_md_setup(), to use
- * the MD context for an HMAC calculation, then call
- * mbedtls_md_hmac_update() to provide the input data, and
- * mbedtls_md_hmac_finish() to get the HMAC value.
- *
- * \param ctx The message digest context containing an embedded HMAC
- * context.
- * \param key The HMAC secret key.
- * \param keylen The length of the HMAC key in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
- size_t keylen );
- /**
- * \brief This function feeds an input buffer into an ongoing HMAC
- * computation.
- *
- * Call mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
- * before calling this function.
- * You may call this function multiple times to pass the
- * input piecewise.
- * Afterwards, call mbedtls_md_hmac_finish().
- *
- * \param ctx The message digest context containing an embedded HMAC
- * context.
- * \param input The buffer holding the input data.
- * \param ilen The length of the input data.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function finishes the HMAC operation, and writes
- * the result to the output buffer.
- *
- * Call this function after mbedtls_md_hmac_starts() and
- * mbedtls_md_hmac_update() to get the HMAC value. Afterwards
- * you may either call mbedtls_md_free() to clear the context,
- * or call mbedtls_md_hmac_reset() to reuse the context with
- * the same HMAC key.
- *
- * \param ctx The message digest context containing an embedded HMAC
- * context.
- * \param output The generic HMAC checksum result.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
- /**
- * \brief This function prepares to authenticate a new message with
- * the same key as the previous HMAC operation.
- *
- * You may call this function after mbedtls_md_hmac_finish().
- * Afterwards call mbedtls_md_hmac_update() to pass the new
- * input.
- *
- * \param ctx The message digest context containing an embedded HMAC
- * context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
- /**
- * \brief This function calculates the full generic HMAC
- * on the input buffer with the provided key.
- *
- * The function allocates the context, performs the
- * calculation, and frees the context.
- *
- * The HMAC result is calculated as
- * output = generic HMAC(hmac key, input buffer).
- *
- * \param md_info The information structure of the message-digest algorithm
- * to use.
- * \param key The HMAC secret key.
- * \param keylen The length of the HMAC secret key in Bytes.
- * \param input The buffer holding the input data.
- * \param ilen The length of the input data.
- * \param output The generic HMAC result.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
- * failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
- const unsigned char *input, size_t ilen,
- unsigned char *output );
- /* Internal use */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_MD_H */
- /********* Start of file include/mbedtls/md_internal.h ************/
- /**
- * \file md_internal.h
- *
- * \brief Message digest wrappers.
- *
- * \warning This in an internal header. Do not include directly.
- *
- * \author Adriaan de Jong <dejong@fox-it.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_MD_WRAP_H
- #define MBEDTLS_MD_WRAP_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Message digest information.
- * Allows message digest functions to be called in a generic way.
- */
- struct mbedtls_md_info_t
- {
- /** Name of the message digest */
- const char * name;
- /** Digest identifier */
- mbedtls_md_type_t type;
- /** Output length of the digest function in bytes */
- unsigned char size;
- /** Block length of the digest function in bytes */
- unsigned char block_size;
- };
- #if defined(MBEDTLS_MD2_C)
- extern const mbedtls_md_info_t mbedtls_md2_info;
- #endif
- #if defined(MBEDTLS_MD4_C)
- extern const mbedtls_md_info_t mbedtls_md4_info;
- #endif
- #if defined(MBEDTLS_MD5_C)
- extern const mbedtls_md_info_t mbedtls_md5_info;
- #endif
- #if defined(MBEDTLS_RIPEMD160_C)
- extern const mbedtls_md_info_t mbedtls_ripemd160_info;
- #endif
- #if defined(MBEDTLS_SHA1_C)
- extern const mbedtls_md_info_t mbedtls_sha1_info;
- #endif
- #if defined(MBEDTLS_SHA256_C)
- extern const mbedtls_md_info_t mbedtls_sha224_info;
- extern const mbedtls_md_info_t mbedtls_sha256_info;
- #endif
- #if defined(MBEDTLS_SHA512_C)
- #if !defined(MBEDTLS_SHA512_NO_SHA384)
- extern const mbedtls_md_info_t mbedtls_sha384_info;
- #endif
- extern const mbedtls_md_info_t mbedtls_sha512_info;
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_MD_WRAP_H */
- /********* Start of file include/mbedtls/md5.h ************/
- /**
- * \file md5.h
- *
- * \brief MD5 message digest algorithm (hash function)
- *
- * \warning MD5 is considered a weak message digest and its use constitutes a
- * security risk. We recommend considering stronger message
- * digests instead.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_MD5_H
- #define MBEDTLS_MD5_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** MD5 hardware accelerator failed */
- #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_MD5_ALT)
- // Regular implementation
- //
- /**
- * \brief MD5 context structure
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- typedef struct mbedtls_md5_context
- {
- uint32_t total[2]; /*!< number of bytes processed */
- uint32_t state[4]; /*!< intermediate digest state */
- unsigned char buffer[64]; /*!< data block being processed */
- }
- mbedtls_md5_context;
- #else /* MBEDTLS_MD5_ALT */
- #endif /* MBEDTLS_MD5_ALT */
- /**
- * \brief Initialize MD5 context
- *
- * \param ctx MD5 context to be initialized
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md5_init( mbedtls_md5_context *ctx );
- /**
- * \brief Clear MD5 context
- *
- * \param ctx MD5 context to be cleared
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md5_free( mbedtls_md5_context *ctx );
- /**
- * \brief Clone (the state of) an MD5 context
- *
- * \param dst The destination context
- * \param src The context to be cloned
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md5_clone( mbedtls_md5_context *dst,
- const mbedtls_md5_context *src );
- /**
- * \brief MD5 context setup
- *
- * \param ctx context to be initialized
- *
- * \return 0 if successful
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
- /**
- * \brief MD5 process buffer
- *
- * \param ctx MD5 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- *
- * \return 0 if successful
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief MD5 final digest
- *
- * \param ctx MD5 context
- * \param output MD5 checksum result
- *
- * \return 0 if successful
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
- unsigned char output[16] );
- /**
- * \brief MD5 process data block (internal use only)
- *
- * \param ctx MD5 context
- * \param data buffer holding one block of data
- *
- * \return 0 if successful
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
- const unsigned char data[64] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief MD5 context setup
- *
- * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
- *
- * \param ctx context to be initialized
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
- /**
- * \brief MD5 process buffer
- *
- * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
- *
- * \param ctx MD5 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief MD5 final digest
- *
- * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
- *
- * \param ctx MD5 context
- * \param output MD5 checksum result
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
- unsigned char output[16] );
- /**
- * \brief MD5 process data block (internal use only)
- *
- * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
- *
- * \param ctx MD5 context
- * \param data buffer holding one block of data
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
- const unsigned char data[64] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief Output = MD5( input buffer )
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output MD5 checksum result
- *
- * \return 0 if successful
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md5_ret( const unsigned char *input,
- size_t ilen,
- unsigned char output[16] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief Output = MD5( input buffer )
- *
- * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output MD5 checksum result
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
- size_t ilen,
- unsigned char output[16] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- *
- * \warning MD5 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md5_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_md5.h */
- /********* Start of file include/mbedtls/md2.h ************/
- /**
- * \file md2.h
- *
- * \brief MD2 message digest algorithm (hash function)
- *
- * \warning MD2 is considered a weak message digest and its use constitutes a
- * security risk. We recommend considering stronger message digests
- * instead.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- #ifndef MBEDTLS_MD2_H
- #define MBEDTLS_MD2_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- /* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** MD2 hardware accelerator failed */
- #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_MD2_ALT)
- // Regular implementation
- //
- /**
- * \brief MD2 context structure
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- typedef struct mbedtls_md2_context
- {
- unsigned char cksum[16]; /*!< checksum of the data block */
- unsigned char state[48]; /*!< intermediate digest state */
- unsigned char buffer[16]; /*!< data block being processed */
- size_t left; /*!< amount of data in buffer */
- }
- mbedtls_md2_context;
- #else /* MBEDTLS_MD2_ALT */
- #endif /* MBEDTLS_MD2_ALT */
- /**
- * \brief Initialize MD2 context
- *
- * \param ctx MD2 context to be initialized
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md2_init( mbedtls_md2_context *ctx );
- /**
- * \brief Clear MD2 context
- *
- * \param ctx MD2 context to be cleared
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md2_free( mbedtls_md2_context *ctx );
- /**
- * \brief Clone (the state of) an MD2 context
- *
- * \param dst The destination context
- * \param src The context to be cloned
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md2_clone( mbedtls_md2_context *dst,
- const mbedtls_md2_context *src );
- /**
- * \brief MD2 context setup
- *
- * \param ctx context to be initialized
- *
- * \return 0 if successful
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
- /**
- * \brief MD2 process buffer
- *
- * \param ctx MD2 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- *
- * \return 0 if successful
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief MD2 final digest
- *
- * \param ctx MD2 context
- * \param output MD2 checksum result
- *
- * \return 0 if successful
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
- unsigned char output[16] );
- /**
- * \brief MD2 process data block (internal use only)
- *
- * \param ctx MD2 context
- *
- * \return 0 if successful
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief MD2 context setup
- *
- * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
- *
- * \param ctx context to be initialized
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
- /**
- * \brief MD2 process buffer
- *
- * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
- *
- * \param ctx MD2 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief MD2 final digest
- *
- * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
- *
- * \param ctx MD2 context
- * \param output MD2 checksum result
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
- unsigned char output[16] );
- /**
- * \brief MD2 process data block (internal use only)
- *
- * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
- *
- * \param ctx MD2 context
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief Output = MD2( input buffer )
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output MD2 checksum result
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md2_ret( const unsigned char *input,
- size_t ilen,
- unsigned char output[16] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief Output = MD2( input buffer )
- *
- * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output MD2 checksum result
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
- size_t ilen,
- unsigned char output[16] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- *
- * \warning MD2 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md2_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_md2.h */
- /********* Start of file include/mbedtls/md4.h ************/
- /**
- * \file md4.h
- *
- * \brief MD4 message digest algorithm (hash function)
- *
- * \warning MD4 is considered a weak message digest and its use constitutes a
- * security risk. We recommend considering stronger message digests
- * instead.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- #ifndef MBEDTLS_MD4_H
- #define MBEDTLS_MD4_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** MD4 hardware accelerator failed */
- #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_MD4_ALT)
- // Regular implementation
- //
- /**
- * \brief MD4 context structure
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- typedef struct mbedtls_md4_context
- {
- uint32_t total[2]; /*!< number of bytes processed */
- uint32_t state[4]; /*!< intermediate digest state */
- unsigned char buffer[64]; /*!< data block being processed */
- }
- mbedtls_md4_context;
- #else /* MBEDTLS_MD4_ALT */
- #endif /* MBEDTLS_MD4_ALT */
- /**
- * \brief Initialize MD4 context
- *
- * \param ctx MD4 context to be initialized
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md4_init( mbedtls_md4_context *ctx );
- /**
- * \brief Clear MD4 context
- *
- * \param ctx MD4 context to be cleared
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md4_free( mbedtls_md4_context *ctx );
- /**
- * \brief Clone (the state of) an MD4 context
- *
- * \param dst The destination context
- * \param src The context to be cloned
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- void mbedtls_md4_clone( mbedtls_md4_context *dst,
- const mbedtls_md4_context *src );
- /**
- * \brief MD4 context setup
- *
- * \param ctx context to be initialized
- *
- * \return 0 if successful
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- */
- int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
- /**
- * \brief MD4 process buffer
- *
- * \param ctx MD4 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- *
- * \return 0 if successful
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief MD4 final digest
- *
- * \param ctx MD4 context
- * \param output MD4 checksum result
- *
- * \return 0 if successful
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
- unsigned char output[16] );
- /**
- * \brief MD4 process data block (internal use only)
- *
- * \param ctx MD4 context
- * \param data buffer holding one block of data
- *
- * \return 0 if successful
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
- const unsigned char data[64] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief MD4 context setup
- *
- * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
- *
- * \param ctx context to be initialized
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
- /**
- * \brief MD4 process buffer
- *
- * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
- *
- * \param ctx MD4 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief MD4 final digest
- *
- * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
- *
- * \param ctx MD4 context
- * \param output MD4 checksum result
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
- unsigned char output[16] );
- /**
- * \brief MD4 process data block (internal use only)
- *
- * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
- *
- * \param ctx MD4 context
- * \param data buffer holding one block of data
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
- const unsigned char data[64] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief Output = MD4( input buffer )
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output MD4 checksum result
- *
- * \return 0 if successful
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md4_ret( const unsigned char *input,
- size_t ilen,
- unsigned char output[16] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief Output = MD4( input buffer )
- *
- * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output MD4 checksum result
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
- size_t ilen,
- unsigned char output[16] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- *
- * \warning MD4 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- int mbedtls_md4_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_md4.h */
- /********* Start of file include/mbedtls/rsa.h ************/
- /**
- * \file rsa.h
- *
- * \brief This file provides an API for the RSA public-key cryptosystem.
- *
- * The RSA public-key cryptosystem is defined in <em>Public-Key
- * Cryptography Standards (PKCS) #1 v1.5: RSA Encryption</em>
- * and <em>Public-Key Cryptography Standards (PKCS) #1 v2.1:
- * RSA Cryptography Specifications</em>.
- *
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_RSA_H
- #define MBEDTLS_RSA_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_THREADING_C)
- #endif
- /*
- * RSA Error codes
- */
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080
- /** Input data contains invalid padding and is rejected. */
- #define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100
- /** Something failed during generation of a key. */
- #define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180
- /** Key failed to pass the validity check of the library. */
- #define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200
- /** The public key operation failed. */
- #define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280
- /** The private key operation failed. */
- #define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300
- /** The PKCS#1 verification failed. */
- #define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380
- /** The output buffer for decryption is not large enough. */
- #define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
- /** The random generator failed to generate non-zeros. */
- #define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480
- /* MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION is deprecated and should not be used.
- */
- /** The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */
- #define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500
- /* MBEDTLS_ERR_RSA_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** RSA hardware accelerator failed. */
- #define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580
- /*
- * RSA constants
- */
- #define MBEDTLS_RSA_PUBLIC 0 /**< Request private key operation. */
- #define MBEDTLS_RSA_PRIVATE 1 /**< Request public key operation. */
- #define MBEDTLS_RSA_PKCS_V15 0 /**< Use PKCS#1 v1.5 encoding. */
- #define MBEDTLS_RSA_PKCS_V21 1 /**< Use PKCS#1 v2.1 encoding. */
- #define MBEDTLS_RSA_SIGN 1 /**< Identifier for RSA signature operations. */
- #define MBEDTLS_RSA_CRYPT 2 /**< Identifier for RSA encryption and decryption operations. */
- #define MBEDTLS_RSA_SALT_LEN_ANY -1
- /*
- * The above constants may be used even if the RSA module is compile out,
- * eg for alternative (PKCS#11) RSA implemenations in the PK layers.
- */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_RSA_ALT)
- // Regular implementation
- //
- /**
- * \brief The RSA context structure.
- *
- * \note Direct manipulation of the members of this structure
- * is deprecated. All manipulation should instead be done through
- * the public interface functions.
- */
- typedef struct mbedtls_rsa_context
- {
- int ver; /*!< Reserved for internal purposes.
- * Do not set this field in application
- * code. Its meaning might change without
- * notice. */
- size_t len; /*!< The size of \p N in Bytes. */
- mbedtls_mpi N; /*!< The public modulus. */
- mbedtls_mpi E; /*!< The public exponent. */
- mbedtls_mpi D; /*!< The private exponent. */
- mbedtls_mpi P; /*!< The first prime factor. */
- mbedtls_mpi Q; /*!< The second prime factor. */
- mbedtls_mpi DP; /*!< <code>D % (P - 1)</code>. */
- mbedtls_mpi DQ; /*!< <code>D % (Q - 1)</code>. */
- mbedtls_mpi QP; /*!< <code>1 / (Q % P)</code>. */
- mbedtls_mpi RN; /*!< cached <code>R^2 mod N</code>. */
- mbedtls_mpi RP; /*!< cached <code>R^2 mod P</code>. */
- mbedtls_mpi RQ; /*!< cached <code>R^2 mod Q</code>. */
- mbedtls_mpi Vi; /*!< The cached blinding value. */
- mbedtls_mpi Vf; /*!< The cached un-blinding value. */
- int padding; /*!< Selects padding mode:
- #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
- #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */
- int hash_id; /*!< Hash identifier of mbedtls_md_type_t type,
- as specified in md.h for use in the MGF
- mask generating function used in the
- EME-OAEP and EMSA-PSS encodings. */
- #if defined(MBEDTLS_THREADING_C)
- /* Invariant: the mutex is initialized iff ver != 0. */
- mbedtls_threading_mutex_t mutex; /*!< Thread-safety mutex. */
- #endif
- }
- mbedtls_rsa_context;
- #else /* MBEDTLS_RSA_ALT */
- #endif /* MBEDTLS_RSA_ALT */
- /**
- * \brief This function initializes an RSA context.
- *
- * \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
- * encryption scheme and the RSASSA-PSS signature scheme.
- *
- * \note The \p hash_id parameter is ignored when using
- * #MBEDTLS_RSA_PKCS_V15 padding.
- *
- * \note The choice of padding mode is strictly enforced for private key
- * operations, since there might be security concerns in
- * mixing padding modes. For public key operations it is
- * a default value, which can be overridden by calling specific
- * \c rsa_rsaes_xxx or \c rsa_rsassa_xxx functions.
- *
- * \note The hash selected in \p hash_id is always used for OEAP
- * encryption. For PSS signatures, it is always used for
- * making signatures, but can be overridden for verifying them.
- * If set to #MBEDTLS_MD_NONE, it is always overridden.
- *
- * \param ctx The RSA context to initialize. This must not be \c NULL.
- * \param padding The padding mode to use. This must be either
- * #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
- * \param hash_id The hash identifier of ::mbedtls_md_type_t type, if
- * \p padding is #MBEDTLS_RSA_PKCS_V21. It is unused
- * otherwise.
- */
- void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
- int padding,
- int hash_id );
- /**
- * \brief This function imports a set of core parameters into an
- * RSA context.
- *
- * \note This function can be called multiple times for successive
- * imports, if the parameters are not simultaneously present.
- *
- * Any sequence of calls to this function should be followed
- * by a call to mbedtls_rsa_complete(), which checks and
- * completes the provided information to a ready-for-use
- * public or private RSA key.
- *
- * \note See mbedtls_rsa_complete() for more information on which
- * parameters are necessary to set up a private or public
- * RSA key.
- *
- * \note The imported parameters are copied and need not be preserved
- * for the lifetime of the RSA context being set up.
- *
- * \param ctx The initialized RSA context to store the parameters in.
- * \param N The RSA modulus. This may be \c NULL.
- * \param P The first prime factor of \p N. This may be \c NULL.
- * \param Q The second prime factor of \p N. This may be \c NULL.
- * \param D The private exponent. This may be \c NULL.
- * \param E The public exponent. This may be \c NULL.
- *
- * \return \c 0 on success.
- * \return A non-zero error code on failure.
- */
- int mbedtls_rsa_import( mbedtls_rsa_context *ctx,
- const mbedtls_mpi *N,
- const mbedtls_mpi *P, const mbedtls_mpi *Q,
- const mbedtls_mpi *D, const mbedtls_mpi *E );
- /**
- * \brief This function imports core RSA parameters, in raw big-endian
- * binary format, into an RSA context.
- *
- * \note This function can be called multiple times for successive
- * imports, if the parameters are not simultaneously present.
- *
- * Any sequence of calls to this function should be followed
- * by a call to mbedtls_rsa_complete(), which checks and
- * completes the provided information to a ready-for-use
- * public or private RSA key.
- *
- * \note See mbedtls_rsa_complete() for more information on which
- * parameters are necessary to set up a private or public
- * RSA key.
- *
- * \note The imported parameters are copied and need not be preserved
- * for the lifetime of the RSA context being set up.
- *
- * \param ctx The initialized RSA context to store the parameters in.
- * \param N The RSA modulus. This may be \c NULL.
- * \param N_len The Byte length of \p N; it is ignored if \p N == NULL.
- * \param P The first prime factor of \p N. This may be \c NULL.
- * \param P_len The Byte length of \p P; it ns ignored if \p P == NULL.
- * \param Q The second prime factor of \p N. This may be \c NULL.
- * \param Q_len The Byte length of \p Q; it is ignored if \p Q == NULL.
- * \param D The private exponent. This may be \c NULL.
- * \param D_len The Byte length of \p D; it is ignored if \p D == NULL.
- * \param E The public exponent. This may be \c NULL.
- * \param E_len The Byte length of \p E; it is ignored if \p E == NULL.
- *
- * \return \c 0 on success.
- * \return A non-zero error code on failure.
- */
- int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx,
- unsigned char const *N, size_t N_len,
- unsigned char const *P, size_t P_len,
- unsigned char const *Q, size_t Q_len,
- unsigned char const *D, size_t D_len,
- unsigned char const *E, size_t E_len );
- /**
- * \brief This function completes an RSA context from
- * a set of imported core parameters.
- *
- * To setup an RSA public key, precisely \p N and \p E
- * must have been imported.
- *
- * To setup an RSA private key, sufficient information must
- * be present for the other parameters to be derivable.
- *
- * The default implementation supports the following:
- * <ul><li>Derive \p P, \p Q from \p N, \p D, \p E.</li>
- * <li>Derive \p N, \p D from \p P, \p Q, \p E.</li></ul>
- * Alternative implementations need not support these.
- *
- * If this function runs successfully, it guarantees that
- * the RSA context can be used for RSA operations without
- * the risk of failure or crash.
- *
- * \warning This function need not perform consistency checks
- * for the imported parameters. In particular, parameters that
- * are not needed by the implementation might be silently
- * discarded and left unchecked. To check the consistency
- * of the key material, see mbedtls_rsa_check_privkey().
- *
- * \param ctx The initialized RSA context holding imported parameters.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_RSA_BAD_INPUT_DATA if the attempted derivations
- * failed.
- *
- */
- int mbedtls_rsa_complete( mbedtls_rsa_context *ctx );
- /**
- * \brief This function exports the core parameters of an RSA key.
- *
- * If this function runs successfully, the non-NULL buffers
- * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
- * written, with additional unused space filled leading by
- * zero Bytes.
- *
- * Possible reasons for returning
- * #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:<ul>
- * <li>An alternative RSA implementation is in use, which
- * stores the key externally, and either cannot or should
- * not export it into RAM.</li>
- * <li>A SW or HW implementation might not support a certain
- * deduction. For example, \p P, \p Q from \p N, \p D,
- * and \p E if the former are not part of the
- * implementation.</li></ul>
- *
- * If the function fails due to an unsupported operation,
- * the RSA context stays intact and remains usable.
- *
- * \param ctx The initialized RSA context.
- * \param N The MPI to hold the RSA modulus.
- * This may be \c NULL if this field need not be exported.
- * \param P The MPI to hold the first prime factor of \p N.
- * This may be \c NULL if this field need not be exported.
- * \param Q The MPI to hold the second prime factor of \p N.
- * This may be \c NULL if this field need not be exported.
- * \param D The MPI to hold the private exponent.
- * This may be \c NULL if this field need not be exported.
- * \param E The MPI to hold the public exponent.
- * This may be \c NULL if this field need not be exported.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED if exporting the
- * requested parameters cannot be done due to missing
- * functionality or because of security policies.
- * \return A non-zero return code on any other failure.
- *
- */
- int mbedtls_rsa_export( const mbedtls_rsa_context *ctx,
- mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q,
- mbedtls_mpi *D, mbedtls_mpi *E );
- /**
- * \brief This function exports core parameters of an RSA key
- * in raw big-endian binary format.
- *
- * If this function runs successfully, the non-NULL buffers
- * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
- * written, with additional unused space filled leading by
- * zero Bytes.
- *
- * Possible reasons for returning
- * #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:<ul>
- * <li>An alternative RSA implementation is in use, which
- * stores the key externally, and either cannot or should
- * not export it into RAM.</li>
- * <li>A SW or HW implementation might not support a certain
- * deduction. For example, \p P, \p Q from \p N, \p D,
- * and \p E if the former are not part of the
- * implementation.</li></ul>
- * If the function fails due to an unsupported operation,
- * the RSA context stays intact and remains usable.
- *
- * \note The length parameters are ignored if the corresponding
- * buffer pointers are NULL.
- *
- * \param ctx The initialized RSA context.
- * \param N The Byte array to store the RSA modulus,
- * or \c NULL if this field need not be exported.
- * \param N_len The size of the buffer for the modulus.
- * \param P The Byte array to hold the first prime factor of \p N,
- * or \c NULL if this field need not be exported.
- * \param P_len The size of the buffer for the first prime factor.
- * \param Q The Byte array to hold the second prime factor of \p N,
- * or \c NULL if this field need not be exported.
- * \param Q_len The size of the buffer for the second prime factor.
- * \param D The Byte array to hold the private exponent,
- * or \c NULL if this field need not be exported.
- * \param D_len The size of the buffer for the private exponent.
- * \param E The Byte array to hold the public exponent,
- * or \c NULL if this field need not be exported.
- * \param E_len The size of the buffer for the public exponent.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED if exporting the
- * requested parameters cannot be done due to missing
- * functionality or because of security policies.
- * \return A non-zero return code on any other failure.
- */
- int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx,
- unsigned char *N, size_t N_len,
- unsigned char *P, size_t P_len,
- unsigned char *Q, size_t Q_len,
- unsigned char *D, size_t D_len,
- unsigned char *E, size_t E_len );
- /**
- * \brief This function exports CRT parameters of a private RSA key.
- *
- * \note Alternative RSA implementations not using CRT-parameters
- * internally can implement this function based on
- * mbedtls_rsa_deduce_opt().
- *
- * \param ctx The initialized RSA context.
- * \param DP The MPI to hold \c D modulo `P-1`,
- * or \c NULL if it need not be exported.
- * \param DQ The MPI to hold \c D modulo `Q-1`,
- * or \c NULL if it need not be exported.
- * \param QP The MPI to hold modular inverse of \c Q modulo \c P,
- * or \c NULL if it need not be exported.
- *
- * \return \c 0 on success.
- * \return A non-zero error code on failure.
- *
- */
- int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx,
- mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP );
- /**
- * \brief This function sets padding for an already initialized RSA
- * context. See mbedtls_rsa_init() for details.
- *
- * \param ctx The initialized RSA context to be configured.
- * \param padding The padding mode to use. This must be either
- * #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
- * \param hash_id The #MBEDTLS_RSA_PKCS_V21 hash identifier.
- */
- void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
- int hash_id );
- /**
- * \brief This function retrieves the length of RSA modulus in Bytes.
- *
- * \param ctx The initialized RSA context.
- *
- * \return The length of the RSA modulus in Bytes.
- *
- */
- size_t mbedtls_rsa_get_len( const mbedtls_rsa_context *ctx );
- /**
- * \brief This function generates an RSA keypair.
- *
- * \note mbedtls_rsa_init() must be called before this function,
- * to set up the RSA context.
- *
- * \param ctx The initialized RSA context used to hold the key.
- * \param f_rng The RNG function to be used for key generation.
- * This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng.
- * This may be \c NULL if \p f_rng doesn't need a context.
- * \param nbits The size of the public key in bits.
- * \param exponent The public exponent to use. For example, \c 65537.
- * This must be odd and greater than \c 1.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- unsigned int nbits, int exponent );
- /**
- * \brief This function checks if a context contains at least an RSA
- * public key.
- *
- * If the function runs successfully, it is guaranteed that
- * enough information is present to perform an RSA public key
- * operation using mbedtls_rsa_public().
- *
- * \param ctx The initialized RSA context to check.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- *
- */
- int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx );
- /**
- * \brief This function checks if a context contains an RSA private key
- * and perform basic consistency checks.
- *
- * \note The consistency checks performed by this function not only
- * ensure that mbedtls_rsa_private() can be called successfully
- * on the given context, but that the various parameters are
- * mutually consistent with high probability, in the sense that
- * mbedtls_rsa_public() and mbedtls_rsa_private() are inverses.
- *
- * \warning This function should catch accidental misconfigurations
- * like swapping of parameters, but it cannot establish full
- * trust in neither the quality nor the consistency of the key
- * material that was used to setup the given RSA context:
- * <ul><li>Consistency: Imported parameters that are irrelevant
- * for the implementation might be silently dropped. If dropped,
- * the current function does not have access to them,
- * and therefore cannot check them. See mbedtls_rsa_complete().
- * If you want to check the consistency of the entire
- * content of an PKCS1-encoded RSA private key, for example, you
- * should use mbedtls_rsa_validate_params() before setting
- * up the RSA context.
- * Additionally, if the implementation performs empirical checks,
- * these checks substantiate but do not guarantee consistency.</li>
- * <li>Quality: This function is not expected to perform
- * extended quality assessments like checking that the prime
- * factors are safe. Additionally, it is the responsibility of the
- * user to ensure the trustworthiness of the source of his RSA
- * parameters, which goes beyond what is effectively checkable
- * by the library.</li></ul>
- *
- * \param ctx The initialized RSA context to check.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx );
- /**
- * \brief This function checks a public-private RSA key pair.
- *
- * It checks each of the contexts, and makes sure they match.
- *
- * \param pub The initialized RSA context holding the public key.
- * \param prv The initialized RSA context holding the private key.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub,
- const mbedtls_rsa_context *prv );
- /**
- * \brief This function performs an RSA public key operation.
- *
- * \param ctx The initialized RSA context to use.
- * \param input The input buffer. This must be a readable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- * \param output The output buffer. This must be a writable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \note This function does not handle message padding.
- *
- * \note Make sure to set \p input[0] = 0 or ensure that
- * input is smaller than \p N.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function performs an RSA private key operation.
- *
- * \note Blinding is used if and only if a PRNG is provided.
- *
- * \note If blinding is used, both the base of exponentation
- * and the exponent are blinded, providing protection
- * against some side-channel attacks.
- *
- * \warning It is deprecated and a security risk to not provide
- * a PRNG here and thereby prevent the use of blinding.
- * Future versions of the library may enforce the presence
- * of a PRNG.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function, used for blinding. It is discouraged
- * and deprecated to pass \c NULL here, in which case
- * blinding will be omitted.
- * \param p_rng The RNG context to pass to \p f_rng. This may be \c NULL
- * if \p f_rng is \c NULL or if \p f_rng doesn't need a context.
- * \param input The input buffer. This must be a readable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- * \param output The output buffer. This must be a writable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- *
- */
- int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function adds the message padding, then performs an RSA
- * operation.
- *
- * It is the generic wrapper for performing a PKCS#1 encryption
- * operation using the \p mode from the context.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PUBLIC.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG to use. It is mandatory for PKCS#1 v2.1 padding
- * encoding, and for PKCS#1 v1.5 padding encoding when used
- * with \p mode set to #MBEDTLS_RSA_PUBLIC. For PKCS#1 v1.5
- * padding encoding and \p mode set to #MBEDTLS_RSA_PRIVATE,
- * it is used for blinding and should be provided in this
- * case; see mbedtls_rsa_private() for more.
- * \param p_rng The RNG context to be passed to \p f_rng. May be
- * \c NULL if \p f_rng is \c NULL or if \p f_rng doesn't
- * need a context argument.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
- * \param ilen The length of the plaintext in Bytes.
- * \param input The input data to encrypt. This must be a readable
- * buffer of size \p ilen Bytes. It may be \c NULL if
- * `ilen == 0`.
- * \param output The output buffer. This must be a writable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode, size_t ilen,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function performs a PKCS#1 v1.5 encryption operation
- * (RSAES-PKCS1-v1_5-ENCRYPT).
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PUBLIC.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function to use. It is needed for padding generation
- * if \p mode is #MBEDTLS_RSA_PUBLIC. If \p mode is
- * #MBEDTLS_RSA_PRIVATE (discouraged), it is used for
- * blinding and should be provided; see mbedtls_rsa_private().
- * \param p_rng The RNG context to be passed to \p f_rng. This may
- * be \c NULL if \p f_rng is \c NULL or if \p f_rng
- * doesn't need a context argument.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
- * \param ilen The length of the plaintext in Bytes.
- * \param input The input data to encrypt. This must be a readable
- * buffer of size \p ilen Bytes. It may be \c NULL if
- * `ilen == 0`.
- * \param output The output buffer. This must be a writable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode, size_t ilen,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function performs a PKCS#1 v2.1 OAEP encryption
- * operation (RSAES-OAEP-ENCRYPT).
- *
- * \note The output buffer must be as large as the size
- * of ctx->N. For example, 128 Bytes if RSA-1024 is used.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PUBLIC.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initnialized RSA context to use.
- * \param f_rng The RNG function to use. This is needed for padding
- * generation and must be provided.
- * \param p_rng The RNG context to be passed to \p f_rng. This may
- * be \c NULL if \p f_rng doesn't need a context argument.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
- * \param label The buffer holding the custom label to use.
- * This must be a readable buffer of length \p label_len
- * Bytes. It may be \c NULL if \p label_len is \c 0.
- * \param label_len The length of the label in Bytes.
- * \param ilen The length of the plaintext buffer \p input in Bytes.
- * \param input The input data to encrypt. This must be a readable
- * buffer of size \p ilen Bytes. It may be \c NULL if
- * `ilen == 0`.
- * \param output The output buffer. This must be a writable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- const unsigned char *label, size_t label_len,
- size_t ilen,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function performs an RSA operation, then removes the
- * message padding.
- *
- * It is the generic wrapper for performing a PKCS#1 decryption
- * operation using the \p mode from the context.
- *
- * \note The output buffer length \c output_max_len should be
- * as large as the size \p ctx->len of \p ctx->N (for example,
- * 128 Bytes if RSA-1024 is used) to be able to hold an
- * arbitrary decrypted message. If it is not large enough to
- * hold the decryption of the particular ciphertext provided,
- * the function returns \c MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PRIVATE.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. If \p mode is
- * #MBEDTLS_RSA_PUBLIC, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a context.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
- * \param olen The address at which to store the length of
- * the plaintext. This must not be \c NULL.
- * \param input The ciphertext buffer. This must be a readable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- * \param output The buffer used to hold the plaintext. This must
- * be a writable buffer of length \p output_max_len Bytes.
- * \param output_max_len The length in Bytes of the output buffer \p output.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode, size_t *olen,
- const unsigned char *input,
- unsigned char *output,
- size_t output_max_len );
- /**
- * \brief This function performs a PKCS#1 v1.5 decryption
- * operation (RSAES-PKCS1-v1_5-DECRYPT).
- *
- * \note The output buffer length \c output_max_len should be
- * as large as the size \p ctx->len of \p ctx->N, for example,
- * 128 Bytes if RSA-1024 is used, to be able to hold an
- * arbitrary decrypted message. If it is not large enough to
- * hold the decryption of the particular ciphertext provided,
- * the function returns #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PRIVATE.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. If \p mode is
- * #MBEDTLS_RSA_PUBLIC, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a context.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
- * \param olen The address at which to store the length of
- * the plaintext. This must not be \c NULL.
- * \param input The ciphertext buffer. This must be a readable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- * \param output The buffer used to hold the plaintext. This must
- * be a writable buffer of length \p output_max_len Bytes.
- * \param output_max_len The length in Bytes of the output buffer \p output.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- *
- */
- int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode, size_t *olen,
- const unsigned char *input,
- unsigned char *output,
- size_t output_max_len );
- /**
- * \brief This function performs a PKCS#1 v2.1 OAEP decryption
- * operation (RSAES-OAEP-DECRYPT).
- *
- * \note The output buffer length \c output_max_len should be
- * as large as the size \p ctx->len of \p ctx->N, for
- * example, 128 Bytes if RSA-1024 is used, to be able to
- * hold an arbitrary decrypted message. If it is not
- * large enough to hold the decryption of the particular
- * ciphertext provided, the function returns
- * #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PRIVATE.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. If \p mode is
- * #MBEDTLS_RSA_PUBLIC, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a context.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
- * \param label The buffer holding the custom label to use.
- * This must be a readable buffer of length \p label_len
- * Bytes. It may be \c NULL if \p label_len is \c 0.
- * \param label_len The length of the label in Bytes.
- * \param olen The address at which to store the length of
- * the plaintext. This must not be \c NULL.
- * \param input The ciphertext buffer. This must be a readable buffer
- * of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- * \param output The buffer used to hold the plaintext. This must
- * be a writable buffer of length \p output_max_len Bytes.
- * \param output_max_len The length in Bytes of the output buffer \p output.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- const unsigned char *label, size_t label_len,
- size_t *olen,
- const unsigned char *input,
- unsigned char *output,
- size_t output_max_len );
- /**
- * \brief This function performs a private RSA operation to sign
- * a message digest using PKCS#1.
- *
- * It is the generic wrapper for performing a PKCS#1
- * signature using the \p mode from the context.
- *
- * \note The \p sig buffer must be as large as the size
- * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
- *
- * \note For PKCS#1 v2.1 encoding, see comments on
- * mbedtls_rsa_rsassa_pss_sign() for details on
- * \p md_alg and \p hash_id.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PRIVATE.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function to use. If the padding mode is PKCS#1 v2.1,
- * this must be provided. If the padding mode is PKCS#1 v1.5 and
- * \p mode is #MBEDTLS_RSA_PRIVATE, it is used for blinding
- * and should be provided; see mbedtls_rsa_private() for more
- * more. It is ignored otherwise.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
- * if \p f_rng is \c NULL or doesn't need a context argument.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param sig The buffer to hold the signature. This must be a writable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus. A buffer length of
- * #MBEDTLS_MPI_MAX_SIZE is always safe.
- *
- * \return \c 0 if the signing operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- unsigned char *sig );
- /**
- * \brief This function performs a PKCS#1 v1.5 signature
- * operation (RSASSA-PKCS1-v1_5-SIGN).
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PRIVATE.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. If \p mode is
- * #MBEDTLS_RSA_PUBLIC, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
- * if \p f_rng is \c NULL or doesn't need a context argument.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param sig The buffer to hold the signature. This must be a writable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus. A buffer length of
- * #MBEDTLS_MPI_MAX_SIZE is always safe.
- *
- * \return \c 0 if the signing operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- unsigned char *sig );
- /**
- * \brief This function performs a PKCS#1 v2.1 PSS signature
- * operation (RSASSA-PSS-SIGN).
- *
- * \note The \c hash_id set in \p ctx (when calling
- * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
- * afterwards) selects the hash used for the
- * encoding operation and for the mask generation function
- * (MGF1). For more details on the encoding operation and the
- * mask generation function, consult <em>RFC-3447: Public-Key
- * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
- * Specifications</em>.
- *
- * \note This function enforces that the provided salt length complies
- * with FIPS 186-4 §5.5 (e) and RFC 8017 (PKCS#1 v2.2) §9.1.1
- * step 3. The constraint is that the hash length plus the salt
- * length plus 2 bytes must be at most the key length. If this
- * constraint is not met, this function returns
- * #MBEDTLS_ERR_RSA_BAD_INPUT_DATA.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function. It must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
- * if \p f_rng doesn't need a context argument.
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param saltlen The length of the salt that should be used.
- * If passed #MBEDTLS_RSA_SALT_LEN_ANY, the function will use
- * the largest possible salt length up to the hash length,
- * which is the largest permitted by some standards including
- * FIPS 186-4 §5.5.
- * \param sig The buffer to hold the signature. This must be a writable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus. A buffer length of
- * #MBEDTLS_MPI_MAX_SIZE is always safe.
- *
- * \return \c 0 if the signing operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsassa_pss_sign_ext( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- int saltlen,
- unsigned char *sig );
- /**
- * \brief This function performs a PKCS#1 v2.1 PSS signature
- * operation (RSASSA-PSS-SIGN).
- *
- * \note The \c hash_id set in \p ctx (when calling
- * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
- * afterwards) selects the hash used for the
- * encoding operation and for the mask generation function
- * (MGF1). For more details on the encoding operation and the
- * mask generation function, consult <em>RFC-3447: Public-Key
- * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
- * Specifications</em>.
- *
- * \note This function always uses the maximum possible salt size,
- * up to the length of the payload hash. This choice of salt
- * size complies with FIPS 186-4 §5.5 (e) and RFC 8017 (PKCS#1
- * v2.2) §9.1.1 step 3. Furthermore this function enforces a
- * minimum salt size which is the hash size minus 2 bytes. If
- * this minimum size is too large given the key size (the salt
- * size, plus the hash size, plus 2 bytes must be no more than
- * the key size in bytes), this function returns
- * #MBEDTLS_ERR_RSA_BAD_INPUT_DATA.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PRIVATE.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA context to use.
- * \param f_rng The RNG function. It must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
- * if \p f_rng doesn't need a context argument.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param sig The buffer to hold the signature. This must be a writable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus. A buffer length of
- * #MBEDTLS_MPI_MAX_SIZE is always safe.
- *
- * \return \c 0 if the signing operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- unsigned char *sig );
- /**
- * \brief This function performs a public RSA operation and checks
- * the message digest.
- *
- * This is the generic wrapper for performing a PKCS#1
- * verification using the mode from the context.
- *
- * \note For PKCS#1 v2.1 encoding, see comments on
- * mbedtls_rsa_rsassa_pss_verify() about \p md_alg and
- * \p hash_id.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * set to #MBEDTLS_RSA_PUBLIC.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA public key context to use.
- * \param f_rng The RNG function to use. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. Otherwise, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a context.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param sig The buffer holding the signature. This must be a readable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 if the verify operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- const unsigned char *sig );
- /**
- * \brief This function performs a PKCS#1 v1.5 verification
- * operation (RSASSA-PKCS1-v1_5-VERIFY).
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * set to #MBEDTLS_RSA_PUBLIC.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA public key context to use.
- * \param f_rng The RNG function to use. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. Otherwise, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a context.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param sig The buffer holding the signature. This must be a readable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 if the verify operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- const unsigned char *sig );
- /**
- * \brief This function performs a PKCS#1 v2.1 PSS verification
- * operation (RSASSA-PSS-VERIFY).
- *
- * \note The \c hash_id set in \p ctx (when calling
- * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
- * afterwards) selects the hash used for the
- * encoding operation and for the mask generation function
- * (MGF1). For more details on the encoding operation and the
- * mask generation function, consult <em>RFC-3447: Public-Key
- * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
- * Specifications</em>. If the \c hash_id set in \p ctx is
- * #MBEDTLS_MD_NONE, the \p md_alg parameter is used.
- *
- * \deprecated It is deprecated and discouraged to call this function
- * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
- * are likely to remove the \p mode argument and have it
- * implicitly set to #MBEDTLS_RSA_PUBLIC.
- *
- * \note Alternative implementations of RSA need not support
- * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
- * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
- *
- * \param ctx The initialized RSA public key context to use.
- * \param f_rng The RNG function to use. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. Otherwise, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a context.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param sig The buffer holding the signature. This must be a readable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 if the verify operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- const unsigned char *sig );
- /**
- * \brief This function performs a PKCS#1 v2.1 PSS verification
- * operation (RSASSA-PSS-VERIFY).
- *
- * \note The \p sig buffer must be as large as the size
- * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
- *
- * \note The \c hash_id set in \p ctx (when calling
- * mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
- * afterwards) is ignored.
- *
- * \param ctx The initialized RSA public key context to use.
- * \param f_rng The RNG function to use. If \p mode is #MBEDTLS_RSA_PRIVATE,
- * this is used for blinding and should be provided; see
- * mbedtls_rsa_private() for more. Otherwise, it is ignored.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a context.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
- * \param md_alg The message-digest algorithm used to hash the original data.
- * Use #MBEDTLS_MD_NONE for signing raw data.
- * \param hashlen The length of the message digest.
- * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
- * \param hash The buffer holding the message digest or raw data.
- * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
- * buffer of length \p hashlen Bytes. If \p md_alg is not
- * #MBEDTLS_MD_NONE, it must be a readable buffer of length
- * the size of the hash corresponding to \p md_alg.
- * \param mgf1_hash_id The message digest algorithm used for the
- * verification operation and the mask generation
- * function (MGF1). For more details on the encoding
- * operation and the mask generation function, consult
- * <em>RFC-3447: Public-Key Cryptography Standards
- * (PKCS) #1 v2.1: RSA Cryptography
- * Specifications</em>.
- * \param expected_salt_len The length of the salt used in padding. Use
- * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
- * \param sig The buffer holding the signature. This must be a readable
- * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
- * for an 2048-bit RSA modulus.
- *
- * \return \c 0 if the verify operation was successful.
- * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
- */
- int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- mbedtls_md_type_t mgf1_hash_id,
- int expected_salt_len,
- const unsigned char *sig );
- /**
- * \brief This function copies the components of an RSA context.
- *
- * \param dst The destination context. This must be initialized.
- * \param src The source context. This must be initialized.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory allocation failure.
- */
- int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src );
- /**
- * \brief This function frees the components of an RSA key.
- *
- * \param ctx The RSA context to free. May be \c NULL, in which case
- * this function is a no-op. If it is not \c NULL, it must
- * point to an initialized RSA context.
- */
- void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The RSA checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_rsa_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* rsa.h */
- /********* Start of file include/mbedtls/rsa_internal.h ************/
- /**
- * \file rsa_internal.h
- *
- * \brief Context-independent RSA helper functions
- *
- * This module declares some RSA-related helper functions useful when
- * implementing the RSA interface. These functions are provided in a separate
- * compilation unit in order to make it easy for designers of alternative RSA
- * implementations to use them in their own code, as it is conceived that the
- * functionality they provide will be necessary for most complete
- * implementations.
- *
- * End-users of Mbed TLS who are not providing their own alternative RSA
- * implementations should not use these functions directly, and should instead
- * use only the functions declared in rsa.h.
- *
- * The interface provided by this module will be maintained through LTS (Long
- * Term Support) branches of Mbed TLS, but may otherwise be subject to change,
- * and must be considered an internal interface of the library.
- *
- * There are two classes of helper functions:
- *
- * (1) Parameter-generating helpers. These are:
- * - mbedtls_rsa_deduce_primes
- * - mbedtls_rsa_deduce_private_exponent
- * - mbedtls_rsa_deduce_crt
- * Each of these functions takes a set of core RSA parameters and
- * generates some other, or CRT related parameters.
- *
- * (2) Parameter-checking helpers. These are:
- * - mbedtls_rsa_validate_params
- * - mbedtls_rsa_validate_crt
- * They take a set of core or CRT related RSA parameters and check their
- * validity.
- *
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- #ifndef MBEDTLS_RSA_INTERNAL_H
- #define MBEDTLS_RSA_INTERNAL_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Compute RSA prime moduli P, Q from public modulus N=PQ
- * and a pair of private and public key.
- *
- * \note This is a 'static' helper function not operating on
- * an RSA context. Alternative implementations need not
- * overwrite it.
- *
- * \param N RSA modulus N = PQ, with P, Q to be found
- * \param E RSA public exponent
- * \param D RSA private exponent
- * \param P Pointer to MPI holding first prime factor of N on success
- * \param Q Pointer to MPI holding second prime factor of N on success
- *
- * \return
- * - 0 if successful. In this case, P and Q constitute a
- * factorization of N.
- * - A non-zero error code otherwise.
- *
- * \note It is neither checked that P, Q are prime nor that
- * D, E are modular inverses wrt. P-1 and Q-1. For that,
- * use the helper function \c mbedtls_rsa_validate_params.
- *
- */
- int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, mbedtls_mpi const *E,
- mbedtls_mpi const *D,
- mbedtls_mpi *P, mbedtls_mpi *Q );
- /**
- * \brief Compute RSA private exponent from
- * prime moduli and public key.
- *
- * \note This is a 'static' helper function not operating on
- * an RSA context. Alternative implementations need not
- * overwrite it.
- *
- * \param P First prime factor of RSA modulus
- * \param Q Second prime factor of RSA modulus
- * \param E RSA public exponent
- * \param D Pointer to MPI holding the private exponent on success.
- *
- * \return
- * - 0 if successful. In this case, D is set to a simultaneous
- * modular inverse of E modulo both P-1 and Q-1.
- * - A non-zero error code otherwise.
- *
- * \note This function does not check whether P and Q are primes.
- *
- */
- int mbedtls_rsa_deduce_private_exponent( mbedtls_mpi const *P,
- mbedtls_mpi const *Q,
- mbedtls_mpi const *E,
- mbedtls_mpi *D );
- /**
- * \brief Generate RSA-CRT parameters
- *
- * \note This is a 'static' helper function not operating on
- * an RSA context. Alternative implementations need not
- * overwrite it.
- *
- * \param P First prime factor of N
- * \param Q Second prime factor of N
- * \param D RSA private exponent
- * \param DP Output variable for D modulo P-1
- * \param DQ Output variable for D modulo Q-1
- * \param QP Output variable for the modular inverse of Q modulo P.
- *
- * \return 0 on success, non-zero error code otherwise.
- *
- * \note This function does not check whether P, Q are
- * prime and whether D is a valid private exponent.
- *
- */
- int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
- const mbedtls_mpi *D, mbedtls_mpi *DP,
- mbedtls_mpi *DQ, mbedtls_mpi *QP );
- /**
- * \brief Check validity of core RSA parameters
- *
- * \note This is a 'static' helper function not operating on
- * an RSA context. Alternative implementations need not
- * overwrite it.
- *
- * \param N RSA modulus N = PQ
- * \param P First prime factor of N
- * \param Q Second prime factor of N
- * \param D RSA private exponent
- * \param E RSA public exponent
- * \param f_rng PRNG to be used for primality check, or NULL
- * \param p_rng PRNG context for f_rng, or NULL
- *
- * \return
- * - 0 if the following conditions are satisfied
- * if all relevant parameters are provided:
- * - P prime if f_rng != NULL (%)
- * - Q prime if f_rng != NULL (%)
- * - 1 < N = P * Q
- * - 1 < D, E < N
- * - D and E are modular inverses modulo P-1 and Q-1
- * (%) This is only done if MBEDTLS_GENPRIME is defined.
- * - A non-zero error code otherwise.
- *
- * \note The function can be used with a restricted set of arguments
- * to perform specific checks only. E.g., calling it with
- * (-,P,-,-,-) and a PRNG amounts to a primality check for P.
- */
- int mbedtls_rsa_validate_params( const mbedtls_mpi *N, const mbedtls_mpi *P,
- const mbedtls_mpi *Q, const mbedtls_mpi *D,
- const mbedtls_mpi *E,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief Check validity of RSA CRT parameters
- *
- * \note This is a 'static' helper function not operating on
- * an RSA context. Alternative implementations need not
- * overwrite it.
- *
- * \param P First prime factor of RSA modulus
- * \param Q Second prime factor of RSA modulus
- * \param D RSA private exponent
- * \param DP MPI to check for D modulo P-1
- * \param DQ MPI to check for D modulo P-1
- * \param QP MPI to check for the modular inverse of Q modulo P.
- *
- * \return
- * - 0 if the following conditions are satisfied:
- * - D = DP mod P-1 if P, D, DP != NULL
- * - Q = DQ mod P-1 if P, D, DQ != NULL
- * - QP = Q^-1 mod P if P, Q, QP != NULL
- * - \c MBEDTLS_ERR_RSA_KEY_CHECK_FAILED if check failed,
- * potentially including \c MBEDTLS_ERR_MPI_XXX if some
- * MPI calculations failed.
- * - \c MBEDTLS_ERR_RSA_BAD_INPUT_DATA if insufficient
- * data was provided to check DP, DQ or QP.
- *
- * \note The function can be used with a restricted set of arguments
- * to perform specific checks only. E.g., calling it with the
- * parameters (P, -, D, DP, -, -) will check DP = D mod P-1.
- */
- int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
- const mbedtls_mpi *D, const mbedtls_mpi *DP,
- const mbedtls_mpi *DQ, const mbedtls_mpi *QP );
- #ifdef __cplusplus
- }
- #endif
- #endif /* rsa_internal.h */
- /********* Start of file include/mbedtls/asn1.h ************/
- /**
- * \file asn1.h
- *
- * \brief Generic ASN.1 parsing
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ASN1_H
- #define MBEDTLS_ASN1_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #if defined(MBEDTLS_BIGNUM_C)
- #endif
- /**
- * \addtogroup asn1_module
- * \{
- */
- /**
- * \name ASN1 Error codes
- * These error codes are OR'ed to X509 error codes for
- * higher error granularity.
- * ASN1 is a standard to specify data structures.
- * \{
- */
- /** Out of data when parsing an ASN1 data structure. */
- #define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060
- /** ASN1 tag was of an unexpected value. */
- #define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062
- /** Error when trying to determine the length or invalid length. */
- #define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064
- /** Actual length differs from expected length. */
- #define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066
- /** Data is invalid. */
- #define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068
- /** Memory allocation failed */
- #define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A
- /** Buffer too small when writing ASN.1 data structure. */
- #define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C
- /* \} name */
- /**
- * \name DER constants
- * These constants comply with the DER encoded ASN.1 type tags.
- * DER encoding uses hexadecimal representation.
- * An example DER sequence is:\n
- * - 0x02 -- tag indicating INTEGER
- * - 0x01 -- length in octets
- * - 0x05 -- value
- * Such sequences are typically read into \c ::mbedtls_x509_buf.
- * \{
- */
- #define MBEDTLS_ASN1_BOOLEAN 0x01
- #define MBEDTLS_ASN1_INTEGER 0x02
- #define MBEDTLS_ASN1_BIT_STRING 0x03
- #define MBEDTLS_ASN1_OCTET_STRING 0x04
- #define MBEDTLS_ASN1_NULL 0x05
- #define MBEDTLS_ASN1_OID 0x06
- #define MBEDTLS_ASN1_ENUMERATED 0x0A
- #define MBEDTLS_ASN1_UTF8_STRING 0x0C
- #define MBEDTLS_ASN1_SEQUENCE 0x10
- #define MBEDTLS_ASN1_SET 0x11
- #define MBEDTLS_ASN1_PRINTABLE_STRING 0x13
- #define MBEDTLS_ASN1_T61_STRING 0x14
- #define MBEDTLS_ASN1_IA5_STRING 0x16
- #define MBEDTLS_ASN1_UTC_TIME 0x17
- #define MBEDTLS_ASN1_GENERALIZED_TIME 0x18
- #define MBEDTLS_ASN1_UNIVERSAL_STRING 0x1C
- #define MBEDTLS_ASN1_BMP_STRING 0x1E
- #define MBEDTLS_ASN1_PRIMITIVE 0x00
- #define MBEDTLS_ASN1_CONSTRUCTED 0x20
- #define MBEDTLS_ASN1_CONTEXT_SPECIFIC 0x80
- /* Slightly smaller way to check if tag is a string tag
- * compared to canonical implementation. */
- #define MBEDTLS_ASN1_IS_STRING_TAG( tag ) \
- ( ( tag ) < 32u && ( \
- ( ( 1u << ( tag ) ) & ( ( 1u << MBEDTLS_ASN1_BMP_STRING ) | \
- ( 1u << MBEDTLS_ASN1_UTF8_STRING ) | \
- ( 1u << MBEDTLS_ASN1_T61_STRING ) | \
- ( 1u << MBEDTLS_ASN1_IA5_STRING ) | \
- ( 1u << MBEDTLS_ASN1_UNIVERSAL_STRING ) | \
- ( 1u << MBEDTLS_ASN1_PRINTABLE_STRING ) | \
- ( 1u << MBEDTLS_ASN1_BIT_STRING ) ) ) != 0 ) )
- /*
- * Bit masks for each of the components of an ASN.1 tag as specified in
- * ITU X.690 (08/2015), section 8.1 "General rules for encoding",
- * paragraph 8.1.2.2:
- *
- * Bit 8 7 6 5 1
- * +-------+-----+------------+
- * | Class | P/C | Tag number |
- * +-------+-----+------------+
- */
- #define MBEDTLS_ASN1_TAG_CLASS_MASK 0xC0
- #define MBEDTLS_ASN1_TAG_PC_MASK 0x20
- #define MBEDTLS_ASN1_TAG_VALUE_MASK 0x1F
- /* \} name */
- /* \} addtogroup asn1_module */
- /** Returns the size of the binary string, without the trailing \\0 */
- #define MBEDTLS_OID_SIZE(x) (sizeof(x) - 1)
- /**
- * Compares an mbedtls_asn1_buf structure to a reference OID.
- *
- * Only works for 'defined' oid_str values (MBEDTLS_OID_HMAC_SHA1), you cannot use a
- * 'unsigned char *oid' here!
- */
- #define MBEDTLS_OID_CMP(oid_str, oid_buf) \
- ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len ) || \
- memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 )
- #define MBEDTLS_OID_CMP_RAW(oid_str, oid_buf, oid_buf_len) \
- ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf_len) ) || \
- memcmp( (oid_str), (oid_buf), (oid_buf_len) ) != 0 )
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \name Functions to parse ASN.1 data structures
- * \{
- */
- /**
- * Type-length-value structure that allows for ASN1 using DER.
- */
- typedef struct mbedtls_asn1_buf
- {
- int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
- size_t len; /**< ASN1 length, in octets. */
- unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
- }
- mbedtls_asn1_buf;
- /**
- * Container for ASN1 bit strings.
- */
- typedef struct mbedtls_asn1_bitstring
- {
- size_t len; /**< ASN1 length, in octets. */
- unsigned char unused_bits; /**< Number of unused bits at the end of the string */
- unsigned char *p; /**< Raw ASN1 data for the bit string */
- }
- mbedtls_asn1_bitstring;
- /**
- * Container for a sequence of ASN.1 items
- */
- typedef struct mbedtls_asn1_sequence
- {
- mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
- struct mbedtls_asn1_sequence *next; /**< The next entry in the sequence. */
- }
- mbedtls_asn1_sequence;
- /**
- * Container for a sequence or list of 'named' ASN.1 data items
- */
- typedef struct mbedtls_asn1_named_data
- {
- mbedtls_asn1_buf oid; /**< The object identifier. */
- mbedtls_asn1_buf val; /**< The named value. */
- struct mbedtls_asn1_named_data *next; /**< The next entry in the sequence. */
- unsigned char next_merged; /**< Merge next item into the current one? */
- }
- mbedtls_asn1_named_data;
- /**
- * \brief Get the length of an ASN.1 element.
- * Updates the pointer to immediately behind the length.
- *
- * \param p On entry, \c *p points to the first byte of the length,
- * i.e. immediately after the tag.
- * On successful completion, \c *p points to the first byte
- * after the length, i.e. the first byte of the content.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param len On successful completion, \c *len contains the length
- * read from the ASN.1 input.
- *
- * \return 0 if successful.
- * \return #MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element
- * would end beyond \p end.
- * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable.
- */
- int mbedtls_asn1_get_len( unsigned char **p,
- const unsigned char *end,
- size_t *len );
- /**
- * \brief Get the tag and length of the element.
- * Check for the requested tag.
- * Updates the pointer to immediately behind the tag and length.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * after the length, i.e. the first byte of the content.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param len On successful completion, \c *len contains the length
- * read from the ASN.1 input.
- * \param tag The expected tag.
- *
- * \return 0 if successful.
- * \return #MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if the data does not start
- * with the requested tag.
- * \return #MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element
- * would end beyond \p end.
- * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable.
- */
- int mbedtls_asn1_get_tag( unsigned char **p,
- const unsigned char *end,
- size_t *len, int tag );
- /**
- * \brief Retrieve a boolean ASN.1 tag and its value.
- * Updates the pointer to immediately behind the full tag.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * beyond the ASN.1 element.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param val On success, the parsed value (\c 0 or \c 1).
- *
- * \return 0 if successful.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 BOOLEAN.
- */
- int mbedtls_asn1_get_bool( unsigned char **p,
- const unsigned char *end,
- int *val );
- /**
- * \brief Retrieve an integer ASN.1 tag and its value.
- * Updates the pointer to immediately behind the full tag.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * beyond the ASN.1 element.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param val On success, the parsed value.
- *
- * \return 0 if successful.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 INTEGER.
- * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
- * not fit in an \c int.
- */
- int mbedtls_asn1_get_int( unsigned char **p,
- const unsigned char *end,
- int *val );
- /**
- * \brief Retrieve an enumerated ASN.1 tag and its value.
- * Updates the pointer to immediately behind the full tag.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * beyond the ASN.1 element.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param val On success, the parsed value.
- *
- * \return 0 if successful.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 ENUMERATED.
- * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
- * not fit in an \c int.
- */
- int mbedtls_asn1_get_enum( unsigned char **p,
- const unsigned char *end,
- int *val );
- /**
- * \brief Retrieve a bitstring ASN.1 tag and its value.
- * Updates the pointer to immediately behind the full tag.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p is equal to \p end.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param bs On success, ::mbedtls_asn1_bitstring information about
- * the parsed value.
- *
- * \return 0 if successful.
- * \return #MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input contains
- * extra data after a valid BIT STRING.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 BIT STRING.
- */
- int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
- mbedtls_asn1_bitstring *bs );
- /**
- * \brief Retrieve a bitstring ASN.1 tag without unused bits and its
- * value.
- * Updates the pointer to the beginning of the bit/octet string.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * of the content of the BIT STRING.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param len On success, \c *len is the length of the content in bytes.
- *
- * \return 0 if successful.
- * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if the input starts with
- * a valid BIT STRING with a nonzero number of unused bits.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 BIT STRING.
- */
- int mbedtls_asn1_get_bitstring_null( unsigned char **p,
- const unsigned char *end,
- size_t *len );
- /**
- * \brief Parses and splits an ASN.1 "SEQUENCE OF <tag>".
- * Updates the pointer to immediately behind the full sequence tag.
- *
- * This function allocates memory for the sequence elements. You can free
- * the allocated memory with mbedtls_asn1_sequence_free().
- *
- * \note On error, this function may return a partial list in \p cur.
- * You must set `cur->next = NULL` before calling this function!
- * Otherwise it is impossible to distinguish a previously non-null
- * pointer from a pointer to an object allocated by this function.
- *
- * \note If the sequence is empty, this function does not modify
- * \c *cur. If the sequence is valid and non-empty, this
- * function sets `cur->buf.tag` to \p tag. This allows
- * callers to distinguish between an empty sequence and
- * a one-element sequence.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p is equal to \p end.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param cur A ::mbedtls_asn1_sequence which this function fills.
- * When this function returns, \c *cur is the head of a linked
- * list. Each node in this list is allocated with
- * mbedtls_calloc() apart from \p cur itself, and should
- * therefore be freed with mbedtls_free().
- * The list describes the content of the sequence.
- * The head of the list (i.e. \c *cur itself) describes the
- * first element, `*cur->next` describes the second element, etc.
- * For each element, `buf.tag == tag`, `buf.len` is the length
- * of the content of the content of the element, and `buf.p`
- * points to the first byte of the content (i.e. immediately
- * past the length of the element).
- * Note that list elements may be allocated even on error.
- * \param tag Each element of the sequence must have this tag.
- *
- * \return 0 if successful.
- * \return #MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input contains
- * extra data after a valid SEQUENCE OF \p tag.
- * \return #MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if the input starts with
- * an ASN.1 SEQUENCE in which an element has a tag that
- * is different from \p tag.
- * \return #MBEDTLS_ERR_ASN1_ALLOC_FAILED if a memory allocation failed.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 SEQUENCE.
- */
- int mbedtls_asn1_get_sequence_of( unsigned char **p,
- const unsigned char *end,
- mbedtls_asn1_sequence *cur,
- int tag );
- /**
- * \brief Free a heap-allocated linked list presentation of
- * an ASN.1 sequence, including the first element.
- *
- * There are two common ways to manage the memory used for the representation
- * of a parsed ASN.1 sequence:
- * - Allocate a head node `mbedtls_asn1_sequence *head` with mbedtls_calloc().
- * Pass this node as the `cur` argument to mbedtls_asn1_get_sequence_of().
- * When you have finished processing the sequence,
- * call mbedtls_asn1_sequence_free() on `head`.
- * - Allocate a head node `mbedtls_asn1_sequence *head` in any manner,
- * for example on the stack. Make sure that `head->next == NULL`.
- * Pass `head` as the `cur` argument to mbedtls_asn1_get_sequence_of().
- * When you have finished processing the sequence,
- * call mbedtls_asn1_sequence_free() on `head->cur`,
- * then free `head` itself in the appropriate manner.
- *
- * \param seq The address of the first sequence component. This may
- * be \c NULL, in which case this functions returns
- * immediately.
- */
- void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq );
- /**
- * \brief Traverse an ASN.1 SEQUENCE container and
- * call a callback for each entry.
- *
- * This function checks that the input is a SEQUENCE of elements that
- * each have a "must" tag, and calls a callback function on the elements
- * that have a "may" tag.
- *
- * For example, to validate that the input is a SEQUENCE of `tag1` and call
- * `cb` on each element, use
- * ```
- * mbedtls_asn1_traverse_sequence_of(&p, end, 0xff, tag1, 0, 0, cb, ctx);
- * ```
- *
- * To validate that the input is a SEQUENCE of ANY and call `cb` on
- * each element, use
- * ```
- * mbedtls_asn1_traverse_sequence_of(&p, end, 0, 0, 0, 0, cb, ctx);
- * ```
- *
- * To validate that the input is a SEQUENCE of CHOICE {NULL, OCTET STRING}
- * and call `cb` on each element that is an OCTET STRING, use
- * ```
- * mbedtls_asn1_traverse_sequence_of(&p, end, 0xfe, 0x04, 0xff, 0x04, cb, ctx);
- * ```
- *
- * The callback is called on the elements with a "may" tag from left to
- * right. If the input is not a valid SEQUENCE of elements with a "must" tag,
- * the callback is called on the elements up to the leftmost point where
- * the input is invalid.
- *
- * \warning This function is still experimental and may change
- * at any time.
- *
- * \param p The address of the pointer to the beginning of
- * the ASN.1 SEQUENCE header. This is updated to
- * point to the end of the ASN.1 SEQUENCE container
- * on a successful invocation.
- * \param end The end of the ASN.1 SEQUENCE container.
- * \param tag_must_mask A mask to be applied to the ASN.1 tags found within
- * the SEQUENCE before comparing to \p tag_must_value.
- * \param tag_must_val The required value of each ASN.1 tag found in the
- * SEQUENCE, after masking with \p tag_must_mask.
- * Mismatching tags lead to an error.
- * For example, a value of \c 0 for both \p tag_must_mask
- * and \p tag_must_val means that every tag is allowed,
- * while a value of \c 0xFF for \p tag_must_mask means
- * that \p tag_must_val is the only allowed tag.
- * \param tag_may_mask A mask to be applied to the ASN.1 tags found within
- * the SEQUENCE before comparing to \p tag_may_value.
- * \param tag_may_val The desired value of each ASN.1 tag found in the
- * SEQUENCE, after masking with \p tag_may_mask.
- * Mismatching tags will be silently ignored.
- * For example, a value of \c 0 for \p tag_may_mask and
- * \p tag_may_val means that any tag will be considered,
- * while a value of \c 0xFF for \p tag_may_mask means
- * that all tags with value different from \p tag_may_val
- * will be ignored.
- * \param cb The callback to trigger for each component
- * in the ASN.1 SEQUENCE that matches \p tag_may_val.
- * The callback function is called with the following
- * parameters:
- * - \p ctx.
- * - The tag of the current element.
- * - A pointer to the start of the current element's
- * content inside the input.
- * - The length of the content of the current element.
- * If the callback returns a non-zero value,
- * the function stops immediately,
- * forwarding the callback's return value.
- * \param ctx The context to be passed to the callback \p cb.
- *
- * \return \c 0 if successful the entire ASN.1 SEQUENCE
- * was traversed without parsing or callback errors.
- * \return #MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input
- * contains extra data after a valid SEQUENCE
- * of elements with an accepted tag.
- * \return #MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if the input starts
- * with an ASN.1 SEQUENCE in which an element has a tag
- * that is not accepted.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 SEQUENCE.
- * \return A non-zero error code forwarded from the callback
- * \p cb in case the latter returns a non-zero value.
- */
- int mbedtls_asn1_traverse_sequence_of(
- unsigned char **p,
- const unsigned char *end,
- unsigned char tag_must_mask, unsigned char tag_must_val,
- unsigned char tag_may_mask, unsigned char tag_may_val,
- int (*cb)( void *ctx, int tag,
- unsigned char* start, size_t len ),
- void *ctx );
- #if defined(MBEDTLS_BIGNUM_C)
- /**
- * \brief Retrieve an integer ASN.1 tag and its value.
- * Updates the pointer to immediately behind the full tag.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * beyond the ASN.1 element.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param X On success, the parsed value.
- *
- * \return 0 if successful.
- * \return An ASN.1 error code if the input does not start with
- * a valid ASN.1 INTEGER.
- * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
- * not fit in an \c int.
- * \return An MPI error code if the parsed value is too large.
- */
- int mbedtls_asn1_get_mpi( unsigned char **p,
- const unsigned char *end,
- mbedtls_mpi *X );
- #endif /* MBEDTLS_BIGNUM_C */
- /**
- * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence.
- * Updates the pointer to immediately behind the full
- * AlgorithmIdentifier.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * beyond the AlgorithmIdentifier element.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param alg The buffer to receive the OID.
- * \param params The buffer to receive the parameters.
- * This is zeroized if there are no parameters.
- *
- * \return 0 if successful or a specific ASN.1 or MPI error code.
- */
- int mbedtls_asn1_get_alg( unsigned char **p,
- const unsigned char *end,
- mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params );
- /**
- * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no
- * params.
- * Updates the pointer to immediately behind the full
- * AlgorithmIdentifier.
- *
- * \param p On entry, \c *p points to the start of the ASN.1 element.
- * On successful completion, \c *p points to the first byte
- * beyond the AlgorithmIdentifier element.
- * On error, the value of \c *p is undefined.
- * \param end End of data.
- * \param alg The buffer to receive the OID.
- *
- * \return 0 if successful or a specific ASN.1 or MPI error code.
- */
- int mbedtls_asn1_get_alg_null( unsigned char **p,
- const unsigned char *end,
- mbedtls_asn1_buf *alg );
- /**
- * \brief Find a specific named_data entry in a sequence or list based on
- * the OID.
- *
- * \param list The list to seek through
- * \param oid The OID to look for
- * \param len Size of the OID
- *
- * \return NULL if not found, or a pointer to the existing entry.
- */
- mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
- const char *oid, size_t len );
- /**
- * \brief Free a mbedtls_asn1_named_data entry
- *
- * \param entry The named data entry to free.
- * This function calls mbedtls_free() on
- * `entry->oid.p` and `entry->val.p`.
- */
- void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *entry );
- /**
- * \brief Free all entries in a mbedtls_asn1_named_data list.
- *
- * \param head Pointer to the head of the list of named data entries to free.
- * This function calls mbedtls_asn1_free_named_data() and
- * mbedtls_free() on each list element and
- * sets \c *head to \c NULL.
- */
- void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head );
- #ifdef __cplusplus
- }
- #endif
- #endif /* asn1.h */
- /********* Start of file include/mbedtls/ecp.h ************/
- /**
- * \file ecp.h
- *
- * \brief This file provides an API for Elliptic Curves over GF(P) (ECP).
- *
- * The use of ECP in cryptography and TLS is defined in
- * <em>Standards for Efficient Cryptography Group (SECG): SEC1
- * Elliptic Curve Cryptography</em> and
- * <em>RFC-4492: Elliptic Curve Cryptography (ECC) Cipher Suites
- * for Transport Layer Security (TLS)</em>.
- *
- * <em>RFC-2409: The Internet Key Exchange (IKE)</em> defines ECP
- * group types.
- *
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ECP_H
- #define MBEDTLS_ECP_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /*
- * ECP error codes
- */
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80
- /** The buffer is too small to write to. */
- #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00
- /** The requested feature is not available, for example, the requested curve is not supported. */
- #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80
- /** The signature is not valid. */
- #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00
- /** Memory allocation failed. */
- #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80
- /** Generation of random value, such as ephemeral key, failed. */
- #define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00
- /** Invalid private or public key. */
- #define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80
- /** The buffer contains a valid signature followed by more data. */
- #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00
- /* MBEDTLS_ERR_ECP_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** The ECP hardware accelerator failed. */
- #define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80
- /** Operation in progress, call again with the same parameters to continue. */
- #define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00
- /* Flags indicating whether to include code that is specific to certain
- * types of curves. These flags are for internal library use only. */
- #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \
- defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
- #define MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED
- #endif
- #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || \
- defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
- #define MBEDTLS_ECP_MONTGOMERY_ENABLED
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Domain-parameter identifiers: curve, subgroup, and generator.
- *
- * \note Only curves over prime fields are supported.
- *
- * \warning This library does not support validation of arbitrary domain
- * parameters. Therefore, only standardized domain parameters from trusted
- * sources should be used. See mbedtls_ecp_group_load().
- */
- /* Note: when adding a new curve:
- * - Add it at the end of this enum, otherwise you'll break the ABI by
- * changing the numerical value for existing curves.
- * - Increment MBEDTLS_ECP_DP_MAX below if needed.
- * - Update the calculation of MBEDTLS_ECP_MAX_BITS_MIN below.
- * - Add the corresponding MBEDTLS_ECP_DP_xxx_ENABLED macro definition to
- * config.h.
- * - List the curve as a dependency of MBEDTLS_ECP_C and
- * MBEDTLS_ECDSA_C if supported in check_config.h.
- * - Add the curve to the appropriate curve type macro
- * MBEDTLS_ECP_yyy_ENABLED above.
- * - Add the necessary definitions to ecp_curves.c.
- * - Add the curve to the ecp_supported_curves array in ecp.c.
- * - Add the curve to applicable profiles in x509_crt.c if applicable.
- */
- typedef enum
- {
- MBEDTLS_ECP_DP_NONE = 0, /*!< Curve not defined. */
- MBEDTLS_ECP_DP_SECP192R1, /*!< Domain parameters for the 192-bit curve defined by FIPS 186-4 and SEC1. */
- MBEDTLS_ECP_DP_SECP224R1, /*!< Domain parameters for the 224-bit curve defined by FIPS 186-4 and SEC1. */
- MBEDTLS_ECP_DP_SECP256R1, /*!< Domain parameters for the 256-bit curve defined by FIPS 186-4 and SEC1. */
- MBEDTLS_ECP_DP_SECP384R1, /*!< Domain parameters for the 384-bit curve defined by FIPS 186-4 and SEC1. */
- MBEDTLS_ECP_DP_SECP521R1, /*!< Domain parameters for the 521-bit curve defined by FIPS 186-4 and SEC1. */
- MBEDTLS_ECP_DP_BP256R1, /*!< Domain parameters for 256-bit Brainpool curve. */
- MBEDTLS_ECP_DP_BP384R1, /*!< Domain parameters for 384-bit Brainpool curve. */
- MBEDTLS_ECP_DP_BP512R1, /*!< Domain parameters for 512-bit Brainpool curve. */
- MBEDTLS_ECP_DP_CURVE25519, /*!< Domain parameters for Curve25519. */
- MBEDTLS_ECP_DP_SECP192K1, /*!< Domain parameters for 192-bit "Koblitz" curve. */
- MBEDTLS_ECP_DP_SECP224K1, /*!< Domain parameters for 224-bit "Koblitz" curve. */
- MBEDTLS_ECP_DP_SECP256K1, /*!< Domain parameters for 256-bit "Koblitz" curve. */
- MBEDTLS_ECP_DP_CURVE448, /*!< Domain parameters for Curve448. */
- } mbedtls_ecp_group_id;
- /**
- * The number of supported curves, plus one for #MBEDTLS_ECP_DP_NONE.
- *
- * \note Montgomery curves are currently excluded.
- */
- #define MBEDTLS_ECP_DP_MAX 12
- /*
- * Curve types
- */
- typedef enum
- {
- MBEDTLS_ECP_TYPE_NONE = 0,
- MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS, /* y^2 = x^3 + a x + b */
- MBEDTLS_ECP_TYPE_MONTGOMERY, /* y^2 = x^3 + a x^2 + x */
- } mbedtls_ecp_curve_type;
- /**
- * Curve information, for use by other modules.
- */
- typedef struct mbedtls_ecp_curve_info
- {
- mbedtls_ecp_group_id grp_id; /*!< An internal identifier. */
- uint16_t tls_id; /*!< The TLS NamedCurve identifier. */
- uint16_t bit_size; /*!< The curve size in bits. */
- const char *name; /*!< A human-friendly name. */
- } mbedtls_ecp_curve_info;
- /**
- * \brief The ECP point structure, in Jacobian coordinates.
- *
- * \note All functions expect and return points satisfying
- * the following condition: <code>Z == 0</code> or
- * <code>Z == 1</code>. Other values of \p Z are
- * used only by internal functions.
- * The point is zero, or "at infinity", if <code>Z == 0</code>.
- * Otherwise, \p X and \p Y are its standard (affine)
- * coordinates.
- */
- typedef struct mbedtls_ecp_point
- {
- mbedtls_mpi X; /*!< The X coordinate of the ECP point. */
- mbedtls_mpi Y; /*!< The Y coordinate of the ECP point. */
- mbedtls_mpi Z; /*!< The Z coordinate of the ECP point. */
- }
- mbedtls_ecp_point;
- /* Determine the minimum safe value of MBEDTLS_ECP_MAX_BITS. */
- #if !defined(MBEDTLS_ECP_C)
- #define MBEDTLS_ECP_MAX_BITS_MIN 0
- /* Note: the curves must be listed in DECREASING size! */
- #elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 521
- #elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 512
- #elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 448
- #elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 384
- #elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 384
- #elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 256
- #elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 256
- #elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 256
- #elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 255
- #elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 225 // n is slightly above 2^224
- #elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 224
- #elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 192
- #elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
- #define MBEDTLS_ECP_MAX_BITS_MIN 192
- #else
- #error "MBEDTLS_ECP_C enabled, but no curve?"
- #endif
- #if !defined(MBEDTLS_ECP_ALT)
- /*
- * default mbed TLS elliptic curve arithmetic implementation
- *
- * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
- * alternative implementation for the whole module and it will replace this
- * one.)
- */
- /**
- * \brief The ECP group structure.
- *
- * We consider two types of curve equations:
- * <ul><li>Short Weierstrass: <code>y^2 = x^3 + A x + B mod P</code>
- * (SEC1 + RFC-4492)</li>
- * <li>Montgomery: <code>y^2 = x^3 + A x^2 + x mod P</code> (Curve25519,
- * Curve448)</li></ul>
- * In both cases, the generator (\p G) for a prime-order subgroup is fixed.
- *
- * For Short Weierstrass, this subgroup is the whole curve, and its
- * cardinality is denoted by \p N. Our code requires that \p N is an
- * odd prime as mbedtls_ecp_mul() requires an odd number, and
- * mbedtls_ecdsa_sign() requires that it is prime for blinding purposes.
- *
- * For Montgomery curves, we do not store \p A, but <code>(A + 2) / 4</code>,
- * which is the quantity used in the formulas. Additionally, \p nbits is
- * not the size of \p N but the required size for private keys.
- *
- * If \p modp is NULL, reduction modulo \p P is done using a generic algorithm.
- * Otherwise, \p modp must point to a function that takes an \p mbedtls_mpi in the
- * range of <code>0..2^(2*pbits)-1</code>, and transforms it in-place to an integer
- * which is congruent mod \p P to the given MPI, and is close enough to \p pbits
- * in size, so that it may be efficiently brought in the 0..P-1 range by a few
- * additions or subtractions. Therefore, it is only an approximative modular
- * reduction. It must return 0 on success and non-zero on failure.
- *
- * \note Alternative implementations must keep the group IDs distinct. If
- * two group structures have the same ID, then they must be
- * identical.
- *
- */
- typedef struct mbedtls_ecp_group
- {
- mbedtls_ecp_group_id id; /*!< An internal group identifier. */
- mbedtls_mpi P; /*!< The prime modulus of the base field. */
- mbedtls_mpi A; /*!< For Short Weierstrass: \p A in the equation. For
- Montgomery curves: <code>(A + 2) / 4</code>. */
- mbedtls_mpi B; /*!< For Short Weierstrass: \p B in the equation.
- For Montgomery curves: unused. */
- mbedtls_ecp_point G; /*!< The generator of the subgroup used. */
- mbedtls_mpi N; /*!< The order of \p G. */
- size_t pbits; /*!< The number of bits in \p P.*/
- size_t nbits; /*!< For Short Weierstrass: The number of bits in \p P.
- For Montgomery curves: the number of bits in the
- private keys. */
- unsigned int h; /*!< \internal 1 if the constants are static. */
- int (*modp)(mbedtls_mpi *); /*!< The function for fast pseudo-reduction
- mod \p P (see above).*/
- int (*t_pre)(mbedtls_ecp_point *, void *); /*!< Unused. */
- int (*t_post)(mbedtls_ecp_point *, void *); /*!< Unused. */
- void *t_data; /*!< Unused. */
- mbedtls_ecp_point *T; /*!< Pre-computed points for ecp_mul_comb(). */
- size_t T_size; /*!< The number of pre-computed points. */
- }
- mbedtls_ecp_group;
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h, or define them using the compiler command line.
- * \{
- */
- #if defined(MBEDTLS_ECP_MAX_BITS)
- #if MBEDTLS_ECP_MAX_BITS < MBEDTLS_ECP_MAX_BITS_MIN
- #error "MBEDTLS_ECP_MAX_BITS is smaller than the largest supported curve"
- #endif
- #elif defined(MBEDTLS_ECP_C)
- /**
- * The maximum size of the groups, that is, of \c N and \c P.
- */
- #define MBEDTLS_ECP_MAX_BITS MBEDTLS_ECP_MAX_BITS_MIN
- #else
- /* MBEDTLS_ECP_MAX_BITS is not relevant without MBEDTLS_ECP_C, but set it
- * to a nonzero value so that code that unconditionally allocates an array
- * of a size based on it keeps working if built without ECC support. */
- #define MBEDTLS_ECP_MAX_BITS 1
- #endif
- #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
- #define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
- #if !defined(MBEDTLS_ECP_WINDOW_SIZE)
- /*
- * Maximum "window" size used for point multiplication.
- * Default: a point where higher memory usage yields disminishing performance
- * returns.
- * Minimum value: 2. Maximum value: 7.
- *
- * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
- * points used for point multiplication. This value is directly tied to EC
- * peak memory usage, so decreasing it by one should roughly cut memory usage
- * by two (if large curves are in use).
- *
- * Reduction in size may reduce speed, but larger curves are impacted first.
- * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
- * w-size: 6 5 4 3 2
- * 521 145 141 135 120 97
- * 384 214 209 198 177 146
- * 256 320 320 303 262 226
- * 224 475 475 453 398 342
- * 192 640 640 633 587 476
- */
- #define MBEDTLS_ECP_WINDOW_SIZE 4 /**< The maximum window size used. */
- #endif /* MBEDTLS_ECP_WINDOW_SIZE */
- #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
- /*
- * Trade memory for speed on fixed-point multiplication.
- *
- * This speeds up repeated multiplication of the generator (that is, the
- * multiplication in ECDSA signatures, and half of the multiplications in
- * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
- *
- * The cost is increasing EC peak memory usage by a factor roughly 2.
- *
- * Change this value to 0 to reduce peak memory usage.
- */
- #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up. */
- #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
- /* \} name SECTION: Module settings */
- #else /* MBEDTLS_ECP_ALT */
- #endif /* MBEDTLS_ECP_ALT */
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Internal restart context for multiplication
- *
- * \note Opaque struct
- */
- typedef struct mbedtls_ecp_restart_mul mbedtls_ecp_restart_mul_ctx;
- /**
- * \brief Internal restart context for ecp_muladd()
- *
- * \note Opaque struct
- */
- typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx;
- /**
- * \brief General context for resuming ECC operations
- */
- typedef struct
- {
- unsigned ops_done; /*!< current ops count */
- unsigned depth; /*!< call depth (0 = top-level) */
- mbedtls_ecp_restart_mul_ctx *rsm; /*!< ecp_mul_comb() sub-context */
- mbedtls_ecp_restart_muladd_ctx *ma; /*!< ecp_muladd() sub-context */
- } mbedtls_ecp_restart_ctx;
- /*
- * Operation counts for restartable functions
- */
- #define MBEDTLS_ECP_OPS_CHK 3 /*!< basic ops count for ecp_check_pubkey() */
- #define MBEDTLS_ECP_OPS_DBL 8 /*!< basic ops count for ecp_double_jac() */
- #define MBEDTLS_ECP_OPS_ADD 11 /*!< basic ops count for see ecp_add_mixed() */
- #define MBEDTLS_ECP_OPS_INV 120 /*!< empirical equivalent for mpi_mod_inv() */
- /**
- * \brief Internal; for restartable functions in other modules.
- * Check and update basic ops budget.
- *
- * \param grp Group structure
- * \param rs_ctx Restart context
- * \param ops Number of basic ops to do
- *
- * \return \c 0 if doing \p ops basic ops is still allowed,
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS otherwise.
- */
- int mbedtls_ecp_check_budget( const mbedtls_ecp_group *grp,
- mbedtls_ecp_restart_ctx *rs_ctx,
- unsigned ops );
- /* Utility macro for checking and updating ops budget */
- #define MBEDTLS_ECP_BUDGET( ops ) \
- MBEDTLS_MPI_CHK( mbedtls_ecp_check_budget( grp, rs_ctx, \
- (unsigned) (ops) ) );
- #else /* MBEDTLS_ECP_RESTARTABLE */
- #define MBEDTLS_ECP_BUDGET( ops ) /* no-op; for compatibility */
- /* We want to declare restartable versions of existing functions anyway */
- typedef void mbedtls_ecp_restart_ctx;
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- /**
- * \brief The ECP key-pair structure.
- *
- * A generic key-pair that may be used for ECDSA and fixed ECDH, for example.
- *
- * \note Members are deliberately in the same order as in the
- * ::mbedtls_ecdsa_context structure.
- */
- typedef struct mbedtls_ecp_keypair
- {
- mbedtls_ecp_group grp; /*!< Elliptic curve and base point */
- mbedtls_mpi d; /*!< our secret value */
- mbedtls_ecp_point Q; /*!< our public value */
- }
- mbedtls_ecp_keypair;
- /*
- * Point formats, from RFC 4492's enum ECPointFormat
- */
- #define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format. */
- #define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format. */
- /*
- * Some other constants from RFC 4492
- */
- #define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< The named_curve of ECCurveType. */
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Set the maximum number of basic operations done in a row.
- *
- * If more operations are needed to complete a computation,
- * #MBEDTLS_ERR_ECP_IN_PROGRESS will be returned by the
- * function performing the computation. It is then the
- * caller's responsibility to either call again with the same
- * parameters until it returns 0 or an error code; or to free
- * the restart context if the operation is to be aborted.
- *
- * It is strictly required that all input parameters and the
- * restart context be the same on successive calls for the
- * same operation, but output parameters need not be the
- * same; they must not be used until the function finally
- * returns 0.
- *
- * This only applies to functions whose documentation
- * mentions they may return #MBEDTLS_ERR_ECP_IN_PROGRESS (or
- * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS for functions in the
- * SSL module). For functions that accept a "restart context"
- * argument, passing NULL disables restart and makes the
- * function equivalent to the function with the same name
- * with \c _restartable removed. For functions in the ECDH
- * module, restart is disabled unless the function accepts
- * an "ECDH context" argument and
- * mbedtls_ecdh_enable_restart() was previously called on
- * that context. For function in the SSL module, restart is
- * only enabled for specific sides and key exchanges
- * (currently only for clients and ECDHE-ECDSA).
- *
- * \param max_ops Maximum number of basic operations done in a row.
- * Default: 0 (unlimited).
- * Lower (non-zero) values mean ECC functions will block for
- * a lesser maximum amount of time.
- *
- * \note A "basic operation" is defined as a rough equivalent of a
- * multiplication in GF(p) for the NIST P-256 curve.
- * As an indication, with default settings, a scalar
- * multiplication (full run of \c mbedtls_ecp_mul()) is:
- * - about 3300 basic operations for P-256
- * - about 9400 basic operations for P-384
- *
- * \note Very low values are not always respected: sometimes
- * functions need to block for a minimum number of
- * operations, and will do so even if max_ops is set to a
- * lower value. That minimum depends on the curve size, and
- * can be made lower by decreasing the value of
- * \c MBEDTLS_ECP_WINDOW_SIZE. As an indication, here is the
- * lowest effective value for various curves and values of
- * that parameter (w for short):
- * w=6 w=5 w=4 w=3 w=2
- * P-256 208 208 160 136 124
- * P-384 682 416 320 272 248
- * P-521 1364 832 640 544 496
- *
- * \note This setting is currently ignored by Curve25519.
- */
- void mbedtls_ecp_set_max_ops( unsigned max_ops );
- /**
- * \brief Check if restart is enabled (max_ops != 0)
- *
- * \return \c 0 if \c max_ops == 0 (restart disabled)
- * \return \c 1 otherwise (restart enabled)
- */
- int mbedtls_ecp_restart_is_enabled( void );
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- /*
- * Get the type of a curve
- */
- mbedtls_ecp_curve_type mbedtls_ecp_get_type( const mbedtls_ecp_group *grp );
- /**
- * \brief This function retrieves the information defined in
- * mbedtls_ecp_curve_info() for all supported curves.
- *
- * \note This function returns information about all curves
- * supported by the library. Some curves may not be
- * supported for all algorithms. Call mbedtls_ecdh_can_do()
- * or mbedtls_ecdsa_can_do() to check if a curve is
- * supported for ECDH or ECDSA.
- *
- * \return A statically allocated array. The last entry is 0.
- */
- const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
- /**
- * \brief This function retrieves the list of internal group
- * identifiers of all supported curves in the order of
- * preference.
- *
- * \note This function returns information about all curves
- * supported by the library. Some curves may not be
- * supported for all algorithms. Call mbedtls_ecdh_can_do()
- * or mbedtls_ecdsa_can_do() to check if a curve is
- * supported for ECDH or ECDSA.
- *
- * \return A statically allocated array,
- * terminated with MBEDTLS_ECP_DP_NONE.
- */
- const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void );
- /**
- * \brief This function retrieves curve information from an internal
- * group identifier.
- *
- * \param grp_id An \c MBEDTLS_ECP_DP_XXX value.
- *
- * \return The associated curve information on success.
- * \return NULL on failure.
- */
- const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_group_id grp_id );
- /**
- * \brief This function retrieves curve information from a TLS
- * NamedCurve value.
- *
- * \param tls_id An \c MBEDTLS_ECP_DP_XXX value.
- *
- * \return The associated curve information on success.
- * \return NULL on failure.
- */
- const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id );
- /**
- * \brief This function retrieves curve information from a
- * human-readable name.
- *
- * \param name The human-readable name.
- *
- * \return The associated curve information on success.
- * \return NULL on failure.
- */
- const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name );
- /**
- * \brief This function initializes a point as zero.
- *
- * \param pt The point to initialize.
- */
- void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
- /**
- * \brief This function initializes an ECP group context
- * without loading any domain parameters.
- *
- * \note After this function is called, domain parameters
- * for various ECP groups can be loaded through the
- * mbedtls_ecp_group_load() or mbedtls_ecp_tls_read_group()
- * functions.
- */
- void mbedtls_ecp_group_init( mbedtls_ecp_group *grp );
- /**
- * \brief This function initializes a key pair as an invalid one.
- *
- * \param key The key pair to initialize.
- */
- void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key );
- /**
- * \brief This function frees the components of a point.
- *
- * \param pt The point to free.
- */
- void mbedtls_ecp_point_free( mbedtls_ecp_point *pt );
- /**
- * \brief This function frees the components of an ECP group.
- *
- * \param grp The group to free. This may be \c NULL, in which
- * case this function returns immediately. If it is not
- * \c NULL, it must point to an initialized ECP group.
- */
- void mbedtls_ecp_group_free( mbedtls_ecp_group *grp );
- /**
- * \brief This function frees the components of a key pair.
- *
- * \param key The key pair to free. This may be \c NULL, in which
- * case this function returns immediately. If it is not
- * \c NULL, it must point to an initialized ECP key pair.
- */
- void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key );
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Initialize a restart context.
- *
- * \param ctx The restart context to initialize. This must
- * not be \c NULL.
- */
- void mbedtls_ecp_restart_init( mbedtls_ecp_restart_ctx *ctx );
- /**
- * \brief Free the components of a restart context.
- *
- * \param ctx The restart context to free. This may be \c NULL, in which
- * case this function returns immediately. If it is not
- * \c NULL, it must point to an initialized restart context.
- */
- void mbedtls_ecp_restart_free( mbedtls_ecp_restart_ctx *ctx );
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- /**
- * \brief This function copies the contents of point \p Q into
- * point \p P.
- *
- * \param P The destination point. This must be initialized.
- * \param Q The source point. This must be initialized.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return Another negative error code for other kinds of failure.
- */
- int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
- /**
- * \brief This function copies the contents of group \p src into
- * group \p dst.
- *
- * \param dst The destination group. This must be initialized.
- * \param src The source group. This must be initialized.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst,
- const mbedtls_ecp_group *src );
- /**
- * \brief This function sets a point to the point at infinity.
- *
- * \param pt The point to set. This must be initialized.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt );
- /**
- * \brief This function checks if a point is the point at infinity.
- *
- * \param pt The point to test. This must be initialized.
- *
- * \return \c 1 if the point is zero.
- * \return \c 0 if the point is non-zero.
- * \return A negative error code on failure.
- */
- int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt );
- /**
- * \brief This function compares two points.
- *
- * \note This assumes that the points are normalized. Otherwise,
- * they may compare as "not equal" even if they are.
- *
- * \param P The first point to compare. This must be initialized.
- * \param Q The second point to compare. This must be initialized.
- *
- * \return \c 0 if the points are equal.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the points are not equal.
- */
- int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P,
- const mbedtls_ecp_point *Q );
- /**
- * \brief This function imports a non-zero point from two ASCII
- * strings.
- *
- * \param P The destination point. This must be initialized.
- * \param radix The numeric base of the input.
- * \param x The first affine coordinate, as a null-terminated string.
- * \param y The second affine coordinate, as a null-terminated string.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_MPI_XXX error code on failure.
- */
- int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix,
- const char *x, const char *y );
- /**
- * \brief This function exports a point into unsigned binary data.
- *
- * \param grp The group to which the point should belong.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param P The point to export. This must be initialized.
- * \param format The point format. This must be either
- * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED.
- * (For groups without these formats, this parameter is
- * ignored. But it still has to be either of the above
- * values.)
- * \param olen The address at which to store the length of
- * the output in Bytes. This must not be \c NULL.
- * \param buf The output buffer. This must be a writable buffer
- * of length \p buflen Bytes.
- * \param buflen The length of the output buffer \p buf in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer
- * is too small to hold the point.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format
- * or the export for the given group is not implemented.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp,
- const mbedtls_ecp_point *P,
- int format, size_t *olen,
- unsigned char *buf, size_t buflen );
- /**
- * \brief This function imports a point from unsigned binary data.
- *
- * \note This function does not check that the point actually
- * belongs to the given group, see mbedtls_ecp_check_pubkey()
- * for that.
- *
- * \param grp The group to which the point should belong.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param P The destination context to import the point to.
- * This must be initialized.
- * \param buf The input buffer. This must be a readable buffer
- * of length \p ilen Bytes.
- * \param ilen The length of the input buffer \p buf in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the import for the
- * given group is not implemented.
- */
- int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp,
- mbedtls_ecp_point *P,
- const unsigned char *buf, size_t ilen );
- /**
- * \brief This function imports a point from a TLS ECPoint record.
- *
- * \note On function return, \p *buf is updated to point immediately
- * after the ECPoint record.
- *
- * \param grp The ECP group to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param pt The destination point.
- * \param buf The address of the pointer to the start of the input buffer.
- * \param len The length of the buffer.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_MPI_XXX error code on initialization
- * failure.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
- */
- int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp,
- mbedtls_ecp_point *pt,
- const unsigned char **buf, size_t len );
- /**
- * \brief This function exports a point as a TLS ECPoint record
- * defined in RFC 4492, Section 5.4.
- *
- * \param grp The ECP group to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param pt The point to be exported. This must be initialized.
- * \param format The point format to use. This must be either
- * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED.
- * \param olen The address at which to store the length in Bytes
- * of the data written.
- * \param buf The target buffer. This must be a writable buffer of
- * length \p blen Bytes.
- * \param blen The length of the target buffer \p buf in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid.
- * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the target buffer
- * is too small to hold the exported point.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp,
- const mbedtls_ecp_point *pt,
- int format, size_t *olen,
- unsigned char *buf, size_t blen );
- /**
- * \brief This function sets up an ECP group context
- * from a standardized set of domain parameters.
- *
- * \note The index should be a value of the NamedCurve enum,
- * as defined in <em>RFC-4492: Elliptic Curve Cryptography
- * (ECC) Cipher Suites for Transport Layer Security (TLS)</em>,
- * usually in the form of an \c MBEDTLS_ECP_DP_XXX macro.
- *
- * \param grp The group context to setup. This must be initialized.
- * \param id The identifier of the domain parameter set to load.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p id doesn't
- * correspond to a known group.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id );
- /**
- * \brief This function sets up an ECP group context from a TLS
- * ECParameters record as defined in RFC 4492, Section 5.4.
- *
- * \note The read pointer \p buf is updated to point right after
- * the ECParameters record on exit.
- *
- * \param grp The group context to setup. This must be initialized.
- * \param buf The address of the pointer to the start of the input buffer.
- * \param len The length of the input buffer \c *buf in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not
- * recognized.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp,
- const unsigned char **buf, size_t len );
- /**
- * \brief This function extracts an elliptic curve group ID from a
- * TLS ECParameters record as defined in RFC 4492, Section 5.4.
- *
- * \note The read pointer \p buf is updated to point right after
- * the ECParameters record on exit.
- *
- * \param grp The address at which to store the group id.
- * This must not be \c NULL.
- * \param buf The address of the pointer to the start of the input buffer.
- * \param len The length of the input buffer \c *buf in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not
- * recognized.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_tls_read_group_id( mbedtls_ecp_group_id *grp,
- const unsigned char **buf,
- size_t len );
- /**
- * \brief This function exports an elliptic curve as a TLS
- * ECParameters record as defined in RFC 4492, Section 5.4.
- *
- * \param grp The ECP group to be exported.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param olen The address at which to store the number of Bytes written.
- * This must not be \c NULL.
- * \param buf The buffer to write to. This must be a writable buffer
- * of length \p blen Bytes.
- * \param blen The length of the output buffer \p buf in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output
- * buffer is too small to hold the exported group.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp,
- size_t *olen,
- unsigned char *buf, size_t blen );
- /**
- * \brief This function performs a scalar multiplication of a point
- * by an integer: \p R = \p m * \p P.
- *
- * It is not thread-safe to use same group in multiple threads.
- *
- * \note To prevent timing attacks, this function
- * executes the exact same sequence of base-field
- * operations for any valid \p m. It avoids any if-branch or
- * array index depending on the value of \p m.
- *
- * \note If \p f_rng is not NULL, it is used to randomize
- * intermediate results to prevent potential timing attacks
- * targeting these results. We recommend always providing
- * a non-NULL \p f_rng. The overhead is negligible.
- * Note: unless #MBEDTLS_ECP_NO_INTERNAL_RNG is defined, when
- * \p f_rng is NULL, an internal RNG (seeded from the value
- * of \p m) will be used instead.
- *
- * \param grp The ECP group to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param R The point in which to store the result of the calculation.
- * This must be initialized.
- * \param m The integer by which to multiply. This must be initialized.
- * \param P The point to multiply. This must be initialized.
- * \param f_rng The RNG function. This may be \c NULL if randomization
- * of intermediate results isn't desired (discouraged).
- * \param p_rng The RNG context to be passed to \p p_rng.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private
- * key, or \p P is not a valid public key.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
- const mbedtls_mpi *m, const mbedtls_ecp_point *P,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
- /**
- * \brief This function performs multiplication of a point by
- * an integer: \p R = \p m * \p P in a restartable way.
- *
- * \see mbedtls_ecp_mul()
- *
- * \note This function does the same as \c mbedtls_ecp_mul(), but
- * it can return early and restart according to the limit set
- * with \c mbedtls_ecp_set_max_ops() to reduce blocking.
- *
- * \param grp The ECP group to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param R The point in which to store the result of the calculation.
- * This must be initialized.
- * \param m The integer by which to multiply. This must be initialized.
- * \param P The point to multiply. This must be initialized.
- * \param f_rng The RNG function. This may be \c NULL if randomization
- * of intermediate results isn't desired (discouraged).
- * \param p_rng The RNG context to be passed to \p p_rng.
- * \param rs_ctx The restart context (NULL disables restart).
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private
- * key, or \p P is not a valid public key.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
- const mbedtls_mpi *m, const mbedtls_ecp_point *P,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- mbedtls_ecp_restart_ctx *rs_ctx );
- #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
- /**
- * \brief This function performs multiplication and addition of two
- * points by integers: \p R = \p m * \p P + \p n * \p Q
- *
- * It is not thread-safe to use same group in multiple threads.
- *
- * \note In contrast to mbedtls_ecp_mul(), this function does not
- * guarantee a constant execution flow and timing.
- *
- * \note This function is only defined for short Weierstrass curves.
- * It may not be included in builds without any short
- * Weierstrass curve.
- *
- * \param grp The ECP group to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param R The point in which to store the result of the calculation.
- * This must be initialized.
- * \param m The integer by which to multiply \p P.
- * This must be initialized.
- * \param P The point to multiply by \p m. This must be initialized.
- * \param n The integer by which to multiply \p Q.
- * This must be initialized.
- * \param Q The point to be multiplied by \p n.
- * This must be initialized.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not
- * valid private keys, or \p P or \p Q are not valid public
- * keys.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not
- * designate a short Weierstrass curve.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
- const mbedtls_mpi *m, const mbedtls_ecp_point *P,
- const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
- /**
- * \brief This function performs multiplication and addition of two
- * points by integers: \p R = \p m * \p P + \p n * \p Q in a
- * restartable way.
- *
- * \see \c mbedtls_ecp_muladd()
- *
- * \note This function works the same as \c mbedtls_ecp_muladd(),
- * but it can return early and restart according to the limit
- * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
- *
- * \note This function is only defined for short Weierstrass curves.
- * It may not be included in builds without any short
- * Weierstrass curve.
- *
- * \param grp The ECP group to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param R The point in which to store the result of the calculation.
- * This must be initialized.
- * \param m The integer by which to multiply \p P.
- * This must be initialized.
- * \param P The point to multiply by \p m. This must be initialized.
- * \param n The integer by which to multiply \p Q.
- * This must be initialized.
- * \param Q The point to be multiplied by \p n.
- * This must be initialized.
- * \param rs_ctx The restart context (NULL disables restart).
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not
- * valid private keys, or \p P or \p Q are not valid public
- * keys.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not
- * designate a short Weierstrass curve.
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_muladd_restartable(
- mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
- const mbedtls_mpi *m, const mbedtls_ecp_point *P,
- const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
- mbedtls_ecp_restart_ctx *rs_ctx );
- #endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
- /**
- * \brief This function checks that a point is a valid public key
- * on this curve.
- *
- * It only checks that the point is non-zero, has
- * valid coordinates and lies on the curve. It does not verify
- * that it is indeed a multiple of \p G. This additional
- * check is computationally more expensive, is not required
- * by standards, and should not be necessary if the group
- * used has a small cofactor. In particular, it is useless for
- * the NIST groups which all have a cofactor of 1.
- *
- * \note This function uses bare components rather than an
- * ::mbedtls_ecp_keypair structure, to ease use with other
- * structures, such as ::mbedtls_ecdh_context or
- * ::mbedtls_ecdsa_context.
- *
- * \param grp The ECP group the point should belong to.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param pt The point to check. This must be initialized.
- *
- * \return \c 0 if the point is a valid public key.
- * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not
- * a valid public key for the given curve.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp,
- const mbedtls_ecp_point *pt );
- /**
- * \brief This function checks that an \p mbedtls_mpi is a
- * valid private key for this curve.
- *
- * \note This function uses bare components rather than an
- * ::mbedtls_ecp_keypair structure to ease use with other
- * structures, such as ::mbedtls_ecdh_context or
- * ::mbedtls_ecdsa_context.
- *
- * \param grp The ECP group the private key should belong to.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param d The integer to check. This must be initialized.
- *
- * \return \c 0 if the point is a valid private key.
- * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not a valid
- * private key for the given curve.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp,
- const mbedtls_mpi *d );
- /**
- * \brief This function generates a private key.
- *
- * \param grp The ECP group to generate a private key for.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param d The destination MPI (secret part). This must be initialized.
- * \param f_rng The RNG function. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
- * on failure.
- */
- int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp,
- mbedtls_mpi *d,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function generates a keypair with a configurable base
- * point.
- *
- * \note This function uses bare components rather than an
- * ::mbedtls_ecp_keypair structure to ease use with other
- * structures, such as ::mbedtls_ecdh_context or
- * ::mbedtls_ecdsa_context.
- *
- * \param grp The ECP group to generate a key pair for.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param G The base point to use. This must be initialized
- * and belong to \p grp. It replaces the default base
- * point \c grp->G used by mbedtls_ecp_gen_keypair().
- * \param d The destination MPI (secret part).
- * This must be initialized.
- * \param Q The destination point (public part).
- * This must be initialized.
- * \param f_rng The RNG function. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may
- * be \c NULL if \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
- * on failure.
- */
- int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp,
- const mbedtls_ecp_point *G,
- mbedtls_mpi *d, mbedtls_ecp_point *Q,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function generates an ECP keypair.
- *
- * \note This function uses bare components rather than an
- * ::mbedtls_ecp_keypair structure to ease use with other
- * structures, such as ::mbedtls_ecdh_context or
- * ::mbedtls_ecdsa_context.
- *
- * \param grp The ECP group to generate a key pair for.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param d The destination MPI (secret part).
- * This must be initialized.
- * \param Q The destination point (public part).
- * This must be initialized.
- * \param f_rng The RNG function. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may
- * be \c NULL if \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
- * on failure.
- */
- int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d,
- mbedtls_ecp_point *Q,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function generates an ECP key.
- *
- * \param grp_id The ECP group identifier.
- * \param key The destination key. This must be initialized.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may
- * be \c NULL if \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
- * on failure.
- */
- int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function reads an elliptic curve private key.
- *
- * \param grp_id The ECP group identifier.
- * \param key The destination key.
- * \param buf The buffer containing the binary representation of the
- * key. (Big endian integer for Weierstrass curves, byte
- * string for Montgomery curves.)
- * \param buflen The length of the buffer in bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_INVALID_KEY error if the key is
- * invalid.
- * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for
- * the group is not implemented.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
- const unsigned char *buf, size_t buflen );
- /**
- * \brief This function exports an elliptic curve private key.
- *
- * \param key The private key.
- * \param buf The output buffer for containing the binary representation
- * of the key. (Big endian integer for Weierstrass curves, byte
- * string for Montgomery curves.)
- * \param buflen The total length of the buffer in bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the \p key
- representation is larger than the available space in \p buf.
- * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for
- * the group is not implemented.
- * \return Another negative error code on different kinds of failure.
- */
- int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key,
- unsigned char *buf, size_t buflen );
- /**
- * \brief This function checks that the keypair objects
- * \p pub and \p prv have the same group and the
- * same public point, and that the private key in
- * \p prv is consistent with the public key.
- *
- * \param pub The keypair structure holding the public key. This
- * must be initialized. If it contains a private key, that
- * part is ignored.
- * \param prv The keypair structure holding the full keypair.
- * This must be initialized.
- *
- * \return \c 0 on success, meaning that the keys are valid and match.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the keys are invalid or do not match.
- * \return An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX
- * error code on calculation failure.
- */
- int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub,
- const mbedtls_ecp_keypair *prv );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The ECP checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_ecp_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* ecp.h */
- /********* Start of file include/mbedtls/ecdsa.h ************/
- /**
- * \file ecdsa.h
- *
- * \brief This file contains ECDSA definitions and functions.
- *
- * The Elliptic Curve Digital Signature Algorithm (ECDSA) is defined in
- * <em>Standards for Efficient Cryptography Group (SECG):
- * SEC1 Elliptic Curve Cryptography</em>.
- * The use of ECDSA for TLS is defined in <em>RFC-4492: Elliptic Curve
- * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS)</em>.
- *
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ECDSA_H
- #define MBEDTLS_ECDSA_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /**
- * \brief Maximum ECDSA signature size for a given curve bit size
- *
- * \param bits Curve size in bits
- * \return Maximum signature size in bytes
- *
- * \note This macro returns a compile-time constant if its argument
- * is one. It may evaluate its argument multiple times.
- */
- /*
- * Ecdsa-Sig-Value ::= SEQUENCE {
- * r INTEGER,
- * s INTEGER
- * }
- *
- * For each of r and s, the value (V) may include an extra initial "0" bit.
- */
- #define MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) \
- ( /*T,L of SEQUENCE*/ ( ( bits ) >= 61 * 8 ? 3 : 2 ) + \
- /*T,L of r,s*/ 2 * ( ( ( bits ) >= 127 * 8 ? 3 : 2 ) + \
- /*V of r,s*/ ( ( bits ) + 8 ) / 8 ) )
- /** The maximal size of an ECDSA signature in Bytes. */
- #define MBEDTLS_ECDSA_MAX_LEN MBEDTLS_ECDSA_MAX_SIG_LEN( MBEDTLS_ECP_MAX_BITS )
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief The ECDSA context structure.
- *
- * \warning Performing multiple operations concurrently on the same
- * ECDSA context is not supported; objects of this type
- * should not be shared between multiple threads.
- */
- typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Internal restart context for ecdsa_verify()
- *
- * \note Opaque struct, defined in ecdsa.c
- */
- typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;
- /**
- * \brief Internal restart context for ecdsa_sign()
- *
- * \note Opaque struct, defined in ecdsa.c
- */
- typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;
- #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
- /**
- * \brief Internal restart context for ecdsa_sign_det()
- *
- * \note Opaque struct, defined in ecdsa.c
- */
- typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
- #endif
- /**
- * \brief General context for resuming ECDSA operations
- */
- typedef struct
- {
- mbedtls_ecp_restart_ctx ecp; /*!< base context for ECP restart and
- shared administrative info */
- mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */
- mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */
- #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
- mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */
- #endif
- } mbedtls_ecdsa_restart_ctx;
- #else /* MBEDTLS_ECP_RESTARTABLE */
- /* Now we can declare functions that take a pointer to that */
- typedef void mbedtls_ecdsa_restart_ctx;
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- /**
- * \brief This function checks whether a given group can be used
- * for ECDSA.
- *
- * \param gid The ECP group ID to check.
- *
- * \return \c 1 if the group can be used, \c 0 otherwise
- */
- int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid );
- /**
- * \brief This function computes the ECDSA signature of a
- * previously-hashed message.
- *
- * \note The deterministic version implemented in
- * mbedtls_ecdsa_sign_det() is usually preferred.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated
- * as defined in <em>Standards for Efficient Cryptography Group
- * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
- * 4.1.3, step 5.
- *
- * \see ecp.h
- *
- * \param grp The context for the elliptic curve to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param r The MPI context in which to store the first part
- * the signature. This must be initialized.
- * \param s The MPI context in which to store the second part
- * the signature. This must be initialized.
- * \param d The private signing key. This must be initialized.
- * \param buf The content to be signed. This is usually the hash of
- * the original data to be signed. This must be a readable
- * buffer of length \p blen Bytes. It may be \c NULL if
- * \p blen is zero.
- * \param blen The length of \p buf in Bytes.
- * \param f_rng The RNG function. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng doesn't need a context parameter.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX
- * or \c MBEDTLS_MPI_XXX error code on failure.
- */
- int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
- const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
- #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
- #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function computes the ECDSA signature of a
- * previously-hashed message, deterministic version.
- *
- * For more information, see <em>RFC-6979: Deterministic
- * Usage of the Digital Signature Algorithm (DSA) and Elliptic
- * Curve Digital Signature Algorithm (ECDSA)</em>.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated as
- * defined in <em>Standards for Efficient Cryptography Group
- * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
- * 4.1.3, step 5.
- *
- * \warning Since the output of the internal RNG is always the same for
- * the same key and message, this limits the efficiency of
- * blinding and leaks information through side channels. For
- * secure behavior use mbedtls_ecdsa_sign_det_ext() instead.
- *
- * (Optimally the blinding is a random value that is different
- * on every execution. In this case the blinding is still
- * random from the attackers perspective, but is the same on
- * each execution. This means that this blinding does not
- * prevent attackers from recovering secrets by combining
- * several measurement traces, but may prevent some attacks
- * that exploit relationships between secret data.)
- *
- * \see ecp.h
- *
- * \param grp The context for the elliptic curve to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param r The MPI context in which to store the first part
- * the signature. This must be initialized.
- * \param s The MPI context in which to store the second part
- * the signature. This must be initialized.
- * \param d The private signing key. This must be initialized
- * and setup, for example through mbedtls_ecp_gen_privkey().
- * \param buf The hashed content to be signed. This must be a readable
- * buffer of length \p blen Bytes. It may be \c NULL if
- * \p blen is zero.
- * \param blen The length of \p buf in Bytes.
- * \param md_alg The hash algorithm used to hash the original data.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
- * error code on failure.
- */
- int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,
- mbedtls_mpi *s, const mbedtls_mpi *d,
- const unsigned char *buf, size_t blen,
- mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
- #undef MBEDTLS_DEPRECATED
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief This function computes the ECDSA signature of a
- * previously-hashed message, deterministic version.
- *
- * For more information, see <em>RFC-6979: Deterministic
- * Usage of the Digital Signature Algorithm (DSA) and Elliptic
- * Curve Digital Signature Algorithm (ECDSA)</em>.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated as
- * defined in <em>Standards for Efficient Cryptography Group
- * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
- * 4.1.3, step 5.
- *
- * \see ecp.h
- *
- * \param grp The context for the elliptic curve to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param r The MPI context in which to store the first part
- * the signature. This must be initialized.
- * \param s The MPI context in which to store the second part
- * the signature. This must be initialized.
- * \param d The private signing key. This must be initialized
- * and setup, for example through mbedtls_ecp_gen_privkey().
- * \param buf The hashed content to be signed. This must be a readable
- * buffer of length \p blen Bytes. It may be \c NULL if
- * \p blen is zero.
- * \param blen The length of \p buf in Bytes.
- * \param md_alg The hash algorithm used to hash the original data.
- * \param f_rng_blind The RNG function used for blinding. This must not be
- * \c NULL.
- * \param p_rng_blind The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng doesn't need a context parameter.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
- * error code on failure.
- */
- int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r,
- mbedtls_mpi *s, const mbedtls_mpi *d,
- const unsigned char *buf, size_t blen,
- mbedtls_md_type_t md_alg,
- int (*f_rng_blind)(void *, unsigned char *, size_t),
- void *p_rng_blind );
- #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
- /**
- * \brief This function verifies the ECDSA signature of a
- * previously-hashed message.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated as
- * defined in <em>Standards for Efficient Cryptography Group
- * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
- * 4.1.4, step 3.
- *
- * \see ecp.h
- *
- * \param grp The ECP group to use.
- * This must be initialized and have group parameters
- * set, for example through mbedtls_ecp_group_load().
- * \param buf The hashed content that was signed. This must be a readable
- * buffer of length \p blen Bytes. It may be \c NULL if
- * \p blen is zero.
- * \param blen The length of \p buf in Bytes.
- * \param Q The public key to use for verification. This must be
- * initialized and setup.
- * \param r The first integer of the signature.
- * This must be initialized.
- * \param s The second integer of the signature.
- * This must be initialized.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the signature
- * is invalid.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
- * error code on failure for any other reason.
- */
- int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
- const unsigned char *buf, size_t blen,
- const mbedtls_ecp_point *Q, const mbedtls_mpi *r,
- const mbedtls_mpi *s);
- /**
- * \brief This function computes the ECDSA signature and writes it
- * to a buffer, serialized as defined in <em>RFC-4492:
- * Elliptic Curve Cryptography (ECC) Cipher Suites for
- * Transport Layer Security (TLS)</em>.
- *
- * \warning It is not thread-safe to use the same context in
- * multiple threads.
- *
- * \note The deterministic version is used if
- * #MBEDTLS_ECDSA_DETERMINISTIC is defined. For more
- * information, see <em>RFC-6979: Deterministic Usage
- * of the Digital Signature Algorithm (DSA) and Elliptic
- * Curve Digital Signature Algorithm (ECDSA)</em>.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated as
- * defined in <em>Standards for Efficient Cryptography Group
- * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
- * 4.1.3, step 5.
- *
- * \see ecp.h
- *
- * \param ctx The ECDSA context to use. This must be initialized
- * and have a group and private key bound to it, for example
- * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
- * \param md_alg The message digest that was used to hash the message.
- * \param hash The message hash to be signed. This must be a readable
- * buffer of length \p blen Bytes.
- * \param hlen The length of the hash \p hash in Bytes.
- * \param sig The buffer to which to write the signature. This must be a
- * writable buffer of length at least twice as large as the
- * size of the curve used, plus 9. For example, 73 Bytes if
- * a 256-bit curve is used. A buffer length of
- * #MBEDTLS_ECDSA_MAX_LEN is always safe.
- * \param slen The address at which to store the actual length of
- * the signature written. Must not be \c NULL.
- * \param f_rng The RNG function. This must not be \c NULL if
- * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise,
- * it is used only for blinding and may be set to \c NULL, but
- * doing so is DEPRECATED.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't use a context.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
- * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,
- mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hlen,
- unsigned char *sig, size_t *slen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function computes the ECDSA signature and writes it
- * to a buffer, in a restartable way.
- *
- * \see \c mbedtls_ecdsa_write_signature()
- *
- * \note This function is like \c mbedtls_ecdsa_write_signature()
- * but it can return early and restart according to the limit
- * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
- *
- * \param ctx The ECDSA context to use. This must be initialized
- * and have a group and private key bound to it, for example
- * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
- * \param md_alg The message digest that was used to hash the message.
- * \param hash The message hash to be signed. This must be a readable
- * buffer of length \p blen Bytes.
- * \param hlen The length of the hash \p hash in Bytes.
- * \param sig The buffer to which to write the signature. This must be a
- * writable buffer of length at least twice as large as the
- * size of the curve used, plus 9. For example, 73 Bytes if
- * a 256-bit curve is used. A buffer length of
- * #MBEDTLS_ECDSA_MAX_LEN is always safe.
- * \param slen The address at which to store the actual length of
- * the signature written. Must not be \c NULL.
- * \param f_rng The RNG function. This must not be \c NULL if
- * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise,
- * it is unused and may be set to \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't use a context.
- * \param rs_ctx The restart context to use. This may be \c NULL to disable
- * restarting. If it is not \c NULL, it must point to an
- * initialized restart context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- * \return Another \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
- * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
- mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hlen,
- unsigned char *sig, size_t *slen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng,
- mbedtls_ecdsa_restart_ctx *rs_ctx );
- #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
- #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function computes an ECDSA signature and writes
- * it to a buffer, serialized as defined in <em>RFC-4492:
- * Elliptic Curve Cryptography (ECC) Cipher Suites for
- * Transport Layer Security (TLS)</em>.
- *
- * The deterministic version is defined in <em>RFC-6979:
- * Deterministic Usage of the Digital Signature Algorithm (DSA)
- * and Elliptic Curve Digital Signature Algorithm (ECDSA)</em>.
- *
- * \warning It is not thread-safe to use the same context in
- * multiple threads.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated as
- * defined in <em>Standards for Efficient Cryptography Group
- * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
- * 4.1.3, step 5.
- *
- * \see ecp.h
- *
- * \deprecated Superseded by mbedtls_ecdsa_write_signature() in
- * Mbed TLS version 2.0 and later.
- *
- * \param ctx The ECDSA context to use. This must be initialized
- * and have a group and private key bound to it, for example
- * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
- * \param hash The message hash to be signed. This must be a readable
- * buffer of length \p blen Bytes.
- * \param hlen The length of the hash \p hash in Bytes.
- * \param sig The buffer to which to write the signature. This must be a
- * writable buffer of length at least twice as large as the
- * size of the curve used, plus 9. For example, 73 Bytes if
- * a 256-bit curve is used. A buffer length of
- * #MBEDTLS_ECDSA_MAX_LEN is always safe.
- * \param slen The address at which to store the actual length of
- * the signature written. Must not be \c NULL.
- * \param md_alg The message digest that was used to hash the message.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
- * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
- const unsigned char *hash, size_t hlen,
- unsigned char *sig, size_t *slen,
- mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
- #undef MBEDTLS_DEPRECATED
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
- /**
- * \brief This function reads and verifies an ECDSA signature.
- *
- * \note If the bitlength of the message hash is larger than the
- * bitlength of the group order, then the hash is truncated as
- * defined in <em>Standards for Efficient Cryptography Group
- * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
- * 4.1.4, step 3.
- *
- * \see ecp.h
- *
- * \param ctx The ECDSA context to use. This must be initialized
- * and have a group and public key bound to it.
- * \param hash The message hash that was signed. This must be a readable
- * buffer of length \p size Bytes.
- * \param hlen The size of the hash \p hash.
- * \param sig The signature to read and verify. This must be a readable
- * buffer of length \p slen Bytes.
- * \param slen The size of \p sig in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid.
- * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid
- * signature in \p sig, but its length is less than \p siglen.
- * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX
- * error code on failure for any other reason.
- */
- int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
- const unsigned char *hash, size_t hlen,
- const unsigned char *sig, size_t slen );
- /**
- * \brief This function reads and verifies an ECDSA signature,
- * in a restartable way.
- *
- * \see \c mbedtls_ecdsa_read_signature()
- *
- * \note This function is like \c mbedtls_ecdsa_read_signature()
- * but it can return early and restart according to the limit
- * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
- *
- * \param ctx The ECDSA context to use. This must be initialized
- * and have a group and public key bound to it.
- * \param hash The message hash that was signed. This must be a readable
- * buffer of length \p size Bytes.
- * \param hlen The size of the hash \p hash.
- * \param sig The signature to read and verify. This must be a readable
- * buffer of length \p slen Bytes.
- * \param slen The size of \p sig in Bytes.
- * \param rs_ctx The restart context to use. This may be \c NULL to disable
- * restarting. If it is not \c NULL, it must point to an
- * initialized restart context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid.
- * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid
- * signature in \p sig, but its length is less than \p siglen.
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- * \return Another \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX
- * error code on failure for any other reason.
- */
- int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
- const unsigned char *hash, size_t hlen,
- const unsigned char *sig, size_t slen,
- mbedtls_ecdsa_restart_ctx *rs_ctx );
- /**
- * \brief This function generates an ECDSA keypair on the given curve.
- *
- * \see ecp.h
- *
- * \param ctx The ECDSA context to store the keypair in.
- * This must be initialized.
- * \param gid The elliptic curve to use. One of the various
- * \c MBEDTLS_ECP_DP_XXX macros depending on configuration.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX code on failure.
- */
- int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
- /**
- * \brief This function sets up an ECDSA context from an EC key pair.
- *
- * \see ecp.h
- *
- * \param ctx The ECDSA context to setup. This must be initialized.
- * \param key The EC key to use. This must be initialized and hold
- * a private-public key pair or a public key. In the former
- * case, the ECDSA context may be used for signature creation
- * and verification after this call. In the latter case, it
- * may be used for signature verification.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX code on failure.
- */
- int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx,
- const mbedtls_ecp_keypair *key );
- /**
- * \brief This function initializes an ECDSA context.
- *
- * \param ctx The ECDSA context to initialize.
- * This must not be \c NULL.
- */
- void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
- /**
- * \brief This function frees an ECDSA context.
- *
- * \param ctx The ECDSA context to free. This may be \c NULL,
- * in which case this function does nothing. If it
- * is not \c NULL, it must be initialized.
- */
- void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Initialize a restart context.
- *
- * \param ctx The restart context to initialize.
- * This must not be \c NULL.
- */
- void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
- /**
- * \brief Free the components of a restart context.
- *
- * \param ctx The restart context to free. This may be \c NULL,
- * in which case this function does nothing. If it
- * is not \c NULL, it must be initialized.
- */
- void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- #ifdef __cplusplus
- }
- #endif
- #endif /* ecdsa.h */
- /********* Start of file include/mbedtls/ecjpake.h ************/
- /**
- * \file ecjpake.h
- *
- * \brief Elliptic curve J-PAKE
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ECJPAKE_H
- #define MBEDTLS_ECJPAKE_H
- /*
- * J-PAKE is a password-authenticated key exchange that allows deriving a
- * strong shared secret from a (potentially low entropy) pre-shared
- * passphrase, with forward secrecy and mutual authentication.
- * https://en.wikipedia.org/wiki/Password_Authenticated_Key_Exchange_by_Juggling
- *
- * This file implements the Elliptic Curve variant of J-PAKE,
- * as defined in Chapter 7.4 of the Thread v1.0 Specification,
- * available to members of the Thread Group http://threadgroup.org/
- *
- * As the J-PAKE algorithm is inherently symmetric, so is our API.
- * Each party needs to send its first round message, in any order, to the
- * other party, then each sends its second round message, in any order.
- * The payloads are serialized in a way suitable for use in TLS, but could
- * also be use outside TLS.
- */
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Roles in the EC J-PAKE exchange
- */
- typedef enum {
- MBEDTLS_ECJPAKE_CLIENT = 0, /**< Client */
- MBEDTLS_ECJPAKE_SERVER, /**< Server */
- } mbedtls_ecjpake_role;
- #if !defined(MBEDTLS_ECJPAKE_ALT)
- /**
- * EC J-PAKE context structure.
- *
- * J-PAKE is a symmetric protocol, except for the identifiers used in
- * Zero-Knowledge Proofs, and the serialization of the second message
- * (KeyExchange) as defined by the Thread spec.
- *
- * In order to benefit from this symmetry, we choose a different naming
- * convetion from the Thread v1.0 spec. Correspondance is indicated in the
- * description as a pair C: client name, S: server name
- */
- typedef struct mbedtls_ecjpake_context
- {
- const mbedtls_md_info_t *md_info; /**< Hash to use */
- mbedtls_ecp_group grp; /**< Elliptic curve */
- mbedtls_ecjpake_role role; /**< Are we client or server? */
- int point_format; /**< Format for point export */
- mbedtls_ecp_point Xm1; /**< My public key 1 C: X1, S: X3 */
- mbedtls_ecp_point Xm2; /**< My public key 2 C: X2, S: X4 */
- mbedtls_ecp_point Xp1; /**< Peer public key 1 C: X3, S: X1 */
- mbedtls_ecp_point Xp2; /**< Peer public key 2 C: X4, S: X2 */
- mbedtls_ecp_point Xp; /**< Peer public key C: Xs, S: Xc */
- mbedtls_mpi xm1; /**< My private key 1 C: x1, S: x3 */
- mbedtls_mpi xm2; /**< My private key 2 C: x2, S: x4 */
- mbedtls_mpi s; /**< Pre-shared secret (passphrase) */
- } mbedtls_ecjpake_context;
- #else /* MBEDTLS_ECJPAKE_ALT */
- #endif /* MBEDTLS_ECJPAKE_ALT */
- /**
- * \brief Initialize an ECJPAKE context.
- *
- * \param ctx The ECJPAKE context to initialize.
- * This must not be \c NULL.
- */
- void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
- /**
- * \brief Set up an ECJPAKE context for use.
- *
- * \note Currently the only values for hash/curve allowed by the
- * standard are #MBEDTLS_MD_SHA256/#MBEDTLS_ECP_DP_SECP256R1.
- *
- * \param ctx The ECJPAKE context to set up. This must be initialized.
- * \param role The role of the caller. This must be either
- * #MBEDTLS_ECJPAKE_CLIENT or #MBEDTLS_ECJPAKE_SERVER.
- * \param hash The identifier of the hash function to use,
- * for example #MBEDTLS_MD_SHA256.
- * \param curve The identifier of the elliptic curve to use,
- * for example #MBEDTLS_ECP_DP_SECP256R1.
- * \param secret The pre-shared secret (passphrase). This must be
- * a readable buffer of length \p len Bytes. It need
- * only be valid for the duration of this call.
- * \param len The length of the pre-shared secret \p secret.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
- mbedtls_ecjpake_role role,
- mbedtls_md_type_t hash,
- mbedtls_ecp_group_id curve,
- const unsigned char *secret,
- size_t len );
- /**
- * \brief Check if an ECJPAKE context is ready for use.
- *
- * \param ctx The ECJPAKE context to check. This must be
- * initialized.
- *
- * \return \c 0 if the context is ready for use.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise.
- */
- int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx );
- /**
- * \brief Generate and write the first round message
- * (TLS: contents of the Client/ServerHello extension,
- * excluding extension type and length bytes).
- *
- * \param ctx The ECJPAKE context to use. This must be
- * initialized and set up.
- * \param buf The buffer to write the contents to. This must be a
- * writable buffer of length \p len Bytes.
- * \param len The length of \p buf in Bytes.
- * \param olen The address at which to store the total number
- * of Bytes written to \p buf. This must not be \c NULL.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng. This
- * may be \c NULL if \p f_rng doesn't use a context.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief Read and process the first round message
- * (TLS: contents of the Client/ServerHello extension,
- * excluding extension type and length bytes).
- *
- * \param ctx The ECJPAKE context to use. This must be initialized
- * and set up.
- * \param buf The buffer holding the first round message. This must
- * be a readable buffer of length \p len Bytes.
- * \param len The length in Bytes of \p buf.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx,
- const unsigned char *buf,
- size_t len );
- /**
- * \brief Generate and write the second round message
- * (TLS: contents of the Client/ServerKeyExchange).
- *
- * \param ctx The ECJPAKE context to use. This must be initialized,
- * set up, and already have performed round one.
- * \param buf The buffer to write the round two contents to.
- * This must be a writable buffer of length \p len Bytes.
- * \param len The size of \p buf in Bytes.
- * \param olen The address at which to store the total number of Bytes
- * written to \p buf. This must not be \c NULL.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng. This
- * may be \c NULL if \p f_rng doesn't use a context.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief Read and process the second round message
- * (TLS: contents of the Client/ServerKeyExchange).
- *
- * \param ctx The ECJPAKE context to use. This must be initialized
- * and set up and already have performed round one.
- * \param buf The buffer holding the second round message. This must
- * be a readable buffer of length \p len Bytes.
- * \param len The length in Bytes of \p buf.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx,
- const unsigned char *buf,
- size_t len );
- /**
- * \brief Derive the shared secret
- * (TLS: Pre-Master Secret).
- *
- * \param ctx The ECJPAKE context to use. This must be initialized,
- * set up and have performed both round one and two.
- * \param buf The buffer to write the derived secret to. This must
- * be a writable buffer of length \p len Bytes.
- * \param len The length of \p buf in Bytes.
- * \param olen The address at which to store the total number of Bytes
- * written to \p buf. This must not be \c NULL.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG parameter to be passed to \p f_rng. This
- * may be \c NULL if \p f_rng doesn't use a context.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
- unsigned char *buf, size_t len, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This clears an ECJPAKE context and frees any
- * embedded data structure.
- *
- * \param ctx The ECJPAKE context to free. This may be \c NULL,
- * in which case this function does nothing. If it is not
- * \c NULL, it must point to an initialized ECJPAKE context.
- */
- void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if a test failed
- */
- int mbedtls_ecjpake_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* ecjpake.h */
- /********* Start of file include/mbedtls/pk.h ************/
- /**
- * \file pk.h
- *
- * \brief Public Key abstraction layer
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PK_H
- #define MBEDTLS_PK_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_RSA_C)
- #endif
- #if defined(MBEDTLS_ECP_C)
- #endif
- #if defined(MBEDTLS_ECDSA_C)
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- #endif
- #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
- #define inline __inline
- #endif
- /** Memory allocation failed. */
- #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
- /** Type mismatch, eg attempt to encrypt with an ECDSA key */
- #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
- /** Read/write of file failed. */
- #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
- /** Unsupported key version */
- #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
- /** Invalid key tag or value. */
- #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
- /** Key algorithm is unsupported (only RSA and EC are supported). */
- #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
- /** Private key password can't be empty. */
- #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
- /** Given private key password does not allow for correct decryption. */
- #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
- /** The pubkey tag or value is invalid (only RSA and EC are supported). */
- #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
- /** The algorithm tag or value is invalid. */
- #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
- /** Elliptic curve is unsupported (only NIST curves are supported). */
- #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
- /** Unavailable feature, e.g. RSA disabled for RSA key. */
- #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
- /** The buffer contains a valid signature followed by more data. */
- #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
- /* MBEDTLS_ERR_PK_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** PK hardware accelerator failed. */
- #define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Public key types
- */
- typedef enum {
- MBEDTLS_PK_NONE=0,
- MBEDTLS_PK_RSA,
- MBEDTLS_PK_ECKEY,
- MBEDTLS_PK_ECKEY_DH,
- MBEDTLS_PK_ECDSA,
- MBEDTLS_PK_RSA_ALT,
- MBEDTLS_PK_RSASSA_PSS,
- MBEDTLS_PK_OPAQUE,
- } mbedtls_pk_type_t;
- /**
- * \brief Options for RSASSA-PSS signature verification.
- * See \c mbedtls_rsa_rsassa_pss_verify_ext()
- */
- typedef struct mbedtls_pk_rsassa_pss_options
- {
- mbedtls_md_type_t mgf1_hash_id;
- int expected_salt_len;
- } mbedtls_pk_rsassa_pss_options;
- /**
- * \brief Maximum size of a signature made by mbedtls_pk_sign().
- */
- /* We need to set MBEDTLS_PK_SIGNATURE_MAX_SIZE to the maximum signature
- * size among the supported signature types. Do it by starting at 0,
- * then incrementally increasing to be large enough for each supported
- * signature mechanism.
- *
- * The resulting value can be 0, for example if MBEDTLS_ECDH_C is enabled
- * (which allows the pk module to be included) but neither MBEDTLS_ECDSA_C
- * nor MBEDTLS_RSA_C nor any opaque signature mechanism (PSA or RSA_ALT).
- */
- #define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0
- #if ( defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT) ) && \
- MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
- /* For RSA, the signature can be as large as the bignum module allows.
- * For RSA_ALT, the signature size is not necessarily tied to what the
- * bignum module can do, but in the absence of any specific setting,
- * we use that (rsa_alt_sign_wrap in pk_wrap will check). */
- #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
- #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
- #endif
- #if defined(MBEDTLS_ECDSA_C) && \
- MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE
- /* For ECDSA, the ecdsa module exports a constant for the maximum
- * signature size. */
- #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
- #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- #if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
- /* PSA_SIGNATURE_MAX_SIZE is the maximum size of a signature made
- * through the PSA API in the PSA representation. */
- #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
- #define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
- #endif
- #if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE
- /* The Mbed TLS representation is different for ECDSA signatures:
- * PSA uses the raw concatenation of r and s,
- * whereas Mbed TLS uses the ASN.1 representation (SEQUENCE of two INTEGERs).
- * Add the overhead of ASN.1: up to (1+2) + 2 * (1+2+1) for the
- * types, lengths (represented by up to 2 bytes), and potential leading
- * zeros of the INTEGERs and the SEQUENCE. */
- #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
- #define MBEDTLS_PK_SIGNATURE_MAX_SIZE ( PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 )
- #endif
- #endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */
- /**
- * \brief Types for interfacing with the debug module
- */
- typedef enum
- {
- MBEDTLS_PK_DEBUG_NONE = 0,
- MBEDTLS_PK_DEBUG_MPI,
- MBEDTLS_PK_DEBUG_ECP,
- } mbedtls_pk_debug_type;
- /**
- * \brief Item to send to the debug module
- */
- typedef struct mbedtls_pk_debug_item
- {
- mbedtls_pk_debug_type type;
- const char *name;
- void *value;
- } mbedtls_pk_debug_item;
- /** Maximum number of item send for debugging, plus 1 */
- #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
- /**
- * \brief Public key information and operations
- */
- typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
- /**
- * \brief Public key container
- */
- typedef struct mbedtls_pk_context
- {
- const mbedtls_pk_info_t * pk_info; /**< Public key information */
- void * pk_ctx; /**< Underlying public key context */
- } mbedtls_pk_context;
- #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Context for resuming operations
- */
- typedef struct
- {
- const mbedtls_pk_info_t * pk_info; /**< Public key information */
- void * rs_ctx; /**< Underlying restart context */
- } mbedtls_pk_restart_ctx;
- #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- /* Now we can declare functions that take a pointer to that */
- typedef void mbedtls_pk_restart_ctx;
- #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- #if defined(MBEDTLS_RSA_C)
- /**
- * Quick access to an RSA context inside a PK context.
- *
- * \warning You must make sure the PK context actually holds an RSA context
- * before using this function!
- */
- static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
- {
- return( (mbedtls_rsa_context *) (pk).pk_ctx );
- }
- #endif /* MBEDTLS_RSA_C */
- #if defined(MBEDTLS_ECP_C)
- /**
- * Quick access to an EC context inside a PK context.
- *
- * \warning You must make sure the PK context actually holds an EC context
- * before using this function!
- */
- static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk )
- {
- return( (mbedtls_ecp_keypair *) (pk).pk_ctx );
- }
- #endif /* MBEDTLS_ECP_C */
- #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
- /**
- * \brief Types for RSA-alt abstraction
- */
- typedef int (*mbedtls_pk_rsa_alt_decrypt_func)( void *ctx, int mode, size_t *olen,
- const unsigned char *input, unsigned char *output,
- size_t output_max_len );
- typedef int (*mbedtls_pk_rsa_alt_sign_func)( void *ctx,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
- const unsigned char *hash, unsigned char *sig );
- typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)( void *ctx );
- #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
- /**
- * \brief Return information associated with the given PK type
- *
- * \param pk_type PK type to search for.
- *
- * \return The PK info associated with the type or NULL if not found.
- */
- const mbedtls_pk_info_t *mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type );
- /**
- * \brief Initialize a #mbedtls_pk_context (as NONE).
- *
- * \param ctx The context to initialize.
- * This must not be \c NULL.
- */
- void mbedtls_pk_init( mbedtls_pk_context *ctx );
- /**
- * \brief Free the components of a #mbedtls_pk_context.
- *
- * \param ctx The context to clear. It must have been initialized.
- * If this is \c NULL, this function does nothing.
- *
- * \note For contexts that have been set up with
- * mbedtls_pk_setup_opaque(), this does not free the underlying
- * PSA key and you still need to call psa_destroy_key()
- * independently if you want to destroy that key.
- */
- void mbedtls_pk_free( mbedtls_pk_context *ctx );
- #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Initialize a restart context
- *
- * \param ctx The context to initialize.
- * This must not be \c NULL.
- */
- void mbedtls_pk_restart_init( mbedtls_pk_restart_ctx *ctx );
- /**
- * \brief Free the components of a restart context
- *
- * \param ctx The context to clear. It must have been initialized.
- * If this is \c NULL, this function does nothing.
- */
- void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx );
- #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- /**
- * \brief Initialize a PK context with the information given
- * and allocates the type-specific PK subcontext.
- *
- * \param ctx Context to initialize. It must not have been set
- * up yet (type #MBEDTLS_PK_NONE).
- * \param info Information to use
- *
- * \return 0 on success,
- * MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input,
- * MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
- *
- * \note For contexts holding an RSA-alt key, use
- * \c mbedtls_pk_setup_rsa_alt() instead.
- */
- int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info );
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- /**
- * \brief Initialize a PK context to wrap a PSA key.
- *
- * \note This function replaces mbedtls_pk_setup() for contexts
- * that wrap a (possibly opaque) PSA key instead of
- * storing and manipulating the key material directly.
- *
- * \param ctx The context to initialize. It must be empty (type NONE).
- * \param key The PSA key to wrap, which must hold an ECC key pair
- * (see notes below).
- *
- * \note The wrapped key must remain valid as long as the
- * wrapping PK context is in use, that is at least between
- * the point this function is called and the point
- * mbedtls_pk_free() is called on this context. The wrapped
- * key might then be independently used or destroyed.
- *
- * \note This function is currently only available for ECC key
- * pairs (that is, ECC keys containing private key material).
- * Support for other key types may be added later.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input
- * (context already used, invalid key identifier).
- * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the key is not an
- * ECC key pair.
- * \return #MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
- */
- int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx,
- const psa_key_id_t key );
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
- /**
- * \brief Initialize an RSA-alt context
- *
- * \param ctx Context to initialize. It must not have been set
- * up yet (type #MBEDTLS_PK_NONE).
- * \param key RSA key pointer
- * \param decrypt_func Decryption function
- * \param sign_func Signing function
- * \param key_len_func Function returning key length in bytes
- *
- * \return 0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the
- * context wasn't already initialized as RSA_ALT.
- *
- * \note This function replaces \c mbedtls_pk_setup() for RSA-alt.
- */
- int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key,
- mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
- mbedtls_pk_rsa_alt_sign_func sign_func,
- mbedtls_pk_rsa_alt_key_len_func key_len_func );
- #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
- /**
- * \brief Get the size in bits of the underlying key
- *
- * \param ctx The context to query. It must have been initialized.
- *
- * \return Key size in bits, or 0 on error
- */
- size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx );
- /**
- * \brief Get the length in bytes of the underlying key
- *
- * \param ctx The context to query. It must have been initialized.
- *
- * \return Key length in bytes, or 0 on error
- */
- static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx )
- {
- return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 );
- }
- /**
- * \brief Tell if a context can do the operation given by type
- *
- * \param ctx The context to query. It must have been initialized.
- * \param type The desired type.
- *
- * \return 1 if the context can do operations on the given type.
- * \return 0 if the context cannot do the operations on the given
- * type. This is always the case for a context that has
- * been initialized but not set up, or that has been
- * cleared with mbedtls_pk_free().
- */
- int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type );
- /**
- * \brief Verify signature (including padding if relevant).
- *
- * \param ctx The PK context to use. It must have been set up.
- * \param md_alg Hash algorithm used (see notes)
- * \param hash Hash of the message to sign
- * \param hash_len Hash length or 0 (see notes)
- * \param sig Signature to verify
- * \param sig_len Signature length
- *
- * \return 0 on success (signature is valid),
- * #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
- * signature in sig but its length is less than \p siglen,
- * or a specific error code.
- *
- * \note For RSA keys, the default padding type is PKCS#1 v1.5.
- * Use \c mbedtls_pk_verify_ext( MBEDTLS_PK_RSASSA_PSS, ... )
- * to verify RSASSA_PSS signatures.
- *
- * \note If hash_len is 0, then the length associated with md_alg
- * is used instead, or an error returned if it is invalid.
- *
- * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
- */
- int mbedtls_pk_verify( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- const unsigned char *sig, size_t sig_len );
- /**
- * \brief Restartable version of \c mbedtls_pk_verify()
- *
- * \note Performs the same job as \c mbedtls_pk_verify(), but can
- * return early and restart according to the limit set with
- * \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC
- * operations. For RSA, same as \c mbedtls_pk_verify().
- *
- * \param ctx The PK context to use. It must have been set up.
- * \param md_alg Hash algorithm used (see notes)
- * \param hash Hash of the message to sign
- * \param hash_len Hash length or 0 (see notes)
- * \param sig Signature to verify
- * \param sig_len Signature length
- * \param rs_ctx Restart context (NULL to disable restart)
- *
- * \return See \c mbedtls_pk_verify(), or
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- */
- int mbedtls_pk_verify_restartable( mbedtls_pk_context *ctx,
- mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- const unsigned char *sig, size_t sig_len,
- mbedtls_pk_restart_ctx *rs_ctx );
- /**
- * \brief Verify signature, with options.
- * (Includes verification of the padding depending on type.)
- *
- * \param type Signature type (inc. possible padding type) to verify
- * \param options Pointer to type-specific options, or NULL
- * \param ctx The PK context to use. It must have been set up.
- * \param md_alg Hash algorithm used (see notes)
- * \param hash Hash of the message to sign
- * \param hash_len Hash length or 0 (see notes)
- * \param sig Signature to verify
- * \param sig_len Signature length
- *
- * \return 0 on success (signature is valid),
- * #MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be
- * used for this type of signatures,
- * #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
- * signature in sig but its length is less than \p siglen,
- * or a specific error code.
- *
- * \note If hash_len is 0, then the length associated with md_alg
- * is used instead, or an error returned if it is invalid.
- *
- * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
- *
- * \note If type is MBEDTLS_PK_RSASSA_PSS, then options must point
- * to a mbedtls_pk_rsassa_pss_options structure,
- * otherwise it must be NULL.
- */
- int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
- mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- const unsigned char *sig, size_t sig_len );
- /**
- * \brief Make signature, including padding if relevant.
- *
- * \param ctx The PK context to use. It must have been set up
- * with a private key.
- * \param md_alg Hash algorithm used (see notes)
- * \param hash Hash of the message to sign
- * \param hash_len Hash length or 0 (see notes)
- * \param sig Place to write the signature.
- * It must have enough room for the signature.
- * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
- * You may use a smaller buffer if it is large enough
- * given the key type.
- * \param sig_len On successful return,
- * the number of bytes written to \p sig.
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- *
- * \return 0 on success, or a specific error code.
- *
- * \note For RSA keys, the default padding type is PKCS#1 v1.5.
- * There is no interface in the PK module to make RSASSA-PSS
- * signatures yet.
- *
- * \note If hash_len is 0, then the length associated with md_alg
- * is used instead, or an error returned if it is invalid.
- *
- * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
- * For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
- */
- int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- unsigned char *sig, size_t *sig_len,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
- /**
- * \brief Restartable version of \c mbedtls_pk_sign()
- *
- * \note Performs the same job as \c mbedtls_pk_sign(), but can
- * return early and restart according to the limit set with
- * \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC
- * operations. For RSA, same as \c mbedtls_pk_sign().
- *
- * \param ctx The PK context to use. It must have been set up
- * with a private key.
- * \param md_alg Hash algorithm used (see notes for mbedtls_pk_sign())
- * \param hash Hash of the message to sign
- * \param hash_len Hash length or 0 (see notes for mbedtls_pk_sign())
- * \param sig Place to write the signature.
- * It must have enough room for the signature.
- * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
- * You may use a smaller buffer if it is large enough
- * given the key type.
- * \param sig_len On successful return,
- * the number of bytes written to \p sig.
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- * \param rs_ctx Restart context (NULL to disable restart)
- *
- * \return See \c mbedtls_pk_sign().
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- */
- int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx,
- mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- unsigned char *sig, size_t *sig_len,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- mbedtls_pk_restart_ctx *rs_ctx );
- /**
- * \brief Decrypt message (including padding if relevant).
- *
- * \param ctx The PK context to use. It must have been set up
- * with a private key.
- * \param input Input to decrypt
- * \param ilen Input size
- * \param output Decrypted output
- * \param olen Decrypted message length
- * \param osize Size of the output buffer
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- *
- * \note For RSA keys, the default padding type is PKCS#1 v1.5.
- *
- * \return 0 on success, or a specific error code.
- */
- int mbedtls_pk_decrypt( mbedtls_pk_context *ctx,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen, size_t osize,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
- /**
- * \brief Encrypt message (including padding if relevant).
- *
- * \param ctx The PK context to use. It must have been set up.
- * \param input Message to encrypt
- * \param ilen Message size
- * \param output Encrypted output
- * \param olen Encrypted output length
- * \param osize Size of the output buffer
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- *
- * \note For RSA keys, the default padding type is PKCS#1 v1.5.
- *
- * \return 0 on success, or a specific error code.
- */
- int mbedtls_pk_encrypt( mbedtls_pk_context *ctx,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen, size_t osize,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
- /**
- * \brief Check if a public-private pair of keys matches.
- *
- * \param pub Context holding a public key.
- * \param prv Context holding a private (and public) key.
- *
- * \return \c 0 on success (keys were checked and match each other).
- * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the keys could not
- * be checked - in that case they may or may not match.
- * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA if a context is invalid.
- * \return Another non-zero value if the keys do not match.
- */
- int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_context *prv );
- /**
- * \brief Export debug information
- *
- * \param ctx The PK context to use. It must have been initialized.
- * \param items Place to write debug items
- *
- * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
- */
- int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items );
- /**
- * \brief Access the type name
- *
- * \param ctx The PK context to use. It must have been initialized.
- *
- * \return Type name on success, or "invalid PK"
- */
- const char * mbedtls_pk_get_name( const mbedtls_pk_context *ctx );
- /**
- * \brief Get the key type
- *
- * \param ctx The PK context to use. It must have been initialized.
- *
- * \return Type on success.
- * \return #MBEDTLS_PK_NONE for a context that has not been set up.
- */
- mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx );
- #if defined(MBEDTLS_PK_PARSE_C)
- /** \ingroup pk_module */
- /**
- * \brief Parse a private key in PEM or DER format
- *
- * \param ctx The PK context to fill. It must have been initialized
- * but not set up.
- * \param key Input buffer to parse.
- * The buffer must contain the input exactly, with no
- * extra trailing material. For PEM, the buffer must
- * contain a null-terminated string.
- * \param keylen Size of \b key in bytes.
- * For PEM data, this includes the terminating null byte,
- * so \p keylen must be equal to `strlen(key) + 1`.
- * \param pwd Optional password for decryption.
- * Pass \c NULL if expecting a non-encrypted key.
- * Pass a string of \p pwdlen bytes if expecting an encrypted
- * key; a non-encrypted key will also be accepted.
- * The empty password is not supported.
- * \param pwdlen Size of the password in bytes.
- * Ignored if \p pwd is \c NULL.
- *
- * \note On entry, ctx must be empty, either freshly initialised
- * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
- * specific key type, check the result with mbedtls_pk_can_do().
- *
- * \note The key is also checked for correctness.
- *
- * \return 0 if successful, or a specific PK or PEM error code
- */
- int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
- const unsigned char *key, size_t keylen,
- const unsigned char *pwd, size_t pwdlen );
- /** \ingroup pk_module */
- /**
- * \brief Parse a public key in PEM or DER format
- *
- * \param ctx The PK context to fill. It must have been initialized
- * but not set up.
- * \param key Input buffer to parse.
- * The buffer must contain the input exactly, with no
- * extra trailing material. For PEM, the buffer must
- * contain a null-terminated string.
- * \param keylen Size of \b key in bytes.
- * For PEM data, this includes the terminating null byte,
- * so \p keylen must be equal to `strlen(key) + 1`.
- *
- * \note On entry, ctx must be empty, either freshly initialised
- * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
- * specific key type, check the result with mbedtls_pk_can_do().
- *
- * \note The key is also checked for correctness.
- *
- * \return 0 if successful, or a specific PK or PEM error code
- */
- int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
- const unsigned char *key, size_t keylen );
- #if defined(MBEDTLS_FS_IO)
- /** \ingroup pk_module */
- /**
- * \brief Load and parse a private key
- *
- * \param ctx The PK context to fill. It must have been initialized
- * but not set up.
- * \param path filename to read the private key from
- * \param password Optional password to decrypt the file.
- * Pass \c NULL if expecting a non-encrypted key.
- * Pass a null-terminated string if expecting an encrypted
- * key; a non-encrypted key will also be accepted.
- * The empty password is not supported.
- *
- * \note On entry, ctx must be empty, either freshly initialised
- * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
- * specific key type, check the result with mbedtls_pk_can_do().
- *
- * \note The key is also checked for correctness.
- *
- * \return 0 if successful, or a specific PK or PEM error code
- */
- int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
- const char *path, const char *password );
- /** \ingroup pk_module */
- /**
- * \brief Load and parse a public key
- *
- * \param ctx The PK context to fill. It must have been initialized
- * but not set up.
- * \param path filename to read the public key from
- *
- * \note On entry, ctx must be empty, either freshly initialised
- * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If
- * you need a specific key type, check the result with
- * mbedtls_pk_can_do().
- *
- * \note The key is also checked for correctness.
- *
- * \return 0 if successful, or a specific PK or PEM error code
- */
- int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path );
- #endif /* MBEDTLS_FS_IO */
- #endif /* MBEDTLS_PK_PARSE_C */
- #if defined(MBEDTLS_PK_WRITE_C)
- /**
- * \brief Write a private key to a PKCS#1 or SEC1 DER structure
- * Note: data is written at the end of the buffer! Use the
- * return value to determine where you should start
- * using the buffer
- *
- * \param ctx PK context which must contain a valid private key.
- * \param buf buffer to write to
- * \param size size of the buffer
- *
- * \return length of data written if successful, or a specific
- * error code
- */
- int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
- /**
- * \brief Write a public key to a SubjectPublicKeyInfo DER structure
- * Note: data is written at the end of the buffer! Use the
- * return value to determine where you should start
- * using the buffer
- *
- * \param ctx PK context which must contain a valid public or private key.
- * \param buf buffer to write to
- * \param size size of the buffer
- *
- * \return length of data written if successful, or a specific
- * error code
- */
- int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
- #if defined(MBEDTLS_PEM_WRITE_C)
- /**
- * \brief Write a public key to a PEM string
- *
- * \param ctx PK context which must contain a valid public or private key.
- * \param buf Buffer to write to. The output includes a
- * terminating null byte.
- * \param size Size of the buffer in bytes.
- *
- * \return 0 if successful, or a specific error code
- */
- int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
- /**
- * \brief Write a private key to a PKCS#1 or SEC1 PEM string
- *
- * \param ctx PK context which must contain a valid private key.
- * \param buf Buffer to write to. The output includes a
- * terminating null byte.
- * \param size Size of the buffer in bytes.
- *
- * \return 0 if successful, or a specific error code
- */
- int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
- #endif /* MBEDTLS_PEM_WRITE_C */
- #endif /* MBEDTLS_PK_WRITE_C */
- /*
- * WARNING: Low-level functions. You probably do not want to use these unless
- * you are certain you do ;)
- */
- #if defined(MBEDTLS_PK_PARSE_C)
- /**
- * \brief Parse a SubjectPublicKeyInfo DER structure
- *
- * \param p the position in the ASN.1 data
- * \param end end of the buffer
- * \param pk The PK context to fill. It must have been initialized
- * but not set up.
- *
- * \return 0 if successful, or a specific PK error code
- */
- int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
- mbedtls_pk_context *pk );
- #endif /* MBEDTLS_PK_PARSE_C */
- #if defined(MBEDTLS_PK_WRITE_C)
- /**
- * \brief Write a subjectPublicKey to ASN.1 data
- * Note: function works backwards in data buffer
- *
- * \param p reference to current position pointer
- * \param start start of the buffer (for bounds-checking)
- * \param key PK context which must contain a valid public or private key.
- *
- * \return the length written or a negative error code
- */
- int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
- const mbedtls_pk_context *key );
- #endif /* MBEDTLS_PK_WRITE_C */
- /*
- * Internal module functions. You probably do not want to use these unless you
- * know you do.
- */
- #if defined(MBEDTLS_FS_IO)
- int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n );
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- /**
- * \brief Turn an EC key into an opaque one.
- *
- * \warning This is a temporary utility function for tests. It might
- * change or be removed at any time without notice.
- *
- * \note Only ECDSA keys are supported so far. Signing with the
- * specified hash is the only allowed use of that key.
- *
- * \param pk Input: the EC key to import to a PSA key.
- * Output: a PK context wrapping that PSA key.
- * \param key Output: a PSA key identifier.
- * It's the caller's responsibility to call
- * psa_destroy_key() on that key identifier after calling
- * mbedtls_pk_free() on the PK context.
- * \param hash_alg The hash algorithm to allow for use with that key.
- *
- * \return \c 0 if successful.
- * \return An Mbed TLS error code otherwise.
- */
- int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk,
- psa_key_id_t *key,
- psa_algorithm_t hash_alg );
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_PK_H */
- /********* Start of file include/mbedtls/pk_internal.h ************/
- /**
- * \file pk_internal.h
- *
- * \brief Public Key abstraction layer: wrapper functions
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PK_WRAP_H
- #define MBEDTLS_PK_WRAP_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- struct mbedtls_pk_info_t
- {
- /** Public key type */
- mbedtls_pk_type_t type;
- /** Type name */
- const char *name;
- /** Get key size in bits */
- size_t (*get_bitlen)( const void * );
- /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
- int (*can_do)( mbedtls_pk_type_t type );
- /** Verify signature */
- int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- const unsigned char *sig, size_t sig_len );
- /** Make signature */
- int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- unsigned char *sig, size_t *sig_len,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- /** Verify signature (restartable) */
- int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- const unsigned char *sig, size_t sig_len,
- void *rs_ctx );
- /** Make signature (restartable) */
- int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
- const unsigned char *hash, size_t hash_len,
- unsigned char *sig, size_t *sig_len,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng, void *rs_ctx );
- #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- /** Decrypt message */
- int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen, size_t osize,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /** Encrypt message */
- int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen, size_t osize,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /** Check public-private key pair */
- int (*check_pair_func)( const void *pub, const void *prv );
- /** Allocate a new context */
- void * (*ctx_alloc_func)( void );
- /** Free the given context */
- void (*ctx_free_func)( void *ctx );
- #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- /** Allocate the restart context */
- void * (*rs_alloc_func)( void );
- /** Free the restart context */
- void (*rs_free_func)( void *rs_ctx );
- #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- /** Interface with the debug module */
- void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
- };
- #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
- /* Container for RSA-alt */
- typedef struct
- {
- void *key;
- mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
- mbedtls_pk_rsa_alt_sign_func sign_func;
- mbedtls_pk_rsa_alt_key_len_func key_len_func;
- } mbedtls_rsa_alt_context;
- #endif
- #if defined(MBEDTLS_RSA_C)
- extern const mbedtls_pk_info_t mbedtls_rsa_info;
- #endif
- #if defined(MBEDTLS_ECP_C)
- extern const mbedtls_pk_info_t mbedtls_eckey_info;
- extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
- #endif
- #if defined(MBEDTLS_ECDSA_C)
- extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
- #endif
- #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
- extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
- #endif
- #endif /* MBEDTLS_PK_WRAP_H */
- /********* Start of file include/mbedtls/x509.h ************/
- /**
- * \file x509.h
- *
- * \brief X.509 generic defines and structures
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_X509_H
- #define MBEDTLS_X509_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_RSA_C)
- #endif
- /**
- * \addtogroup x509_module
- * \{
- */
- #if !defined(MBEDTLS_X509_MAX_INTERMEDIATE_CA)
- /**
- * Maximum number of intermediate CAs in a verification chain.
- * That is, maximum length of the chain, excluding the end-entity certificate
- * and the trusted root certificate.
- *
- * Set this to a low value to prevent an adversary from making you waste
- * resources verifying an overlong certificate chain.
- */
- #define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8
- #endif
- /**
- * \name X509 Error codes
- * \{
- */
- /** Unavailable feature, e.g. RSA hashing/encryption combination. */
- #define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080
- /** Requested OID is unknown. */
- #define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100
- /** The CRT/CRL/CSR format is invalid, e.g. different type expected. */
- #define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180
- /** The CRT/CRL/CSR version element is invalid. */
- #define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200
- /** The serial tag or value is invalid. */
- #define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280
- /** The algorithm tag or value is invalid. */
- #define MBEDTLS_ERR_X509_INVALID_ALG -0x2300
- /** The name tag or value is invalid. */
- #define MBEDTLS_ERR_X509_INVALID_NAME -0x2380
- /** The date tag or value is invalid. */
- #define MBEDTLS_ERR_X509_INVALID_DATE -0x2400
- /** The signature tag or value invalid. */
- #define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480
- /** The extension tag or value is invalid. */
- #define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500
- /** CRT/CRL/CSR has an unsupported version number. */
- #define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580
- /** Signature algorithm (oid) is unsupported. */
- #define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600
- /** Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */
- #define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680
- /** Certificate verification failed, e.g. CRL, CA or signature check failed. */
- #define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700
- /** Format not recognized as DER or PEM. */
- #define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780
- /** Input invalid. */
- #define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800
- /** Allocation of memory failed. */
- #define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880
- /** Read/write of file failed. */
- #define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900
- /** Destination buffer is too small. */
- #define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980
- /** A fatal error occurred, eg the chain is too long or the vrfy callback failed. */
- #define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000
- /* \} name */
- /**
- * \name X509 Verify codes
- * \{
- */
- /* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */
- #define MBEDTLS_X509_BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
- #define MBEDTLS_X509_BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
- #define MBEDTLS_X509_BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
- #define MBEDTLS_X509_BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
- #define MBEDTLS_X509_BADCRL_NOT_TRUSTED 0x10 /**< The CRL is not correctly signed by the trusted CA. */
- #define MBEDTLS_X509_BADCRL_EXPIRED 0x20 /**< The CRL is expired. */
- #define MBEDTLS_X509_BADCERT_MISSING 0x40 /**< Certificate was missing. */
- #define MBEDTLS_X509_BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
- #define MBEDTLS_X509_BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
- #define MBEDTLS_X509_BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
- #define MBEDTLS_X509_BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
- #define MBEDTLS_X509_BADCERT_KEY_USAGE 0x0800 /**< Usage does not match the keyUsage extension. */
- #define MBEDTLS_X509_BADCERT_EXT_KEY_USAGE 0x1000 /**< Usage does not match the extendedKeyUsage extension. */
- #define MBEDTLS_X509_BADCERT_NS_CERT_TYPE 0x2000 /**< Usage does not match the nsCertType extension. */
- #define MBEDTLS_X509_BADCERT_BAD_MD 0x4000 /**< The certificate is signed with an unacceptable hash. */
- #define MBEDTLS_X509_BADCERT_BAD_PK 0x8000 /**< The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
- #define MBEDTLS_X509_BADCERT_BAD_KEY 0x010000 /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
- #define MBEDTLS_X509_BADCRL_BAD_MD 0x020000 /**< The CRL is signed with an unacceptable hash. */
- #define MBEDTLS_X509_BADCRL_BAD_PK 0x040000 /**< The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
- #define MBEDTLS_X509_BADCRL_BAD_KEY 0x080000 /**< The CRL is signed with an unacceptable key (eg bad curve, RSA too short). */
- /* \} name */
- /* \} addtogroup x509_module */
- /*
- * X.509 v3 Subject Alternative Name types.
- * otherName [0] OtherName,
- * rfc822Name [1] IA5String,
- * dNSName [2] IA5String,
- * x400Address [3] ORAddress,
- * directoryName [4] Name,
- * ediPartyName [5] EDIPartyName,
- * uniformResourceIdentifier [6] IA5String,
- * iPAddress [7] OCTET STRING,
- * registeredID [8] OBJECT IDENTIFIER
- */
- #define MBEDTLS_X509_SAN_OTHER_NAME 0
- #define MBEDTLS_X509_SAN_RFC822_NAME 1
- #define MBEDTLS_X509_SAN_DNS_NAME 2
- #define MBEDTLS_X509_SAN_X400_ADDRESS_NAME 3
- #define MBEDTLS_X509_SAN_DIRECTORY_NAME 4
- #define MBEDTLS_X509_SAN_EDI_PARTY_NAME 5
- #define MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER 6
- #define MBEDTLS_X509_SAN_IP_ADDRESS 7
- #define MBEDTLS_X509_SAN_REGISTERED_ID 8
- /*
- * X.509 v3 Key Usage Extension flags
- * Reminder: update x509_info_key_usage() when adding new flags.
- */
- #define MBEDTLS_X509_KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
- #define MBEDTLS_X509_KU_NON_REPUDIATION (0x40) /* bit 1 */
- #define MBEDTLS_X509_KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
- #define MBEDTLS_X509_KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
- #define MBEDTLS_X509_KU_KEY_AGREEMENT (0x08) /* bit 4 */
- #define MBEDTLS_X509_KU_KEY_CERT_SIGN (0x04) /* bit 5 */
- #define MBEDTLS_X509_KU_CRL_SIGN (0x02) /* bit 6 */
- #define MBEDTLS_X509_KU_ENCIPHER_ONLY (0x01) /* bit 7 */
- #define MBEDTLS_X509_KU_DECIPHER_ONLY (0x8000) /* bit 8 */
- /*
- * Netscape certificate types
- * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
- */
- #define MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
- #define MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
- #define MBEDTLS_X509_NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
- #define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
- #define MBEDTLS_X509_NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
- #define MBEDTLS_X509_NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
- #define MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
- #define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
- /*
- * X.509 extension types
- *
- * Comments refer to the status for using certificates. Status can be
- * different for writing certificates or reading CRLs or CSRs.
- *
- * Those are defined in oid.h as oid.c needs them in a data structure. Since
- * these were previously defined here, let's have aliases for compatibility.
- */
- #define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER
- #define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER
- #define MBEDTLS_X509_EXT_KEY_USAGE MBEDTLS_OID_X509_EXT_KEY_USAGE
- #define MBEDTLS_X509_EXT_CERTIFICATE_POLICIES MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES
- #define MBEDTLS_X509_EXT_POLICY_MAPPINGS MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS
- #define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME /* Supported (DNS) */
- #define MBEDTLS_X509_EXT_ISSUER_ALT_NAME MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME
- #define MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS
- #define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS /* Supported */
- #define MBEDTLS_X509_EXT_NAME_CONSTRAINTS MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS
- #define MBEDTLS_X509_EXT_POLICY_CONSTRAINTS MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS
- #define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE
- #define MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS
- #define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY
- #define MBEDTLS_X509_EXT_FRESHEST_CRL MBEDTLS_OID_X509_EXT_FRESHEST_CRL
- #define MBEDTLS_X509_EXT_NS_CERT_TYPE MBEDTLS_OID_X509_EXT_NS_CERT_TYPE
- /*
- * Storage format identifiers
- * Recognized formats: PEM and DER
- */
- #define MBEDTLS_X509_FORMAT_DER 1
- #define MBEDTLS_X509_FORMAT_PEM 2
- #define MBEDTLS_X509_MAX_DN_NAME_SIZE 256 /**< Maximum value size of a DN entry */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \addtogroup x509_module
- * \{ */
- /**
- * \name Structures for parsing X.509 certificates, CRLs and CSRs
- * \{
- */
- /**
- * Type-length-value structure that allows for ASN1 using DER.
- */
- typedef mbedtls_asn1_buf mbedtls_x509_buf;
- /**
- * Container for ASN1 bit strings.
- */
- typedef mbedtls_asn1_bitstring mbedtls_x509_bitstring;
- /**
- * Container for ASN1 named information objects.
- * It allows for Relative Distinguished Names (e.g. cn=localhost,ou=code,etc.).
- */
- typedef mbedtls_asn1_named_data mbedtls_x509_name;
- /**
- * Container for a sequence of ASN.1 items
- */
- typedef mbedtls_asn1_sequence mbedtls_x509_sequence;
- /** Container for date and time (precision in seconds). */
- typedef struct mbedtls_x509_time
- {
- int year, mon, day; /**< Date. */
- int hour, min, sec; /**< Time. */
- }
- mbedtls_x509_time;
- /** \} name Structures for parsing X.509 certificates, CRLs and CSRs */
- /** \} addtogroup x509_module */
- /**
- * \brief Store the certificate DN in printable form into buf;
- * no more than size characters will be written.
- *
- * \param buf Buffer to write to
- * \param size Maximum size of buffer
- * \param dn The X509 name to represent
- *
- * \return The length of the string written (not including the
- * terminated nul byte), or a negative error code.
- */
- int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn );
- /**
- * \brief Store the certificate serial in printable form into buf;
- * no more than size characters will be written.
- *
- * \param buf Buffer to write to
- * \param size Maximum size of buffer
- * \param serial The X509 serial to represent
- *
- * \return The length of the string written (not including the
- * terminated nul byte), or a negative error code.
- */
- int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *serial );
- /**
- * \brief Check a given mbedtls_x509_time against the system time
- * and tell if it's in the past.
- *
- * \note Intended usage is "if( is_past( valid_to ) ) ERROR".
- * Hence the return value of 1 if on internal errors.
- *
- * \param to mbedtls_x509_time to check
- *
- * \return 1 if the given time is in the past or an error occurred,
- * 0 otherwise.
- */
- int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
- /**
- * \brief Check a given mbedtls_x509_time against the system time
- * and tell if it's in the future.
- *
- * \note Intended usage is "if( is_future( valid_from ) ) ERROR".
- * Hence the return value of 1 if on internal errors.
- *
- * \param from mbedtls_x509_time to check
- *
- * \return 1 if the given time is in the future or an error occurred,
- * 0 otherwise.
- */
- int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- int mbedtls_x509_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- /*
- * Internal module functions. You probably do not want to use these unless you
- * know you do.
- */
- int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
- mbedtls_x509_name *cur );
- int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
- mbedtls_x509_buf *alg );
- int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
- mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
- #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
- int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
- mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
- int *salt_len );
- #endif
- int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
- int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
- mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
- void **sig_opts );
- int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
- mbedtls_x509_time *t );
- int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
- mbedtls_x509_buf *serial );
- int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
- mbedtls_x509_buf *ext, int tag );
- int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
- mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
- const void *sig_opts );
- int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
- int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
- int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
- int critical, const unsigned char *val,
- size_t val_len );
- int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
- mbedtls_asn1_named_data *first );
- int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
- mbedtls_asn1_named_data *first );
- int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
- const char *oid, size_t oid_len,
- unsigned char *sig, size_t size );
- #define MBEDTLS_X509_SAFE_SNPRINTF \
- do { \
- if( ret < 0 || (size_t) ret >= n ) \
- return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); \
- \
- n -= (size_t) ret; \
- p += (size_t) ret; \
- } while( 0 )
- #ifdef __cplusplus
- }
- #endif
- #endif /* x509.h */
- /********* Start of file include/mbedtls/x509_crl.h ************/
- /**
- * \file x509_crl.h
- *
- * \brief X.509 certificate revocation list parsing
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_X509_CRL_H
- #define MBEDTLS_X509_CRL_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \addtogroup x509_module
- * \{ */
- /**
- * \name Structures and functions for parsing CRLs
- * \{
- */
- /**
- * Certificate revocation list entry.
- * Contains the CA-specific serial numbers and revocation dates.
- */
- typedef struct mbedtls_x509_crl_entry
- {
- mbedtls_x509_buf raw;
- mbedtls_x509_buf serial;
- mbedtls_x509_time revocation_date;
- mbedtls_x509_buf entry_ext;
- struct mbedtls_x509_crl_entry *next;
- }
- mbedtls_x509_crl_entry;
- /**
- * Certificate revocation list structure.
- * Every CRL may have multiple entries.
- */
- typedef struct mbedtls_x509_crl
- {
- mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
- mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
- int version; /**< CRL version (1=v1, 2=v2) */
- mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
- mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
- mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
- mbedtls_x509_time this_update;
- mbedtls_x509_time next_update;
- mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
- mbedtls_x509_buf crl_ext;
- mbedtls_x509_buf sig_oid2;
- mbedtls_x509_buf sig;
- mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
- mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
- void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
- struct mbedtls_x509_crl *next;
- }
- mbedtls_x509_crl;
- /**
- * \brief Parse a DER-encoded CRL and append it to the chained list
- *
- * \param chain points to the start of the chain
- * \param buf buffer holding the CRL data in DER format
- * \param buflen size of the buffer
- * (including the terminating null byte for PEM data)
- *
- * \return 0 if successful, or a specific X509 or PEM error code
- */
- int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
- const unsigned char *buf, size_t buflen );
- /**
- * \brief Parse one or more CRLs and append them to the chained list
- *
- * \note Multiple CRLs are accepted only if using PEM format
- *
- * \param chain points to the start of the chain
- * \param buf buffer holding the CRL data in PEM or DER format
- * \param buflen size of the buffer
- * (including the terminating null byte for PEM data)
- *
- * \return 0 if successful, or a specific X509 or PEM error code
- */
- int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief Load one or more CRLs and append them to the chained list
- *
- * \note Multiple CRLs are accepted only if using PEM format
- *
- * \param chain points to the start of the chain
- * \param path filename to read the CRLs from (in PEM or DER encoding)
- *
- * \return 0 if successful, or a specific X509 or PEM error code
- */
- int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
- #endif /* MBEDTLS_FS_IO */
- /**
- * \brief Returns an informational string about the CRL.
- *
- * \param buf Buffer to write to
- * \param size Maximum size of buffer
- * \param prefix A line prefix
- * \param crl The X509 CRL to represent
- *
- * \return The length of the string written (not including the
- * terminated nul byte), or a negative error code.
- */
- int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
- const mbedtls_x509_crl *crl );
- /**
- * \brief Initialize a CRL (chain)
- *
- * \param crl CRL chain to initialize
- */
- void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
- /**
- * \brief Unallocate all CRL data
- *
- * \param crl CRL chain to free
- */
- void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
- /* \} name */
- /* \} addtogroup x509_module */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_x509_crl.h */
- /********* Start of file include/mbedtls/x509_crt.h ************/
- /**
- * \file x509_crt.h
- *
- * \brief X.509 certificate parsing and writing
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_X509_CRT_H
- #define MBEDTLS_X509_CRT_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /**
- * \addtogroup x509_module
- * \{
- */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \name Structures and functions for parsing and writing X.509 certificates
- * \{
- */
- /**
- * Container for an X.509 certificate. The certificate may be chained.
- */
- typedef struct mbedtls_x509_crt
- {
- int own_buffer; /**< Indicates if \c raw is owned
- * by the structure or not. */
- mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
- mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
- int version; /**< The X.509 version. (1=v1, 2=v2, 3=v3) */
- mbedtls_x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
- mbedtls_x509_buf sig_oid; /**< Signature algorithm, e.g. sha1RSA */
- mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
- mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
- mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
- mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
- mbedtls_x509_time valid_from; /**< Start time of certificate validity. */
- mbedtls_x509_time valid_to; /**< End time of certificate validity. */
- mbedtls_x509_buf pk_raw;
- mbedtls_pk_context pk; /**< Container for the public key context. */
- mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
- mbedtls_x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
- mbedtls_x509_buf v3_ext; /**< Optional X.509 v3 extensions. */
- mbedtls_x509_sequence subject_alt_names; /**< Optional list of raw entries of Subject Alternative Names extension (currently only dNSName and OtherName are listed). */
- mbedtls_x509_sequence certificate_policies; /**< Optional list of certificate policies (Only anyPolicy is printed and enforced, however the rest of the policies are still listed). */
- int ext_types; /**< Bit string containing detected and parsed extensions */
- int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
- 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+ */
- unsigned int key_usage; /**< Optional key usage extension value: See the values in x509.h */
- mbedtls_x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
- unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */
- mbedtls_x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
- mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
- mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
- void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
- struct mbedtls_x509_crt *next; /**< Next certificate in the CA-chain. */
- }
- mbedtls_x509_crt;
- /**
- * From RFC 5280 section 4.2.1.6:
- * OtherName ::= SEQUENCE {
- * type-id OBJECT IDENTIFIER,
- * value [0] EXPLICIT ANY DEFINED BY type-id }
- */
- typedef struct mbedtls_x509_san_other_name
- {
- /**
- * The type_id is an OID as deifned in RFC 5280.
- * To check the value of the type id, you should use
- * \p MBEDTLS_OID_CMP with a known OID mbedtls_x509_buf.
- */
- mbedtls_x509_buf type_id; /**< The type id. */
- union
- {
- /**
- * From RFC 4108 section 5:
- * HardwareModuleName ::= SEQUENCE {
- * hwType OBJECT IDENTIFIER,
- * hwSerialNum OCTET STRING }
- */
- struct
- {
- mbedtls_x509_buf oid; /**< The object identifier. */
- mbedtls_x509_buf val; /**< The named value. */
- }
- hardware_module_name;
- }
- value;
- }
- mbedtls_x509_san_other_name;
- /**
- * A structure for holding the parsed Subject Alternative Name, according to type
- */
- typedef struct mbedtls_x509_subject_alternative_name
- {
- int type; /**< The SAN type, value of MBEDTLS_X509_SAN_XXX. */
- union {
- mbedtls_x509_san_other_name other_name; /**< The otherName supported type. */
- mbedtls_x509_buf unstructured_name; /**< The buffer for the un constructed types. Only dnsName currently supported */
- }
- san; /**< A union of the supported SAN types */
- }
- mbedtls_x509_subject_alternative_name;
- /**
- * Build flag from an algorithm/curve identifier (pk, md, ecp)
- * Since 0 is always XXX_NONE, ignore it.
- */
- #define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( (id) - 1 ) )
- /**
- * Security profile for certificate verification.
- *
- * All lists are bitfields, built by ORing flags from MBEDTLS_X509_ID_FLAG().
- */
- typedef struct mbedtls_x509_crt_profile
- {
- uint32_t allowed_mds; /**< MDs for signatures */
- uint32_t allowed_pks; /**< PK algs for signatures */
- uint32_t allowed_curves; /**< Elliptic curves for ECDSA */
- uint32_t rsa_min_bitlen; /**< Minimum size for RSA keys */
- }
- mbedtls_x509_crt_profile;
- #define MBEDTLS_X509_CRT_VERSION_1 0
- #define MBEDTLS_X509_CRT_VERSION_2 1
- #define MBEDTLS_X509_CRT_VERSION_3 2
- #define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 32
- #define MBEDTLS_X509_RFC5280_UTC_TIME_LEN 15
- #if !defined( MBEDTLS_X509_MAX_FILE_PATH_LEN )
- #define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
- #endif
- /**
- * Container for writing a certificate (CRT)
- */
- typedef struct mbedtls_x509write_cert
- {
- int version;
- mbedtls_mpi serial;
- mbedtls_pk_context *subject_key;
- mbedtls_pk_context *issuer_key;
- mbedtls_asn1_named_data *subject;
- mbedtls_asn1_named_data *issuer;
- mbedtls_md_type_t md_alg;
- char not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
- char not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
- mbedtls_asn1_named_data *extensions;
- }
- mbedtls_x509write_cert;
- /**
- * Item in a verification chain: cert and flags for it
- */
- typedef struct {
- mbedtls_x509_crt *crt;
- uint32_t flags;
- } mbedtls_x509_crt_verify_chain_item;
- /**
- * Max size of verification chain: end-entity + intermediates + trusted root
- */
- #define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE ( MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2 )
- /**
- * Verification chain as built by \c mbedtls_crt_verify_chain()
- */
- typedef struct
- {
- mbedtls_x509_crt_verify_chain_item items[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE];
- unsigned len;
- #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
- /* This stores the list of potential trusted signers obtained from
- * the CA callback used for the CRT verification, if configured.
- * We must track it somewhere because the callback passes its
- * ownership to the caller. */
- mbedtls_x509_crt *trust_ca_cb_result;
- #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
- } mbedtls_x509_crt_verify_chain;
- #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Context for resuming X.509 verify operations
- */
- typedef struct
- {
- /* for check_signature() */
- mbedtls_pk_restart_ctx pk;
- /* for find_parent_in() */
- mbedtls_x509_crt *parent; /* non-null iff parent_in in progress */
- mbedtls_x509_crt *fallback_parent;
- int fallback_signature_is_good;
- /* for find_parent() */
- int parent_is_trusted; /* -1 if find_parent is not in progress */
- /* for verify_chain() */
- enum {
- x509_crt_rs_none,
- x509_crt_rs_find_parent,
- } in_progress; /* none if no operation is in progress */
- int self_cnt;
- mbedtls_x509_crt_verify_chain ver_chain;
- } mbedtls_x509_crt_restart_ctx;
- #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- /* Now we can declare functions that take a pointer to that */
- typedef void mbedtls_x509_crt_restart_ctx;
- #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * Default security profile. Should provide a good balance between security
- * and compatibility with current deployments.
- *
- * This profile permits:
- * - SHA2 hashes.
- * - All supported elliptic curves.
- * - RSA with 2048 bits and above.
- *
- * New minor versions of Mbed TLS may extend this profile, for example if
- * new curves are added to the library. New minor versions of Mbed TLS will
- * not reduce this profile unless serious security concerns require it.
- */
- extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
- /**
- * Expected next default profile. Recommended for new deployments.
- * Currently targets a 128-bit security level, except for allowing RSA-2048.
- */
- extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
- /**
- * NSA Suite B profile.
- */
- extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
- /**
- * \brief Parse a single DER formatted certificate and add it
- * to the end of the provided chained list.
- *
- * \param chain The pointer to the start of the CRT chain to attach to.
- * When parsing the first CRT in a chain, this should point
- * to an instance of ::mbedtls_x509_crt initialized through
- * mbedtls_x509_crt_init().
- * \param buf The buffer holding the DER encoded certificate.
- * \param buflen The size in Bytes of \p buf.
- *
- * \note This function makes an internal copy of the CRT buffer
- * \p buf. In particular, \p buf may be destroyed or reused
- * after this call returns. To avoid duplicating the CRT
- * buffer (at the cost of stricter lifetime constraints),
- * use mbedtls_x509_crt_parse_der_nocopy() instead.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain,
- const unsigned char *buf,
- size_t buflen );
- /**
- * \brief The type of certificate extension callbacks.
- *
- * Callbacks of this type are passed to and used by the
- * mbedtls_x509_crt_parse_der_with_ext_cb() routine when
- * it encounters either an unsupported extension or a
- * "certificate policies" extension containing any
- * unsupported certificate policies.
- * Future versions of the library may invoke the callback
- * in other cases, if and when the need arises.
- *
- * \param p_ctx An opaque context passed to the callback.
- * \param crt The certificate being parsed.
- * \param oid The OID of the extension.
- * \param critical Whether the extension is critical.
- * \param p Pointer to the start of the extension value
- * (the content of the OCTET STRING).
- * \param end End of extension value.
- *
- * \note The callback must fail and return a negative error code
- * if it can not parse or does not support the extension.
- * When the callback fails to parse a critical extension
- * mbedtls_x509_crt_parse_der_with_ext_cb() also fails.
- * When the callback fails to parse a non critical extension
- * mbedtls_x509_crt_parse_der_with_ext_cb() simply skips
- * the extension and continues parsing.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- typedef int (*mbedtls_x509_crt_ext_cb_t)( void *p_ctx,
- mbedtls_x509_crt const *crt,
- mbedtls_x509_buf const *oid,
- int critical,
- const unsigned char *p,
- const unsigned char *end );
- /**
- * \brief Parse a single DER formatted certificate and add it
- * to the end of the provided chained list.
- *
- * \param chain The pointer to the start of the CRT chain to attach to.
- * When parsing the first CRT in a chain, this should point
- * to an instance of ::mbedtls_x509_crt initialized through
- * mbedtls_x509_crt_init().
- * \param buf The buffer holding the DER encoded certificate.
- * \param buflen The size in Bytes of \p buf.
- * \param make_copy When not zero this function makes an internal copy of the
- * CRT buffer \p buf. In particular, \p buf may be destroyed
- * or reused after this call returns.
- * When zero this function avoids duplicating the CRT buffer
- * by taking temporary ownership thereof until the CRT
- * is destroyed (like mbedtls_x509_crt_parse_der_nocopy())
- * \param cb A callback invoked for every unsupported certificate
- * extension.
- * \param p_ctx An opaque context passed to the callback.
- *
- * \note This call is functionally equivalent to
- * mbedtls_x509_crt_parse_der(), and/or
- * mbedtls_x509_crt_parse_der_nocopy()
- * but it calls the callback with every unsupported
- * certificate extension and additionally the
- * "certificate policies" extension if it contains any
- * unsupported certificate policies.
- * The callback must return a negative error code if it
- * does not know how to handle such an extension.
- * When the callback fails to parse a critical extension
- * mbedtls_x509_crt_parse_der_with_ext_cb() also fails.
- * When the callback fails to parse a non critical extension
- * mbedtls_x509_crt_parse_der_with_ext_cb() simply skips
- * the extension and continues parsing.
- * Future versions of the library may invoke the callback
- * in other cases, if and when the need arises.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_x509_crt_parse_der_with_ext_cb( mbedtls_x509_crt *chain,
- const unsigned char *buf,
- size_t buflen,
- int make_copy,
- mbedtls_x509_crt_ext_cb_t cb,
- void *p_ctx );
- /**
- * \brief Parse a single DER formatted certificate and add it
- * to the end of the provided chained list. This is a
- * variant of mbedtls_x509_crt_parse_der() which takes
- * temporary ownership of the CRT buffer until the CRT
- * is destroyed.
- *
- * \param chain The pointer to the start of the CRT chain to attach to.
- * When parsing the first CRT in a chain, this should point
- * to an instance of ::mbedtls_x509_crt initialized through
- * mbedtls_x509_crt_init().
- * \param buf The address of the readable buffer holding the DER encoded
- * certificate to use. On success, this buffer must be
- * retained and not be changed for the liftetime of the
- * CRT chain \p chain, that is, until \p chain is destroyed
- * through a call to mbedtls_x509_crt_free().
- * \param buflen The size in Bytes of \p buf.
- *
- * \note This call is functionally equivalent to
- * mbedtls_x509_crt_parse_der(), but it avoids creating a
- * copy of the input buffer at the cost of stronger lifetime
- * constraints. This is useful in constrained environments
- * where duplication of the CRT cannot be tolerated.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_x509_crt_parse_der_nocopy( mbedtls_x509_crt *chain,
- const unsigned char *buf,
- size_t buflen );
- /**
- * \brief Parse one DER-encoded or one or more concatenated PEM-encoded
- * certificates and add them to the chained list.
- *
- * For CRTs in PEM encoding, the function parses permissively:
- * if at least one certificate can be parsed, the function
- * returns the number of certificates for which parsing failed
- * (hence \c 0 if all certificates were parsed successfully).
- * If no certificate could be parsed, the function returns
- * the first (negative) error encountered during parsing.
- *
- * PEM encoded certificates may be interleaved by other data
- * such as human readable descriptions of their content, as
- * long as the certificates are enclosed in the PEM specific
- * '-----{BEGIN/END} CERTIFICATE-----' delimiters.
- *
- * \param chain The chain to which to add the parsed certificates.
- * \param buf The buffer holding the certificate data in PEM or DER format.
- * For certificates in PEM encoding, this may be a concatenation
- * of multiple certificates; for DER encoding, the buffer must
- * comprise exactly one certificate.
- * \param buflen The size of \p buf, including the terminating \c NULL byte
- * in case of PEM encoded data.
- *
- * \return \c 0 if all certificates were parsed successfully.
- * \return The (positive) number of certificates that couldn't
- * be parsed if parsing was partly successful (see above).
- * \return A negative X509 or PEM error code otherwise.
- *
- */
- int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen );
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief Load one or more certificates and add them
- * to the chained list. Parses permissively. If some
- * certificates can be parsed, the result is the number
- * of failed certificates it encountered. If none complete
- * correctly, the first error is returned.
- *
- * \param chain points to the start of the chain
- * \param path filename to read the certificates from
- *
- * \return 0 if all certificates parsed successfully, a positive number
- * if partly successful or a specific X509 or PEM error code
- */
- int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path );
- /**
- * \brief Load one or more certificate files from a path and add them
- * to the chained list. Parses permissively. If some
- * certificates can be parsed, the result is the number
- * of failed certificates it encountered. If none complete
- * correctly, the first error is returned.
- *
- * \param chain points to the start of the chain
- * \param path directory / folder to read the certificate files from
- *
- * \return 0 if all certificates parsed successfully, a positive number
- * if partly successful or a specific X509 or PEM error code
- */
- int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path );
- #endif /* MBEDTLS_FS_IO */
- /**
- * \brief This function parses an item in the SubjectAlternativeNames
- * extension.
- *
- * \param san_buf The buffer holding the raw data item of the subject
- * alternative name.
- * \param san The target structure to populate with the parsed presentation
- * of the subject alternative name encoded in \p san_raw.
- *
- * \note Only "dnsName" and "otherName" of type hardware_module_name
- * as defined in RFC 4180 is supported.
- *
- * \note This function should be called on a single raw data of
- * subject alternative name. For example, after successful
- * certificate parsing, one must iterate on every item in the
- * \p crt->subject_alt_names sequence, and pass it to
- * this function.
- *
- * \warning The target structure contains pointers to the raw data of the
- * parsed certificate, and its lifetime is restricted by the
- * lifetime of the certificate.
- *
- * \return \c 0 on success
- * \return #MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE for an unsupported
- * SAN type.
- * \return Another negative value for any other failure.
- */
- int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf,
- mbedtls_x509_subject_alternative_name *san );
- /**
- * \brief Returns an informational string about the
- * certificate.
- *
- * \param buf Buffer to write to
- * \param size Maximum size of buffer
- * \param prefix A line prefix
- * \param crt The X509 certificate to represent
- *
- * \return The length of the string written (not including the
- * terminated nul byte), or a negative error code.
- */
- int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
- const mbedtls_x509_crt *crt );
- /**
- * \brief Returns an informational string about the
- * verification status of a certificate.
- *
- * \param buf Buffer to write to
- * \param size Maximum size of buffer
- * \param prefix A line prefix
- * \param flags Verification flags created by mbedtls_x509_crt_verify()
- *
- * \return The length of the string written (not including the
- * terminated nul byte), or a negative error code.
- */
- int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
- uint32_t flags );
- /**
- * \brief Verify a chain of certificates.
- *
- * The verify callback is a user-supplied callback that
- * can clear / modify / add flags for a certificate. If set,
- * the verification callback is called for each
- * certificate in the chain (from the trust-ca down to the
- * presented crt). The parameters for the callback are:
- * (void *parameter, mbedtls_x509_crt *crt, int certificate_depth,
- * int *flags). With the flags representing current flags for
- * that specific certificate and the certificate depth from
- * the bottom (Peer cert depth = 0).
- *
- * All flags left after returning from the callback
- * are also returned to the application. The function should
- * return 0 for anything (including invalid certificates)
- * other than fatal error, as a non-zero return code
- * immediately aborts the verification process. For fatal
- * errors, a specific error code should be used (different
- * from MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not
- * be returned at this point), or MBEDTLS_ERR_X509_FATAL_ERROR
- * can be used if no better code is available.
- *
- * \note In case verification failed, the results can be displayed
- * using \c mbedtls_x509_crt_verify_info()
- *
- * \note Same as \c mbedtls_x509_crt_verify_with_profile() with the
- * default security profile.
- *
- * \note It is your responsibility to provide up-to-date CRLs for
- * all trusted CAs. If no CRL is provided for the CA that was
- * used to sign the certificate, CRL verification is skipped
- * silently, that is *without* setting any flag.
- *
- * \note The \c trust_ca list can contain two types of certificates:
- * (1) those of trusted root CAs, so that certificates
- * chaining up to those CAs will be trusted, and (2)
- * self-signed end-entity certificates to be trusted (for
- * specific peers you know) - in that case, the self-signed
- * certificate doesn't need to have the CA bit set.
- *
- * \param crt The certificate chain to be verified.
- * \param trust_ca The list of trusted CAs.
- * \param ca_crl The list of CRLs for trusted CAs.
- * \param cn The expected Common Name. This will be checked to be
- * present in the certificate's subjectAltNames extension or,
- * if this extension is absent, as a CN component in its
- * Subject name. Currently only DNS names are supported. This
- * may be \c NULL if the CN need not be verified.
- * \param flags The address at which to store the result of the verification.
- * If the verification couldn't be completed, the flag value is
- * set to (uint32_t) -1.
- * \param f_vrfy The verification callback to use. See the documentation
- * of mbedtls_x509_crt_verify() for more information.
- * \param p_vrfy The context to be passed to \p f_vrfy.
- *
- * \return \c 0 if the chain is valid with respect to the
- * passed CN, CAs, CRLs and security profile.
- * \return #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the
- * certificate chain verification failed. In this case,
- * \c *flags will have one or more
- * \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX
- * flags set.
- * \return Another negative error code in case of a fatal error
- * encountered during the verification process.
- */
- int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt,
- mbedtls_x509_crt *trust_ca,
- mbedtls_x509_crl *ca_crl,
- const char *cn, uint32_t *flags,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy );
- /**
- * \brief Verify a chain of certificates with respect to
- * a configurable security profile.
- *
- * \note Same as \c mbedtls_x509_crt_verify(), but with explicit
- * security profile.
- *
- * \note The restrictions on keys (RSA minimum size, allowed curves
- * for ECDSA) apply to all certificates: trusted root,
- * intermediate CAs if any, and end entity certificate.
- *
- * \param crt The certificate chain to be verified.
- * \param trust_ca The list of trusted CAs.
- * \param ca_crl The list of CRLs for trusted CAs.
- * \param profile The security profile to use for the verification.
- * \param cn The expected Common Name. This may be \c NULL if the
- * CN need not be verified.
- * \param flags The address at which to store the result of the verification.
- * If the verification couldn't be completed, the flag value is
- * set to (uint32_t) -1.
- * \param f_vrfy The verification callback to use. See the documentation
- * of mbedtls_x509_crt_verify() for more information.
- * \param p_vrfy The context to be passed to \p f_vrfy.
- *
- * \return \c 0 if the chain is valid with respect to the
- * passed CN, CAs, CRLs and security profile.
- * \return #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the
- * certificate chain verification failed. In this case,
- * \c *flags will have one or more
- * \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX
- * flags set.
- * \return Another negative error code in case of a fatal error
- * encountered during the verification process.
- */
- int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt,
- mbedtls_x509_crt *trust_ca,
- mbedtls_x509_crl *ca_crl,
- const mbedtls_x509_crt_profile *profile,
- const char *cn, uint32_t *flags,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy );
- /**
- * \brief Restartable version of \c mbedtls_crt_verify_with_profile()
- *
- * \note Performs the same job as \c mbedtls_crt_verify_with_profile()
- * but can return early and restart according to the limit
- * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
- *
- * \param crt The certificate chain to be verified.
- * \param trust_ca The list of trusted CAs.
- * \param ca_crl The list of CRLs for trusted CAs.
- * \param profile The security profile to use for the verification.
- * \param cn The expected Common Name. This may be \c NULL if the
- * CN need not be verified.
- * \param flags The address at which to store the result of the verification.
- * If the verification couldn't be completed, the flag value is
- * set to (uint32_t) -1.
- * \param f_vrfy The verification callback to use. See the documentation
- * of mbedtls_x509_crt_verify() for more information.
- * \param p_vrfy The context to be passed to \p f_vrfy.
- * \param rs_ctx The restart context to use. This may be set to \c NULL
- * to disable restartable ECC.
- *
- * \return See \c mbedtls_crt_verify_with_profile(), or
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- */
- int mbedtls_x509_crt_verify_restartable( mbedtls_x509_crt *crt,
- mbedtls_x509_crt *trust_ca,
- mbedtls_x509_crl *ca_crl,
- const mbedtls_x509_crt_profile *profile,
- const char *cn, uint32_t *flags,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy,
- mbedtls_x509_crt_restart_ctx *rs_ctx );
- /**
- * \brief The type of trusted certificate callbacks.
- *
- * Callbacks of this type are passed to and used by the CRT
- * verification routine mbedtls_x509_crt_verify_with_ca_cb()
- * when looking for trusted signers of a given certificate.
- *
- * On success, the callback returns a list of trusted
- * certificates to be considered as potential signers
- * for the input certificate.
- *
- * \param p_ctx An opaque context passed to the callback.
- * \param child The certificate for which to search a potential signer.
- * This will point to a readable certificate.
- * \param candidate_cas The address at which to store the address of the first
- * entry in the generated linked list of candidate signers.
- * This will not be \c NULL.
- *
- * \note The callback must only return a non-zero value on a
- * fatal error. If, in contrast, the search for a potential
- * signer completes without a single candidate, the
- * callback must return \c 0 and set \c *candidate_cas
- * to \c NULL.
- *
- * \return \c 0 on success. In this case, \c *candidate_cas points
- * to a heap-allocated linked list of instances of
- * ::mbedtls_x509_crt, and ownership of this list is passed
- * to the caller.
- * \return A negative error code on failure.
- */
- typedef int (*mbedtls_x509_crt_ca_cb_t)( void *p_ctx,
- mbedtls_x509_crt const *child,
- mbedtls_x509_crt **candidate_cas );
- #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
- /**
- * \brief Version of \c mbedtls_x509_crt_verify_with_profile() which
- * uses a callback to acquire the list of trusted CA
- * certificates.
- *
- * \param crt The certificate chain to be verified.
- * \param f_ca_cb The callback to be used to query for potential signers
- * of a given child certificate. See the documentation of
- * ::mbedtls_x509_crt_ca_cb_t for more information.
- * \param p_ca_cb The opaque context to be passed to \p f_ca_cb.
- * \param profile The security profile for the verification.
- * \param cn The expected Common Name. This may be \c NULL if the
- * CN need not be verified.
- * \param flags The address at which to store the result of the verification.
- * If the verification couldn't be completed, the flag value is
- * set to (uint32_t) -1.
- * \param f_vrfy The verification callback to use. See the documentation
- * of mbedtls_x509_crt_verify() for more information.
- * \param p_vrfy The context to be passed to \p f_vrfy.
- *
- * \return See \c mbedtls_crt_verify_with_profile().
- */
- int mbedtls_x509_crt_verify_with_ca_cb( mbedtls_x509_crt *crt,
- mbedtls_x509_crt_ca_cb_t f_ca_cb,
- void *p_ca_cb,
- const mbedtls_x509_crt_profile *profile,
- const char *cn, uint32_t *flags,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy );
- #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
- #if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
- /**
- * \brief Check usage of certificate against keyUsage extension.
- *
- * \param crt Leaf certificate used.
- * \param usage Intended usage(s) (eg MBEDTLS_X509_KU_KEY_ENCIPHERMENT
- * before using the certificate to perform an RSA key
- * exchange).
- *
- * \note Except for decipherOnly and encipherOnly, a bit set in the
- * usage argument means this bit MUST be set in the
- * certificate. For decipherOnly and encipherOnly, it means
- * that bit MAY be set.
- *
- * \return 0 is these uses of the certificate are allowed,
- * MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
- * is present but does not match the usage argument.
- *
- * \note You should only call this function on leaf certificates, on
- * (intermediate) CAs the keyUsage extension is automatically
- * checked by \c mbedtls_x509_crt_verify().
- */
- int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
- unsigned int usage );
- #endif /* MBEDTLS_X509_CHECK_KEY_USAGE) */
- #if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
- /**
- * \brief Check usage of certificate against extendedKeyUsage.
- *
- * \param crt Leaf certificate used.
- * \param usage_oid Intended usage (eg MBEDTLS_OID_SERVER_AUTH or
- * MBEDTLS_OID_CLIENT_AUTH).
- * \param usage_len Length of usage_oid (eg given by MBEDTLS_OID_SIZE()).
- *
- * \return 0 if this use of the certificate is allowed,
- * MBEDTLS_ERR_X509_BAD_INPUT_DATA if not.
- *
- * \note Usually only makes sense on leaf certificates.
- */
- int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
- const char *usage_oid,
- size_t usage_len );
- #endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
- #if defined(MBEDTLS_X509_CRL_PARSE_C)
- /**
- * \brief Verify the certificate revocation status
- *
- * \param crt a certificate to be verified
- * \param crl the CRL to verify against
- *
- * \return 1 if the certificate is revoked, 0 otherwise
- *
- */
- int mbedtls_x509_crt_is_revoked( const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl );
- #endif /* MBEDTLS_X509_CRL_PARSE_C */
- /**
- * \brief Initialize a certificate (chain)
- *
- * \param crt Certificate chain to initialize
- */
- void mbedtls_x509_crt_init( mbedtls_x509_crt *crt );
- /**
- * \brief Unallocate all certificate data
- *
- * \param crt Certificate chain to free
- */
- void mbedtls_x509_crt_free( mbedtls_x509_crt *crt );
- #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief Initialize a restart context
- */
- void mbedtls_x509_crt_restart_init( mbedtls_x509_crt_restart_ctx *ctx );
- /**
- * \brief Free the components of a restart context
- */
- void mbedtls_x509_crt_restart_free( mbedtls_x509_crt_restart_ctx *ctx );
- #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- /* \} name */
- /* \} addtogroup x509_module */
- #if defined(MBEDTLS_X509_CRT_WRITE_C)
- /**
- * \brief Initialize a CRT writing context
- *
- * \param ctx CRT context to initialize
- */
- void mbedtls_x509write_crt_init( mbedtls_x509write_cert *ctx );
- /**
- * \brief Set the verion for a Certificate
- * Default: MBEDTLS_X509_CRT_VERSION_3
- *
- * \param ctx CRT context to use
- * \param version version to set (MBEDTLS_X509_CRT_VERSION_1, MBEDTLS_X509_CRT_VERSION_2 or
- * MBEDTLS_X509_CRT_VERSION_3)
- */
- void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx, int version );
- /**
- * \brief Set the serial number for a Certificate.
- *
- * \param ctx CRT context to use
- * \param serial serial number to set
- *
- * \return 0 if successful
- */
- int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial );
- /**
- * \brief Set the validity period for a Certificate
- * Timestamps should be in string format for UTC timezone
- * i.e. "YYYYMMDDhhmmss"
- * e.g. "20131231235959" for December 31st 2013
- * at 23:59:59
- *
- * \param ctx CRT context to use
- * \param not_before not_before timestamp
- * \param not_after not_after timestamp
- *
- * \return 0 if timestamp was parsed successfully, or
- * a specific error code
- */
- int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, const char *not_before,
- const char *not_after );
- /**
- * \brief Set the issuer name for a Certificate
- * Issuer names should contain a comma-separated list
- * of OID types and values:
- * e.g. "C=UK,O=ARM,CN=mbed TLS CA"
- *
- * \param ctx CRT context to use
- * \param issuer_name issuer name to set
- *
- * \return 0 if issuer name was parsed successfully, or
- * a specific error code
- */
- int mbedtls_x509write_crt_set_issuer_name( mbedtls_x509write_cert *ctx,
- const char *issuer_name );
- /**
- * \brief Set the subject name for a Certificate
- * Subject names should contain a comma-separated list
- * of OID types and values:
- * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
- *
- * \param ctx CRT context to use
- * \param subject_name subject name to set
- *
- * \return 0 if subject name was parsed successfully, or
- * a specific error code
- */
- int mbedtls_x509write_crt_set_subject_name( mbedtls_x509write_cert *ctx,
- const char *subject_name );
- /**
- * \brief Set the subject public key for the certificate
- *
- * \param ctx CRT context to use
- * \param key public key to include
- */
- void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
- /**
- * \brief Set the issuer key used for signing the certificate
- *
- * \param ctx CRT context to use
- * \param key private key to sign with
- */
- void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
- /**
- * \brief Set the MD algorithm to use for the signature
- * (e.g. MBEDTLS_MD_SHA1)
- *
- * \param ctx CRT context to use
- * \param md_alg MD algorithm to use
- */
- void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg );
- /**
- * \brief Generic function to add to or replace an extension in the
- * CRT
- *
- * \param ctx CRT context to use
- * \param oid OID of the extension
- * \param oid_len length of the OID
- * \param critical if the extension is critical (per the RFC's definition)
- * \param val value of the extension OCTET STRING
- * \param val_len length of the value data
- *
- * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx,
- const char *oid, size_t oid_len,
- int critical,
- const unsigned char *val, size_t val_len );
- /**
- * \brief Set the basicConstraints extension for a CRT
- *
- * \param ctx CRT context to use
- * \param is_ca is this a CA certificate
- * \param max_pathlen maximum length of certificate chains below this
- * certificate (only for CA certificates, -1 is
- * inlimited)
- *
- * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
- int is_ca, int max_pathlen );
- #if defined(MBEDTLS_SHA1_C)
- /**
- * \brief Set the subjectKeyIdentifier extension for a CRT
- * Requires that mbedtls_x509write_crt_set_subject_key() has been
- * called before
- *
- * \param ctx CRT context to use
- *
- * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx );
- /**
- * \brief Set the authorityKeyIdentifier extension for a CRT
- * Requires that mbedtls_x509write_crt_set_issuer_key() has been
- * called before
- *
- * \param ctx CRT context to use
- *
- * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *ctx );
- #endif /* MBEDTLS_SHA1_C */
- /**
- * \brief Set the Key Usage Extension flags
- * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
- *
- * \param ctx CRT context to use
- * \param key_usage key usage flags to set
- *
- * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
- unsigned int key_usage );
- /**
- * \brief Set the Netscape Cert Type flags
- * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
- *
- * \param ctx CRT context to use
- * \param ns_cert_type Netscape Cert Type flags to set
- *
- * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx,
- unsigned char ns_cert_type );
- /**
- * \brief Free the contents of a CRT write context
- *
- * \param ctx CRT context to free
- */
- void mbedtls_x509write_crt_free( mbedtls_x509write_cert *ctx );
- /**
- * \brief Write a built up certificate to a X509 DER structure
- * Note: data is written at the end of the buffer! Use the
- * return value to determine where you should start
- * using the buffer
- *
- * \param ctx certificate to write away
- * \param buf buffer to write to
- * \param size size of the buffer
- * \param f_rng RNG function (for signature, see note)
- * \param p_rng RNG parameter
- *
- * \return length of data written if successful, or a specific
- * error code
- *
- * \note f_rng may be NULL if RSA is used for signature and the
- * signature is made offline (otherwise f_rng is desirable
- * for countermeasures against timing attacks).
- * ECDSA signatures always require a non-NULL f_rng.
- */
- int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #if defined(MBEDTLS_PEM_WRITE_C)
- /**
- * \brief Write a built up certificate to a X509 PEM string
- *
- * \param ctx certificate to write away
- * \param buf buffer to write to
- * \param size size of the buffer
- * \param f_rng RNG function (for signature, see note)
- * \param p_rng RNG parameter
- *
- * \return 0 if successful, or a specific error code
- *
- * \note f_rng may be NULL if RSA is used for signature and the
- * signature is made offline (otherwise f_rng is desirable
- * for countermeasures against timing attacks).
- * ECDSA signatures always require a non-NULL f_rng.
- */
- int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #endif /* MBEDTLS_PEM_WRITE_C */
- #endif /* MBEDTLS_X509_CRT_WRITE_C */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_x509_crt.h */
- /********* Start of file include/mbedtls/x509_csr.h ************/
- /**
- * \file x509_csr.h
- *
- * \brief X.509 certificate signing request parsing and writing
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_X509_CSR_H
- #define MBEDTLS_X509_CSR_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \addtogroup x509_module
- * \{ */
- /**
- * \name Structures and functions for X.509 Certificate Signing Requests (CSR)
- * \{
- */
- /**
- * Certificate Signing Request (CSR) structure.
- */
- typedef struct mbedtls_x509_csr
- {
- mbedtls_x509_buf raw; /**< The raw CSR data (DER). */
- mbedtls_x509_buf cri; /**< The raw CertificateRequestInfo body (DER). */
- int version; /**< CSR version (1=v1). */
- mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). */
- mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
- mbedtls_pk_context pk; /**< Container for the public key context. */
- mbedtls_x509_buf sig_oid;
- mbedtls_x509_buf sig;
- mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
- mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
- void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
- }
- mbedtls_x509_csr;
- /**
- * Container for writing a CSR
- */
- typedef struct mbedtls_x509write_csr
- {
- mbedtls_pk_context *key;
- mbedtls_asn1_named_data *subject;
- mbedtls_md_type_t md_alg;
- mbedtls_asn1_named_data *extensions;
- }
- mbedtls_x509write_csr;
- #if defined(MBEDTLS_X509_CSR_PARSE_C)
- /**
- * \brief Load a Certificate Signing Request (CSR) in DER format
- *
- * \note CSR attributes (if any) are currently silently ignored.
- *
- * \param csr CSR context to fill
- * \param buf buffer holding the CRL data
- * \param buflen size of the buffer
- *
- * \return 0 if successful, or a specific X509 error code
- */
- int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
- const unsigned char *buf, size_t buflen );
- /**
- * \brief Load a Certificate Signing Request (CSR), DER or PEM format
- *
- * \note See notes for \c mbedtls_x509_csr_parse_der()
- *
- * \param csr CSR context to fill
- * \param buf buffer holding the CRL data
- * \param buflen size of the buffer
- * (including the terminating null byte for PEM data)
- *
- * \return 0 if successful, or a specific X509 or PEM error code
- */
- int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen );
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief Load a Certificate Signing Request (CSR)
- *
- * \note See notes for \c mbedtls_x509_csr_parse()
- *
- * \param csr CSR context to fill
- * \param path filename to read the CSR from
- *
- * \return 0 if successful, or a specific X509 or PEM error code
- */
- int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path );
- #endif /* MBEDTLS_FS_IO */
- /**
- * \brief Returns an informational string about the
- * CSR.
- *
- * \param buf Buffer to write to
- * \param size Maximum size of buffer
- * \param prefix A line prefix
- * \param csr The X509 CSR to represent
- *
- * \return The length of the string written (not including the
- * terminated nul byte), or a negative error code.
- */
- int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
- const mbedtls_x509_csr *csr );
- /**
- * \brief Initialize a CSR
- *
- * \param csr CSR to initialize
- */
- void mbedtls_x509_csr_init( mbedtls_x509_csr *csr );
- /**
- * \brief Unallocate all CSR data
- *
- * \param csr CSR to free
- */
- void mbedtls_x509_csr_free( mbedtls_x509_csr *csr );
- #endif /* MBEDTLS_X509_CSR_PARSE_C */
- /* \} name */
- /* \} addtogroup x509_module */
- #if defined(MBEDTLS_X509_CSR_WRITE_C)
- /**
- * \brief Initialize a CSR context
- *
- * \param ctx CSR context to initialize
- */
- void mbedtls_x509write_csr_init( mbedtls_x509write_csr *ctx );
- /**
- * \brief Set the subject name for a CSR
- * Subject names should contain a comma-separated list
- * of OID types and values:
- * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
- *
- * \param ctx CSR context to use
- * \param subject_name subject name to set
- *
- * \return 0 if subject name was parsed successfully, or
- * a specific error code
- */
- int mbedtls_x509write_csr_set_subject_name( mbedtls_x509write_csr *ctx,
- const char *subject_name );
- /**
- * \brief Set the key for a CSR (public key will be included,
- * private key used to sign the CSR when writing it)
- *
- * \param ctx CSR context to use
- * \param key Asymetric key to include
- */
- void mbedtls_x509write_csr_set_key( mbedtls_x509write_csr *ctx, mbedtls_pk_context *key );
- /**
- * \brief Set the MD algorithm to use for the signature
- * (e.g. MBEDTLS_MD_SHA1)
- *
- * \param ctx CSR context to use
- * \param md_alg MD algorithm to use
- */
- void mbedtls_x509write_csr_set_md_alg( mbedtls_x509write_csr *ctx, mbedtls_md_type_t md_alg );
- /**
- * \brief Set the Key Usage Extension flags
- * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
- *
- * \param ctx CSR context to use
- * \param key_usage key usage flags to set
- *
- * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
- *
- * \note The <code>decipherOnly</code> flag from the Key Usage
- * extension is represented by bit 8 (i.e.
- * <code>0x8000</code>), which cannot typically be represented
- * in an unsigned char. Therefore, the flag
- * <code>decipherOnly</code> (i.e.
- * #MBEDTLS_X509_KU_DECIPHER_ONLY) cannot be set using this
- * function.
- */
- int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage );
- /**
- * \brief Set the Netscape Cert Type flags
- * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
- *
- * \param ctx CSR context to use
- * \param ns_cert_type Netscape Cert Type flags to set
- *
- * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx,
- unsigned char ns_cert_type );
- /**
- * \brief Generic function to add to or replace an extension in the
- * CSR
- *
- * \param ctx CSR context to use
- * \param oid OID of the extension
- * \param oid_len length of the OID
- * \param val value of the extension OCTET STRING
- * \param val_len length of the value data
- *
- * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
- */
- int mbedtls_x509write_csr_set_extension( mbedtls_x509write_csr *ctx,
- const char *oid, size_t oid_len,
- const unsigned char *val, size_t val_len );
- /**
- * \brief Free the contents of a CSR context
- *
- * \param ctx CSR context to free
- */
- void mbedtls_x509write_csr_free( mbedtls_x509write_csr *ctx );
- /**
- * \brief Write a CSR (Certificate Signing Request) to a
- * DER structure
- * Note: data is written at the end of the buffer! Use the
- * return value to determine where you should start
- * using the buffer
- *
- * \param ctx CSR to write away
- * \param buf buffer to write to
- * \param size size of the buffer
- * \param f_rng RNG function (for signature, see note)
- * \param p_rng RNG parameter
- *
- * \return length of data written if successful, or a specific
- * error code
- *
- * \note f_rng may be NULL if RSA is used for signature and the
- * signature is made offline (otherwise f_rng is desirable
- * for countermeasures against timing attacks).
- * ECDSA signatures always require a non-NULL f_rng.
- */
- int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #if defined(MBEDTLS_PEM_WRITE_C)
- /**
- * \brief Write a CSR (Certificate Signing Request) to a
- * PEM string
- *
- * \param ctx CSR to write away
- * \param buf buffer to write to
- * \param size size of the buffer
- * \param f_rng RNG function (for signature, see note)
- * \param p_rng RNG parameter
- *
- * \return 0 if successful, or a specific error code
- *
- * \note f_rng may be NULL if RSA is used for signature and the
- * signature is made offline (otherwise f_rng is desirable
- * for countermeasures against timing attacks).
- * ECDSA signatures always require a non-NULL f_rng.
- */
- int mbedtls_x509write_csr_pem( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #endif /* MBEDTLS_PEM_WRITE_C */
- #endif /* MBEDTLS_X509_CSR_WRITE_C */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_x509_csr.h */
- /********* Start of file include/mbedtls/cipher.h ************/
- /**
- * \file cipher.h
- *
- * \brief This file contains an abstraction interface for use with the cipher
- * primitives provided by the library. It provides a common interface to all of
- * the available cipher operations.
- *
- * \author Adriaan de Jong <dejong@fox-it.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CIPHER_H
- #define MBEDTLS_CIPHER_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- #define MBEDTLS_CIPHER_MODE_AEAD
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- #define MBEDTLS_CIPHER_MODE_WITH_PADDING
- #endif
- #if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER) || \
- defined(MBEDTLS_CHACHA20_C)
- #define MBEDTLS_CIPHER_MODE_STREAM
- #endif
- #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
- #define inline __inline
- #endif
- /** The selected feature is not available. */
- #define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080
- /** Bad input parameters. */
- #define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100
- /** Failed to allocate memory. */
- #define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180
- /** Input data contains invalid padding and is rejected. */
- #define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200
- /** Decryption of block requires a full block. */
- #define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280
- /** Authentication failed (for AEAD modes). */
- #define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300
- /** The context is invalid. For example, because it was freed. */
- #define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380
- /* MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** Cipher hardware accelerator failed. */
- #define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400
- #define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 /**< Cipher accepts IVs of variable length. */
- #define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 /**< Cipher accepts keys of variable length. */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Supported cipher types.
- *
- * \warning RC4 and DES are considered weak ciphers and their use
- * constitutes a security risk. Arm recommends considering stronger
- * ciphers instead.
- */
- typedef enum {
- MBEDTLS_CIPHER_ID_NONE = 0, /**< Placeholder to mark the end of cipher ID lists. */
- MBEDTLS_CIPHER_ID_NULL, /**< The identity cipher, treated as a stream cipher. */
- MBEDTLS_CIPHER_ID_AES, /**< The AES cipher. */
- MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. */
- MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. */
- MBEDTLS_CIPHER_ID_CAMELLIA, /**< The Camellia cipher. */
- MBEDTLS_CIPHER_ID_BLOWFISH, /**< The Blowfish cipher. */
- MBEDTLS_CIPHER_ID_ARC4, /**< The RC4 cipher. */
- MBEDTLS_CIPHER_ID_ARIA, /**< The Aria cipher. */
- MBEDTLS_CIPHER_ID_CHACHA20, /**< The ChaCha20 cipher. */
- } mbedtls_cipher_id_t;
- /**
- * \brief Supported {cipher type, cipher mode} pairs.
- *
- * \warning RC4 and DES are considered weak ciphers and their use
- * constitutes a security risk. Arm recommends considering stronger
- * ciphers instead.
- */
- typedef enum {
- MBEDTLS_CIPHER_NONE = 0, /**< Placeholder to mark the end of cipher-pair lists. */
- MBEDTLS_CIPHER_NULL, /**< The identity stream cipher. */
- MBEDTLS_CIPHER_AES_128_ECB, /**< AES cipher with 128-bit ECB mode. */
- MBEDTLS_CIPHER_AES_192_ECB, /**< AES cipher with 192-bit ECB mode. */
- MBEDTLS_CIPHER_AES_256_ECB, /**< AES cipher with 256-bit ECB mode. */
- MBEDTLS_CIPHER_AES_128_CBC, /**< AES cipher with 128-bit CBC mode. */
- MBEDTLS_CIPHER_AES_192_CBC, /**< AES cipher with 192-bit CBC mode. */
- MBEDTLS_CIPHER_AES_256_CBC, /**< AES cipher with 256-bit CBC mode. */
- MBEDTLS_CIPHER_AES_128_CFB128, /**< AES cipher with 128-bit CFB128 mode. */
- MBEDTLS_CIPHER_AES_192_CFB128, /**< AES cipher with 192-bit CFB128 mode. */
- MBEDTLS_CIPHER_AES_256_CFB128, /**< AES cipher with 256-bit CFB128 mode. */
- MBEDTLS_CIPHER_AES_128_CTR, /**< AES cipher with 128-bit CTR mode. */
- MBEDTLS_CIPHER_AES_192_CTR, /**< AES cipher with 192-bit CTR mode. */
- MBEDTLS_CIPHER_AES_256_CTR, /**< AES cipher with 256-bit CTR mode. */
- MBEDTLS_CIPHER_AES_128_GCM, /**< AES cipher with 128-bit GCM mode. */
- MBEDTLS_CIPHER_AES_192_GCM, /**< AES cipher with 192-bit GCM mode. */
- MBEDTLS_CIPHER_AES_256_GCM, /**< AES cipher with 256-bit GCM mode. */
- MBEDTLS_CIPHER_CAMELLIA_128_ECB, /**< Camellia cipher with 128-bit ECB mode. */
- MBEDTLS_CIPHER_CAMELLIA_192_ECB, /**< Camellia cipher with 192-bit ECB mode. */
- MBEDTLS_CIPHER_CAMELLIA_256_ECB, /**< Camellia cipher with 256-bit ECB mode. */
- MBEDTLS_CIPHER_CAMELLIA_128_CBC, /**< Camellia cipher with 128-bit CBC mode. */
- MBEDTLS_CIPHER_CAMELLIA_192_CBC, /**< Camellia cipher with 192-bit CBC mode. */
- MBEDTLS_CIPHER_CAMELLIA_256_CBC, /**< Camellia cipher with 256-bit CBC mode. */
- MBEDTLS_CIPHER_CAMELLIA_128_CFB128, /**< Camellia cipher with 128-bit CFB128 mode. */
- MBEDTLS_CIPHER_CAMELLIA_192_CFB128, /**< Camellia cipher with 192-bit CFB128 mode. */
- MBEDTLS_CIPHER_CAMELLIA_256_CFB128, /**< Camellia cipher with 256-bit CFB128 mode. */
- MBEDTLS_CIPHER_CAMELLIA_128_CTR, /**< Camellia cipher with 128-bit CTR mode. */
- MBEDTLS_CIPHER_CAMELLIA_192_CTR, /**< Camellia cipher with 192-bit CTR mode. */
- MBEDTLS_CIPHER_CAMELLIA_256_CTR, /**< Camellia cipher with 256-bit CTR mode. */
- MBEDTLS_CIPHER_CAMELLIA_128_GCM, /**< Camellia cipher with 128-bit GCM mode. */
- MBEDTLS_CIPHER_CAMELLIA_192_GCM, /**< Camellia cipher with 192-bit GCM mode. */
- MBEDTLS_CIPHER_CAMELLIA_256_GCM, /**< Camellia cipher with 256-bit GCM mode. */
- MBEDTLS_CIPHER_DES_ECB, /**< DES cipher with ECB mode. */
- MBEDTLS_CIPHER_DES_CBC, /**< DES cipher with CBC mode. */
- MBEDTLS_CIPHER_DES_EDE_ECB, /**< DES cipher with EDE ECB mode. */
- MBEDTLS_CIPHER_DES_EDE_CBC, /**< DES cipher with EDE CBC mode. */
- MBEDTLS_CIPHER_DES_EDE3_ECB, /**< DES cipher with EDE3 ECB mode. */
- MBEDTLS_CIPHER_DES_EDE3_CBC, /**< DES cipher with EDE3 CBC mode. */
- MBEDTLS_CIPHER_BLOWFISH_ECB, /**< Blowfish cipher with ECB mode. */
- MBEDTLS_CIPHER_BLOWFISH_CBC, /**< Blowfish cipher with CBC mode. */
- MBEDTLS_CIPHER_BLOWFISH_CFB64, /**< Blowfish cipher with CFB64 mode. */
- MBEDTLS_CIPHER_BLOWFISH_CTR, /**< Blowfish cipher with CTR mode. */
- MBEDTLS_CIPHER_ARC4_128, /**< RC4 cipher with 128-bit mode. */
- MBEDTLS_CIPHER_AES_128_CCM, /**< AES cipher with 128-bit CCM mode. */
- MBEDTLS_CIPHER_AES_192_CCM, /**< AES cipher with 192-bit CCM mode. */
- MBEDTLS_CIPHER_AES_256_CCM, /**< AES cipher with 256-bit CCM mode. */
- MBEDTLS_CIPHER_CAMELLIA_128_CCM, /**< Camellia cipher with 128-bit CCM mode. */
- MBEDTLS_CIPHER_CAMELLIA_192_CCM, /**< Camellia cipher with 192-bit CCM mode. */
- MBEDTLS_CIPHER_CAMELLIA_256_CCM, /**< Camellia cipher with 256-bit CCM mode. */
- MBEDTLS_CIPHER_ARIA_128_ECB, /**< Aria cipher with 128-bit key and ECB mode. */
- MBEDTLS_CIPHER_ARIA_192_ECB, /**< Aria cipher with 192-bit key and ECB mode. */
- MBEDTLS_CIPHER_ARIA_256_ECB, /**< Aria cipher with 256-bit key and ECB mode. */
- MBEDTLS_CIPHER_ARIA_128_CBC, /**< Aria cipher with 128-bit key and CBC mode. */
- MBEDTLS_CIPHER_ARIA_192_CBC, /**< Aria cipher with 192-bit key and CBC mode. */
- MBEDTLS_CIPHER_ARIA_256_CBC, /**< Aria cipher with 256-bit key and CBC mode. */
- MBEDTLS_CIPHER_ARIA_128_CFB128, /**< Aria cipher with 128-bit key and CFB-128 mode. */
- MBEDTLS_CIPHER_ARIA_192_CFB128, /**< Aria cipher with 192-bit key and CFB-128 mode. */
- MBEDTLS_CIPHER_ARIA_256_CFB128, /**< Aria cipher with 256-bit key and CFB-128 mode. */
- MBEDTLS_CIPHER_ARIA_128_CTR, /**< Aria cipher with 128-bit key and CTR mode. */
- MBEDTLS_CIPHER_ARIA_192_CTR, /**< Aria cipher with 192-bit key and CTR mode. */
- MBEDTLS_CIPHER_ARIA_256_CTR, /**< Aria cipher with 256-bit key and CTR mode. */
- MBEDTLS_CIPHER_ARIA_128_GCM, /**< Aria cipher with 128-bit key and GCM mode. */
- MBEDTLS_CIPHER_ARIA_192_GCM, /**< Aria cipher with 192-bit key and GCM mode. */
- MBEDTLS_CIPHER_ARIA_256_GCM, /**< Aria cipher with 256-bit key and GCM mode. */
- MBEDTLS_CIPHER_ARIA_128_CCM, /**< Aria cipher with 128-bit key and CCM mode. */
- MBEDTLS_CIPHER_ARIA_192_CCM, /**< Aria cipher with 192-bit key and CCM mode. */
- MBEDTLS_CIPHER_ARIA_256_CCM, /**< Aria cipher with 256-bit key and CCM mode. */
- MBEDTLS_CIPHER_AES_128_OFB, /**< AES 128-bit cipher in OFB mode. */
- MBEDTLS_CIPHER_AES_192_OFB, /**< AES 192-bit cipher in OFB mode. */
- MBEDTLS_CIPHER_AES_256_OFB, /**< AES 256-bit cipher in OFB mode. */
- MBEDTLS_CIPHER_AES_128_XTS, /**< AES 128-bit cipher in XTS block mode. */
- MBEDTLS_CIPHER_AES_256_XTS, /**< AES 256-bit cipher in XTS block mode. */
- MBEDTLS_CIPHER_CHACHA20, /**< ChaCha20 stream cipher. */
- MBEDTLS_CIPHER_CHACHA20_POLY1305, /**< ChaCha20-Poly1305 AEAD cipher. */
- MBEDTLS_CIPHER_AES_128_KW, /**< AES cipher with 128-bit NIST KW mode. */
- MBEDTLS_CIPHER_AES_192_KW, /**< AES cipher with 192-bit NIST KW mode. */
- MBEDTLS_CIPHER_AES_256_KW, /**< AES cipher with 256-bit NIST KW mode. */
- MBEDTLS_CIPHER_AES_128_KWP, /**< AES cipher with 128-bit NIST KWP mode. */
- MBEDTLS_CIPHER_AES_192_KWP, /**< AES cipher with 192-bit NIST KWP mode. */
- MBEDTLS_CIPHER_AES_256_KWP, /**< AES cipher with 256-bit NIST KWP mode. */
- } mbedtls_cipher_type_t;
- /** Supported cipher modes. */
- typedef enum {
- MBEDTLS_MODE_NONE = 0, /**< None. */
- MBEDTLS_MODE_ECB, /**< The ECB cipher mode. */
- MBEDTLS_MODE_CBC, /**< The CBC cipher mode. */
- MBEDTLS_MODE_CFB, /**< The CFB cipher mode. */
- MBEDTLS_MODE_OFB, /**< The OFB cipher mode. */
- MBEDTLS_MODE_CTR, /**< The CTR cipher mode. */
- MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */
- MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */
- MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */
- MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */
- MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */
- MBEDTLS_MODE_KW, /**< The SP800-38F KW mode */
- MBEDTLS_MODE_KWP, /**< The SP800-38F KWP mode */
- } mbedtls_cipher_mode_t;
- /** Supported cipher padding types. */
- typedef enum {
- MBEDTLS_PADDING_PKCS7 = 0, /**< PKCS7 padding (default). */
- MBEDTLS_PADDING_ONE_AND_ZEROS, /**< ISO/IEC 7816-4 padding. */
- MBEDTLS_PADDING_ZEROS_AND_LEN, /**< ANSI X.923 padding. */
- MBEDTLS_PADDING_ZEROS, /**< Zero padding (not reversible). */
- MBEDTLS_PADDING_NONE, /**< Never pad (full blocks only). */
- } mbedtls_cipher_padding_t;
- /** Type of operation. */
- typedef enum {
- MBEDTLS_OPERATION_NONE = -1,
- MBEDTLS_DECRYPT = 0,
- MBEDTLS_ENCRYPT,
- } mbedtls_operation_t;
- enum {
- /** Undefined key length. */
- MBEDTLS_KEY_LENGTH_NONE = 0,
- /** Key length, in bits (including parity), for DES keys. */
- MBEDTLS_KEY_LENGTH_DES = 64,
- /** Key length in bits, including parity, for DES in two-key EDE. */
- MBEDTLS_KEY_LENGTH_DES_EDE = 128,
- /** Key length in bits, including parity, for DES in three-key EDE. */
- MBEDTLS_KEY_LENGTH_DES_EDE3 = 192,
- };
- /** Maximum length of any IV, in Bytes. */
- /* This should ideally be derived automatically from list of ciphers.
- * This should be kept in sync with MBEDTLS_SSL_MAX_IV_LENGTH defined
- * in ssl_internal.h. */
- #define MBEDTLS_MAX_IV_LENGTH 16
- /** Maximum block size of any cipher, in Bytes. */
- /* This should ideally be derived automatically from list of ciphers.
- * This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined
- * in ssl_internal.h. */
- #define MBEDTLS_MAX_BLOCK_LENGTH 16
- /** Maximum key length, in Bytes. */
- /* This should ideally be derived automatically from list of ciphers.
- * For now, only check whether XTS is enabled which uses 64 Byte keys,
- * and use 32 Bytes as an upper bound for the maximum key length otherwise.
- * This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined
- * in ssl_internal.h, which however deliberately ignores the case of XTS
- * since the latter isn't used in SSL/TLS. */
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- #define MBEDTLS_MAX_KEY_LENGTH 64
- #else
- #define MBEDTLS_MAX_KEY_LENGTH 32
- #endif /* MBEDTLS_CIPHER_MODE_XTS */
- /**
- * Base cipher information (opaque struct).
- */
- typedef struct mbedtls_cipher_base_t mbedtls_cipher_base_t;
- /**
- * CMAC context (opaque struct).
- */
- typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t;
- /**
- * Cipher information. Allows calling cipher functions
- * in a generic way.
- */
- typedef struct mbedtls_cipher_info_t
- {
- /** Full cipher identifier. For example,
- * MBEDTLS_CIPHER_AES_256_CBC.
- */
- mbedtls_cipher_type_t type;
- /** The cipher mode. For example, MBEDTLS_MODE_CBC. */
- mbedtls_cipher_mode_t mode;
- /** The cipher key length, in bits. This is the
- * default length for variable sized ciphers.
- * Includes parity bits for ciphers like DES.
- */
- unsigned int key_bitlen;
- /** Name of the cipher. */
- const char * name;
- /** IV or nonce size, in Bytes.
- * For ciphers that accept variable IV sizes,
- * this is the recommended size.
- */
- unsigned int iv_size;
- /** Bitflag comprised of MBEDTLS_CIPHER_VARIABLE_IV_LEN and
- * MBEDTLS_CIPHER_VARIABLE_KEY_LEN indicating whether the
- * cipher supports variable IV or variable key sizes, respectively.
- */
- int flags;
- /** The block size, in Bytes. */
- unsigned int block_size;
- /** Struct for base cipher information and functions. */
- const mbedtls_cipher_base_t *base;
- } mbedtls_cipher_info_t;
- /**
- * Generic cipher context.
- */
- typedef struct mbedtls_cipher_context_t
- {
- /** Information about the associated cipher. */
- const mbedtls_cipher_info_t *cipher_info;
- /** Key length to use. */
- int key_bitlen;
- /** Operation that the key of the context has been
- * initialized for.
- */
- mbedtls_operation_t operation;
- #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
- /** Padding functions to use, if relevant for
- * the specific cipher mode.
- */
- void (*add_padding)( unsigned char *output, size_t olen, size_t data_len );
- int (*get_padding)( unsigned char *input, size_t ilen, size_t *data_len );
- #endif
- /** Buffer for input that has not been processed yet. */
- unsigned char unprocessed_data[MBEDTLS_MAX_BLOCK_LENGTH];
- /** Number of Bytes that have not been processed yet. */
- size_t unprocessed_len;
- /** Current IV or NONCE_COUNTER for CTR-mode, data unit (or sector) number
- * for XTS-mode. */
- unsigned char iv[MBEDTLS_MAX_IV_LENGTH];
- /** IV size in Bytes, for ciphers with variable-length IVs. */
- size_t iv_size;
- /** The cipher-specific context. */
- void *cipher_ctx;
- #if defined(MBEDTLS_CMAC_C)
- /** CMAC-specific context. */
- mbedtls_cmac_context_t *cmac_ctx;
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- /** Indicates whether the cipher operations should be performed
- * by Mbed TLS' own crypto library or an external implementation
- * of the PSA Crypto API.
- * This is unset if the cipher context was established through
- * mbedtls_cipher_setup(), and set if it was established through
- * mbedtls_cipher_setup_psa().
- */
- unsigned char psa_enabled;
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- } mbedtls_cipher_context_t;
- /**
- * \brief This function retrieves the list of ciphers supported
- * by the generic cipher module.
- *
- * For any cipher identifier in the returned list, you can
- * obtain the corresponding generic cipher information structure
- * via mbedtls_cipher_info_from_type(), which can then be used
- * to prepare a cipher context via mbedtls_cipher_setup().
- *
- *
- * \return A statically-allocated array of cipher identifiers
- * of type cipher_type_t. The last entry is zero.
- */
- const int *mbedtls_cipher_list( void );
- /**
- * \brief This function retrieves the cipher-information
- * structure associated with the given cipher name.
- *
- * \param cipher_name Name of the cipher to search for. This must not be
- * \c NULL.
- *
- * \return The cipher information structure associated with the
- * given \p cipher_name.
- * \return \c NULL if the associated cipher information is not found.
- */
- const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name );
- /**
- * \brief This function retrieves the cipher-information
- * structure associated with the given cipher type.
- *
- * \param cipher_type Type of the cipher to search for.
- *
- * \return The cipher information structure associated with the
- * given \p cipher_type.
- * \return \c NULL if the associated cipher information is not found.
- */
- const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type );
- /**
- * \brief This function retrieves the cipher-information
- * structure associated with the given cipher ID,
- * key size and mode.
- *
- * \param cipher_id The ID of the cipher to search for. For example,
- * #MBEDTLS_CIPHER_ID_AES.
- * \param key_bitlen The length of the key in bits.
- * \param mode The cipher mode. For example, #MBEDTLS_MODE_CBC.
- *
- * \return The cipher information structure associated with the
- * given \p cipher_id.
- * \return \c NULL if the associated cipher information is not found.
- */
- const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id,
- int key_bitlen,
- const mbedtls_cipher_mode_t mode );
- /**
- * \brief This function initializes a \p cipher_context as NONE.
- *
- * \param ctx The context to be initialized. This must not be \c NULL.
- */
- void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx );
- /**
- * \brief This function frees and clears the cipher-specific
- * context of \p ctx. Freeing \p ctx itself remains the
- * responsibility of the caller.
- *
- * \param ctx The context to be freed. If this is \c NULL, the
- * function has no effect, otherwise this must point to an
- * initialized context.
- */
- void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
- /**
- * \brief This function initializes a cipher context for
- * use with the given cipher primitive.
- *
- * \param ctx The context to initialize. This must be initialized.
- * \param cipher_info The cipher to use.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
- * cipher-specific context fails.
- *
- * \internal Currently, the function also clears the structure.
- * In future versions, the caller will be required to call
- * mbedtls_cipher_init() on the structure first.
- */
- int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx,
- const mbedtls_cipher_info_t *cipher_info );
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- /**
- * \brief This function initializes a cipher context for
- * PSA-based use with the given cipher primitive.
- *
- * \note See #MBEDTLS_USE_PSA_CRYPTO for information on PSA.
- *
- * \param ctx The context to initialize. May not be \c NULL.
- * \param cipher_info The cipher to use.
- * \param taglen For AEAD ciphers, the length in bytes of the
- * authentication tag to use. Subsequent uses of
- * mbedtls_cipher_auth_encrypt() or
- * mbedtls_cipher_auth_decrypt() must provide
- * the same tag length.
- * For non-AEAD ciphers, the value must be \c 0.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
- * cipher-specific context fails.
- */
- int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx,
- const mbedtls_cipher_info_t *cipher_info,
- size_t taglen );
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- /**
- * \brief This function returns the block size of the given cipher.
- *
- * \param ctx The context of the cipher. This must be initialized.
- *
- * \return The block size of the underlying cipher.
- * \return \c 0 if \p ctx has not been initialized.
- */
- static inline unsigned int mbedtls_cipher_get_block_size(
- const mbedtls_cipher_context_t *ctx )
- {
- MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
- if( ctx->cipher_info == NULL )
- return 0;
- return ctx->cipher_info->block_size;
- }
- /**
- * \brief This function returns the mode of operation for
- * the cipher. For example, MBEDTLS_MODE_CBC.
- *
- * \param ctx The context of the cipher. This must be initialized.
- *
- * \return The mode of operation.
- * \return #MBEDTLS_MODE_NONE if \p ctx has not been initialized.
- */
- static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(
- const mbedtls_cipher_context_t *ctx )
- {
- MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, MBEDTLS_MODE_NONE );
- if( ctx->cipher_info == NULL )
- return MBEDTLS_MODE_NONE;
- return ctx->cipher_info->mode;
- }
- /**
- * \brief This function returns the size of the IV or nonce
- * of the cipher, in Bytes.
- *
- * \param ctx The context of the cipher. This must be initialized.
- *
- * \return The recommended IV size if no IV has been set.
- * \return \c 0 for ciphers not using an IV or a nonce.
- * \return The actual size if an IV has been set.
- */
- static inline int mbedtls_cipher_get_iv_size(
- const mbedtls_cipher_context_t *ctx )
- {
- MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
- if( ctx->cipher_info == NULL )
- return 0;
- if( ctx->iv_size != 0 )
- return (int) ctx->iv_size;
- return (int) ctx->cipher_info->iv_size;
- }
- /**
- * \brief This function returns the type of the given cipher.
- *
- * \param ctx The context of the cipher. This must be initialized.
- *
- * \return The type of the cipher.
- * \return #MBEDTLS_CIPHER_NONE if \p ctx has not been initialized.
- */
- static inline mbedtls_cipher_type_t mbedtls_cipher_get_type(
- const mbedtls_cipher_context_t *ctx )
- {
- MBEDTLS_INTERNAL_VALIDATE_RET(
- ctx != NULL, MBEDTLS_CIPHER_NONE );
- if( ctx->cipher_info == NULL )
- return MBEDTLS_CIPHER_NONE;
- return ctx->cipher_info->type;
- }
- /**
- * \brief This function returns the name of the given cipher
- * as a string.
- *
- * \param ctx The context of the cipher. This must be initialized.
- *
- * \return The name of the cipher.
- * \return NULL if \p ctx has not been not initialized.
- */
- static inline const char *mbedtls_cipher_get_name(
- const mbedtls_cipher_context_t *ctx )
- {
- MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
- if( ctx->cipher_info == NULL )
- return 0;
- return ctx->cipher_info->name;
- }
- /**
- * \brief This function returns the key length of the cipher.
- *
- * \param ctx The context of the cipher. This must be initialized.
- *
- * \return The key length of the cipher in bits.
- * \return #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been
- * initialized.
- */
- static inline int mbedtls_cipher_get_key_bitlen(
- const mbedtls_cipher_context_t *ctx )
- {
- MBEDTLS_INTERNAL_VALIDATE_RET(
- ctx != NULL, MBEDTLS_KEY_LENGTH_NONE );
- if( ctx->cipher_info == NULL )
- return MBEDTLS_KEY_LENGTH_NONE;
- return (int) ctx->cipher_info->key_bitlen;
- }
- /**
- * \brief This function returns the operation of the given cipher.
- *
- * \param ctx The context of the cipher. This must be initialized.
- *
- * \return The type of operation: #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
- * \return #MBEDTLS_OPERATION_NONE if \p ctx has not been initialized.
- */
- static inline mbedtls_operation_t mbedtls_cipher_get_operation(
- const mbedtls_cipher_context_t *ctx )
- {
- MBEDTLS_INTERNAL_VALIDATE_RET(
- ctx != NULL, MBEDTLS_OPERATION_NONE );
- if( ctx->cipher_info == NULL )
- return MBEDTLS_OPERATION_NONE;
- return ctx->operation;
- }
- /**
- * \brief This function sets the key to use with the given context.
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a cipher information structure.
- * \param key The key to use. This must be a readable buffer of at
- * least \p key_bitlen Bits.
- * \param key_bitlen The key length to use, in Bits.
- * \param operation The operation that the key will be used for:
- * #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx,
- const unsigned char *key,
- int key_bitlen,
- const mbedtls_operation_t operation );
- #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
- /**
- * \brief This function sets the padding mode, for cipher modes
- * that use padding.
- *
- * The default passing mode is PKCS7 padding.
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a cipher information structure.
- * \param mode The padding mode.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
- * if the selected padding mode is not supported.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode
- * does not support padding.
- */
- int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx,
- mbedtls_cipher_padding_t mode );
- #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
- /**
- * \brief This function sets the initialization vector (IV)
- * or nonce.
- *
- * \note Some ciphers do not use IVs nor nonce. For these
- * ciphers, this function has no effect.
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a cipher information structure.
- * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. This
- * must be a readable buffer of at least \p iv_len Bytes.
- * \param iv_len The IV length for ciphers with variable-size IV.
- * This parameter is discarded by ciphers with fixed-size IV.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- */
- int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
- const unsigned char *iv,
- size_t iv_len );
- /**
- * \brief This function resets the cipher state.
- *
- * \param ctx The generic cipher context. This must be initialized.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- */
- int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx );
- #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- /**
- * \brief This function adds additional data for AEAD ciphers.
- * Currently supported with GCM and ChaCha20+Poly1305.
- * This must be called exactly once, after
- * mbedtls_cipher_reset().
- *
- * \param ctx The generic cipher context. This must be initialized.
- * \param ad The additional data to use. This must be a readable
- * buffer of at least \p ad_len Bytes.
- * \param ad_len The length of \p ad in Bytes.
- *
- * \return \c 0 on success.
- * \return A specific error code on failure.
- */
- int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
- const unsigned char *ad, size_t ad_len );
- #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
- /**
- * \brief The generic cipher update function. It encrypts or
- * decrypts using the given cipher context. Writes as
- * many block-sized blocks of data as possible to output.
- * Any data that cannot be written immediately is either
- * added to the next block, or flushed when
- * mbedtls_cipher_finish() is called.
- * Exception: For MBEDTLS_MODE_ECB, expects a single block
- * in size. For example, 16 Bytes for AES.
- *
- * \note If the underlying cipher is used in GCM mode, all calls
- * to this function, except for the last one before
- * mbedtls_cipher_finish(), must have \p ilen as a
- * multiple of the block size of the cipher.
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a key.
- * \param input The buffer holding the input data. This must be a
- * readable buffer of at least \p ilen Bytes.
- * \param ilen The length of the input data.
- * \param output The buffer for the output data. This must be able to
- * hold at least `ilen + block_size`. This must not be the
- * same buffer as \p input.
- * \param olen The length of the output data, to be updated with the
- * actual number of Bytes written. This must not be
- * \c NULL.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE on an
- * unsupported mode for a cipher.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx,
- const unsigned char *input,
- size_t ilen, unsigned char *output,
- size_t *olen );
- /**
- * \brief The generic cipher finalization function. If data still
- * needs to be flushed from an incomplete block, the data
- * contained in it is padded to the size of
- * the last block, and written to the \p output buffer.
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a key.
- * \param output The buffer to write data to. This needs to be a writable
- * buffer of at least \p block_size Bytes.
- * \param olen The length of the data written to the \p output buffer.
- * This may not be \c NULL.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
- * expecting a full block but not receiving one.
- * \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
- * while decrypting.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
- unsigned char *output, size_t *olen );
- #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- /**
- * \brief This function writes a tag for AEAD ciphers.
- * Currently supported with GCM and ChaCha20+Poly1305.
- * This must be called after mbedtls_cipher_finish().
- *
- * \param ctx The generic cipher context. This must be initialized,
- * bound to a key, and have just completed a cipher
- * operation through mbedtls_cipher_finish() the tag for
- * which should be written.
- * \param tag The buffer to write the tag to. This must be a writable
- * buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the tag to write.
- *
- * \return \c 0 on success.
- * \return A specific error code on failure.
- */
- int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
- unsigned char *tag, size_t tag_len );
- /**
- * \brief This function checks the tag for AEAD ciphers.
- * Currently supported with GCM and ChaCha20+Poly1305.
- * This must be called after mbedtls_cipher_finish().
- *
- * \param ctx The generic cipher context. This must be initialized.
- * \param tag The buffer holding the tag. This must be a readable
- * buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the tag to check.
- *
- * \return \c 0 on success.
- * \return A specific error code on failure.
- */
- int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
- const unsigned char *tag, size_t tag_len );
- #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
- /**
- * \brief The generic all-in-one encryption/decryption function,
- * for all ciphers except AEAD constructs.
- *
- * \param ctx The generic cipher context. This must be initialized.
- * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
- * This must be a readable buffer of at least \p iv_len
- * Bytes.
- * \param iv_len The IV length for ciphers with variable-size IV.
- * This parameter is discarded by ciphers with fixed-size
- * IV.
- * \param input The buffer holding the input data. This must be a
- * readable buffer of at least \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- * \param output The buffer for the output data. This must be able to
- * hold at least `ilen + block_size`. This must not be the
- * same buffer as \p input.
- * \param olen The length of the output data, to be updated with the
- * actual number of Bytes written. This must not be
- * \c NULL.
- *
- * \note Some ciphers do not use IVs nor nonce. For these
- * ciphers, use \p iv = NULL and \p iv_len = 0.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
- * expecting a full block but not receiving one.
- * \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
- * while decrypting.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen );
- #if defined(MBEDTLS_CIPHER_MODE_AEAD)
- #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif /* MBEDTLS_DEPRECATED_WARNING */
- /**
- * \brief The generic authenticated encryption (AEAD) function.
- *
- * \deprecated Superseded by mbedtls_cipher_auth_encrypt_ext().
- *
- * \note This function only supports AEAD algorithms, not key
- * wrapping algorithms such as NIST_KW; for this, see
- * mbedtls_cipher_auth_encrypt_ext().
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a key associated with an AEAD algorithm.
- * \param iv The nonce to use. This must be a readable buffer of
- * at least \p iv_len Bytes and must not be \c NULL.
- * \param iv_len The length of the nonce. This must satisfy the
- * constraints imposed by the AEAD cipher used.
- * \param ad The additional data to authenticate. This must be a
- * readable buffer of at least \p ad_len Bytes, and may
- * be \c NULL is \p ad_len is \c 0.
- * \param ad_len The length of \p ad.
- * \param input The buffer holding the input data. This must be a
- * readable buffer of at least \p ilen Bytes, and may be
- * \c NULL if \p ilen is \c 0.
- * \param ilen The length of the input data.
- * \param output The buffer for the output data. This must be a
- * writable buffer of at least \p ilen Bytes, and must
- * not be \c NULL.
- * \param olen This will be filled with the actual number of Bytes
- * written to the \p output buffer. This must point to a
- * writable object of type \c size_t.
- * \param tag The buffer for the authentication tag. This must be a
- * writable buffer of at least \p tag_len Bytes. See note
- * below regarding restrictions with PSA-based contexts.
- * \param tag_len The desired length of the authentication tag. This
- * must match the constraints imposed by the AEAD cipher
- * used, and in particular must not be \c 0.
- *
- * \note If the context is based on PSA (that is, it was set up
- * with mbedtls_cipher_setup_psa()), then it is required
- * that \c tag == output + ilen. That is, the tag must be
- * appended to the ciphertext as recommended by RFC 5116.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *ad, size_t ad_len,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen,
- unsigned char *tag, size_t tag_len )
- MBEDTLS_DEPRECATED;
- /**
- * \brief The generic authenticated decryption (AEAD) function.
- *
- * \deprecated Superseded by mbedtls_cipher_auth_decrypt_ext().
- *
- * \note This function only supports AEAD algorithms, not key
- * wrapping algorithms such as NIST_KW; for this, see
- * mbedtls_cipher_auth_decrypt_ext().
- *
- * \note If the data is not authentic, then the output buffer
- * is zeroed out to prevent the unauthentic plaintext being
- * used, making this interface safer.
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a key associated with an AEAD algorithm.
- * \param iv The nonce to use. This must be a readable buffer of
- * at least \p iv_len Bytes and must not be \c NULL.
- * \param iv_len The length of the nonce. This must satisfy the
- * constraints imposed by the AEAD cipher used.
- * \param ad The additional data to authenticate. This must be a
- * readable buffer of at least \p ad_len Bytes, and may
- * be \c NULL is \p ad_len is \c 0.
- * \param ad_len The length of \p ad.
- * \param input The buffer holding the input data. This must be a
- * readable buffer of at least \p ilen Bytes, and may be
- * \c NULL if \p ilen is \c 0.
- * \param ilen The length of the input data.
- * \param output The buffer for the output data. This must be a
- * writable buffer of at least \p ilen Bytes, and must
- * not be \c NULL.
- * \param olen This will be filled with the actual number of Bytes
- * written to the \p output buffer. This must point to a
- * writable object of type \c size_t.
- * \param tag The buffer for the authentication tag. This must be a
- * readable buffer of at least \p tag_len Bytes. See note
- * below regarding restrictions with PSA-based contexts.
- * \param tag_len The length of the authentication tag. This must match
- * the constraints imposed by the AEAD cipher used, and in
- * particular must not be \c 0.
- *
- * \note If the context is based on PSA (that is, it was set up
- * with mbedtls_cipher_setup_psa()), then it is required
- * that \c tag == input + len. That is, the tag must be
- * appended to the ciphertext as recommended by RFC 5116.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *ad, size_t ad_len,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t *olen,
- const unsigned char *tag, size_t tag_len )
- MBEDTLS_DEPRECATED;
- #undef MBEDTLS_DEPRECATED
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- #endif /* MBEDTLS_CIPHER_MODE_AEAD */
- #if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
- /**
- * \brief The authenticated encryption (AEAD/NIST_KW) function.
- *
- * \note For AEAD modes, the tag will be appended to the
- * ciphertext, as recommended by RFC 5116.
- * (NIST_KW doesn't have a separate tag.)
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a key, with an AEAD algorithm or NIST_KW.
- * \param iv The nonce to use. This must be a readable buffer of
- * at least \p iv_len Bytes and may be \c NULL if \p
- * iv_len is \c 0.
- * \param iv_len The length of the nonce. For AEAD ciphers, this must
- * satisfy the constraints imposed by the cipher used.
- * For NIST_KW, this must be \c 0.
- * \param ad The additional data to authenticate. This must be a
- * readable buffer of at least \p ad_len Bytes, and may
- * be \c NULL is \p ad_len is \c 0.
- * \param ad_len The length of \p ad. For NIST_KW, this must be \c 0.
- * \param input The buffer holding the input data. This must be a
- * readable buffer of at least \p ilen Bytes, and may be
- * \c NULL if \p ilen is \c 0.
- * \param ilen The length of the input data.
- * \param output The buffer for the output data. This must be a
- * writable buffer of at least \p output_len Bytes, and
- * must not be \c NULL.
- * \param output_len The length of the \p output buffer in Bytes. For AEAD
- * ciphers, this must be at least \p ilen + \p tag_len.
- * For NIST_KW, this must be at least \p ilen + 8
- * (rounded up to a multiple of 8 if KWP is used);
- * \p ilen + 15 is always a safe value.
- * \param olen This will be filled with the actual number of Bytes
- * written to the \p output buffer. This must point to a
- * writable object of type \c size_t.
- * \param tag_len The desired length of the authentication tag. For AEAD
- * ciphers, this must match the constraints imposed by
- * the cipher used, and in particular must not be \c 0.
- * For NIST_KW, this must be \c 0.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *ad, size_t ad_len,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t output_len,
- size_t *olen, size_t tag_len );
- /**
- * \brief The authenticated encryption (AEAD/NIST_KW) function.
- *
- * \note If the data is not authentic, then the output buffer
- * is zeroed out to prevent the unauthentic plaintext being
- * used, making this interface safer.
- *
- * \note For AEAD modes, the tag must be appended to the
- * ciphertext, as recommended by RFC 5116.
- * (NIST_KW doesn't have a separate tag.)
- *
- * \param ctx The generic cipher context. This must be initialized and
- * bound to a key, with an AEAD algorithm or NIST_KW.
- * \param iv The nonce to use. This must be a readable buffer of
- * at least \p iv_len Bytes and may be \c NULL if \p
- * iv_len is \c 0.
- * \param iv_len The length of the nonce. For AEAD ciphers, this must
- * satisfy the constraints imposed by the cipher used.
- * For NIST_KW, this must be \c 0.
- * \param ad The additional data to authenticate. This must be a
- * readable buffer of at least \p ad_len Bytes, and may
- * be \c NULL is \p ad_len is \c 0.
- * \param ad_len The length of \p ad. For NIST_KW, this must be \c 0.
- * \param input The buffer holding the input data. This must be a
- * readable buffer of at least \p ilen Bytes, and may be
- * \c NULL if \p ilen is \c 0.
- * \param ilen The length of the input data. For AEAD ciphers this
- * must be at least \p tag_len. For NIST_KW this must be
- * at least \c 8.
- * \param output The buffer for the output data. This must be a
- * writable buffer of at least \p output_len Bytes, and
- * may be \c NULL if \p output_len is \c 0.
- * \param output_len The length of the \p output buffer in Bytes. For AEAD
- * ciphers, this must be at least \p ilen - \p tag_len.
- * For NIST_KW, this must be at least \p ilen - 8.
- * \param olen This will be filled with the actual number of Bytes
- * written to the \p output buffer. This must point to a
- * writable object of type \c size_t.
- * \param tag_len The actual length of the authentication tag. For AEAD
- * ciphers, this must match the constraints imposed by
- * the cipher used, and in particular must not be \c 0.
- * For NIST_KW, this must be \c 0.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
- * parameter-verification failure.
- * \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *ad, size_t ad_len,
- const unsigned char *input, size_t ilen,
- unsigned char *output, size_t output_len,
- size_t *olen, size_t tag_len );
- #endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_CIPHER_H */
- /********* Start of file include/mbedtls/ssl_ciphersuites.h ************/
- /**
- * \file ssl_ciphersuites.h
- *
- * \brief SSL Ciphersuites for mbed TLS
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SSL_CIPHERSUITES_H
- #define MBEDTLS_SSL_CIPHERSUITES_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*
- * Supported ciphersuites (Official IANA names)
- */
- #define MBEDTLS_TLS_RSA_WITH_NULL_MD5 0x01 /**< Weak! */
- #define MBEDTLS_TLS_RSA_WITH_NULL_SHA 0x02 /**< Weak! */
- #define MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 0x04
- #define MBEDTLS_TLS_RSA_WITH_RC4_128_SHA 0x05
- #define MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA 0x09 /**< Weak! Not in TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0A
- #define MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA 0x15 /**< Weak! Not in TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x16
- #define MBEDTLS_TLS_PSK_WITH_NULL_SHA 0x2C /**< Weak! */
- #define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA 0x2D /**< Weak! */
- #define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA 0x2E /**< Weak! */
- #define MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA 0x2F
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x33
- #define MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA 0x35
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x39
- #define MBEDTLS_TLS_RSA_WITH_NULL_SHA256 0x3B /**< Weak! */
- #define MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 0x3C /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 0x3D /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA 0x41
- #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x45
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x67 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x6B /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x84
- #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x88
- #define MBEDTLS_TLS_PSK_WITH_RC4_128_SHA 0x8A
- #define MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA 0x8B
- #define MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA 0x8C
- #define MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA 0x8D
- #define MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA 0x8E
- #define MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA 0x8F
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA 0x90
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA 0x91
- #define MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA 0x92
- #define MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA 0x93
- #define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA 0x94
- #define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA 0x95
- #define MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 0x9C /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 0x9D /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x9E /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x9F /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 0xA8 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 0xA9 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 0xAA /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 0xAB /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 0xAC /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 0xAD /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 0xAE
- #define MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 0xAF
- #define MBEDTLS_TLS_PSK_WITH_NULL_SHA256 0xB0 /**< Weak! */
- #define MBEDTLS_TLS_PSK_WITH_NULL_SHA384 0xB1 /**< Weak! */
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 0xB2
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 0xB3
- #define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 0xB4 /**< Weak! */
- #define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 0xB5 /**< Weak! */
- #define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 0xB6
- #define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 0xB7
- #define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 0xB8 /**< Weak! */
- #define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 0xB9 /**< Weak! */
- #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBA /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBE /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC0 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC4 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA 0xC001 /**< Weak! */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA 0xC002 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC003 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA 0xC006 /**< Weak! */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA 0xC007 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC008 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA 0xC00B /**< Weak! */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA 0xC00C /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 0xC00D /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA 0xC010 /**< Weak! */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA 0xC011 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 0xC012 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 0xC025 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 0xC026 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 0xC028 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 0xC029 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 0xC02A /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0xC02D /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0xC02E /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 0xC031 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 0xC032 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA 0xC033 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0xC034 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0xC038 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA 0xC039 /**< Weak! No SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 0xC03A /**< Weak! No SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 0xC03B /**< Weak! No SSL3! */
- #define MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256 0xC03C /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384 0xC03D /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256 0xC044 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384 0xC045 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256 0xC048 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384 0xC049 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256 0xC04A /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384 0xC04B /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256 0xC04C /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384 0xC04D /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256 0xC04E /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384 0xC04F /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256 0xC050 /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384 0xC051 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256 0xC052 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384 0xC053 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 0xC05C /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 0xC05D /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 0xC05E /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 0xC05F /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 0xC060 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 0xC061 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 0xC062 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 0xC063 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256 0xC064 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384 0xC065 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256 0xC066 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384 0xC067 /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256 0xC068 /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384 0xC069 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256 0xC06A /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384 0xC06B /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256 0xC06C /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384 0xC06D /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256 0xC06E /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384 0xC06F /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 0xC070 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 0xC071 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC072 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC073 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC074 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC075 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC076 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC077 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC078 /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC079 /**< Not in SSL3! */
- #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07A /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07B /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07C /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07D /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC086 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC087 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC088 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC089 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08A /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08B /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08C /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08D /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC08E /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC08F /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC090 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC091 /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC092 /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC093 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC094
- #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC095
- #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC096
- #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC097
- #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC098
- #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC099
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC09A /**< Not in SSL3! */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC09B /**< Not in SSL3! */
- #define MBEDTLS_TLS_RSA_WITH_AES_128_CCM 0xC09C /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_AES_256_CCM 0xC09D /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM 0xC09E /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM 0xC09F /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8 0xC0A0 /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8 0xC0A1 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8 0xC0A2 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8 0xC0A3 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_AES_128_CCM 0xC0A4 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_AES_256_CCM 0xC0A5 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM 0xC0A6 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM 0xC0A7 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8 0xC0A8 /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8 0xC0A9 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8 0xC0AA /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8 0xC0AB /**< TLS 1.2 */
- /* The last two are named with PSK_DHE in the RFC, which looks like a typo */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM 0xC0AC /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM 0xC0AD /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 0xC0AE /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 0xC0AF /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 0xC0FF /**< experimental */
- /* RFC 7905 */
- #define MBEDTLS_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA8 /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA9 /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCAA /**< TLS 1.2 */
- #define MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAB /**< TLS 1.2 */
- #define MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAC /**< TLS 1.2 */
- #define MBEDTLS_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAD /**< TLS 1.2 */
- #define MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256 0xCCAE /**< TLS 1.2 */
- /* Reminder: update mbedtls_ssl_premaster_secret when adding a new key exchange.
- * Reminder: update MBEDTLS_KEY_EXCHANGE__xxx below
- */
- typedef enum {
- MBEDTLS_KEY_EXCHANGE_NONE = 0,
- MBEDTLS_KEY_EXCHANGE_RSA,
- MBEDTLS_KEY_EXCHANGE_DHE_RSA,
- MBEDTLS_KEY_EXCHANGE_ECDHE_RSA,
- MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA,
- MBEDTLS_KEY_EXCHANGE_PSK,
- MBEDTLS_KEY_EXCHANGE_DHE_PSK,
- MBEDTLS_KEY_EXCHANGE_RSA_PSK,
- MBEDTLS_KEY_EXCHANGE_ECDHE_PSK,
- MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
- MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
- MBEDTLS_KEY_EXCHANGE_ECJPAKE,
- } mbedtls_key_exchange_type_t;
- /* Key exchanges using a certificate */
- #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED
- #endif
- /* Key exchanges allowing client certificate requests */
- #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED
- #endif
- /* Key exchanges involving server signature in ServerKeyExchange */
- #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED
- #endif
- /* Key exchanges using ECDH */
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED
- #endif
- /* Key exchanges that don't involve ephemeral keys */
- #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED
- #endif
- /* Key exchanges that involve ephemeral keys */
- #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED
- #endif
- /* Key exchanges using a PSK */
- #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED
- #endif
- /* Key exchanges using DHE */
- #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_SOME_DHE_ENABLED
- #endif
- /* Key exchanges using ECDHE */
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
- #define MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED
- #endif
- typedef struct mbedtls_ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t;
- #define MBEDTLS_CIPHERSUITE_WEAK 0x01 /**< Weak ciphersuite flag */
- #define MBEDTLS_CIPHERSUITE_SHORT_TAG 0x02 /**< Short authentication tag,
- eg for CCM_8 */
- #define MBEDTLS_CIPHERSUITE_NODTLS 0x04 /**< Can't be used with DTLS */
- /**
- * \brief This structure is used for storing ciphersuite information
- */
- struct mbedtls_ssl_ciphersuite_t
- {
- int id;
- const char * name;
- mbedtls_cipher_type_t cipher;
- mbedtls_md_type_t mac;
- mbedtls_key_exchange_type_t key_exchange;
- int min_major_ver;
- int min_minor_ver;
- int max_major_ver;
- int max_minor_ver;
- unsigned char flags;
- };
- const int *mbedtls_ssl_list_ciphersuites( void );
- const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_string( const char *ciphersuite_name );
- const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_id( int ciphersuite_id );
- #if defined(MBEDTLS_PK_C)
- mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_pk_alg( const mbedtls_ssl_ciphersuite_t *info );
- mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_alg( const mbedtls_ssl_ciphersuite_t *info );
- #endif
- int mbedtls_ssl_ciphersuite_uses_ec( const mbedtls_ssl_ciphersuite_t *info );
- int mbedtls_ssl_ciphersuite_uses_psk( const mbedtls_ssl_ciphersuite_t *info );
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED)
- static inline int mbedtls_ssl_ciphersuite_has_pfs( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_DHE_PSK:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
- case MBEDTLS_KEY_EXCHANGE_ECJPAKE:
- return( 1 );
- default:
- return( 0 );
- }
- }
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED */
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED)
- static inline int mbedtls_ssl_ciphersuite_no_pfs( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
- case MBEDTLS_KEY_EXCHANGE_RSA:
- case MBEDTLS_KEY_EXCHANGE_PSK:
- case MBEDTLS_KEY_EXCHANGE_RSA_PSK:
- return( 1 );
- default:
- return( 0 );
- }
- }
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED */
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED)
- static inline int mbedtls_ssl_ciphersuite_uses_ecdh( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
- return( 1 );
- default:
- return( 0 );
- }
- }
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED */
- static inline int mbedtls_ssl_ciphersuite_cert_req_allowed( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_RSA:
- case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
- return( 1 );
- default:
- return( 0 );
- }
- }
- static inline int mbedtls_ssl_ciphersuite_uses_srv_cert( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_RSA:
- case MBEDTLS_KEY_EXCHANGE_RSA_PSK:
- case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
- return( 1 );
- default:
- return( 0 );
- }
- }
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_DHE_ENABLED)
- static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_DHE_PSK:
- return( 1 );
- default:
- return( 0 );
- }
- }
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_DHE_ENABLED) */
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED)
- static inline int mbedtls_ssl_ciphersuite_uses_ecdhe( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
- return( 1 );
- default:
- return( 0 );
- }
- }
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED) */
- #if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED)
- static inline int mbedtls_ssl_ciphersuite_uses_server_signature( const mbedtls_ssl_ciphersuite_t *info )
- {
- switch( info->key_exchange )
- {
- case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
- case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
- return( 1 );
- default:
- return( 0 );
- }
- }
- #endif /* MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED */
- #ifdef __cplusplus
- }
- #endif
- #endif /* ssl_ciphersuites.h */
- /********* Start of file include/mbedtls/cipher_internal.h ************/
- /**
- * \file cipher_internal.h
- *
- * \brief Cipher wrappers.
- *
- * \author Adriaan de Jong <dejong@fox-it.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CIPHER_WRAP_H
- #define MBEDTLS_CIPHER_WRAP_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Base cipher information. The non-mode specific functions and values.
- */
- struct mbedtls_cipher_base_t
- {
- /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
- mbedtls_cipher_id_t cipher;
- /** Encrypt using ECB */
- int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
- const unsigned char *input, unsigned char *output );
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- /** Encrypt using CBC */
- int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
- unsigned char *iv, const unsigned char *input,
- unsigned char *output );
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- /** Encrypt using CFB (Full length) */
- int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
- unsigned char *iv, const unsigned char *input,
- unsigned char *output );
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- /** Encrypt using OFB (Full length) */
- int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
- unsigned char *iv,
- const unsigned char *input,
- unsigned char *output );
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- /** Encrypt using CTR */
- int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
- unsigned char *nonce_counter, unsigned char *stream_block,
- const unsigned char *input, unsigned char *output );
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- /** Encrypt or decrypt using XTS. */
- int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length,
- const unsigned char data_unit[16],
- const unsigned char *input, unsigned char *output );
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_STREAM)
- /** Encrypt using STREAM */
- int (*stream_func)( void *ctx, size_t length,
- const unsigned char *input, unsigned char *output );
- #endif
- /** Set key for encryption purposes */
- int (*setkey_enc_func)( void *ctx, const unsigned char *key,
- unsigned int key_bitlen );
- /** Set key for decryption purposes */
- int (*setkey_dec_func)( void *ctx, const unsigned char *key,
- unsigned int key_bitlen);
- /** Allocate a new context */
- void * (*ctx_alloc_func)( void );
- /** Free the given context */
- void (*ctx_free_func)( void *ctx );
- };
- typedef struct
- {
- mbedtls_cipher_type_t type;
- const mbedtls_cipher_info_t *info;
- } mbedtls_cipher_definition_t;
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- typedef enum
- {
- MBEDTLS_CIPHER_PSA_KEY_UNSET = 0,
- MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */
- /* use raw key material internally imported */
- /* as a volatile key, and which hence need */
- /* to destroy that key when the context is */
- /* freed. */
- MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts */
- /* which use a key provided by the */
- /* user, and which hence will not be */
- /* destroyed when the context is freed. */
- } mbedtls_cipher_psa_key_ownership;
- typedef struct
- {
- psa_algorithm_t alg;
- psa_key_id_t slot;
- mbedtls_cipher_psa_key_ownership slot_state;
- } mbedtls_cipher_context_psa;
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
- extern int mbedtls_cipher_supported[];
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_CIPHER_WRAP_H */
- /********* Start of file include/mbedtls/ecdh.h ************/
- /**
- * \file ecdh.h
- *
- * \brief This file contains ECDH definitions and functions.
- *
- * The Elliptic Curve Diffie-Hellman (ECDH) protocol is an anonymous
- * key agreement protocol allowing two parties to establish a shared
- * secret over an insecure channel. Each party must have an
- * elliptic-curve public–private key pair.
- *
- * For more information, see <em>NIST SP 800-56A Rev. 2: Recommendation for
- * Pair-Wise Key Establishment Schemes Using Discrete Logarithm
- * Cryptography</em>.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ECDH_H
- #define MBEDTLS_ECDH_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
- #undef MBEDTLS_ECDH_LEGACY_CONTEXT
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Defines the source of the imported EC key.
- */
- typedef enum
- {
- MBEDTLS_ECDH_OURS, /**< Our key. */
- MBEDTLS_ECDH_THEIRS, /**< The key of the peer. */
- } mbedtls_ecdh_side;
- #if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
- /**
- * Defines the ECDH implementation used.
- *
- * Later versions of the library may add new variants, therefore users should
- * not make any assumptions about them.
- */
- typedef enum
- {
- MBEDTLS_ECDH_VARIANT_NONE = 0, /*!< Implementation not defined. */
- MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,/*!< The default Mbed TLS implementation */
- #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
- MBEDTLS_ECDH_VARIANT_EVEREST /*!< Everest implementation */
- #endif
- } mbedtls_ecdh_variant;
- /**
- * The context used by the default ECDH implementation.
- *
- * Later versions might change the structure of this context, therefore users
- * should not make any assumptions about the structure of
- * mbedtls_ecdh_context_mbed.
- */
- typedef struct mbedtls_ecdh_context_mbed
- {
- mbedtls_ecp_group grp; /*!< The elliptic curve used. */
- mbedtls_mpi d; /*!< The private key. */
- mbedtls_ecp_point Q; /*!< The public key. */
- mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */
- mbedtls_mpi z; /*!< The shared secret. */
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */
- #endif
- } mbedtls_ecdh_context_mbed;
- #endif
- /**
- *
- * \warning Performing multiple operations concurrently on the same
- * ECDSA context is not supported; objects of this type
- * should not be shared between multiple threads.
- * \brief The ECDH context structure.
- */
- typedef struct mbedtls_ecdh_context
- {
- #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
- mbedtls_ecp_group grp; /*!< The elliptic curve used. */
- mbedtls_mpi d; /*!< The private key. */
- mbedtls_ecp_point Q; /*!< The public key. */
- mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */
- mbedtls_mpi z; /*!< The shared secret. */
- int point_format; /*!< The format of point export in TLS messages. */
- mbedtls_ecp_point Vi; /*!< The blinding value. */
- mbedtls_ecp_point Vf; /*!< The unblinding value. */
- mbedtls_mpi _d; /*!< The previous \p d. */
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- int restart_enabled; /*!< The flag for restartable mode. */
- mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- #else
- uint8_t point_format; /*!< The format of point export in TLS messages
- as defined in RFC 4492. */
- mbedtls_ecp_group_id grp_id;/*!< The elliptic curve used. */
- mbedtls_ecdh_variant var; /*!< The ECDH implementation/structure used. */
- union
- {
- mbedtls_ecdh_context_mbed mbed_ecdh;
- #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
- mbedtls_ecdh_context_everest everest_ecdh;
- #endif
- } ctx; /*!< Implementation-specific context. The
- context in use is specified by the \c var
- field. */
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- uint8_t restart_enabled; /*!< The flag for restartable mode. Functions of
- an alternative implementation not supporting
- restartable mode must return
- MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED error
- if this flag is set. */
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- #endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
- }
- mbedtls_ecdh_context;
- /**
- * \brief Check whether a given group can be used for ECDH.
- *
- * \param gid The ECP group ID to check.
- *
- * \return \c 1 if the group can be used, \c 0 otherwise
- */
- int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid );
- /**
- * \brief This function generates an ECDH keypair on an elliptic
- * curve.
- *
- * This function performs the first of two core computations
- * implemented during the ECDH key exchange. The second core
- * computation is performed by mbedtls_ecdh_compute_shared().
- *
- * \see ecp.h
- *
- * \param grp The ECP group to use. This must be initialized and have
- * domain parameters loaded, for example through
- * mbedtls_ecp_load() or mbedtls_ecp_tls_read_group().
- * \param d The destination MPI (private key).
- * This must be initialized.
- * \param Q The destination point (public key).
- * This must be initialized.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL in case \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return Another \c MBEDTLS_ERR_ECP_XXX or
- * \c MBEDTLS_MPI_XXX error code on failure.
- */
- int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function computes the shared secret.
- *
- * This function performs the second of two core computations
- * implemented during the ECDH key exchange. The first core
- * computation is performed by mbedtls_ecdh_gen_public().
- *
- * \see ecp.h
- *
- * \note If \p f_rng is not NULL, it is used to implement
- * countermeasures against side-channel attacks.
- * For more information, see mbedtls_ecp_mul().
- *
- * \param grp The ECP group to use. This must be initialized and have
- * domain parameters loaded, for example through
- * mbedtls_ecp_load() or mbedtls_ecp_tls_read_group().
- * \param z The destination MPI (shared secret).
- * This must be initialized.
- * \param Q The public key from another party.
- * This must be initialized.
- * \param d Our secret exponent (private key).
- * This must be initialized.
- * \param f_rng The RNG function. This may be \c NULL if randomization
- * of intermediate results during the ECP computations is
- * not needed (discouraged). See the documentation of
- * mbedtls_ecp_mul() for more.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL if \p f_rng is \c NULL or doesn't need a
- * context argument.
- *
- * \return \c 0 on success.
- * \return Another \c MBEDTLS_ERR_ECP_XXX or
- * \c MBEDTLS_MPI_XXX error code on failure.
- */
- int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
- const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function initializes an ECDH context.
- *
- * \param ctx The ECDH context to initialize. This must not be \c NULL.
- */
- void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
- /**
- * \brief This function sets up the ECDH context with the information
- * given.
- *
- * This function should be called after mbedtls_ecdh_init() but
- * before mbedtls_ecdh_make_params(). There is no need to call
- * this function before mbedtls_ecdh_read_params().
- *
- * This is the first function used by a TLS server for ECDHE
- * ciphersuites.
- *
- * \param ctx The ECDH context to set up. This must be initialized.
- * \param grp_id The group id of the group to set up the context for.
- *
- * \return \c 0 on success.
- */
- int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx,
- mbedtls_ecp_group_id grp_id );
- /**
- * \brief This function frees a context.
- *
- * \param ctx The context to free. This may be \c NULL, in which
- * case this function does nothing. If it is not \c NULL,
- * it must point to an initialized ECDH context.
- */
- void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
- /**
- * \brief This function generates an EC key pair and exports its
- * in the format used in a TLS ServerKeyExchange handshake
- * message.
- *
- * This is the second function used by a TLS server for ECDHE
- * ciphersuites. (It is called after mbedtls_ecdh_setup().)
- *
- * \see ecp.h
- *
- * \param ctx The ECDH context to use. This must be initialized
- * and bound to a group, for example via mbedtls_ecdh_setup().
- * \param olen The address at which to store the number of Bytes written.
- * \param buf The destination buffer. This must be a writable buffer of
- * length \p blen Bytes.
- * \param blen The length of the destination buffer \p buf in Bytes.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL in case \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
- */
- int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
- unsigned char *buf, size_t blen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function parses the ECDHE parameters in a
- * TLS ServerKeyExchange handshake message.
- *
- * \note In a TLS handshake, this is the how the client
- * sets up its ECDHE context from the server's public
- * ECDHE key material.
- *
- * \see ecp.h
- *
- * \param ctx The ECDHE context to use. This must be initialized.
- * \param buf On input, \c *buf must be the start of the input buffer.
- * On output, \c *buf is updated to point to the end of the
- * data that has been read. On success, this is the first byte
- * past the end of the ServerKeyExchange parameters.
- * On error, this is the point at which an error has been
- * detected, which is usually not useful except to debug
- * failures.
- * \param end The end of the input buffer.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
- *
- */
- int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
- const unsigned char **buf,
- const unsigned char *end );
- /**
- * \brief This function sets up an ECDH context from an EC key.
- *
- * It is used by clients and servers in place of the
- * ServerKeyEchange for static ECDH, and imports ECDH
- * parameters from the EC key information of a certificate.
- *
- * \see ecp.h
- *
- * \param ctx The ECDH context to set up. This must be initialized.
- * \param key The EC key to use. This must be initialized.
- * \param side Defines the source of the key. Possible values are:
- * - #MBEDTLS_ECDH_OURS: The key is ours.
- * - #MBEDTLS_ECDH_THEIRS: The key is that of the peer.
- *
- * \return \c 0 on success.
- * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
- *
- */
- int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx,
- const mbedtls_ecp_keypair *key,
- mbedtls_ecdh_side side );
- /**
- * \brief This function generates a public key and exports it
- * as a TLS ClientKeyExchange payload.
- *
- * This is the second function used by a TLS client for ECDH(E)
- * ciphersuites.
- *
- * \see ecp.h
- *
- * \param ctx The ECDH context to use. This must be initialized
- * and bound to a group, the latter usually by
- * mbedtls_ecdh_read_params().
- * \param olen The address at which to store the number of Bytes written.
- * This must not be \c NULL.
- * \param buf The destination buffer. This must be a writable buffer
- * of length \p blen Bytes.
- * \param blen The size of the destination buffer \p buf in Bytes.
- * \param f_rng The RNG function to use. This must not be \c NULL.
- * \param p_rng The RNG context to be passed to \p f_rng. This may be
- * \c NULL in case \p f_rng doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
- */
- int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
- unsigned char *buf, size_t blen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief This function parses and processes the ECDHE payload of a
- * TLS ClientKeyExchange message.
- *
- * This is the third function used by a TLS server for ECDH(E)
- * ciphersuites. (It is called after mbedtls_ecdh_setup() and
- * mbedtls_ecdh_make_params().)
- *
- * \see ecp.h
- *
- * \param ctx The ECDH context to use. This must be initialized
- * and bound to a group, for example via mbedtls_ecdh_setup().
- * \param buf The pointer to the ClientKeyExchange payload. This must
- * be a readable buffer of length \p blen Bytes.
- * \param blen The length of the input buffer \p buf in Bytes.
- *
- * \return \c 0 on success.
- * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
- */
- int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
- const unsigned char *buf, size_t blen );
- /**
- * \brief This function derives and exports the shared secret.
- *
- * This is the last function used by both TLS client
- * and servers.
- *
- * \note If \p f_rng is not NULL, it is used to implement
- * countermeasures against side-channel attacks.
- * For more information, see mbedtls_ecp_mul().
- *
- * \see ecp.h
- * \param ctx The ECDH context to use. This must be initialized
- * and have its own private key generated and the peer's
- * public key imported.
- * \param olen The address at which to store the total number of
- * Bytes written on success. This must not be \c NULL.
- * \param buf The buffer to write the generated shared key to. This
- * must be a writable buffer of size \p blen Bytes.
- * \param blen The length of the destination buffer \p buf in Bytes.
- * \param f_rng The RNG function, for blinding purposes. This may
- * b \c NULL if blinding isn't needed.
- * \param p_rng The RNG context. This may be \c NULL if \p f_rng
- * doesn't need a context argument.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
- * operations was reached: see \c mbedtls_ecp_set_max_ops().
- * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
- */
- int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
- unsigned char *buf, size_t blen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- #if defined(MBEDTLS_ECP_RESTARTABLE)
- /**
- * \brief This function enables restartable EC computations for this
- * context. (Default: disabled.)
- *
- * \see \c mbedtls_ecp_set_max_ops()
- *
- * \note It is not possible to safely disable restartable
- * computations once enabled, except by free-ing the context,
- * which cancels possible in-progress operations.
- *
- * \param ctx The ECDH context to use. This must be initialized.
- */
- void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
- #endif /* MBEDTLS_ECP_RESTARTABLE */
- #ifdef __cplusplus
- }
- #endif
- #endif /* ecdh.h */
- /********* Start of file include/mbedtls/sha1.h ************/
- /**
- * \file sha1.h
- *
- * \brief This file contains SHA-1 definitions and functions.
- *
- * The Secure Hash Algorithm 1 (SHA-1) cryptographic hash function is defined in
- * <em>FIPS 180-4: Secure Hash Standard (SHS)</em>.
- *
- * \warning SHA-1 is considered a weak message digest and its use constitutes
- * a security risk. We recommend considering stronger message
- * digests instead.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SHA1_H
- #define MBEDTLS_SHA1_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /* MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** SHA-1 hardware accelerator failed */
- #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035
- /** SHA-1 input data was malformed. */
- #define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_SHA1_ALT)
- // Regular implementation
- //
- /**
- * \brief The SHA-1 context structure.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- */
- typedef struct mbedtls_sha1_context
- {
- uint32_t total[2]; /*!< The number of Bytes processed. */
- uint32_t state[5]; /*!< The intermediate digest state. */
- unsigned char buffer[64]; /*!< The data block being processed. */
- }
- mbedtls_sha1_context;
- #else /* MBEDTLS_SHA1_ALT */
- #endif /* MBEDTLS_SHA1_ALT */
- /**
- * \brief This function initializes a SHA-1 context.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param ctx The SHA-1 context to initialize.
- * This must not be \c NULL.
- *
- */
- void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
- /**
- * \brief This function clears a SHA-1 context.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param ctx The SHA-1 context to clear. This may be \c NULL,
- * in which case this function does nothing. If it is
- * not \c NULL, it must point to an initialized
- * SHA-1 context.
- *
- */
- void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
- /**
- * \brief This function clones the state of a SHA-1 context.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param dst The SHA-1 context to clone to. This must be initialized.
- * \param src The SHA-1 context to clone from. This must be initialized.
- *
- */
- void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
- const mbedtls_sha1_context *src );
- /**
- * \brief This function starts a SHA-1 checksum calculation.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param ctx The SHA-1 context to initialize. This must be initialized.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- *
- */
- int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
- /**
- * \brief This function feeds an input buffer into an ongoing SHA-1
- * checksum calculation.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param ctx The SHA-1 context. This must be initialized
- * and have a hash operation started.
- * \param input The buffer holding the input data.
- * This must be a readable buffer of length \p ilen Bytes.
- * \param ilen The length of the input data \p input in Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function finishes the SHA-1 operation, and writes
- * the result to the output buffer.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param ctx The SHA-1 context to use. This must be initialized and
- * have a hash operation started.
- * \param output The SHA-1 checksum result. This must be a writable
- * buffer of length \c 20 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
- unsigned char output[20] );
- /**
- * \brief SHA-1 process data block (internal use only).
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param ctx The SHA-1 context to use. This must be initialized.
- * \param data The data block being processed. This must be a
- * readable buffer of length \c 64 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- *
- */
- int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
- const unsigned char data[64] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function starts a SHA-1 checksum calculation.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0.
- *
- * \param ctx The SHA-1 context to initialize. This must be initialized.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
- /**
- * \brief This function feeds an input buffer into an ongoing SHA-1
- * checksum calculation.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0.
- *
- * \param ctx The SHA-1 context. This must be initialized and
- * have a hash operation started.
- * \param input The buffer holding the input data.
- * This must be a readable buffer of length \p ilen Bytes.
- * \param ilen The length of the input data \p input in Bytes.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function finishes the SHA-1 operation, and writes
- * the result to the output buffer.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0.
- *
- * \param ctx The SHA-1 context. This must be initialized and
- * have a hash operation started.
- * \param output The SHA-1 checksum result.
- * This must be a writable buffer of length \c 20 Bytes.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
- unsigned char output[20] );
- /**
- * \brief SHA-1 process data block (internal use only).
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0.
- *
- * \param ctx The SHA-1 context. This must be initialized.
- * \param data The data block being processed.
- * This must be a readable buffer of length \c 64 bytes.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
- const unsigned char data[64] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief This function calculates the SHA-1 checksum of a buffer.
- *
- * The function allocates the context, performs the
- * calculation, and frees the context.
- *
- * The SHA-1 result is calculated as
- * output = SHA-1(input buffer).
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \param input The buffer holding the input data.
- * This must be a readable buffer of length \p ilen Bytes.
- * \param ilen The length of the input data \p input in Bytes.
- * \param output The SHA-1 checksum result.
- * This must be a writable buffer of length \c 20 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- *
- */
- int mbedtls_sha1_ret( const unsigned char *input,
- size_t ilen,
- unsigned char output[20] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function calculates the SHA-1 checksum of a buffer.
- *
- * The function allocates the context, performs the
- * calculation, and frees the context.
- *
- * The SHA-1 result is calculated as
- * output = SHA-1(input buffer).
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0
- *
- * \param input The buffer holding the input data.
- * This must be a readable buffer of length \p ilen Bytes.
- * \param ilen The length of the input data \p input in Bytes.
- * \param output The SHA-1 checksum result. This must be a writable
- * buffer of size \c 20 Bytes.
- *
- */
- MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
- size_t ilen,
- unsigned char output[20] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The SHA-1 checkup routine.
- *
- * \warning SHA-1 is considered a weak message digest and its use
- * constitutes a security risk. We recommend considering
- * stronger message digests instead.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- *
- */
- int mbedtls_sha1_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_sha1.h */
- /********* Start of file include/mbedtls/sha256.h ************/
- /**
- * \file sha256.h
- *
- * \brief This file contains SHA-224 and SHA-256 definitions and functions.
- *
- * The Secure Hash Algorithms 224 and 256 (SHA-224 and SHA-256) cryptographic
- * hash functions are defined in <em>FIPS 180-4: Secure Hash Standard (SHS)</em>.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SHA256_H
- #define MBEDTLS_SHA256_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /* MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** SHA-256 hardware accelerator failed */
- #define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037
- /** SHA-256 input data was malformed. */
- #define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_SHA256_ALT)
- // Regular implementation
- //
- /**
- * \brief The SHA-256 context structure.
- *
- * The structure is used both for SHA-256 and for SHA-224
- * checksum calculations. The choice between these two is
- * made in the call to mbedtls_sha256_starts_ret().
- */
- typedef struct mbedtls_sha256_context
- {
- uint32_t total[2]; /*!< The number of Bytes processed. */
- uint32_t state[8]; /*!< The intermediate digest state. */
- unsigned char buffer[64]; /*!< The data block being processed. */
- int is224; /*!< Determines which function to use:
- 0: Use SHA-256, or 1: Use SHA-224. */
- }
- mbedtls_sha256_context;
- #else /* MBEDTLS_SHA256_ALT */
- #endif /* MBEDTLS_SHA256_ALT */
- /**
- * \brief This function initializes a SHA-256 context.
- *
- * \param ctx The SHA-256 context to initialize. This must not be \c NULL.
- */
- void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
- /**
- * \brief This function clears a SHA-256 context.
- *
- * \param ctx The SHA-256 context to clear. This may be \c NULL, in which
- * case this function returns immediately. If it is not \c NULL,
- * it must point to an initialized SHA-256 context.
- */
- void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
- /**
- * \brief This function clones the state of a SHA-256 context.
- *
- * \param dst The destination context. This must be initialized.
- * \param src The context to clone. This must be initialized.
- */
- void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
- const mbedtls_sha256_context *src );
- /**
- * \brief This function starts a SHA-224 or SHA-256 checksum
- * calculation.
- *
- * \param ctx The context to use. This must be initialized.
- * \param is224 This determines which function to use. This must be
- * either \c 0 for SHA-256, or \c 1 for SHA-224.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
- /**
- * \brief This function feeds an input buffer into an ongoing
- * SHA-256 checksum calculation.
- *
- * \param ctx The SHA-256 context. This must be initialized
- * and have a hash operation started.
- * \param input The buffer holding the data. This must be a readable
- * buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function finishes the SHA-256 operation, and writes
- * the result to the output buffer.
- *
- * \param ctx The SHA-256 context. This must be initialized
- * and have a hash operation started.
- * \param output The SHA-224 or SHA-256 checksum result.
- * This must be a writable buffer of length \c 32 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
- unsigned char output[32] );
- /**
- * \brief This function processes a single data block within
- * the ongoing SHA-256 computation. This function is for
- * internal use only.
- *
- * \param ctx The SHA-256 context. This must be initialized.
- * \param data The buffer holding one block of data. This must
- * be a readable buffer of length \c 64 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
- const unsigned char data[64] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function starts a SHA-224 or SHA-256 checksum
- * calculation.
- *
- * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
- *
- * \param ctx The context to use. This must be initialized.
- * \param is224 Determines which function to use. This must be
- * either \c 0 for SHA-256, or \c 1 for SHA-224.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
- int is224 );
- /**
- * \brief This function feeds an input buffer into an ongoing
- * SHA-256 checksum calculation.
- *
- * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
- *
- * \param ctx The SHA-256 context to use. This must be
- * initialized and have a hash operation started.
- * \param input The buffer holding the data. This must be a readable
- * buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function finishes the SHA-256 operation, and writes
- * the result to the output buffer.
- *
- * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
- *
- * \param ctx The SHA-256 context. This must be initialized and
- * have a hash operation started.
- * \param output The SHA-224 or SHA-256 checksum result. This must be
- * a writable buffer of length \c 32 Bytes.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
- unsigned char output[32] );
- /**
- * \brief This function processes a single data block within
- * the ongoing SHA-256 computation. This function is for
- * internal use only.
- *
- * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0.
- *
- * \param ctx The SHA-256 context. This must be initialized.
- * \param data The buffer holding one block of data. This must be
- * a readable buffer of size \c 64 Bytes.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
- const unsigned char data[64] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief This function calculates the SHA-224 or SHA-256
- * checksum of a buffer.
- *
- * The function allocates the context, performs the
- * calculation, and frees the context.
- *
- * The SHA-256 result is calculated as
- * output = SHA-256(input buffer).
- *
- * \param input The buffer holding the data. This must be a readable
- * buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- * \param output The SHA-224 or SHA-256 checksum result. This must
- * be a writable buffer of length \c 32 Bytes.
- * \param is224 Determines which function to use. This must be
- * either \c 0 for SHA-256, or \c 1 for SHA-224.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha256_ret( const unsigned char *input,
- size_t ilen,
- unsigned char output[32],
- int is224 );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function calculates the SHA-224 or SHA-256 checksum
- * of a buffer.
- *
- * The function allocates the context, performs the
- * calculation, and frees the context.
- *
- * The SHA-256 result is calculated as
- * output = SHA-256(input buffer).
- *
- * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0.
- *
- * \param input The buffer holding the data. This must be a readable
- * buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- * \param output The SHA-224 or SHA-256 checksum result. This must be
- * a writable buffer of length \c 32 Bytes.
- * \param is224 Determines which function to use. This must be either
- * \c 0 for SHA-256, or \c 1 for SHA-224.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
- size_t ilen,
- unsigned char output[32],
- int is224 );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The SHA-224 and SHA-256 checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_sha256_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_sha256.h */
- /********* Start of file include/mbedtls/sha512.h ************/
- /**
- * \file sha512.h
- * \brief This file contains SHA-384 and SHA-512 definitions and functions.
- *
- * The Secure Hash Algorithms 384 and 512 (SHA-384 and SHA-512) cryptographic
- * hash functions are defined in <em>FIPS 180-4: Secure Hash Standard (SHS)</em>.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SHA512_H
- #define MBEDTLS_SHA512_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /* MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** SHA-512 hardware accelerator failed */
- #define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039
- /** SHA-512 input data was malformed. */
- #define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA -0x0075
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_SHA512_ALT)
- // Regular implementation
- //
- /**
- * \brief The SHA-512 context structure.
- *
- * The structure is used both for SHA-384 and for SHA-512
- * checksum calculations. The choice between these two is
- * made in the call to mbedtls_sha512_starts_ret().
- */
- typedef struct mbedtls_sha512_context
- {
- uint64_t total[2]; /*!< The number of Bytes processed. */
- uint64_t state[8]; /*!< The intermediate digest state. */
- unsigned char buffer[128]; /*!< The data block being processed. */
- #if !defined(MBEDTLS_SHA512_NO_SHA384)
- int is384; /*!< Determines which function to use:
- 0: Use SHA-512, or 1: Use SHA-384. */
- #endif
- }
- mbedtls_sha512_context;
- #else /* MBEDTLS_SHA512_ALT */
- #endif /* MBEDTLS_SHA512_ALT */
- /**
- * \brief This function initializes a SHA-512 context.
- *
- * \param ctx The SHA-512 context to initialize. This must
- * not be \c NULL.
- */
- void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
- /**
- * \brief This function clears a SHA-512 context.
- *
- * \param ctx The SHA-512 context to clear. This may be \c NULL,
- * in which case this function does nothing. If it
- * is not \c NULL, it must point to an initialized
- * SHA-512 context.
- */
- void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
- /**
- * \brief This function clones the state of a SHA-512 context.
- *
- * \param dst The destination context. This must be initialized.
- * \param src The context to clone. This must be initialized.
- */
- void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
- const mbedtls_sha512_context *src );
- /**
- * \brief This function starts a SHA-384 or SHA-512 checksum
- * calculation.
- *
- * \param ctx The SHA-512 context to use. This must be initialized.
- * \param is384 Determines which function to use. This must be
- * either \c 0 for SHA-512, or \c 1 for SHA-384.
- *
- * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must
- * be \c 0, or the function will return
- * #MBEDTLS_ERR_SHA512_BAD_INPUT_DATA.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
- /**
- * \brief This function feeds an input buffer into an ongoing
- * SHA-512 checksum calculation.
- *
- * \param ctx The SHA-512 context. This must be initialized
- * and have a hash operation started.
- * \param input The buffer holding the input data. This must
- * be a readable buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function finishes the SHA-512 operation, and writes
- * the result to the output buffer.
- *
- * \param ctx The SHA-512 context. This must be initialized
- * and have a hash operation started.
- * \param output The SHA-384 or SHA-512 checksum result.
- * This must be a writable buffer of length \c 64 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
- unsigned char output[64] );
- /**
- * \brief This function processes a single data block within
- * the ongoing SHA-512 computation.
- * This function is for internal use only.
- *
- * \param ctx The SHA-512 context. This must be initialized.
- * \param data The buffer holding one block of data. This
- * must be a readable buffer of length \c 128 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
- const unsigned char data[128] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function starts a SHA-384 or SHA-512 checksum
- * calculation.
- *
- * \deprecated Superseded by mbedtls_sha512_starts_ret() in 2.7.0
- *
- * \param ctx The SHA-512 context to use. This must be initialized.
- * \param is384 Determines which function to use. This must be either
- * \c 0 for SHA-512 or \c 1 for SHA-384.
- *
- * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must
- * be \c 0, or the function will fail to work.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha512_starts( mbedtls_sha512_context *ctx,
- int is384 );
- /**
- * \brief This function feeds an input buffer into an ongoing
- * SHA-512 checksum calculation.
- *
- * \deprecated Superseded by mbedtls_sha512_update_ret() in 2.7.0.
- *
- * \param ctx The SHA-512 context. This must be initialized
- * and have a hash operation started.
- * \param input The buffer holding the data. This must be a readable
- * buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha512_update( mbedtls_sha512_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function finishes the SHA-512 operation, and writes
- * the result to the output buffer.
- *
- * \deprecated Superseded by mbedtls_sha512_finish_ret() in 2.7.0.
- *
- * \param ctx The SHA-512 context. This must be initialized
- * and have a hash operation started.
- * \param output The SHA-384 or SHA-512 checksum result. This must
- * be a writable buffer of size \c 64 Bytes.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha512_finish( mbedtls_sha512_context *ctx,
- unsigned char output[64] );
- /**
- * \brief This function processes a single data block within
- * the ongoing SHA-512 computation. This function is for
- * internal use only.
- *
- * \deprecated Superseded by mbedtls_internal_sha512_process() in 2.7.0.
- *
- * \param ctx The SHA-512 context. This must be initialized.
- * \param data The buffer holding one block of data. This must be
- * a readable buffer of length \c 128 Bytes.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha512_process(
- mbedtls_sha512_context *ctx,
- const unsigned char data[128] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief This function calculates the SHA-512 or SHA-384
- * checksum of a buffer.
- *
- * The function allocates the context, performs the
- * calculation, and frees the context.
- *
- * The SHA-512 result is calculated as
- * output = SHA-512(input buffer).
- *
- * \param input The buffer holding the input data. This must be
- * a readable buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- * \param output The SHA-384 or SHA-512 checksum result.
- * This must be a writable buffer of length \c 64 Bytes.
- * \param is384 Determines which function to use. This must be either
- * \c 0 for SHA-512, or \c 1 for SHA-384.
- *
- * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must
- * be \c 0, or the function will return
- * #MBEDTLS_ERR_SHA512_BAD_INPUT_DATA.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_sha512_ret( const unsigned char *input,
- size_t ilen,
- unsigned char output[64],
- int is384 );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function calculates the SHA-512 or SHA-384
- * checksum of a buffer.
- *
- * The function allocates the context, performs the
- * calculation, and frees the context.
- *
- * The SHA-512 result is calculated as
- * output = SHA-512(input buffer).
- *
- * \deprecated Superseded by mbedtls_sha512_ret() in 2.7.0
- *
- * \param input The buffer holding the data. This must be a
- * readable buffer of length \p ilen Bytes.
- * \param ilen The length of the input data in Bytes.
- * \param output The SHA-384 or SHA-512 checksum result. This must
- * be a writable buffer of length \c 64 Bytes.
- * \param is384 Determines which function to use. This must be either
- * \c 0 for SHA-512, or \c 1 for SHA-384.
- *
- * \note When \c MBEDTLS_SHA512_NO_SHA384 is defined, \p is384 must
- * be \c 0, or the function will fail to work.
- */
- MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
- size_t ilen,
- unsigned char output[64],
- int is384 );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The SHA-384 or SHA-512 checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_sha512_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_sha512.h */
- /********* Start of file include/mbedtls/aes.h ************/
- /**
- * \file aes.h
- *
- * \brief This file contains AES definitions and functions.
- *
- * The Advanced Encryption Standard (AES) specifies a FIPS-approved
- * cryptographic algorithm that can be used to protect electronic
- * data.
- *
- * The AES algorithm is a symmetric block cipher that can
- * encrypt and decrypt information. For more information, see
- * <em>FIPS Publication 197: Advanced Encryption Standard</em> and
- * <em>ISO/IEC 18033-2:2006: Information technology -- Security
- * techniques -- Encryption algorithms -- Part 2: Asymmetric
- * ciphers</em>.
- *
- * The AES-XTS block mode is standardized by NIST SP 800-38E
- * <https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38e.pdf>
- * and described in detail by IEEE P1619
- * <https://ieeexplore.ieee.org/servlet/opac?punumber=4375278>.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_AES_H
- #define MBEDTLS_AES_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /* padlock.c and aesni.c rely on these values! */
- #define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
- #define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
- /* Error codes in range 0x0020-0x0022 */
- /** Invalid key length. */
- #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
- /** Invalid data input length. */
- #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
- /* Error codes in range 0x0021-0x0025 */
- /** Invalid input data. */
- #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
- /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
- /** Feature not available. For example, an unsupported AES key size. */
- #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
- /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** AES hardware accelerator failed. */
- #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
- #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
- #define inline __inline
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_AES_ALT)
- // Regular implementation
- //
- /**
- * \brief The AES context-type definition.
- */
- typedef struct mbedtls_aes_context
- {
- int nr; /*!< The number of rounds. */
- uint32_t *rk; /*!< AES round keys. */
- uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
- hold 32 extra Bytes, which can be used for
- one of the following purposes:
- <ul><li>Alignment if VIA padlock is
- used.</li>
- <li>Simplifying key expansion in the 256-bit
- case by generating an extra round key.
- </li></ul> */
- }
- mbedtls_aes_context;
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- /**
- * \brief The AES XTS context-type definition.
- */
- typedef struct mbedtls_aes_xts_context
- {
- mbedtls_aes_context crypt; /*!< The AES context to use for AES block
- encryption or decryption. */
- mbedtls_aes_context tweak; /*!< The AES context used for tweak
- computation. */
- } mbedtls_aes_xts_context;
- #endif /* MBEDTLS_CIPHER_MODE_XTS */
- #else /* MBEDTLS_AES_ALT */
- #endif /* MBEDTLS_AES_ALT */
- /**
- * \brief This function initializes the specified AES context.
- *
- * It must be the first API called before using
- * the context.
- *
- * \param ctx The AES context to initialize. This must not be \c NULL.
- */
- void mbedtls_aes_init( mbedtls_aes_context *ctx );
- /**
- * \brief This function releases and clears the specified AES context.
- *
- * \param ctx The AES context to clear.
- * If this is \c NULL, this function does nothing.
- * Otherwise, the context must have been at least initialized.
- */
- void mbedtls_aes_free( mbedtls_aes_context *ctx );
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- /**
- * \brief This function initializes the specified AES XTS context.
- *
- * It must be the first API called before using
- * the context.
- *
- * \param ctx The AES XTS context to initialize. This must not be \c NULL.
- */
- void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
- /**
- * \brief This function releases and clears the specified AES XTS context.
- *
- * \param ctx The AES XTS context to clear.
- * If this is \c NULL, this function does nothing.
- * Otherwise, the context must have been at least initialized.
- */
- void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
- #endif /* MBEDTLS_CIPHER_MODE_XTS */
- /**
- * \brief This function sets the encryption key.
- *
- * \param ctx The AES context to which the key should be bound.
- * It must be initialized.
- * \param key The encryption key.
- * This must be a readable buffer of size \p keybits bits.
- * \param keybits The size of data passed in bits. Valid options are:
- * <ul><li>128 bits</li>
- * <li>192 bits</li>
- * <li>256 bits</li></ul>
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
- unsigned int keybits );
- /**
- * \brief This function sets the decryption key.
- *
- * \param ctx The AES context to which the key should be bound.
- * It must be initialized.
- * \param key The decryption key.
- * This must be a readable buffer of size \p keybits bits.
- * \param keybits The size of data passed. Valid options are:
- * <ul><li>128 bits</li>
- * <li>192 bits</li>
- * <li>256 bits</li></ul>
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
- unsigned int keybits );
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- /**
- * \brief This function prepares an XTS context for encryption and
- * sets the encryption key.
- *
- * \param ctx The AES XTS context to which the key should be bound.
- * It must be initialized.
- * \param key The encryption key. This is comprised of the XTS key1
- * concatenated with the XTS key2.
- * This must be a readable buffer of size \p keybits bits.
- * \param keybits The size of \p key passed in bits. Valid options are:
- * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
- * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
- const unsigned char *key,
- unsigned int keybits );
- /**
- * \brief This function prepares an XTS context for decryption and
- * sets the decryption key.
- *
- * \param ctx The AES XTS context to which the key should be bound.
- * It must be initialized.
- * \param key The decryption key. This is comprised of the XTS key1
- * concatenated with the XTS key2.
- * This must be a readable buffer of size \p keybits bits.
- * \param keybits The size of \p key passed in bits. Valid options are:
- * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
- * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
- const unsigned char *key,
- unsigned int keybits );
- #endif /* MBEDTLS_CIPHER_MODE_XTS */
- /**
- * \brief This function performs an AES single-block encryption or
- * decryption operation.
- *
- * It performs the operation defined in the \p mode parameter
- * (encrypt or decrypt), on the input data buffer defined in
- * the \p input parameter.
- *
- * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
- * mbedtls_aes_setkey_dec() must be called before the first
- * call to this API with the same context.
- *
- * \param ctx The AES context to use for encryption or decryption.
- * It must be initialized and bound to a key.
- * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
- * #MBEDTLS_AES_DECRYPT.
- * \param input The buffer holding the input data.
- * It must be readable and at least \c 16 Bytes long.
- * \param output The buffer where the output data will be written.
- * It must be writeable and at least \c 16 Bytes long.
- * \return \c 0 on success.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
- int mode,
- const unsigned char input[16],
- unsigned char output[16] );
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- /**
- * \brief This function performs an AES-CBC encryption or decryption operation
- * on full blocks.
- *
- * It performs the operation defined in the \p mode
- * parameter (encrypt/decrypt), on the input data buffer defined in
- * the \p input parameter.
- *
- * It can be called as many times as needed, until all the input
- * data is processed. mbedtls_aes_init(), and either
- * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
- * before the first call to this API with the same context.
- *
- * \note This function operates on full blocks, that is, the input size
- * must be a multiple of the AES block size of \c 16 Bytes.
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the same function again on the next
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If you need to retain the contents of the IV, you should
- * either save it manually or use the cipher module instead.
- *
- *
- * \param ctx The AES context to use for encryption or decryption.
- * It must be initialized and bound to a key.
- * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
- * #MBEDTLS_AES_DECRYPT.
- * \param length The length of the input data in Bytes. This must be a
- * multiple of the block size (\c 16 Bytes).
- * \param iv Initialization vector (updated after use).
- * It must be a readable and writeable buffer of \c 16 Bytes.
- * \param input The buffer holding the input data.
- * It must be readable and of size \p length Bytes.
- * \param output The buffer holding the output data.
- * It must be writeable and of size \p length Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
- * on failure.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_XTS)
- /**
- * \brief This function performs an AES-XTS encryption or decryption
- * operation for an entire XTS data unit.
- *
- * AES-XTS encrypts or decrypts blocks based on their location as
- * defined by a data unit number. The data unit number must be
- * provided by \p data_unit.
- *
- * NIST SP 800-38E limits the maximum size of a data unit to 2^20
- * AES blocks. If the data unit is larger than this, this function
- * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
- *
- * \param ctx The AES XTS context to use for AES XTS operations.
- * It must be initialized and bound to a key.
- * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
- * #MBEDTLS_AES_DECRYPT.
- * \param length The length of a data unit in Bytes. This can be any
- * length between 16 bytes and 2^24 bytes inclusive
- * (between 1 and 2^20 block cipher blocks).
- * \param data_unit The address of the data unit encoded as an array of 16
- * bytes in little-endian format. For disk encryption, this
- * is typically the index of the block device sector that
- * contains the data.
- * \param input The buffer holding the input data (which is an entire
- * data unit). This function reads \p length Bytes from \p
- * input.
- * \param output The buffer holding the output data (which is an entire
- * data unit). This function writes \p length Bytes to \p
- * output.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
- * smaller than an AES block in size (16 Bytes) or if \p
- * length is larger than 2^20 blocks (16 MiB).
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
- int mode,
- size_t length,
- const unsigned char data_unit[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_XTS */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- /**
- * \brief This function performs an AES-CFB128 encryption or decryption
- * operation.
- *
- * It performs the operation defined in the \p mode
- * parameter (encrypt or decrypt), on the input data buffer
- * defined in the \p input parameter.
- *
- * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
- * regardless of whether you are performing an encryption or decryption
- * operation, that is, regardless of the \p mode parameter. This is
- * because CFB mode uses the same key schedule for encryption and
- * decryption.
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the same function again on the next
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If you need to retain the contents of the
- * IV, you must either save it manually or use the cipher
- * module instead.
- *
- *
- * \param ctx The AES context to use for encryption or decryption.
- * It must be initialized and bound to a key.
- * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
- * #MBEDTLS_AES_DECRYPT.
- * \param length The length of the input data in Bytes.
- * \param iv_off The offset in IV (updated after use).
- * It must point to a valid \c size_t.
- * \param iv The initialization vector (updated after use).
- * It must be a readable and writeable buffer of \c 16 Bytes.
- * \param input The buffer holding the input data.
- * It must be readable and of size \p length Bytes.
- * \param output The buffer holding the output data.
- * It must be writeable and of size \p length Bytes.
- *
- * \return \c 0 on success.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
- int mode,
- size_t length,
- size_t *iv_off,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function performs an AES-CFB8 encryption or decryption
- * operation.
- *
- * It performs the operation defined in the \p mode
- * parameter (encrypt/decrypt), on the input data buffer defined
- * in the \p input parameter.
- *
- * Due to the nature of CFB, you must use the same key schedule for
- * both encryption and decryption operations. Therefore, you must
- * use the context initialized with mbedtls_aes_setkey_enc() for
- * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the same function again on the next
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If you need to retain the contents of the
- * IV, you should either save it manually or use the cipher
- * module instead.
- *
- *
- * \param ctx The AES context to use for encryption or decryption.
- * It must be initialized and bound to a key.
- * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
- * #MBEDTLS_AES_DECRYPT
- * \param length The length of the input data.
- * \param iv The initialization vector (updated after use).
- * It must be a readable and writeable buffer of \c 16 Bytes.
- * \param input The buffer holding the input data.
- * It must be readable and of size \p length Bytes.
- * \param output The buffer holding the output data.
- * It must be writeable and of size \p length Bytes.
- *
- * \return \c 0 on success.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /*MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_OFB)
- /**
- * \brief This function performs an AES-OFB (Output Feedback Mode)
- * encryption or decryption operation.
- *
- * For OFB, you must set up the context with
- * mbedtls_aes_setkey_enc(), regardless of whether you are
- * performing an encryption or decryption operation. This is
- * because OFB mode uses the same key schedule for encryption and
- * decryption.
- *
- * The OFB operation is identical for encryption or decryption,
- * therefore no operation mode needs to be specified.
- *
- * \note Upon exit, the content of iv, the Initialisation Vector, is
- * updated so that you can call the same function again on the next
- * block(s) of data and get the same result as if it was encrypted
- * in one call. This allows a "streaming" usage, by initialising
- * iv_off to 0 before the first call, and preserving its value
- * between calls.
- *
- * For non-streaming use, the iv should be initialised on each call
- * to a unique value, and iv_off set to 0 on each call.
- *
- * If you need to retain the contents of the initialisation vector,
- * you must either save it manually or use the cipher module
- * instead.
- *
- * \warning For the OFB mode, the initialisation vector must be unique
- * every encryption operation. Reuse of an initialisation vector
- * will compromise security.
- *
- * \param ctx The AES context to use for encryption or decryption.
- * It must be initialized and bound to a key.
- * \param length The length of the input data.
- * \param iv_off The offset in IV (updated after use).
- * It must point to a valid \c size_t.
- * \param iv The initialization vector (updated after use).
- * It must be a readable and writeable buffer of \c 16 Bytes.
- * \param input The buffer holding the input data.
- * It must be readable and of size \p length Bytes.
- * \param output The buffer holding the output data.
- * It must be writeable and of size \p length Bytes.
- *
- * \return \c 0 on success.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
- size_t length,
- size_t *iv_off,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_OFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- /**
- * \brief This function performs an AES-CTR encryption or decryption
- * operation.
- *
- * Due to the nature of CTR, you must use the same key schedule
- * for both encryption and decryption operations. Therefore, you
- * must use the context initialized with mbedtls_aes_setkey_enc()
- * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
- *
- * \warning You must never reuse a nonce value with the same key. Doing so
- * would void the encryption for the two messages encrypted with
- * the same nonce and key.
- *
- * There are two common strategies for managing nonces with CTR:
- *
- * 1. You can handle everything as a single message processed over
- * successive calls to this function. In that case, you want to
- * set \p nonce_counter and \p nc_off to 0 for the first call, and
- * then preserve the values of \p nonce_counter, \p nc_off and \p
- * stream_block across calls to this function as they will be
- * updated by this function.
- *
- * With this strategy, you must not encrypt more than 2**128
- * blocks of data with the same key.
- *
- * 2. You can encrypt separate messages by dividing the \p
- * nonce_counter buffer in two areas: the first one used for a
- * per-message nonce, handled by yourself, and the second one
- * updated by this function internally.
- *
- * For example, you might reserve the first 12 bytes for the
- * per-message nonce, and the last 4 bytes for internal use. In that
- * case, before calling this function on a new message you need to
- * set the first 12 bytes of \p nonce_counter to your chosen nonce
- * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
- * stream_block to be ignored). That way, you can encrypt at most
- * 2**96 messages of up to 2**32 blocks each with the same key.
- *
- * The per-message nonce (or information sufficient to reconstruct
- * it) needs to be communicated with the ciphertext and must be unique.
- * The recommended way to ensure uniqueness is to use a message
- * counter. An alternative is to generate random nonces, but this
- * limits the number of messages that can be securely encrypted:
- * for example, with 96-bit random nonces, you should not encrypt
- * more than 2**32 messages with the same key.
- *
- * Note that for both stategies, sizes are measured in blocks and
- * that an AES block is 16 bytes.
- *
- * \warning Upon return, \p stream_block contains sensitive data. Its
- * content must not be written to insecure storage and should be
- * securely discarded as soon as it's no longer needed.
- *
- * \param ctx The AES context to use for encryption or decryption.
- * It must be initialized and bound to a key.
- * \param length The length of the input data.
- * \param nc_off The offset in the current \p stream_block, for
- * resuming within the current cipher stream. The
- * offset pointer should be 0 at the start of a stream.
- * It must point to a valid \c size_t.
- * \param nonce_counter The 128-bit nonce and counter.
- * It must be a readable-writeable buffer of \c 16 Bytes.
- * \param stream_block The saved stream block for resuming. This is
- * overwritten by the function.
- * It must be a readable-writeable buffer of \c 16 Bytes.
- * \param input The buffer holding the input data.
- * It must be readable and of size \p length Bytes.
- * \param output The buffer holding the output data.
- * It must be writeable and of size \p length Bytes.
- *
- * \return \c 0 on success.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
- size_t length,
- size_t *nc_off,
- unsigned char nonce_counter[16],
- unsigned char stream_block[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- /**
- * \brief Internal AES block encryption function. This is only
- * exposed to allow overriding it using
- * \c MBEDTLS_AES_ENCRYPT_ALT.
- *
- * \param ctx The AES context to use for encryption.
- * \param input The plaintext block.
- * \param output The output (ciphertext) block.
- *
- * \return \c 0 on success.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] );
- /**
- * \brief Internal AES block decryption function. This is only
- * exposed to allow overriding it using see
- * \c MBEDTLS_AES_DECRYPT_ALT.
- *
- * \param ctx The AES context to use for decryption.
- * \param input The ciphertext block.
- * \param output The output (plaintext) block.
- *
- * \return \c 0 on success.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief Deprecated internal AES block encryption function
- * without return value.
- *
- * \deprecated Superseded by mbedtls_internal_aes_encrypt()
- *
- * \param ctx The AES context to use for encryption.
- * \param input Plaintext block.
- * \param output Output (ciphertext) block.
- */
- MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] );
- /**
- * \brief Deprecated internal AES block decryption function
- * without return value.
- *
- * \deprecated Superseded by mbedtls_internal_aes_decrypt()
- *
- * \param ctx The AES context to use for decryption.
- * \param input Ciphertext block.
- * \param output Output (plaintext) block.
- */
- MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
- const unsigned char input[16],
- unsigned char output[16] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- MBEDTLS_CHECK_RETURN_CRITICAL
- int mbedtls_aes_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* aes.h */
- /********* Start of file include/mbedtls/aesni.h ************/
- /**
- * \file aesni.h
- *
- * \brief AES-NI for hardware AES acceleration on some Intel processors
- *
- * \warning These functions are only for internal use by other library
- * functions; you must not call them directly.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_AESNI_H
- #define MBEDTLS_AESNI_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #define MBEDTLS_AESNI_AES 0x02000000u
- #define MBEDTLS_AESNI_CLMUL 0x00000002u
- #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
- ( defined(__amd64__) || defined(__x86_64__) ) && \
- ! defined(MBEDTLS_HAVE_X86_64)
- #define MBEDTLS_HAVE_X86_64
- #endif
- #if defined(MBEDTLS_HAVE_X86_64)
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Internal function to detect the AES-NI feature in CPUs.
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param what The feature to detect
- * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
- *
- * \return 1 if CPU has support for the feature, 0 otherwise
- */
- int mbedtls_aesni_has_support( unsigned int what );
- /**
- * \brief Internal AES-NI AES-ECB block encryption and decryption
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param ctx AES context
- * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
- * \param input 16-byte input block
- * \param output 16-byte output block
- *
- * \return 0 on success (cannot fail)
- */
- int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
- int mode,
- const unsigned char input[16],
- unsigned char output[16] );
- /**
- * \brief Internal GCM multiplication: c = a * b in GF(2^128)
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param c Result
- * \param a First operand
- * \param b Second operand
- *
- * \note Both operands and result are bit strings interpreted as
- * elements of GF(2^128) as per the GCM spec.
- */
- void mbedtls_aesni_gcm_mult( unsigned char c[16],
- const unsigned char a[16],
- const unsigned char b[16] );
- /**
- * \brief Internal round key inversion. This function computes
- * decryption round keys from the encryption round keys.
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param invkey Round keys for the equivalent inverse cipher
- * \param fwdkey Original round keys (for encryption)
- * \param nr Number of rounds (that is, number of round keys minus one)
- */
- void mbedtls_aesni_inverse_key( unsigned char *invkey,
- const unsigned char *fwdkey,
- int nr );
- /**
- * \brief Internal key expansion for encryption
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param rk Destination buffer where the round keys are written
- * \param key Encryption key
- * \param bits Key size in bits (must be 128, 192 or 256)
- *
- * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
- */
- int mbedtls_aesni_setkey_enc( unsigned char *rk,
- const unsigned char *key,
- size_t bits );
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_HAVE_X86_64 */
- #endif /* MBEDTLS_AESNI_H */
- /********* Start of file include/mbedtls/arc4.h ************/
- /**
- * \file arc4.h
- *
- * \brief The ARCFOUR stream cipher
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers instead.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- #ifndef MBEDTLS_ARC4_H
- #define MBEDTLS_ARC4_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- /* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** ARC4 hardware accelerator failed. */
- #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_ARC4_ALT)
- // Regular implementation
- //
- /**
- * \brief ARC4 context structure
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers instead.
- *
- */
- typedef struct mbedtls_arc4_context
- {
- int x; /*!< permutation index */
- int y; /*!< permutation index */
- unsigned char m[256]; /*!< permutation table */
- }
- mbedtls_arc4_context;
- #else /* MBEDTLS_ARC4_ALT */
- #endif /* MBEDTLS_ARC4_ALT */
- /**
- * \brief Initialize ARC4 context
- *
- * \param ctx ARC4 context to be initialized
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- *
- */
- void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
- /**
- * \brief Clear ARC4 context
- *
- * \param ctx ARC4 context to be cleared
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- *
- */
- void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
- /**
- * \brief ARC4 key schedule
- *
- * \param ctx ARC4 context to be setup
- * \param key the secret key
- * \param keylen length of the key, in bytes
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- *
- */
- void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
- unsigned int keylen );
- /**
- * \brief ARC4 cipher function
- *
- * \param ctx ARC4 context
- * \param length length of the input data
- * \param input buffer holding the input data
- * \param output buffer for the output data
- *
- * \return 0 if successful
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- *
- */
- int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
- unsigned char *output );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- *
- * \warning ARC4 is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- *
- */
- int mbedtls_arc4_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* arc4.h */
- /********* Start of file include/mbedtls/base64.h ************/
- /**
- * \file base64.h
- *
- * \brief RFC 1521 base64 encoding/decoding
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_BASE64_H
- #define MBEDTLS_BASE64_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- /** Output buffer too small. */
- #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A
- /** Invalid character in input. */
- #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Encode a buffer into base64 format
- *
- * \param dst destination buffer
- * \param dlen size of the destination buffer
- * \param olen number of bytes written
- * \param src source buffer
- * \param slen amount of data to be encoded
- *
- * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
- * *olen is always updated to reflect the amount
- * of data that has (or would have) been written.
- * If that length cannot be represented, then no data is
- * written to the buffer and *olen is set to the maximum
- * length representable as a size_t.
- *
- * \note Call this function with dlen = 0 to obtain the
- * required buffer size in *olen
- */
- int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
- const unsigned char *src, size_t slen );
- /**
- * \brief Decode a base64-formatted buffer
- *
- * \param dst destination buffer (can be NULL for checking size)
- * \param dlen size of the destination buffer
- * \param olen number of bytes written
- * \param src source buffer
- * \param slen amount of data to be decoded
- *
- * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
- * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
- * not correct. *olen is always updated to reflect the amount
- * of data that has (or would have) been written.
- *
- * \note Call this function with *dst = NULL or dlen = 0 to obtain
- * the required buffer size in *olen
- */
- int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
- const unsigned char *src, size_t slen );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- int mbedtls_base64_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* base64.h */
- /********* Start of file include/mbedtls/bn_mul.h ************/
- /**
- * \file bn_mul.h
- *
- * \brief Multi-precision integer library
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /*
- * Multiply source vector [s] with b, add result
- * to destination vector [d] and set carry c.
- *
- * Currently supports:
- *
- * . IA-32 (386+) . AMD64 / EM64T
- * . IA-32 (SSE2) . Motorola 68000
- * . PowerPC, 32-bit . MicroBlaze
- * . PowerPC, 64-bit . TriCore
- * . SPARC v8 . ARM v3+
- * . Alpha . MIPS32
- * . C, longlong . C, generic
- */
- #ifndef MBEDTLS_BN_MUL_H
- #define MBEDTLS_BN_MUL_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /*
- * Conversion macros for embedded constants:
- * build lists of mbedtls_mpi_uint's from lists of unsigned char's grouped by 8, 4 or 2
- */
- #if defined(MBEDTLS_HAVE_INT32)
- #define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ) \
- ( (mbedtls_mpi_uint) (a) << 0 ) | \
- ( (mbedtls_mpi_uint) (b) << 8 ) | \
- ( (mbedtls_mpi_uint) (c) << 16 ) | \
- ( (mbedtls_mpi_uint) (d) << 24 )
- #define MBEDTLS_BYTES_TO_T_UINT_2( a, b ) \
- MBEDTLS_BYTES_TO_T_UINT_4( a, b, 0, 0 )
- #define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \
- MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ), \
- MBEDTLS_BYTES_TO_T_UINT_4( e, f, g, h )
- #else /* 64-bits */
- #define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \
- ( (mbedtls_mpi_uint) (a) << 0 ) | \
- ( (mbedtls_mpi_uint) (b) << 8 ) | \
- ( (mbedtls_mpi_uint) (c) << 16 ) | \
- ( (mbedtls_mpi_uint) (d) << 24 ) | \
- ( (mbedtls_mpi_uint) (e) << 32 ) | \
- ( (mbedtls_mpi_uint) (f) << 40 ) | \
- ( (mbedtls_mpi_uint) (g) << 48 ) | \
- ( (mbedtls_mpi_uint) (h) << 56 )
- #define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ) \
- MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, 0, 0, 0, 0 )
- #define MBEDTLS_BYTES_TO_T_UINT_2( a, b ) \
- MBEDTLS_BYTES_TO_T_UINT_8( a, b, 0, 0, 0, 0, 0, 0 )
- #endif /* bits in mbedtls_mpi_uint */
- #if defined(MBEDTLS_HAVE_ASM)
- #ifndef asm
- #define asm __asm
- #endif
- /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
- #if defined(__GNUC__) && \
- ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
- /*
- * Disable use of the i386 assembly code below if option -O0, to disable all
- * compiler optimisations, is passed, detected with __OPTIMIZE__
- * This is done as the number of registers used in the assembly code doesn't
- * work with the -O0 option.
- */
- #if defined(__i386__) && defined(__OPTIMIZE__)
- #define MULADDC_INIT \
- asm( \
- "movl %%ebx, %0 \n\t" \
- "movl %5, %%esi \n\t" \
- "movl %6, %%edi \n\t" \
- "movl %7, %%ecx \n\t" \
- "movl %8, %%ebx \n\t"
- #define MULADDC_CORE \
- "lodsl \n\t" \
- "mull %%ebx \n\t" \
- "addl %%ecx, %%eax \n\t" \
- "adcl $0, %%edx \n\t" \
- "addl (%%edi), %%eax \n\t" \
- "adcl $0, %%edx \n\t" \
- "movl %%edx, %%ecx \n\t" \
- "stosl \n\t"
- #if defined(MBEDTLS_HAVE_SSE2)
- #define MULADDC_HUIT \
- "movd %%ecx, %%mm1 \n\t" \
- "movd %%ebx, %%mm0 \n\t" \
- "movd (%%edi), %%mm3 \n\t" \
- "paddq %%mm3, %%mm1 \n\t" \
- "movd (%%esi), %%mm2 \n\t" \
- "pmuludq %%mm0, %%mm2 \n\t" \
- "movd 4(%%esi), %%mm4 \n\t" \
- "pmuludq %%mm0, %%mm4 \n\t" \
- "movd 8(%%esi), %%mm6 \n\t" \
- "pmuludq %%mm0, %%mm6 \n\t" \
- "movd 12(%%esi), %%mm7 \n\t" \
- "pmuludq %%mm0, %%mm7 \n\t" \
- "paddq %%mm2, %%mm1 \n\t" \
- "movd 4(%%edi), %%mm3 \n\t" \
- "paddq %%mm4, %%mm3 \n\t" \
- "movd 8(%%edi), %%mm5 \n\t" \
- "paddq %%mm6, %%mm5 \n\t" \
- "movd 12(%%edi), %%mm4 \n\t" \
- "paddq %%mm4, %%mm7 \n\t" \
- "movd %%mm1, (%%edi) \n\t" \
- "movd 16(%%esi), %%mm2 \n\t" \
- "pmuludq %%mm0, %%mm2 \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "movd 20(%%esi), %%mm4 \n\t" \
- "pmuludq %%mm0, %%mm4 \n\t" \
- "paddq %%mm3, %%mm1 \n\t" \
- "movd 24(%%esi), %%mm6 \n\t" \
- "pmuludq %%mm0, %%mm6 \n\t" \
- "movd %%mm1, 4(%%edi) \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "movd 28(%%esi), %%mm3 \n\t" \
- "pmuludq %%mm0, %%mm3 \n\t" \
- "paddq %%mm5, %%mm1 \n\t" \
- "movd 16(%%edi), %%mm5 \n\t" \
- "paddq %%mm5, %%mm2 \n\t" \
- "movd %%mm1, 8(%%edi) \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "paddq %%mm7, %%mm1 \n\t" \
- "movd 20(%%edi), %%mm5 \n\t" \
- "paddq %%mm5, %%mm4 \n\t" \
- "movd %%mm1, 12(%%edi) \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "paddq %%mm2, %%mm1 \n\t" \
- "movd 24(%%edi), %%mm5 \n\t" \
- "paddq %%mm5, %%mm6 \n\t" \
- "movd %%mm1, 16(%%edi) \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "paddq %%mm4, %%mm1 \n\t" \
- "movd 28(%%edi), %%mm5 \n\t" \
- "paddq %%mm5, %%mm3 \n\t" \
- "movd %%mm1, 20(%%edi) \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "paddq %%mm6, %%mm1 \n\t" \
- "movd %%mm1, 24(%%edi) \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "paddq %%mm3, %%mm1 \n\t" \
- "movd %%mm1, 28(%%edi) \n\t" \
- "addl $32, %%edi \n\t" \
- "addl $32, %%esi \n\t" \
- "psrlq $32, %%mm1 \n\t" \
- "movd %%mm1, %%ecx \n\t"
- #define MULADDC_STOP \
- "emms \n\t" \
- "movl %4, %%ebx \n\t" \
- "movl %%ecx, %1 \n\t" \
- "movl %%edi, %2 \n\t" \
- "movl %%esi, %3 \n\t" \
- : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
- : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
- : "eax", "ebx", "ecx", "edx", "esi", "edi" \
- );
- #else
- #define MULADDC_STOP \
- "movl %4, %%ebx \n\t" \
- "movl %%ecx, %1 \n\t" \
- "movl %%edi, %2 \n\t" \
- "movl %%esi, %3 \n\t" \
- : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
- : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
- : "eax", "ebx", "ecx", "edx", "esi", "edi" \
- );
- #endif /* SSE2 */
- #endif /* i386 */
- #if defined(__amd64__) || defined (__x86_64__)
- #define MULADDC_INIT \
- asm( \
- "xorq %%r8, %%r8\n"
- #define MULADDC_CORE \
- "movq (%%rsi), %%rax\n" \
- "mulq %%rbx\n" \
- "addq $8, %%rsi\n" \
- "addq %%rcx, %%rax\n" \
- "movq %%r8, %%rcx\n" \
- "adcq $0, %%rdx\n" \
- "nop \n" \
- "addq %%rax, (%%rdi)\n" \
- "adcq %%rdx, %%rcx\n" \
- "addq $8, %%rdi\n"
- #define MULADDC_STOP \
- : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
- : "b" (b), "m" (*(const uint64_t (*)[16]) s) \
- : "rax", "rdx", "r8" \
- );
- #endif /* AMD64 */
- #if defined(__aarch64__)
- #define MULADDC_INIT \
- asm(
- #define MULADDC_CORE \
- "ldr x4, [%2], #8 \n\t" \
- "ldr x5, [%1] \n\t" \
- "mul x6, x4, %4 \n\t" \
- "umulh x7, x4, %4 \n\t" \
- "adds x5, x5, x6 \n\t" \
- "adc x7, x7, xzr \n\t" \
- "adds x5, x5, %0 \n\t" \
- "adc %0, x7, xzr \n\t" \
- "str x5, [%1], #8 \n\t"
- #define MULADDC_STOP \
- : "+r" (c), "+r" (d), "+r" (s), "+m" (*(uint64_t (*)[16]) d) \
- : "r" (b), "m" (*(const uint64_t (*)[16]) s) \
- : "x4", "x5", "x6", "x7", "cc" \
- );
- #endif /* Aarch64 */
- #if defined(__mc68020__) || defined(__mcpu32__)
- #define MULADDC_INIT \
- asm( \
- "movl %3, %%a2 \n\t" \
- "movl %4, %%a3 \n\t" \
- "movl %5, %%d3 \n\t" \
- "movl %6, %%d2 \n\t" \
- "moveq #0, %%d0 \n\t"
- #define MULADDC_CORE \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d4:%%d1 \n\t" \
- "addl %%d3, %%d1 \n\t" \
- "addxl %%d0, %%d4 \n\t" \
- "moveq #0, %%d3 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "addxl %%d4, %%d3 \n\t"
- #define MULADDC_STOP \
- "movl %%d3, %0 \n\t" \
- "movl %%a3, %1 \n\t" \
- "movl %%a2, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "d0", "d1", "d2", "d3", "d4", "a2", "a3" \
- );
- #define MULADDC_HUIT \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d4:%%d1 \n\t" \
- "addxl %%d3, %%d1 \n\t" \
- "addxl %%d0, %%d4 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d3:%%d1 \n\t" \
- "addxl %%d4, %%d1 \n\t" \
- "addxl %%d0, %%d3 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d4:%%d1 \n\t" \
- "addxl %%d3, %%d1 \n\t" \
- "addxl %%d0, %%d4 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d3:%%d1 \n\t" \
- "addxl %%d4, %%d1 \n\t" \
- "addxl %%d0, %%d3 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d4:%%d1 \n\t" \
- "addxl %%d3, %%d1 \n\t" \
- "addxl %%d0, %%d4 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d3:%%d1 \n\t" \
- "addxl %%d4, %%d1 \n\t" \
- "addxl %%d0, %%d3 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d4:%%d1 \n\t" \
- "addxl %%d3, %%d1 \n\t" \
- "addxl %%d0, %%d4 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "movel %%a2@+, %%d1 \n\t" \
- "mulul %%d2, %%d3:%%d1 \n\t" \
- "addxl %%d4, %%d1 \n\t" \
- "addxl %%d0, %%d3 \n\t" \
- "addl %%d1, %%a3@+ \n\t" \
- "addxl %%d0, %%d3 \n\t"
- #endif /* MC68000 */
- #if defined(__powerpc64__) || defined(__ppc64__)
- #if defined(__MACH__) && defined(__APPLE__)
- #define MULADDC_INIT \
- asm( \
- "ld r3, %3 \n\t" \
- "ld r4, %4 \n\t" \
- "ld r5, %5 \n\t" \
- "ld r6, %6 \n\t" \
- "addi r3, r3, -8 \n\t" \
- "addi r4, r4, -8 \n\t" \
- "addic r5, r5, 0 \n\t"
- #define MULADDC_CORE \
- "ldu r7, 8(r3) \n\t" \
- "mulld r8, r7, r6 \n\t" \
- "mulhdu r9, r7, r6 \n\t" \
- "adde r8, r8, r5 \n\t" \
- "ld r7, 8(r4) \n\t" \
- "addze r5, r9 \n\t" \
- "addc r8, r8, r7 \n\t" \
- "stdu r8, 8(r4) \n\t"
- #define MULADDC_STOP \
- "addze r5, r5 \n\t" \
- "addi r4, r4, 8 \n\t" \
- "addi r3, r3, 8 \n\t" \
- "std r5, %0 \n\t" \
- "std r4, %1 \n\t" \
- "std r3, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
- );
- #else /* __MACH__ && __APPLE__ */
- #define MULADDC_INIT \
- asm( \
- "ld %%r3, %3 \n\t" \
- "ld %%r4, %4 \n\t" \
- "ld %%r5, %5 \n\t" \
- "ld %%r6, %6 \n\t" \
- "addi %%r3, %%r3, -8 \n\t" \
- "addi %%r4, %%r4, -8 \n\t" \
- "addic %%r5, %%r5, 0 \n\t"
- #define MULADDC_CORE \
- "ldu %%r7, 8(%%r3) \n\t" \
- "mulld %%r8, %%r7, %%r6 \n\t" \
- "mulhdu %%r9, %%r7, %%r6 \n\t" \
- "adde %%r8, %%r8, %%r5 \n\t" \
- "ld %%r7, 8(%%r4) \n\t" \
- "addze %%r5, %%r9 \n\t" \
- "addc %%r8, %%r8, %%r7 \n\t" \
- "stdu %%r8, 8(%%r4) \n\t"
- #define MULADDC_STOP \
- "addze %%r5, %%r5 \n\t" \
- "addi %%r4, %%r4, 8 \n\t" \
- "addi %%r3, %%r3, 8 \n\t" \
- "std %%r5, %0 \n\t" \
- "std %%r4, %1 \n\t" \
- "std %%r3, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
- );
- #endif /* __MACH__ && __APPLE__ */
- #elif defined(__powerpc__) || defined(__ppc__) /* end PPC64/begin PPC32 */
- #if defined(__MACH__) && defined(__APPLE__)
- #define MULADDC_INIT \
- asm( \
- "lwz r3, %3 \n\t" \
- "lwz r4, %4 \n\t" \
- "lwz r5, %5 \n\t" \
- "lwz r6, %6 \n\t" \
- "addi r3, r3, -4 \n\t" \
- "addi r4, r4, -4 \n\t" \
- "addic r5, r5, 0 \n\t"
- #define MULADDC_CORE \
- "lwzu r7, 4(r3) \n\t" \
- "mullw r8, r7, r6 \n\t" \
- "mulhwu r9, r7, r6 \n\t" \
- "adde r8, r8, r5 \n\t" \
- "lwz r7, 4(r4) \n\t" \
- "addze r5, r9 \n\t" \
- "addc r8, r8, r7 \n\t" \
- "stwu r8, 4(r4) \n\t"
- #define MULADDC_STOP \
- "addze r5, r5 \n\t" \
- "addi r4, r4, 4 \n\t" \
- "addi r3, r3, 4 \n\t" \
- "stw r5, %0 \n\t" \
- "stw r4, %1 \n\t" \
- "stw r3, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
- );
- #else /* __MACH__ && __APPLE__ */
- #define MULADDC_INIT \
- asm( \
- "lwz %%r3, %3 \n\t" \
- "lwz %%r4, %4 \n\t" \
- "lwz %%r5, %5 \n\t" \
- "lwz %%r6, %6 \n\t" \
- "addi %%r3, %%r3, -4 \n\t" \
- "addi %%r4, %%r4, -4 \n\t" \
- "addic %%r5, %%r5, 0 \n\t"
- #define MULADDC_CORE \
- "lwzu %%r7, 4(%%r3) \n\t" \
- "mullw %%r8, %%r7, %%r6 \n\t" \
- "mulhwu %%r9, %%r7, %%r6 \n\t" \
- "adde %%r8, %%r8, %%r5 \n\t" \
- "lwz %%r7, 4(%%r4) \n\t" \
- "addze %%r5, %%r9 \n\t" \
- "addc %%r8, %%r8, %%r7 \n\t" \
- "stwu %%r8, 4(%%r4) \n\t"
- #define MULADDC_STOP \
- "addze %%r5, %%r5 \n\t" \
- "addi %%r4, %%r4, 4 \n\t" \
- "addi %%r3, %%r3, 4 \n\t" \
- "stw %%r5, %0 \n\t" \
- "stw %%r4, %1 \n\t" \
- "stw %%r3, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
- );
- #endif /* __MACH__ && __APPLE__ */
- #endif /* PPC32 */
- /*
- * The Sparc(64) assembly is reported to be broken.
- * Disable it for now, until we're able to fix it.
- */
- #if 0 && defined(__sparc__)
- #if defined(__sparc64__)
- #define MULADDC_INIT \
- asm( \
- "ldx %3, %%o0 \n\t" \
- "ldx %4, %%o1 \n\t" \
- "ld %5, %%o2 \n\t" \
- "ld %6, %%o3 \n\t"
- #define MULADDC_CORE \
- "ld [%%o0], %%o4 \n\t" \
- "inc 4, %%o0 \n\t" \
- "ld [%%o1], %%o5 \n\t" \
- "umul %%o3, %%o4, %%o4 \n\t" \
- "addcc %%o4, %%o2, %%o4 \n\t" \
- "rd %%y, %%g1 \n\t" \
- "addx %%g1, 0, %%g1 \n\t" \
- "addcc %%o4, %%o5, %%o4 \n\t" \
- "st %%o4, [%%o1] \n\t" \
- "addx %%g1, 0, %%o2 \n\t" \
- "inc 4, %%o1 \n\t"
- #define MULADDC_STOP \
- "st %%o2, %0 \n\t" \
- "stx %%o1, %1 \n\t" \
- "stx %%o0, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "g1", "o0", "o1", "o2", "o3", "o4", \
- "o5" \
- );
- #else /* __sparc64__ */
- #define MULADDC_INIT \
- asm( \
- "ld %3, %%o0 \n\t" \
- "ld %4, %%o1 \n\t" \
- "ld %5, %%o2 \n\t" \
- "ld %6, %%o3 \n\t"
- #define MULADDC_CORE \
- "ld [%%o0], %%o4 \n\t" \
- "inc 4, %%o0 \n\t" \
- "ld [%%o1], %%o5 \n\t" \
- "umul %%o3, %%o4, %%o4 \n\t" \
- "addcc %%o4, %%o2, %%o4 \n\t" \
- "rd %%y, %%g1 \n\t" \
- "addx %%g1, 0, %%g1 \n\t" \
- "addcc %%o4, %%o5, %%o4 \n\t" \
- "st %%o4, [%%o1] \n\t" \
- "addx %%g1, 0, %%o2 \n\t" \
- "inc 4, %%o1 \n\t"
- #define MULADDC_STOP \
- "st %%o2, %0 \n\t" \
- "st %%o1, %1 \n\t" \
- "st %%o0, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "g1", "o0", "o1", "o2", "o3", "o4", \
- "o5" \
- );
- #endif /* __sparc64__ */
- #endif /* __sparc__ */
- #if defined(__microblaze__) || defined(microblaze)
- #define MULADDC_INIT \
- asm( \
- "lwi r3, %3 \n\t" \
- "lwi r4, %4 \n\t" \
- "lwi r5, %5 \n\t" \
- "lwi r6, %6 \n\t" \
- "andi r7, r6, 0xffff \n\t" \
- "bsrli r6, r6, 16 \n\t"
- #define MULADDC_CORE \
- "lhui r8, r3, 0 \n\t" \
- "addi r3, r3, 2 \n\t" \
- "lhui r9, r3, 0 \n\t" \
- "addi r3, r3, 2 \n\t" \
- "mul r10, r9, r6 \n\t" \
- "mul r11, r8, r7 \n\t" \
- "mul r12, r9, r7 \n\t" \
- "mul r13, r8, r6 \n\t" \
- "bsrli r8, r10, 16 \n\t" \
- "bsrli r9, r11, 16 \n\t" \
- "add r13, r13, r8 \n\t" \
- "add r13, r13, r9 \n\t" \
- "bslli r10, r10, 16 \n\t" \
- "bslli r11, r11, 16 \n\t" \
- "add r12, r12, r10 \n\t" \
- "addc r13, r13, r0 \n\t" \
- "add r12, r12, r11 \n\t" \
- "addc r13, r13, r0 \n\t" \
- "lwi r10, r4, 0 \n\t" \
- "add r12, r12, r10 \n\t" \
- "addc r13, r13, r0 \n\t" \
- "add r12, r12, r5 \n\t" \
- "addc r5, r13, r0 \n\t" \
- "swi r12, r4, 0 \n\t" \
- "addi r4, r4, 4 \n\t"
- #define MULADDC_STOP \
- "swi r5, %0 \n\t" \
- "swi r4, %1 \n\t" \
- "swi r3, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "r3", "r4", "r5", "r6", "r7", "r8", \
- "r9", "r10", "r11", "r12", "r13" \
- );
- #endif /* MicroBlaze */
- #if defined(__tricore__)
- #define MULADDC_INIT \
- asm( \
- "ld.a %%a2, %3 \n\t" \
- "ld.a %%a3, %4 \n\t" \
- "ld.w %%d4, %5 \n\t" \
- "ld.w %%d1, %6 \n\t" \
- "xor %%d5, %%d5 \n\t"
- #define MULADDC_CORE \
- "ld.w %%d0, [%%a2+] \n\t" \
- "madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \
- "ld.w %%d0, [%%a3] \n\t" \
- "addx %%d2, %%d2, %%d0 \n\t" \
- "addc %%d3, %%d3, 0 \n\t" \
- "mov %%d4, %%d3 \n\t" \
- "st.w [%%a3+], %%d2 \n\t"
- #define MULADDC_STOP \
- "st.w %0, %%d4 \n\t" \
- "st.a %1, %%a3 \n\t" \
- "st.a %2, %%a2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "d0", "d1", "e2", "d4", "a2", "a3" \
- );
- #endif /* TriCore */
- /*
- * Note, gcc -O0 by default uses r7 for the frame pointer, so it complains about
- * our use of r7 below, unless -fomit-frame-pointer is passed.
- *
- * On the other hand, -fomit-frame-pointer is implied by any -Ox options with
- * x !=0, which we can detect using __OPTIMIZE__ (which is also defined by
- * clang and armcc5 under the same conditions).
- *
- * So, only use the optimized assembly below for optimized build, which avoids
- * the build error and is pretty reasonable anyway.
- */
- #if defined(__GNUC__) && !defined(__OPTIMIZE__)
- #define MULADDC_CANNOT_USE_R7
- #endif
- #if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
- #if defined(__thumb__) && !defined(__thumb2__)
- #define MULADDC_INIT \
- asm( \
- "ldr r0, %3 \n\t" \
- "ldr r1, %4 \n\t" \
- "ldr r2, %5 \n\t" \
- "ldr r3, %6 \n\t" \
- "lsr r7, r3, #16 \n\t" \
- "mov r9, r7 \n\t" \
- "lsl r7, r3, #16 \n\t" \
- "lsr r7, r7, #16 \n\t" \
- "mov r8, r7 \n\t"
- #define MULADDC_CORE \
- "ldmia r0!, {r6} \n\t" \
- "lsr r7, r6, #16 \n\t" \
- "lsl r6, r6, #16 \n\t" \
- "lsr r6, r6, #16 \n\t" \
- "mov r4, r8 \n\t" \
- "mul r4, r6 \n\t" \
- "mov r3, r9 \n\t" \
- "mul r6, r3 \n\t" \
- "mov r5, r9 \n\t" \
- "mul r5, r7 \n\t" \
- "mov r3, r8 \n\t" \
- "mul r7, r3 \n\t" \
- "lsr r3, r6, #16 \n\t" \
- "add r5, r5, r3 \n\t" \
- "lsr r3, r7, #16 \n\t" \
- "add r5, r5, r3 \n\t" \
- "add r4, r4, r2 \n\t" \
- "mov r2, #0 \n\t" \
- "adc r5, r2 \n\t" \
- "lsl r3, r6, #16 \n\t" \
- "add r4, r4, r3 \n\t" \
- "adc r5, r2 \n\t" \
- "lsl r3, r7, #16 \n\t" \
- "add r4, r4, r3 \n\t" \
- "adc r5, r2 \n\t" \
- "ldr r3, [r1] \n\t" \
- "add r4, r4, r3 \n\t" \
- "adc r2, r5 \n\t" \
- "stmia r1!, {r4} \n\t"
- #define MULADDC_STOP \
- "str r2, %0 \n\t" \
- "str r1, %1 \n\t" \
- "str r0, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "r0", "r1", "r2", "r3", "r4", "r5", \
- "r6", "r7", "r8", "r9", "cc" \
- );
- #elif (__ARM_ARCH >= 6) && \
- defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)
- #define MULADDC_INIT \
- asm(
- #define MULADDC_CORE \
- "ldr r0, [%0], #4 \n\t" \
- "ldr r1, [%1] \n\t" \
- "umaal r1, %2, %3, r0 \n\t" \
- "str r1, [%1], #4 \n\t"
- #define MULADDC_STOP \
- : "=r" (s), "=r" (d), "=r" (c) \
- : "r" (b), "0" (s), "1" (d), "2" (c) \
- : "r0", "r1", "memory" \
- );
- #else
- #define MULADDC_INIT \
- asm( \
- "ldr r0, %3 \n\t" \
- "ldr r1, %4 \n\t" \
- "ldr r2, %5 \n\t" \
- "ldr r3, %6 \n\t"
- #define MULADDC_CORE \
- "ldr r4, [r0], #4 \n\t" \
- "mov r5, #0 \n\t" \
- "ldr r6, [r1] \n\t" \
- "umlal r2, r5, r3, r4 \n\t" \
- "adds r7, r6, r2 \n\t" \
- "adc r2, r5, #0 \n\t" \
- "str r7, [r1], #4 \n\t"
- #define MULADDC_STOP \
- "str r2, %0 \n\t" \
- "str r1, %1 \n\t" \
- "str r0, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "r0", "r1", "r2", "r3", "r4", "r5", \
- "r6", "r7", "cc" \
- );
- #endif /* Thumb */
- #endif /* ARMv3 */
- #if defined(__alpha__)
- #define MULADDC_INIT \
- asm( \
- "ldq $1, %3 \n\t" \
- "ldq $2, %4 \n\t" \
- "ldq $3, %5 \n\t" \
- "ldq $4, %6 \n\t"
- #define MULADDC_CORE \
- "ldq $6, 0($1) \n\t" \
- "addq $1, 8, $1 \n\t" \
- "mulq $6, $4, $7 \n\t" \
- "umulh $6, $4, $6 \n\t" \
- "addq $7, $3, $7 \n\t" \
- "cmpult $7, $3, $3 \n\t" \
- "ldq $5, 0($2) \n\t" \
- "addq $7, $5, $7 \n\t" \
- "cmpult $7, $5, $5 \n\t" \
- "stq $7, 0($2) \n\t" \
- "addq $2, 8, $2 \n\t" \
- "addq $6, $3, $3 \n\t" \
- "addq $5, $3, $3 \n\t"
- #define MULADDC_STOP \
- "stq $3, %0 \n\t" \
- "stq $2, %1 \n\t" \
- "stq $1, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "$1", "$2", "$3", "$4", "$5", "$6", "$7" \
- );
- #endif /* Alpha */
- #if defined(__mips__) && !defined(__mips64)
- #define MULADDC_INIT \
- asm( \
- "lw $10, %3 \n\t" \
- "lw $11, %4 \n\t" \
- "lw $12, %5 \n\t" \
- "lw $13, %6 \n\t"
- #define MULADDC_CORE \
- "lw $14, 0($10) \n\t" \
- "multu $13, $14 \n\t" \
- "addi $10, $10, 4 \n\t" \
- "mflo $14 \n\t" \
- "mfhi $9 \n\t" \
- "addu $14, $12, $14 \n\t" \
- "lw $15, 0($11) \n\t" \
- "sltu $12, $14, $12 \n\t" \
- "addu $15, $14, $15 \n\t" \
- "sltu $14, $15, $14 \n\t" \
- "addu $12, $12, $9 \n\t" \
- "sw $15, 0($11) \n\t" \
- "addu $12, $12, $14 \n\t" \
- "addi $11, $11, 4 \n\t"
- #define MULADDC_STOP \
- "sw $12, %0 \n\t" \
- "sw $11, %1 \n\t" \
- "sw $10, %2 \n\t" \
- : "=m" (c), "=m" (d), "=m" (s) \
- : "m" (s), "m" (d), "m" (c), "m" (b) \
- : "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \
- );
- #endif /* MIPS */
- #endif /* GNUC */
- #if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
- #define MULADDC_INIT \
- __asm mov esi, s \
- __asm mov edi, d \
- __asm mov ecx, c \
- __asm mov ebx, b
- #define MULADDC_CORE \
- __asm lodsd \
- __asm mul ebx \
- __asm add eax, ecx \
- __asm adc edx, 0 \
- __asm add eax, [edi] \
- __asm adc edx, 0 \
- __asm mov ecx, edx \
- __asm stosd
- #if defined(MBEDTLS_HAVE_SSE2)
- #define EMIT __asm _emit
- #define MULADDC_HUIT \
- EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
- EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
- EMIT 0x0F EMIT 0x6E EMIT 0x1F \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
- EMIT 0x0F EMIT 0x6E EMIT 0x16 \
- EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
- EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
- EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
- EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
- EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
- EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
- EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
- EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
- EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
- EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
- EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
- EMIT 0x0F EMIT 0x7E EMIT 0x0F \
- EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
- EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
- EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
- EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
- EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
- EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
- EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
- EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
- EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
- EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
- EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
- EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
- EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
- EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
- EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
- EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
- EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
- EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
- EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
- EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
- EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
- EMIT 0x0F EMIT 0x7E EMIT 0xC9
- #define MULADDC_STOP \
- EMIT 0x0F EMIT 0x77 \
- __asm mov c, ecx \
- __asm mov d, edi \
- __asm mov s, esi \
- #else
- #define MULADDC_STOP \
- __asm mov c, ecx \
- __asm mov d, edi \
- __asm mov s, esi \
- #endif /* SSE2 */
- #endif /* MSVC */
- #endif /* MBEDTLS_HAVE_ASM */
- #if !defined(MULADDC_CORE)
- #if defined(MBEDTLS_HAVE_UDBL)
- #define MULADDC_INIT \
- { \
- mbedtls_t_udbl r; \
- mbedtls_mpi_uint r0, r1;
- #define MULADDC_CORE \
- r = *(s++) * (mbedtls_t_udbl) b; \
- r0 = (mbedtls_mpi_uint) r; \
- r1 = (mbedtls_mpi_uint)( r >> biL ); \
- r0 += c; r1 += (r0 < c); \
- r0 += *d; r1 += (r0 < *d); \
- c = r1; *(d++) = r0;
- #define MULADDC_STOP \
- }
- #else
- #define MULADDC_INIT \
- { \
- mbedtls_mpi_uint s0, s1, b0, b1; \
- mbedtls_mpi_uint r0, r1, rx, ry; \
- b0 = ( b << biH ) >> biH; \
- b1 = ( b >> biH );
- #define MULADDC_CORE \
- s0 = ( *s << biH ) >> biH; \
- s1 = ( *s >> biH ); s++; \
- rx = s0 * b1; r0 = s0 * b0; \
- ry = s1 * b0; r1 = s1 * b1; \
- r1 += ( rx >> biH ); \
- r1 += ( ry >> biH ); \
- rx <<= biH; ry <<= biH; \
- r0 += rx; r1 += (r0 < rx); \
- r0 += ry; r1 += (r0 < ry); \
- r0 += c; r1 += (r0 < c); \
- r0 += *d; r1 += (r0 < *d); \
- c = r1; *(d++) = r0;
- #define MULADDC_STOP \
- }
- #endif /* C (generic) */
- #endif /* C (longlong) */
- #endif /* bn_mul.h */
- /********* Start of file include/mbedtls/chacha20.h ************/
- /**
- * \file chacha20.h
- *
- * \brief This file contains ChaCha20 definitions and functions.
- *
- * ChaCha20 is a stream cipher that can encrypt and decrypt
- * information. ChaCha was created by Daniel Bernstein as a variant of
- * its Salsa cipher https://cr.yp.to/chacha/chacha-20080128.pdf
- * ChaCha20 is the variant with 20 rounds, that was also standardized
- * in RFC 7539.
- *
- * \author Daniel King <damaki.gh@gmail.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CHACHA20_H
- #define MBEDTLS_CHACHA20_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stdint.h>
- #include <stddef.h>
- /** Invalid input parameter(s). */
- #define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
- /* MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE is deprecated and should not be
- * used. */
- /** Feature not available. For example, s part of the API is not implemented. */
- #define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053
- /* MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED is deprecated and should not be used.
- */
- /** Chacha20 hardware accelerator failed. */
- #define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_CHACHA20_ALT)
- typedef struct mbedtls_chacha20_context
- {
- uint32_t state[16]; /*! The state (before round operations). */
- uint8_t keystream8[64]; /*! Leftover keystream bytes. */
- size_t keystream_bytes_used; /*! Number of keystream bytes already used. */
- }
- mbedtls_chacha20_context;
- #else /* MBEDTLS_CHACHA20_ALT */
- #endif /* MBEDTLS_CHACHA20_ALT */
- /**
- * \brief This function initializes the specified ChaCha20 context.
- *
- * It must be the first API called before using
- * the context.
- *
- * It is usually followed by calls to
- * \c mbedtls_chacha20_setkey() and
- * \c mbedtls_chacha20_starts(), then one or more calls to
- * to \c mbedtls_chacha20_update(), and finally to
- * \c mbedtls_chacha20_free().
- *
- * \param ctx The ChaCha20 context to initialize.
- * This must not be \c NULL.
- */
- void mbedtls_chacha20_init( mbedtls_chacha20_context *ctx );
- /**
- * \brief This function releases and clears the specified
- * ChaCha20 context.
- *
- * \param ctx The ChaCha20 context to clear. This may be \c NULL,
- * in which case this function is a no-op. If it is not
- * \c NULL, it must point to an initialized context.
- *
- */
- void mbedtls_chacha20_free( mbedtls_chacha20_context *ctx );
- /**
- * \brief This function sets the encryption/decryption key.
- *
- * \note After using this function, you must also call
- * \c mbedtls_chacha20_starts() to set a nonce before you
- * start encrypting/decrypting data with
- * \c mbedtls_chacha_update().
- *
- * \param ctx The ChaCha20 context to which the key should be bound.
- * It must be initialized.
- * \param key The encryption/decryption key. This must be \c 32 Bytes
- * in length.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or key is NULL.
- */
- int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx,
- const unsigned char key[32] );
- /**
- * \brief This function sets the nonce and initial counter value.
- *
- * \note A ChaCha20 context can be re-used with the same key by
- * calling this function to change the nonce.
- *
- * \warning You must never use the same nonce twice with the same key.
- * This would void any confidentiality guarantees for the
- * messages encrypted with the same nonce and key.
- *
- * \param ctx The ChaCha20 context to which the nonce should be bound.
- * It must be initialized and bound to a key.
- * \param nonce The nonce. This must be \c 12 Bytes in size.
- * \param counter The initial counter value. This is usually \c 0.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or nonce is
- * NULL.
- */
- int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx,
- const unsigned char nonce[12],
- uint32_t counter );
- /**
- * \brief This function encrypts or decrypts data.
- *
- * Since ChaCha20 is a stream cipher, the same operation is
- * used for encrypting and decrypting data.
- *
- * \note The \p input and \p output pointers must either be equal or
- * point to non-overlapping buffers.
- *
- * \note \c mbedtls_chacha20_setkey() and
- * \c mbedtls_chacha20_starts() must be called at least once
- * to setup the context before this function can be called.
- *
- * \note This function can be called multiple times in a row in
- * order to encrypt of decrypt data piecewise with the same
- * key and nonce.
- *
- * \param ctx The ChaCha20 context to use for encryption or decryption.
- * It must be initialized and bound to a key and nonce.
- * \param size The length of the input data in Bytes.
- * \param input The buffer holding the input data.
- * This pointer can be \c NULL if `size == 0`.
- * \param output The buffer holding the output data.
- * This must be able to hold \p size Bytes.
- * This pointer can be \c NULL if `size == 0`.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
- size_t size,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function encrypts or decrypts data with ChaCha20 and
- * the given key and nonce.
- *
- * Since ChaCha20 is a stream cipher, the same operation is
- * used for encrypting and decrypting data.
- *
- * \warning You must never use the same (key, nonce) pair more than
- * once. This would void any confidentiality guarantees for
- * the messages encrypted with the same nonce and key.
- *
- * \note The \p input and \p output pointers must either be equal or
- * point to non-overlapping buffers.
- *
- * \param key The encryption/decryption key.
- * This must be \c 32 Bytes in length.
- * \param nonce The nonce. This must be \c 12 Bytes in size.
- * \param counter The initial counter value. This is usually \c 0.
- * \param size The length of the input data in Bytes.
- * \param input The buffer holding the input data.
- * This pointer can be \c NULL if `size == 0`.
- * \param output The buffer holding the output data.
- * This must be able to hold \p size Bytes.
- * This pointer can be \c NULL if `size == 0`.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_chacha20_crypt( const unsigned char key[32],
- const unsigned char nonce[12],
- uint32_t counter,
- size_t size,
- const unsigned char* input,
- unsigned char* output );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The ChaCha20 checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_chacha20_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_CHACHA20_H */
- /********* Start of file include/mbedtls/poly1305.h ************/
- /**
- * \file poly1305.h
- *
- * \brief This file contains Poly1305 definitions and functions.
- *
- * Poly1305 is a one-time message authenticator that can be used to
- * authenticate messages. Poly1305-AES was created by Daniel
- * Bernstein https://cr.yp.to/mac/poly1305-20050329.pdf The generic
- * Poly1305 algorithm (not tied to AES) was also standardized in RFC
- * 7539.
- *
- * \author Daniel King <damaki.gh@gmail.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_POLY1305_H
- #define MBEDTLS_POLY1305_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stdint.h>
- #include <stddef.h>
- /** Invalid input parameter(s). */
- #define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0057
- /* MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE is deprecated and should not be
- * used. */
- /** Feature not available. For example, s part of the API is not implemented. */
- #define MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE -0x0059
- /* MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED is deprecated and should not be used.
- */
- /** Poly1305 hardware accelerator failed. */
- #define MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED -0x005B
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_POLY1305_ALT)
- typedef struct mbedtls_poly1305_context
- {
- uint32_t r[4]; /** The value for 'r' (low 128 bits of the key). */
- uint32_t s[4]; /** The value for 's' (high 128 bits of the key). */
- uint32_t acc[5]; /** The accumulator number. */
- uint8_t queue[16]; /** The current partial block of data. */
- size_t queue_len; /** The number of bytes stored in 'queue'. */
- }
- mbedtls_poly1305_context;
- #else /* MBEDTLS_POLY1305_ALT */
- #endif /* MBEDTLS_POLY1305_ALT */
- /**
- * \brief This function initializes the specified Poly1305 context.
- *
- * It must be the first API called before using
- * the context.
- *
- * It is usually followed by a call to
- * \c mbedtls_poly1305_starts(), then one or more calls to
- * \c mbedtls_poly1305_update(), then one call to
- * \c mbedtls_poly1305_finish(), then finally
- * \c mbedtls_poly1305_free().
- *
- * \param ctx The Poly1305 context to initialize. This must
- * not be \c NULL.
- */
- void mbedtls_poly1305_init( mbedtls_poly1305_context *ctx );
- /**
- * \brief This function releases and clears the specified
- * Poly1305 context.
- *
- * \param ctx The Poly1305 context to clear. This may be \c NULL, in which
- * case this function is a no-op. If it is not \c NULL, it must
- * point to an initialized Poly1305 context.
- */
- void mbedtls_poly1305_free( mbedtls_poly1305_context *ctx );
- /**
- * \brief This function sets the one-time authentication key.
- *
- * \warning The key must be unique and unpredictable for each
- * invocation of Poly1305.
- *
- * \param ctx The Poly1305 context to which the key should be bound.
- * This must be initialized.
- * \param key The buffer containing the \c 32 Byte (\c 256 Bit) key.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx,
- const unsigned char key[32] );
- /**
- * \brief This functions feeds an input buffer into an ongoing
- * Poly1305 computation.
- *
- * It is called between \c mbedtls_cipher_poly1305_starts() and
- * \c mbedtls_cipher_poly1305_finish().
- * It can be called repeatedly to process a stream of data.
- *
- * \param ctx The Poly1305 context to use for the Poly1305 operation.
- * This must be initialized and bound to a key.
- * \param ilen The length of the input data in Bytes.
- * Any value is accepted.
- * \param input The buffer holding the input data.
- * This pointer can be \c NULL if `ilen == 0`.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief This function generates the Poly1305 Message
- * Authentication Code (MAC).
- *
- * \param ctx The Poly1305 context to use for the Poly1305 operation.
- * This must be initialized and bound to a key.
- * \param mac The buffer to where the MAC is written. This must
- * be a writable buffer of length \c 16 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx,
- unsigned char mac[16] );
- /**
- * \brief This function calculates the Poly1305 MAC of the input
- * buffer with the provided key.
- *
- * \warning The key must be unique and unpredictable for each
- * invocation of Poly1305.
- *
- * \param key The buffer containing the \c 32 Byte (\c 256 Bit) key.
- * \param ilen The length of the input data in Bytes.
- * Any value is accepted.
- * \param input The buffer holding the input data.
- * This pointer can be \c NULL if `ilen == 0`.
- * \param mac The buffer to where the MAC is written. This must be
- * a writable buffer of length \c 16 Bytes.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_poly1305_mac( const unsigned char key[32],
- const unsigned char *input,
- size_t ilen,
- unsigned char mac[16] );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The Poly1305 checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_poly1305_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_POLY1305_H */
- /********* Start of file include/mbedtls/chachapoly.h ************/
- /**
- * \file chachapoly.h
- *
- * \brief This file contains the AEAD-ChaCha20-Poly1305 definitions and
- * functions.
- *
- * ChaCha20-Poly1305 is an algorithm for Authenticated Encryption
- * with Associated Data (AEAD) that can be used to encrypt and
- * authenticate data. It is based on ChaCha20 and Poly1305 by Daniel
- * Bernstein and was standardized in RFC 7539.
- *
- * \author Daniel King <damaki.gh@gmail.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CHACHAPOLY_H
- #define MBEDTLS_CHACHAPOLY_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /* for shared error codes */
- /** The requested operation is not permitted in the current state. */
- #define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054
- /** Authenticated decryption failed: data was not authentic. */
- #define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef enum
- {
- MBEDTLS_CHACHAPOLY_ENCRYPT, /**< The mode value for performing encryption. */
- MBEDTLS_CHACHAPOLY_DECRYPT /**< The mode value for performing decryption. */
- }
- mbedtls_chachapoly_mode_t;
- #if !defined(MBEDTLS_CHACHAPOLY_ALT)
- typedef struct mbedtls_chachapoly_context
- {
- mbedtls_chacha20_context chacha20_ctx; /**< The ChaCha20 context. */
- mbedtls_poly1305_context poly1305_ctx; /**< The Poly1305 context. */
- uint64_t aad_len; /**< The length (bytes) of the Additional Authenticated Data. */
- uint64_t ciphertext_len; /**< The length (bytes) of the ciphertext. */
- int state; /**< The current state of the context. */
- mbedtls_chachapoly_mode_t mode; /**< Cipher mode (encrypt or decrypt). */
- }
- mbedtls_chachapoly_context;
- #else /* !MBEDTLS_CHACHAPOLY_ALT */
- #endif /* !MBEDTLS_CHACHAPOLY_ALT */
- /**
- * \brief This function initializes the specified ChaCha20-Poly1305 context.
- *
- * It must be the first API called before using
- * the context. It must be followed by a call to
- * \c mbedtls_chachapoly_setkey() before any operation can be
- * done, and to \c mbedtls_chachapoly_free() once all
- * operations with that context have been finished.
- *
- * In order to encrypt or decrypt full messages at once, for
- * each message you should make a single call to
- * \c mbedtls_chachapoly_crypt_and_tag() or
- * \c mbedtls_chachapoly_auth_decrypt().
- *
- * In order to encrypt messages piecewise, for each
- * message you should make a call to
- * \c mbedtls_chachapoly_starts(), then 0 or more calls to
- * \c mbedtls_chachapoly_update_aad(), then 0 or more calls to
- * \c mbedtls_chachapoly_update(), then one call to
- * \c mbedtls_chachapoly_finish().
- *
- * \warning Decryption with the piecewise API is discouraged! Always
- * use \c mbedtls_chachapoly_auth_decrypt() when possible!
- *
- * If however this is not possible because the data is too
- * large to fit in memory, you need to:
- *
- * - call \c mbedtls_chachapoly_starts() and (if needed)
- * \c mbedtls_chachapoly_update_aad() as above,
- * - call \c mbedtls_chachapoly_update() multiple times and
- * ensure its output (the plaintext) is NOT used in any other
- * way than placing it in temporary storage at this point,
- * - call \c mbedtls_chachapoly_finish() to compute the
- * authentication tag and compared it in constant time to the
- * tag received with the ciphertext.
- *
- * If the tags are not equal, you must immediately discard
- * all previous outputs of \c mbedtls_chachapoly_update(),
- * otherwise you can now safely use the plaintext.
- *
- * \param ctx The ChachaPoly context to initialize. Must not be \c NULL.
- */
- void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
- /**
- * \brief This function releases and clears the specified
- * ChaCha20-Poly1305 context.
- *
- * \param ctx The ChachaPoly context to clear. This may be \c NULL, in which
- * case this function is a no-op.
- */
- void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
- /**
- * \brief This function sets the ChaCha20-Poly1305
- * symmetric encryption key.
- *
- * \param ctx The ChaCha20-Poly1305 context to which the key should be
- * bound. This must be initialized.
- * \param key The \c 256 Bit (\c 32 Bytes) key.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
- const unsigned char key[32] );
- /**
- * \brief This function starts a ChaCha20-Poly1305 encryption or
- * decryption operation.
- *
- * \warning You must never use the same nonce twice with the same key.
- * This would void any confidentiality and authenticity
- * guarantees for the messages encrypted with the same nonce
- * and key.
- *
- * \note If the context is being used for AAD only (no data to
- * encrypt or decrypt) then \p mode can be set to any value.
- *
- * \warning Decryption with the piecewise API is discouraged, see the
- * warning on \c mbedtls_chachapoly_init().
- *
- * \param ctx The ChaCha20-Poly1305 context. This must be initialized
- * and bound to a key.
- * \param nonce The nonce/IV to use for the message.
- * This must be a redable buffer of length \c 12 Bytes.
- * \param mode The operation to perform: #MBEDTLS_CHACHAPOLY_ENCRYPT or
- * #MBEDTLS_CHACHAPOLY_DECRYPT (discouraged, see warning).
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
- const unsigned char nonce[12],
- mbedtls_chachapoly_mode_t mode );
- /**
- * \brief This function feeds additional data to be authenticated
- * into an ongoing ChaCha20-Poly1305 operation.
- *
- * The Additional Authenticated Data (AAD), also called
- * Associated Data (AD) is only authenticated but not
- * encrypted nor included in the encrypted output. It is
- * usually transmitted separately from the ciphertext or
- * computed locally by each party.
- *
- * \note This function is called before data is encrypted/decrypted.
- * I.e. call this function to process the AAD before calling
- * \c mbedtls_chachapoly_update().
- *
- * You may call this function multiple times to process
- * an arbitrary amount of AAD. It is permitted to call
- * this function 0 times, if no AAD is used.
- *
- * This function cannot be called any more if data has
- * been processed by \c mbedtls_chachapoly_update(),
- * or if the context has been finished.
- *
- * \warning Decryption with the piecewise API is discouraged, see the
- * warning on \c mbedtls_chachapoly_init().
- *
- * \param ctx The ChaCha20-Poly1305 context. This must be initialized
- * and bound to a key.
- * \param aad_len The length in Bytes of the AAD. The length has no
- * restrictions.
- * \param aad Buffer containing the AAD.
- * This pointer can be \c NULL if `aad_len == 0`.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA
- * if \p ctx or \p aad are NULL.
- * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE
- * if the operations has not been started or has been
- * finished, or if the AAD has been finished.
- */
- int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
- const unsigned char *aad,
- size_t aad_len );
- /**
- * \brief Thus function feeds data to be encrypted or decrypted
- * into an on-going ChaCha20-Poly1305
- * operation.
- *
- * The direction (encryption or decryption) depends on the
- * mode that was given when calling
- * \c mbedtls_chachapoly_starts().
- *
- * You may call this function multiple times to process
- * an arbitrary amount of data. It is permitted to call
- * this function 0 times, if no data is to be encrypted
- * or decrypted.
- *
- * \warning Decryption with the piecewise API is discouraged, see the
- * warning on \c mbedtls_chachapoly_init().
- *
- * \param ctx The ChaCha20-Poly1305 context to use. This must be initialized.
- * \param len The length (in bytes) of the data to encrypt or decrypt.
- * \param input The buffer containing the data to encrypt or decrypt.
- * This pointer can be \c NULL if `len == 0`.
- * \param output The buffer to where the encrypted or decrypted data is
- * written. This must be able to hold \p len bytes.
- * This pointer can be \c NULL if `len == 0`.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE
- * if the operation has not been started or has been
- * finished.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
- size_t len,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function finished the ChaCha20-Poly1305 operation and
- * generates the MAC (authentication tag).
- *
- * \param ctx The ChaCha20-Poly1305 context to use. This must be initialized.
- * \param mac The buffer to where the 128-bit (16 bytes) MAC is written.
- *
- * \warning Decryption with the piecewise API is discouraged, see the
- * warning on \c mbedtls_chachapoly_init().
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE
- * if the operation has not been started or has been
- * finished.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
- unsigned char mac[16] );
- /**
- * \brief This function performs a complete ChaCha20-Poly1305
- * authenticated encryption with the previously-set key.
- *
- * \note Before using this function, you must set the key with
- * \c mbedtls_chachapoly_setkey().
- *
- * \warning You must never use the same nonce twice with the same key.
- * This would void any confidentiality and authenticity
- * guarantees for the messages encrypted with the same nonce
- * and key.
- *
- * \param ctx The ChaCha20-Poly1305 context to use (holds the key).
- * This must be initialized.
- * \param length The length (in bytes) of the data to encrypt or decrypt.
- * \param nonce The 96-bit (12 bytes) nonce/IV to use.
- * \param aad The buffer containing the additional authenticated
- * data (AAD). This pointer can be \c NULL if `aad_len == 0`.
- * \param aad_len The length (in bytes) of the AAD data to process.
- * \param input The buffer containing the data to encrypt or decrypt.
- * This pointer can be \c NULL if `ilen == 0`.
- * \param output The buffer to where the encrypted or decrypted data
- * is written. This pointer can be \c NULL if `ilen == 0`.
- * \param tag The buffer to where the computed 128-bit (16 bytes) MAC
- * is written. This must not be \c NULL.
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
- size_t length,
- const unsigned char nonce[12],
- const unsigned char *aad,
- size_t aad_len,
- const unsigned char *input,
- unsigned char *output,
- unsigned char tag[16] );
- /**
- * \brief This function performs a complete ChaCha20-Poly1305
- * authenticated decryption with the previously-set key.
- *
- * \note Before using this function, you must set the key with
- * \c mbedtls_chachapoly_setkey().
- *
- * \param ctx The ChaCha20-Poly1305 context to use (holds the key).
- * \param length The length (in Bytes) of the data to decrypt.
- * \param nonce The \c 96 Bit (\c 12 bytes) nonce/IV to use.
- * \param aad The buffer containing the additional authenticated data (AAD).
- * This pointer can be \c NULL if `aad_len == 0`.
- * \param aad_len The length (in bytes) of the AAD data to process.
- * \param tag The buffer holding the authentication tag.
- * This must be a readable buffer of length \c 16 Bytes.
- * \param input The buffer containing the data to decrypt.
- * This pointer can be \c NULL if `ilen == 0`.
- * \param output The buffer to where the decrypted data is written.
- * This pointer can be \c NULL if `ilen == 0`.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED
- * if the data was not authentic.
- * \return Another negative error code on other kinds of failure.
- */
- int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
- size_t length,
- const unsigned char nonce[12],
- const unsigned char *aad,
- size_t aad_len,
- const unsigned char tag[16],
- const unsigned char *input,
- unsigned char *output );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The ChaCha20-Poly1305 checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_chachapoly_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_CHACHAPOLY_H */
- /********* Start of file include/mbedtls/camellia.h ************/
- /**
- * \file camellia.h
- *
- * \brief Camellia block cipher
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CAMELLIA_H
- #define MBEDTLS_CAMELLIA_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- #define MBEDTLS_CAMELLIA_ENCRYPT 1
- #define MBEDTLS_CAMELLIA_DECRYPT 0
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0024 )
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /** Bad input data. */
- #define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024
- /** Invalid data input length. */
- #define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026
- /* MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED is deprecated and should not be used.
- */
- /** Camellia hardware accelerator failed. */
- #define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_CAMELLIA_ALT)
- // Regular implementation
- //
- /**
- * \brief CAMELLIA context structure
- */
- typedef struct mbedtls_camellia_context
- {
- int nr; /*!< number of rounds */
- uint32_t rk[68]; /*!< CAMELLIA round keys */
- }
- mbedtls_camellia_context;
- #else /* MBEDTLS_CAMELLIA_ALT */
- #endif /* MBEDTLS_CAMELLIA_ALT */
- /**
- * \brief Initialize a CAMELLIA context.
- *
- * \param ctx The CAMELLIA context to be initialized.
- * This must not be \c NULL.
- */
- void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
- /**
- * \brief Clear a CAMELLIA context.
- *
- * \param ctx The CAMELLIA context to be cleared. This may be \c NULL,
- * in which case this function returns immediately. If it is not
- * \c NULL, it must be initialized.
- */
- void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
- /**
- * \brief Perform a CAMELLIA key schedule operation for encryption.
- *
- * \param ctx The CAMELLIA context to use. This must be initialized.
- * \param key The encryption key to use. This must be a readable buffer
- * of size \p keybits Bits.
- * \param keybits The length of \p key in Bits. This must be either \c 128,
- * \c 192 or \c 256.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
- const unsigned char *key,
- unsigned int keybits );
- /**
- * \brief Perform a CAMELLIA key schedule operation for decryption.
- *
- * \param ctx The CAMELLIA context to use. This must be initialized.
- * \param key The decryption key. This must be a readable buffer
- * of size \p keybits Bits.
- * \param keybits The length of \p key in Bits. This must be either \c 128,
- * \c 192 or \c 256.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx,
- const unsigned char *key,
- unsigned int keybits );
- /**
- * \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
- *
- * \param ctx The CAMELLIA context to use. This must be initialized
- * and bound to a key.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
- * \param input The input block. This must be a readable buffer
- * of size \c 16 Bytes.
- * \param output The output block. This must be a writable buffer
- * of size \c 16 Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
- int mode,
- const unsigned char input[16],
- unsigned char output[16] );
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- /**
- * \brief Perform a CAMELLIA-CBC buffer encryption/decryption operation.
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the function same function again on the following
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If on the other hand you need to retain the contents of the
- * IV, you should either save it manually or use the cipher
- * module instead.
- *
- * \param ctx The CAMELLIA context to use. This must be initialized
- * and bound to a key.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
- * \param length The length in Bytes of the input data \p input.
- * This must be a multiple of \c 16 Bytes.
- * \param iv The initialization vector. This must be a read/write buffer
- * of length \c 16 Bytes. It is updated to allow streaming
- * use as explained above.
- * \param input The buffer holding the input data. This must point to a
- * readable buffer of length \p length Bytes.
- * \param output The buffer holding the output data. This must point to a
- * writable buffer of length \p length Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- /**
- * \brief Perform a CAMELLIA-CFB128 buffer encryption/decryption
- * operation.
- *
- * \note Due to the nature of CFB mode, you should use the same
- * key for both encryption and decryption. In particular, calls
- * to this function should be preceded by a key-schedule via
- * mbedtls_camellia_setkey_enc() regardless of whether \p mode
- * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the function same function again on the following
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If on the other hand you need to retain the contents of the
- * IV, you should either save it manually or use the cipher
- * module instead.
- *
- * \param ctx The CAMELLIA context to use. This must be initialized
- * and bound to a key.
- * \param mode The mode of operation. This must be either
- * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
- * \param length The length of the input data \p input. Any value is allowed.
- * \param iv_off The current offset in the IV. This must be smaller
- * than \c 16 Bytes. It is updated after this call to allow
- * the aforementioned streaming usage.
- * \param iv The initialization vector. This must be a read/write buffer
- * of length \c 16 Bytes. It is updated after this call to
- * allow the aforementioned streaming usage.
- * \param input The buffer holding the input data. This must be a readable
- * buffer of size \p length Bytes.
- * \param output The buffer to hold the output data. This must be a writable
- * buffer of length \p length Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
- int mode,
- size_t length,
- size_t *iv_off,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- /**
- * \brief Perform a CAMELLIA-CTR buffer encryption/decryption operation.
- *
- * *note Due to the nature of CTR mode, you should use the same
- * key for both encryption and decryption. In particular, calls
- * to this function should be preceded by a key-schedule via
- * mbedtls_camellia_setkey_enc() regardless of whether \p mode
- * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
- *
- * \warning You must never reuse a nonce value with the same key. Doing so
- * would void the encryption for the two messages encrypted with
- * the same nonce and key.
- *
- * There are two common strategies for managing nonces with CTR:
- *
- * 1. You can handle everything as a single message processed over
- * successive calls to this function. In that case, you want to
- * set \p nonce_counter and \p nc_off to 0 for the first call, and
- * then preserve the values of \p nonce_counter, \p nc_off and \p
- * stream_block across calls to this function as they will be
- * updated by this function.
- *
- * With this strategy, you must not encrypt more than 2**128
- * blocks of data with the same key.
- *
- * 2. You can encrypt separate messages by dividing the \p
- * nonce_counter buffer in two areas: the first one used for a
- * per-message nonce, handled by yourself, and the second one
- * updated by this function internally.
- *
- * For example, you might reserve the first \c 12 Bytes for the
- * per-message nonce, and the last \c 4 Bytes for internal use.
- * In that case, before calling this function on a new message you
- * need to set the first \c 12 Bytes of \p nonce_counter to your
- * chosen nonce value, the last four to \c 0, and \p nc_off to \c 0
- * (which will cause \p stream_block to be ignored). That way, you
- * can encrypt at most \c 2**96 messages of up to \c 2**32 blocks
- * each with the same key.
- *
- * The per-message nonce (or information sufficient to reconstruct
- * it) needs to be communicated with the ciphertext and must be
- * unique. The recommended way to ensure uniqueness is to use a
- * message counter. An alternative is to generate random nonces,
- * but this limits the number of messages that can be securely
- * encrypted: for example, with 96-bit random nonces, you should
- * not encrypt more than 2**32 messages with the same key.
- *
- * Note that for both stategies, sizes are measured in blocks and
- * that a CAMELLIA block is \c 16 Bytes.
- *
- * \warning Upon return, \p stream_block contains sensitive data. Its
- * content must not be written to insecure storage and should be
- * securely discarded as soon as it's no longer needed.
- *
- * \param ctx The CAMELLIA context to use. This must be initialized
- * and bound to a key.
- * \param length The length of the input data \p input in Bytes.
- * Any value is allowed.
- * \param nc_off The offset in the current \p stream_block (for resuming
- * within current cipher stream). The offset pointer to
- * should be \c 0 at the start of a stream. It is updated
- * at the end of this call.
- * \param nonce_counter The 128-bit nonce and counter. This must be a read/write
- * buffer of length \c 16 Bytes.
- * \param stream_block The saved stream-block for resuming. This must be a
- * read/write buffer of length \c 16 Bytes.
- * \param input The input data stream. This must be a readable buffer of
- * size \p length Bytes.
- * \param output The output data stream. This must be a writable buffer
- * of size \p length Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
- size_t length,
- size_t *nc_off,
- unsigned char nonce_counter[16],
- unsigned char stream_block[16],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- int mbedtls_camellia_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* camellia.h */
- /********* Start of file include/mbedtls/ctr_drbg.h ************/
- /**
- * \file ctr_drbg.h
- *
- * \brief This file contains definitions and functions for the
- * CTR_DRBG pseudorandom generator.
- *
- * CTR_DRBG is a standardized way of building a PRNG from a block-cipher
- * in counter mode operation, as defined in <em>NIST SP 800-90A:
- * Recommendation for Random Number Generation Using Deterministic Random
- * Bit Generators</em>.
- *
- * The Mbed TLS implementation of CTR_DRBG uses AES-256 (default) or AES-128
- * (if \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled at compile time)
- * as the underlying block cipher, with a derivation function.
- *
- * The security strength as defined in NIST SP 800-90A is
- * 128 bits when AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled)
- * and 256 bits otherwise, provided that #MBEDTLS_CTR_DRBG_ENTROPY_LEN is
- * kept at its default value (and not overridden in config.h) and that the
- * DRBG instance is set up with default parameters.
- * See the documentation of mbedtls_ctr_drbg_seed() for more
- * information.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CTR_DRBG_H
- #define MBEDTLS_CTR_DRBG_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_THREADING_C)
- #endif
- /** The entropy source failed. */
- #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
- /** The requested random buffer length is too big. */
- #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
- /** The input (entropy + additional data) is too large. */
- #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
- /** Read or write error in file. */
- #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
- #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */
- #if defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY)
- #define MBEDTLS_CTR_DRBG_KEYSIZE 16
- /**< The key size in bytes used by the cipher.
- *
- * Compile-time choice: 16 bytes (128 bits)
- * because #MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled.
- */
- #else
- #define MBEDTLS_CTR_DRBG_KEYSIZE 32
- /**< The key size in bytes used by the cipher.
- *
- * Compile-time choice: 32 bytes (256 bits)
- * because \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is disabled.
- */
- #endif
- #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) /**< The key size for the DRBG operation, in bits. */
- #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) /**< The seed length, calculated as (counter + AES key). */
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them using the compiler command
- * line.
- * \{
- */
- /** \def MBEDTLS_CTR_DRBG_ENTROPY_LEN
- *
- * \brief The amount of entropy used per seed by default, in bytes.
- */
- #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
- #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
- /** This is 48 bytes because the entropy module uses SHA-512
- * (\c MBEDTLS_ENTROPY_FORCE_SHA256 is disabled).
- */
- #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
- #else /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
- /** This is 32 bytes because the entropy module uses SHA-256
- * (the SHA512 module is disabled or
- * \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled).
- */
- #if !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY)
- /** \warning To achieve a 256-bit security strength, you must pass a nonce
- * to mbedtls_ctr_drbg_seed().
- */
- #endif /* !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY) */
- #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
- #endif /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
- #endif /* !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) */
- #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
- #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
- /**< The interval before reseed is performed by default. */
- #endif
- #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
- #define MBEDTLS_CTR_DRBG_MAX_INPUT 256
- /**< The maximum number of additional input Bytes. */
- #endif
- #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
- #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
- /**< The maximum number of requested Bytes per call. */
- #endif
- #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
- #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
- /**< The maximum size of seed or reseed buffer in bytes. */
- #endif
- /* \} name SECTION: Module settings */
- #define MBEDTLS_CTR_DRBG_PR_OFF 0
- /**< Prediction resistance is disabled. */
- #define MBEDTLS_CTR_DRBG_PR_ON 1
- /**< Prediction resistance is enabled. */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if MBEDTLS_CTR_DRBG_ENTROPY_LEN >= MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
- /** The default length of the nonce read from the entropy source.
- *
- * This is \c 0 because a single read from the entropy source is sufficient
- * to include a nonce.
- * See the documentation of mbedtls_ctr_drbg_seed() for more information.
- */
- #define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN 0
- #else
- /** The default length of the nonce read from the entropy source.
- *
- * This is half of the default entropy length because a single read from
- * the entropy source does not provide enough material to form a nonce.
- * See the documentation of mbedtls_ctr_drbg_seed() for more information.
- */
- #define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN ( MBEDTLS_CTR_DRBG_ENTROPY_LEN + 1 ) / 2
- #endif
- /**
- * \brief The CTR_DRBG context structure.
- */
- typedef struct mbedtls_ctr_drbg_context
- {
- unsigned char counter[16]; /*!< The counter (V). */
- int reseed_counter; /*!< The reseed counter.
- * This is the number of requests that have
- * been made since the last (re)seeding,
- * minus one.
- * Before the initial seeding, this field
- * contains the amount of entropy in bytes
- * to use as a nonce for the initial seeding,
- * or -1 if no nonce length has been explicitly
- * set (see mbedtls_ctr_drbg_set_nonce_len()).
- */
- int prediction_resistance; /*!< This determines whether prediction
- resistance is enabled, that is
- whether to systematically reseed before
- each random generation. */
- size_t entropy_len; /*!< The amount of entropy grabbed on each
- seed or reseed operation, in bytes. */
- int reseed_interval; /*!< The reseed interval.
- * This is the maximum number of requests
- * that can be made between reseedings. */
- mbedtls_aes_context aes_ctx; /*!< The AES context. */
- /*
- * Callbacks (Entropy)
- */
- int (*f_entropy)(void *, unsigned char *, size_t);
- /*!< The entropy callback function. */
- void *p_entropy; /*!< The context for the entropy function. */
- #if defined(MBEDTLS_THREADING_C)
- /* Invariant: the mutex is initialized if and only if f_entropy != NULL.
- * This means that the mutex is initialized during the initial seeding
- * in mbedtls_ctr_drbg_seed() and freed in mbedtls_ctr_drbg_free().
- *
- * Note that this invariant may change without notice. Do not rely on it
- * and do not access the mutex directly in application code.
- */
- mbedtls_threading_mutex_t mutex;
- #endif
- }
- mbedtls_ctr_drbg_context;
- /**
- * \brief This function initializes the CTR_DRBG context,
- * and prepares it for mbedtls_ctr_drbg_seed()
- * or mbedtls_ctr_drbg_free().
- *
- * \note The reseed interval is
- * #MBEDTLS_CTR_DRBG_RESEED_INTERVAL by default.
- * You can override it by calling
- * mbedtls_ctr_drbg_set_reseed_interval().
- *
- * \param ctx The CTR_DRBG context to initialize.
- */
- void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
- /**
- * \brief This function seeds and sets up the CTR_DRBG
- * entropy source for future reseeds.
- *
- * A typical choice for the \p f_entropy and \p p_entropy parameters is
- * to use the entropy module:
- * - \p f_entropy is mbedtls_entropy_func();
- * - \p p_entropy is an instance of ::mbedtls_entropy_context initialized
- * with mbedtls_entropy_init() (which registers the platform's default
- * entropy sources).
- *
- * The entropy length is #MBEDTLS_CTR_DRBG_ENTROPY_LEN by default.
- * You can override it by calling mbedtls_ctr_drbg_set_entropy_len().
- *
- * The entropy nonce length is:
- * - \c 0 if the entropy length is at least 3/2 times the entropy length,
- * which guarantees that the security strength is the maximum permitted
- * by the key size and entropy length according to NIST SP 800-90A §10.2.1;
- * - Half the entropy length otherwise.
- * You can override it by calling mbedtls_ctr_drbg_set_nonce_len().
- * With the default entropy length, the entropy nonce length is
- * #MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN.
- *
- * You can provide a nonce and personalization string in addition to the
- * entropy source, to make this instantiation as unique as possible.
- * See SP 800-90A §8.6.7 for more details about nonces.
- *
- * The _seed_material_ value passed to the derivation function in
- * the CTR_DRBG Instantiate Process described in NIST SP 800-90A §10.2.1.3.2
- * is the concatenation of the following strings:
- * - A string obtained by calling \p f_entropy function for the entropy
- * length.
- */
- #if MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN == 0
- /**
- * - If mbedtls_ctr_drbg_set_nonce_len() has been called, a string
- * obtained by calling \p f_entropy function for the specified length.
- */
- #else
- /**
- * - A string obtained by calling \p f_entropy function for the entropy nonce
- * length. If the entropy nonce length is \c 0, this function does not
- * make a second call to \p f_entropy.
- */
- #endif
- #if defined(MBEDTLS_THREADING_C)
- /**
- * \note When Mbed TLS is built with threading support,
- * after this function returns successfully,
- * it is safe to call mbedtls_ctr_drbg_random()
- * from multiple threads. Other operations, including
- * reseeding, are not thread-safe.
- */
- #endif /* MBEDTLS_THREADING_C */
- /**
- * - The \p custom string.
- *
- * \note To achieve the nominal security strength permitted
- * by CTR_DRBG, the entropy length must be:
- * - at least 16 bytes for a 128-bit strength
- * (maximum achievable strength when using AES-128);
- * - at least 32 bytes for a 256-bit strength
- * (maximum achievable strength when using AES-256).
- *
- * In addition, if you do not pass a nonce in \p custom,
- * the sum of the entropy length
- * and the entropy nonce length must be:
- * - at least 24 bytes for a 128-bit strength
- * (maximum achievable strength when using AES-128);
- * - at least 48 bytes for a 256-bit strength
- * (maximum achievable strength when using AES-256).
- *
- * \param ctx The CTR_DRBG context to seed.
- * It must have been initialized with
- * mbedtls_ctr_drbg_init().
- * After a successful call to mbedtls_ctr_drbg_seed(),
- * you may not call mbedtls_ctr_drbg_seed() again on
- * the same context unless you call
- * mbedtls_ctr_drbg_free() and mbedtls_ctr_drbg_init()
- * again first.
- * After a failed call to mbedtls_ctr_drbg_seed(),
- * you must call mbedtls_ctr_drbg_free().
- * \param f_entropy The entropy callback, taking as arguments the
- * \p p_entropy context, the buffer to fill, and the
- * length of the buffer.
- * \p f_entropy is always called with a buffer size
- * less than or equal to the entropy length.
- * \param p_entropy The entropy context to pass to \p f_entropy.
- * \param custom The personalization string.
- * This can be \c NULL, in which case the personalization
- * string is empty regardless of the value of \p len.
- * \param len The length of the personalization string.
- * This must be at most
- * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
- * - #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
- */
- int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
- int (*f_entropy)(void *, unsigned char *, size_t),
- void *p_entropy,
- const unsigned char *custom,
- size_t len );
- /**
- * \brief This function resets CTR_DRBG context to the state immediately
- * after initial call of mbedtls_ctr_drbg_init().
- *
- * \param ctx The CTR_DRBG context to clear.
- */
- void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
- /**
- * \brief This function turns prediction resistance on or off.
- * The default value is off.
- *
- * \note If enabled, entropy is gathered at the beginning of
- * every call to mbedtls_ctr_drbg_random_with_add()
- * or mbedtls_ctr_drbg_random().
- * Only use this if your entropy source has sufficient
- * throughput.
- *
- * \param ctx The CTR_DRBG context.
- * \param resistance #MBEDTLS_CTR_DRBG_PR_ON or #MBEDTLS_CTR_DRBG_PR_OFF.
- */
- void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
- int resistance );
- /**
- * \brief This function sets the amount of entropy grabbed on each
- * seed or reseed.
- *
- * The default value is #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
- *
- * \note The security strength of CTR_DRBG is bounded by the
- * entropy length. Thus:
- * - When using AES-256
- * (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is disabled,
- * which is the default),
- * \p len must be at least 32 (in bytes)
- * to achieve a 256-bit strength.
- * - When using AES-128
- * (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled)
- * \p len must be at least 16 (in bytes)
- * to achieve a 128-bit strength.
- *
- * \param ctx The CTR_DRBG context.
- * \param len The amount of entropy to grab, in bytes.
- * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
- * and at most the maximum length accepted by the
- * entropy function that is set in the context.
- */
- void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
- size_t len );
- /**
- * \brief This function sets the amount of entropy grabbed
- * as a nonce for the initial seeding.
- *
- * Call this function before calling mbedtls_ctr_drbg_seed() to read
- * a nonce from the entropy source during the initial seeding.
- *
- * \param ctx The CTR_DRBG context.
- * \param len The amount of entropy to grab for the nonce, in bytes.
- * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
- * and at most the maximum length accepted by the
- * entropy function that is set in the context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if \p len is
- * more than #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
- * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
- * if the initial seeding has already taken place.
- */
- int mbedtls_ctr_drbg_set_nonce_len( mbedtls_ctr_drbg_context *ctx,
- size_t len );
- /**
- * \brief This function sets the reseed interval.
- *
- * The reseed interval is the number of calls to mbedtls_ctr_drbg_random()
- * or mbedtls_ctr_drbg_random_with_add() after which the entropy function
- * is called again.
- *
- * The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL.
- *
- * \param ctx The CTR_DRBG context.
- * \param interval The reseed interval.
- */
- void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
- int interval );
- /**
- * \brief This function reseeds the CTR_DRBG context, that is
- * extracts data from the entropy source.
- *
- * \note This function is not thread-safe. It is not safe
- * to call this function if another thread might be
- * concurrently obtaining random numbers from the same
- * context or updating or reseeding the same context.
- *
- * \param ctx The CTR_DRBG context.
- * \param additional Additional data to add to the state. Can be \c NULL.
- * \param len The length of the additional data.
- * This must be less than
- * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - \c entropy_len
- * where \c entropy_len is the entropy length
- * configured for the context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
- */
- int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
- const unsigned char *additional, size_t len );
- /**
- * \brief This function updates the state of the CTR_DRBG context.
- *
- * \note This function is not thread-safe. It is not safe
- * to call this function if another thread might be
- * concurrently obtaining random numbers from the same
- * context or updating or reseeding the same context.
- *
- * \param ctx The CTR_DRBG context.
- * \param additional The data to update the state with. This must not be
- * \c NULL unless \p add_len is \c 0.
- * \param add_len Length of \p additional in bytes. This must be at
- * most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if
- * \p add_len is more than
- * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
- * \return An error from the underlying AES cipher on failure.
- */
- int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx,
- const unsigned char *additional,
- size_t add_len );
- /**
- * \brief This function updates a CTR_DRBG instance with additional
- * data and uses it to generate random data.
- *
- * This function automatically reseeds if the reseed counter is exceeded
- * or prediction resistance is enabled.
- *
- * \note This function is not thread-safe. It is not safe
- * to call this function if another thread might be
- * concurrently obtaining random numbers from the same
- * context or updating or reseeding the same context.
- *
- * \param p_rng The CTR_DRBG context. This must be a pointer to a
- * #mbedtls_ctr_drbg_context structure.
- * \param output The buffer to fill.
- * \param output_len The length of the buffer in bytes.
- * \param additional Additional data to update. Can be \c NULL, in which
- * case the additional data is empty regardless of
- * the value of \p add_len.
- * \param add_len The length of the additional data
- * if \p additional is not \c NULL.
- * This must be less than #MBEDTLS_CTR_DRBG_MAX_INPUT
- * and less than
- * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - \c entropy_len
- * where \c entropy_len is the entropy length
- * configured for the context.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
- * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
- */
- int mbedtls_ctr_drbg_random_with_add( void *p_rng,
- unsigned char *output, size_t output_len,
- const unsigned char *additional, size_t add_len );
- /**
- * \brief This function uses CTR_DRBG to generate random data.
- *
- * This function automatically reseeds if the reseed counter is exceeded
- * or prediction resistance is enabled.
- */
- #if defined(MBEDTLS_THREADING_C)
- /**
- * \note When Mbed TLS is built with threading support,
- * it is safe to call mbedtls_ctr_drbg_random()
- * from multiple threads. Other operations, including
- * reseeding, are not thread-safe.
- */
- #endif /* MBEDTLS_THREADING_C */
- /**
- * \param p_rng The CTR_DRBG context. This must be a pointer to a
- * #mbedtls_ctr_drbg_context structure.
- * \param output The buffer to fill.
- * \param output_len The length of the buffer in bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
- * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
- */
- int mbedtls_ctr_drbg_random( void *p_rng,
- unsigned char *output, size_t output_len );
- #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function updates the state of the CTR_DRBG context.
- *
- * \deprecated Superseded by mbedtls_ctr_drbg_update_ret()
- * in 2.16.0.
- *
- * \note If \p add_len is greater than
- * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, only the first
- * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used.
- * The remaining Bytes are silently discarded.
- *
- * \param ctx The CTR_DRBG context.
- * \param additional The data to update the state with.
- * \param add_len Length of \p additional data.
- */
- MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update(
- mbedtls_ctr_drbg_context *ctx,
- const unsigned char *additional,
- size_t add_len );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief This function writes a seed file.
- *
- * \param ctx The CTR_DRBG context.
- * \param path The name of the file.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error.
- * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on reseed
- * failure.
- */
- int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
- /**
- * \brief This function reads and updates a seed file. The seed
- * is added to this instance.
- *
- * \param ctx The CTR_DRBG context.
- * \param path The name of the file.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error.
- * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on
- * reseed failure.
- * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if the existing
- * seed file is too large.
- */
- int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
- #endif /* MBEDTLS_FS_IO */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The CTR_DRBG checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_ctr_drbg_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* ctr_drbg.h */
- /********* Start of file include/mbedtls/des.h ************/
- /**
- * \file des.h
- *
- * \brief DES block cipher
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- #ifndef MBEDTLS_DES_H
- #define MBEDTLS_DES_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- #define MBEDTLS_DES_ENCRYPT 1
- #define MBEDTLS_DES_DECRYPT 0
- /** The data input has an invalid length. */
- #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
- /* MBEDTLS_ERR_DES_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** DES hardware accelerator failed. */
- #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
- #define MBEDTLS_DES_KEY_SIZE 8
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_DES_ALT)
- // Regular implementation
- //
- /**
- * \brief DES context structure
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- typedef struct mbedtls_des_context
- {
- uint32_t sk[32]; /*!< DES subkeys */
- }
- mbedtls_des_context;
- /**
- * \brief Triple-DES context structure
- */
- typedef struct mbedtls_des3_context
- {
- uint32_t sk[96]; /*!< 3DES subkeys */
- }
- mbedtls_des3_context;
- #else /* MBEDTLS_DES_ALT */
- #endif /* MBEDTLS_DES_ALT */
- /**
- * \brief Initialize DES context
- *
- * \param ctx DES context to be initialized
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- void mbedtls_des_init( mbedtls_des_context *ctx );
- /**
- * \brief Clear DES context
- *
- * \param ctx DES context to be cleared
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- void mbedtls_des_free( mbedtls_des_context *ctx );
- /**
- * \brief Initialize Triple-DES context
- *
- * \param ctx DES3 context to be initialized
- */
- void mbedtls_des3_init( mbedtls_des3_context *ctx );
- /**
- * \brief Clear Triple-DES context
- *
- * \param ctx DES3 context to be cleared
- */
- void mbedtls_des3_free( mbedtls_des3_context *ctx );
- /**
- * \brief Set key parity on the given key to odd.
- *
- * DES keys are 56 bits long, but each byte is padded with
- * a parity bit to allow verification.
- *
- * \param key 8-byte secret key
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
- /**
- * \brief Check that key parity on the given key is odd.
- *
- * DES keys are 56 bits long, but each byte is padded with
- * a parity bit to allow verification.
- *
- * \param key 8-byte secret key
- *
- * \return 0 is parity was ok, 1 if parity was not correct.
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
- /**
- * \brief Check that key is not a weak or semi-weak DES key
- *
- * \param key 8-byte secret key
- *
- * \return 0 if no weak key was found, 1 if a weak key was identified.
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
- /**
- * \brief DES key schedule (56-bit, encryption)
- *
- * \param ctx DES context to be initialized
- * \param key 8-byte secret key
- *
- * \return 0
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
- /**
- * \brief DES key schedule (56-bit, decryption)
- *
- * \param ctx DES context to be initialized
- * \param key 8-byte secret key
- *
- * \return 0
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
- /**
- * \brief Triple-DES key schedule (112-bit, encryption)
- *
- * \param ctx 3DES context to be initialized
- * \param key 16-byte secret key
- *
- * \return 0
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
- const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
- /**
- * \brief Triple-DES key schedule (112-bit, decryption)
- *
- * \param ctx 3DES context to be initialized
- * \param key 16-byte secret key
- *
- * \return 0
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
- const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
- /**
- * \brief Triple-DES key schedule (168-bit, encryption)
- *
- * \param ctx 3DES context to be initialized
- * \param key 24-byte secret key
- *
- * \return 0
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
- const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
- /**
- * \brief Triple-DES key schedule (168-bit, decryption)
- *
- * \param ctx 3DES context to be initialized
- * \param key 24-byte secret key
- *
- * \return 0
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
- const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
- /**
- * \brief DES-ECB block encryption/decryption
- *
- * \param ctx DES context
- * \param input 64-bit input block
- * \param output 64-bit output block
- *
- * \return 0 if successful
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
- const unsigned char input[8],
- unsigned char output[8] );
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- /**
- * \brief DES-CBC buffer encryption/decryption
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the function same function again on the following
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If on the other hand you need to retain the contents of the
- * IV, you should either save it manually or use the cipher
- * module instead.
- *
- * \param ctx DES context
- * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
- * \param length length of the input data
- * \param iv initialization vector (updated after use)
- * \param input buffer holding the input data
- * \param output buffer holding the output data
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[8],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- /**
- * \brief 3DES-ECB block encryption/decryption
- *
- * \param ctx 3DES context
- * \param input 64-bit input block
- * \param output 64-bit output block
- *
- * \return 0 if successful
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
- const unsigned char input[8],
- unsigned char output[8] );
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- /**
- * \brief 3DES-CBC buffer encryption/decryption
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the function same function again on the following
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If on the other hand you need to retain the contents of the
- * IV, you should either save it manually or use the cipher
- * module instead.
- *
- * \param ctx 3DES context
- * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
- * \param length length of the input data
- * \param iv initialization vector (updated after use)
- * \param input buffer holding the input data
- * \param output buffer holding the output data
- *
- * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
- */
- MBEDTLS_CHECK_RETURN_TYPICAL
- int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[8],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- /**
- * \brief Internal function for key expansion.
- * (Only exposed to allow overriding it,
- * see MBEDTLS_DES_SETKEY_ALT)
- *
- * \param SK Round keys
- * \param key Base key
- *
- * \warning DES is considered a weak cipher and its use constitutes a
- * security risk. We recommend considering stronger ciphers
- * instead.
- */
- void mbedtls_des_setkey( uint32_t SK[32],
- const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- MBEDTLS_CHECK_RETURN_CRITICAL
- int mbedtls_des_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* des.h */
- /********* Start of file include/mbedtls/entropy.h ************/
- /**
- * \file entropy.h
- *
- * \brief Entropy accumulator implementation
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ENTROPY_H
- #define MBEDTLS_ENTROPY_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
- #define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR
- #else
- #if defined(MBEDTLS_SHA256_C)
- #define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR
- #endif
- #endif
- #if defined(MBEDTLS_THREADING_C)
- #endif
- #if defined(MBEDTLS_HAVEGE_C)
- #endif
- /** Critical entropy source failure. */
- #define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C
- /** No more sources can be added. */
- #define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E
- /** No sources have been added to poll. */
- #define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
- /** No strong sources have been added to poll. */
- #define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D
- /** Read/write error in file. */
- #define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- #if !defined(MBEDTLS_ENTROPY_MAX_SOURCES)
- #define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
- #endif
- #if !defined(MBEDTLS_ENTROPY_MAX_GATHER)
- #define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
- #endif
- /* \} name SECTION: Module settings */
- #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
- #define MBEDTLS_ENTROPY_BLOCK_SIZE 64 /**< Block size of entropy accumulator (SHA-512) */
- #else
- #define MBEDTLS_ENTROPY_BLOCK_SIZE 32 /**< Block size of entropy accumulator (SHA-256) */
- #endif
- #define MBEDTLS_ENTROPY_MAX_SEED_SIZE 1024 /**< Maximum size of seed we read from seed file */
- #define MBEDTLS_ENTROPY_SOURCE_MANUAL MBEDTLS_ENTROPY_MAX_SOURCES
- #define MBEDTLS_ENTROPY_SOURCE_STRONG 1 /**< Entropy source is strong */
- #define MBEDTLS_ENTROPY_SOURCE_WEAK 0 /**< Entropy source is weak */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Entropy poll callback pointer
- *
- * \param data Callback-specific data pointer
- * \param output Data to fill
- * \param len Maximum size to provide
- * \param olen The actual amount of bytes put into the buffer (Can be 0)
- *
- * \return 0 if no critical failures occurred,
- * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED otherwise
- */
- typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len,
- size_t *olen);
- /**
- * \brief Entropy source state
- */
- typedef struct mbedtls_entropy_source_state
- {
- mbedtls_entropy_f_source_ptr f_source; /**< The entropy source callback */
- void * p_source; /**< The callback data pointer */
- size_t size; /**< Amount received in bytes */
- size_t threshold; /**< Minimum bytes required before release */
- int strong; /**< Is the source strong? */
- }
- mbedtls_entropy_source_state;
- /**
- * \brief Entropy context structure
- */
- typedef struct mbedtls_entropy_context
- {
- int accumulator_started; /* 0 after init.
- * 1 after the first update.
- * -1 after free. */
- #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
- mbedtls_sha512_context accumulator;
- #elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR)
- mbedtls_sha256_context accumulator;
- #endif
- int source_count; /* Number of entries used in source. */
- mbedtls_entropy_source_state source[MBEDTLS_ENTROPY_MAX_SOURCES];
- #if defined(MBEDTLS_HAVEGE_C)
- mbedtls_havege_state havege_data;
- #endif
- #if defined(MBEDTLS_THREADING_C)
- mbedtls_threading_mutex_t mutex; /*!< mutex */
- #endif
- #if defined(MBEDTLS_ENTROPY_NV_SEED)
- int initial_entropy_run;
- #endif
- }
- mbedtls_entropy_context;
- /**
- * \brief Initialize the context
- *
- * \param ctx Entropy context to initialize
- */
- void mbedtls_entropy_init( mbedtls_entropy_context *ctx );
- /**
- * \brief Free the data in the context
- *
- * \param ctx Entropy context to free
- */
- void mbedtls_entropy_free( mbedtls_entropy_context *ctx );
- /**
- * \brief Adds an entropy source to poll
- * (Thread-safe if MBEDTLS_THREADING_C is enabled)
- *
- * \param ctx Entropy context
- * \param f_source Entropy function
- * \param p_source Function data
- * \param threshold Minimum required from source before entropy is released
- * ( with mbedtls_entropy_func() ) (in bytes)
- * \param strong MBEDTLS_ENTROPY_SOURCE_STRONG or
- * MBEDTLS_ENTROPY_SOURCE_WEAK.
- * At least one strong source needs to be added.
- * Weaker sources (such as the cycle counter) can be used as
- * a complement.
- *
- * \return 0 if successful or MBEDTLS_ERR_ENTROPY_MAX_SOURCES
- */
- int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx,
- mbedtls_entropy_f_source_ptr f_source, void *p_source,
- size_t threshold, int strong );
- /**
- * \brief Trigger an extra gather poll for the accumulator
- * (Thread-safe if MBEDTLS_THREADING_C is enabled)
- *
- * \param ctx Entropy context
- *
- * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
- */
- int mbedtls_entropy_gather( mbedtls_entropy_context *ctx );
- /**
- * \brief Retrieve entropy from the accumulator
- * (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE)
- * (Thread-safe if MBEDTLS_THREADING_C is enabled)
- *
- * \param data Entropy context
- * \param output Buffer to fill
- * \param len Number of bytes desired, must be at most MBEDTLS_ENTROPY_BLOCK_SIZE
- *
- * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
- */
- int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
- /**
- * \brief Add data to the accumulator manually
- * (Thread-safe if MBEDTLS_THREADING_C is enabled)
- *
- * \param ctx Entropy context
- * \param data Data to add
- * \param len Length of data
- *
- * \return 0 if successful
- */
- int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
- const unsigned char *data, size_t len );
- #if defined(MBEDTLS_ENTROPY_NV_SEED)
- /**
- * \brief Trigger an update of the seed file in NV by using the
- * current entropy pool.
- *
- * \param ctx Entropy context
- *
- * \return 0 if successful
- */
- int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
- #endif /* MBEDTLS_ENTROPY_NV_SEED */
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief Write a seed file
- *
- * \param ctx Entropy context
- * \param path Name of the file
- *
- * \return 0 if successful,
- * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error, or
- * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
- */
- int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path );
- /**
- * \brief Read and update a seed file. Seed is added to this
- * instance. No more than MBEDTLS_ENTROPY_MAX_SEED_SIZE bytes are
- * read from the seed file. The rest is ignored.
- *
- * \param ctx Entropy context
- * \param path Name of the file
- *
- * \return 0 if successful,
- * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error,
- * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
- */
- int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
- #endif /* MBEDTLS_FS_IO */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * This module self-test also calls the entropy self-test,
- * mbedtls_entropy_source_self_test();
- *
- * \return 0 if successful, or 1 if a test failed
- */
- int mbedtls_entropy_self_test( int verbose );
- #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
- /**
- * \brief Checkup routine
- *
- * Verifies the integrity of the hardware entropy source
- * provided by the function 'mbedtls_hardware_poll()'.
- *
- * Note this is the only hardware entropy source that is known
- * at link time, and other entropy sources configured
- * dynamically at runtime by the function
- * mbedtls_entropy_add_source() will not be tested.
- *
- * \return 0 if successful, or 1 if a test failed
- */
- int mbedtls_entropy_source_self_test( int verbose );
- #endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* entropy.h */
- /********* Start of file include/mbedtls/entropy_poll.h ************/
- /**
- * \file entropy_poll.h
- *
- * \brief Platform-specific and custom entropy polling functions
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ENTROPY_POLL_H
- #define MBEDTLS_ENTROPY_POLL_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*
- * Default thresholds for built-in sources, in bytes
- */
- #define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */
- #define MBEDTLS_ENTROPY_MIN_HAVEGE 32 /**< Minimum for HAVEGE */
- #define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */
- #if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
- #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
- #endif
- /**
- * \brief Entropy poll callback that provides 0 entropy.
- */
- #if defined(MBEDTLS_TEST_NULL_ENTROPY)
- int mbedtls_null_entropy_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
- #endif
- #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
- /**
- * \brief Platform-specific entropy poll callback
- */
- int mbedtls_platform_entropy_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
- #endif
- #if defined(MBEDTLS_HAVEGE_C)
- /**
- * \brief HAVEGE based entropy poll callback
- *
- * Requires an HAVEGE state as its data pointer.
- */
- int mbedtls_havege_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
- #endif
- #if defined(MBEDTLS_TIMING_C)
- /**
- * \brief mbedtls_timing_hardclock-based entropy poll callback
- */
- int mbedtls_hardclock_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
- #endif
- #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
- /**
- * \brief Entropy poll callback for a hardware source
- *
- * \warning This is not provided by mbed TLS!
- * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h.
- *
- * \note This must accept NULL as its first argument.
- */
- int mbedtls_hardware_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
- #endif
- #if defined(MBEDTLS_ENTROPY_NV_SEED)
- /**
- * \brief Entropy poll callback for a non-volatile seed file
- *
- * \note This must accept NULL as its first argument.
- */
- int mbedtls_nv_seed_poll( void *data,
- unsigned char *output, size_t len, size_t *olen );
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* entropy_poll.h */
- /********* Start of file include/mbedtls/havege.h ************/
- /**
- * \file havege.h
- *
- * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_HAVEGE_H
- #define MBEDTLS_HAVEGE_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief HAVEGE state structure
- */
- typedef struct mbedtls_havege_state
- {
- uint32_t PT1, PT2, offset[2];
- uint32_t pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
- uint32_t WALK[8192];
- }
- mbedtls_havege_state;
- /**
- * \brief HAVEGE initialization
- *
- * \param hs HAVEGE state to be initialized
- */
- void mbedtls_havege_init( mbedtls_havege_state *hs );
- /**
- * \brief Clear HAVEGE state
- *
- * \param hs HAVEGE state to be cleared
- */
- void mbedtls_havege_free( mbedtls_havege_state *hs );
- /**
- * \brief HAVEGE rand function
- *
- * \param p_rng A HAVEGE state
- * \param output Buffer to fill
- * \param len Length of buffer
- *
- * \return 0
- */
- int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
- #ifdef __cplusplus
- }
- #endif
- #endif /* havege.h */
- /********* Start of file include/mbedtls/memory_buffer_alloc.h ************/
- /**
- * \file memory_buffer_alloc.h
- *
- * \brief Buffer-based memory allocator
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_MEMORY_BUFFER_ALLOC_H
- #define MBEDTLS_MEMORY_BUFFER_ALLOC_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- #if !defined(MBEDTLS_MEMORY_ALIGN_MULTIPLE)
- #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
- #endif
- /* \} name SECTION: Module settings */
- #define MBEDTLS_MEMORY_VERIFY_NONE 0
- #define MBEDTLS_MEMORY_VERIFY_ALLOC (1 << 0)
- #define MBEDTLS_MEMORY_VERIFY_FREE (1 << 1)
- #define MBEDTLS_MEMORY_VERIFY_ALWAYS (MBEDTLS_MEMORY_VERIFY_ALLOC | MBEDTLS_MEMORY_VERIFY_FREE)
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Initialize use of stack-based memory allocator.
- * The stack-based allocator does memory management inside the
- * presented buffer and does not call calloc() and free().
- * It sets the global mbedtls_calloc() and mbedtls_free() pointers
- * to its own functions.
- * (Provided mbedtls_calloc() and mbedtls_free() are thread-safe if
- * MBEDTLS_THREADING_C is defined)
- *
- * \note This code is not optimized and provides a straight-forward
- * implementation of a stack-based memory allocator.
- *
- * \param buf buffer to use as heap
- * \param len size of the buffer
- */
- void mbedtls_memory_buffer_alloc_init( unsigned char *buf, size_t len );
- /**
- * \brief Free the mutex for thread-safety and clear remaining memory
- */
- void mbedtls_memory_buffer_alloc_free( void );
- /**
- * \brief Determine when the allocator should automatically verify the state
- * of the entire chain of headers / meta-data.
- * (Default: MBEDTLS_MEMORY_VERIFY_NONE)
- *
- * \param verify One of MBEDTLS_MEMORY_VERIFY_NONE, MBEDTLS_MEMORY_VERIFY_ALLOC,
- * MBEDTLS_MEMORY_VERIFY_FREE or MBEDTLS_MEMORY_VERIFY_ALWAYS
- */
- void mbedtls_memory_buffer_set_verify( int verify );
- #if defined(MBEDTLS_MEMORY_DEBUG)
- /**
- * \brief Print out the status of the allocated memory (primarily for use
- * after a program should have de-allocated all memory)
- * Prints out a list of 'still allocated' blocks and their stack
- * trace if MBEDTLS_MEMORY_BACKTRACE is defined.
- */
- void mbedtls_memory_buffer_alloc_status( void );
- /**
- * \brief Get the peak heap usage so far
- *
- * \param max_used Peak number of bytes in use or committed. This
- * includes bytes in allocated blocks too small to split
- * into smaller blocks but larger than the requested size.
- * \param max_blocks Peak number of blocks in use, including free and used
- */
- void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks );
- /**
- * \brief Reset peak statistics
- */
- void mbedtls_memory_buffer_alloc_max_reset( void );
- /**
- * \brief Get the current heap usage
- *
- * \param cur_used Current number of bytes in use or committed. This
- * includes bytes in allocated blocks too small to split
- * into smaller blocks but larger than the requested size.
- * \param cur_blocks Current number of blocks in use, including free and used
- */
- void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks );
- #endif /* MBEDTLS_MEMORY_DEBUG */
- /**
- * \brief Verifies that all headers in the memory buffer are correct
- * and contain sane values. Helps debug buffer-overflow errors.
- *
- * Prints out first failure if MBEDTLS_MEMORY_DEBUG is defined.
- * Prints out full header information if MBEDTLS_MEMORY_DEBUG
- * is defined. (Includes stack trace information for each block if
- * MBEDTLS_MEMORY_BACKTRACE is defined as well).
- *
- * \return 0 if verified, 1 otherwise
- */
- int mbedtls_memory_buffer_alloc_verify( void );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if a test failed
- */
- int mbedtls_memory_buffer_alloc_self_test( int verbose );
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* memory_buffer_alloc.h */
- /********* Start of file include/mbedtls/padlock.h ************/
- /**
- * \file padlock.h
- *
- * \brief VIA PadLock ACE for HW encryption/decryption supported by some
- * processors
- *
- * \warning These functions are only for internal use by other library
- * functions; you must not call them directly.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PADLOCK_H
- #define MBEDTLS_PADLOCK_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /** Input data should be aligned. */
- #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030
- #if defined(__has_feature)
- #if __has_feature(address_sanitizer)
- #define MBEDTLS_HAVE_ASAN
- #endif
- #endif
- /* Some versions of ASan result in errors about not enough registers */
- #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
- !defined(MBEDTLS_HAVE_ASAN)
- #ifndef MBEDTLS_HAVE_X86
- #define MBEDTLS_HAVE_X86
- #endif
- #include <stdint.h>
- #define MBEDTLS_PADLOCK_RNG 0x000C
- #define MBEDTLS_PADLOCK_ACE 0x00C0
- #define MBEDTLS_PADLOCK_PHE 0x0C00
- #define MBEDTLS_PADLOCK_PMM 0x3000
- #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Internal PadLock detection routine
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param feature The feature to detect
- *
- * \return non-zero if CPU has support for the feature, 0 otherwise
- */
- int mbedtls_padlock_has_support( int feature );
- /**
- * \brief Internal PadLock AES-ECB block en(de)cryption
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param ctx AES context
- * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
- * \param input 16-byte input block
- * \param output 16-byte output block
- *
- * \return 0 if success, 1 if operation failed
- */
- int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
- int mode,
- const unsigned char input[16],
- unsigned char output[16] );
- /**
- * \brief Internal PadLock AES-CBC buffer en(de)cryption
- *
- * \note This function is only for internal use by other library
- * functions; you must not call it directly.
- *
- * \param ctx AES context
- * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
- * \param length length of the input data
- * \param iv initialization vector (updated after use)
- * \param input buffer holding the input data
- * \param output buffer holding the output data
- *
- * \return 0 if success, 1 if operation failed
- */
- int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[16],
- const unsigned char *input,
- unsigned char *output );
- #ifdef __cplusplus
- }
- #endif
- #endif /* HAVE_X86 */
- #endif /* padlock.h */
- /********* Start of file include/mbedtls/timing.h ************/
- /**
- * \file timing.h
- *
- * \brief Portable interface to timeouts and to the CPU cycle counter
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_TIMING_H
- #define MBEDTLS_TIMING_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stdint.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_TIMING_ALT)
- // Regular implementation
- //
- /**
- * \brief timer structure
- */
- struct mbedtls_timing_hr_time
- {
- unsigned char opaque[32];
- };
- /**
- * \brief Context for mbedtls_timing_set/get_delay()
- */
- typedef struct mbedtls_timing_delay_context
- {
- struct mbedtls_timing_hr_time timer;
- uint32_t int_ms;
- uint32_t fin_ms;
- } mbedtls_timing_delay_context;
- #else /* MBEDTLS_TIMING_ALT */
- #endif /* MBEDTLS_TIMING_ALT */
- extern volatile int mbedtls_timing_alarmed;
- /**
- * \brief Return the CPU cycle counter value
- *
- * \warning This is only a best effort! Do not rely on this!
- * In particular, it is known to be unreliable on virtual
- * machines.
- *
- * \note This value starts at an unspecified origin and
- * may wrap around.
- */
- unsigned long mbedtls_timing_hardclock( void );
- /**
- * \brief Return the elapsed time in milliseconds
- *
- * \param val points to a timer structure
- * \param reset If 0, query the elapsed time. Otherwise (re)start the timer.
- *
- * \return Elapsed time since the previous reset in ms. When
- * restarting, this is always 0.
- *
- * \note To initialize a timer, call this function with reset=1.
- *
- * Determining the elapsed time and resetting the timer is not
- * atomic on all platforms, so after the sequence
- * `{ get_timer(1); ...; time1 = get_timer(1); ...; time2 =
- * get_timer(0) }` the value time1+time2 is only approximately
- * the delay since the first reset.
- */
- unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset );
- /**
- * \brief Setup an alarm clock
- *
- * \param seconds delay before the "mbedtls_timing_alarmed" flag is set
- * (must be >=0)
- *
- * \warning Only one alarm at a time is supported. In a threaded
- * context, this means one for the whole process, not one per
- * thread.
- */
- void mbedtls_set_alarm( int seconds );
- /**
- * \brief Set a pair of delays to watch
- * (See \c mbedtls_timing_get_delay().)
- *
- * \param data Pointer to timing data.
- * Must point to a valid \c mbedtls_timing_delay_context struct.
- * \param int_ms First (intermediate) delay in milliseconds.
- * The effect if int_ms > fin_ms is unspecified.
- * \param fin_ms Second (final) delay in milliseconds.
- * Pass 0 to cancel the current delay.
- *
- * \note To set a single delay, either use \c mbedtls_timing_set_timer
- * directly or use this function with int_ms == fin_ms.
- */
- void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms );
- /**
- * \brief Get the status of delays
- * (Memory helper: number of delays passed.)
- *
- * \param data Pointer to timing data
- * Must point to a valid \c mbedtls_timing_delay_context struct.
- *
- * \return -1 if cancelled (fin_ms = 0),
- * 0 if none of the delays are passed,
- * 1 if only the intermediate delay is passed,
- * 2 if the final delay is passed.
- */
- int mbedtls_timing_get_delay( void *data );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if a test failed
- */
- int mbedtls_timing_self_test( int verbose );
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* timing.h */
- /********* Start of file include/mbedtls/xtea.h ************/
- /**
- * \file xtea.h
- *
- * \brief XTEA block cipher (32-bit)
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_XTEA_H
- #define MBEDTLS_XTEA_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- #define MBEDTLS_XTEA_ENCRYPT 1
- #define MBEDTLS_XTEA_DECRYPT 0
- /** The data input has an invalid length. */
- #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028
- /* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** XTEA hardware accelerator failed. */
- #define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_XTEA_ALT)
- // Regular implementation
- //
- /**
- * \brief XTEA context structure
- */
- typedef struct mbedtls_xtea_context
- {
- uint32_t k[4]; /*!< key */
- }
- mbedtls_xtea_context;
- #else /* MBEDTLS_XTEA_ALT */
- #endif /* MBEDTLS_XTEA_ALT */
- /**
- * \brief Initialize XTEA context
- *
- * \param ctx XTEA context to be initialized
- */
- void mbedtls_xtea_init( mbedtls_xtea_context *ctx );
- /**
- * \brief Clear XTEA context
- *
- * \param ctx XTEA context to be cleared
- */
- void mbedtls_xtea_free( mbedtls_xtea_context *ctx );
- /**
- * \brief XTEA key schedule
- *
- * \param ctx XTEA context to be initialized
- * \param key the secret key
- */
- void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
- /**
- * \brief XTEA cipher function
- *
- * \param ctx XTEA context
- * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
- * \param input 8-byte input block
- * \param output 8-byte output block
- *
- * \return 0 if successful
- */
- int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,
- int mode,
- const unsigned char input[8],
- unsigned char output[8] );
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- /**
- * \brief XTEA CBC cipher function
- *
- * \param ctx XTEA context
- * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
- * \param length the length of input, multiple of 8
- * \param iv initialization vector for CBC mode
- * \param input input block
- * \param output output block
- *
- * \return 0 if successful,
- * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
- */
- int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[8],
- const unsigned char *input,
- unsigned char *output);
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- int mbedtls_xtea_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* xtea.h */
- /********* Start of file include/mbedtls/ssl.h ************/
- /**
- * \file ssl.h
- *
- * \brief SSL/TLS functions.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SSL_H
- #define MBEDTLS_SSL_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- #endif
- #if defined(MBEDTLS_DHM_C)
- #endif
- /* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due
- * to guards also being in ssl_srv.c and ssl_cli.c. There is a gap
- * in functionality that access to ecdh_ctx structure is needed for
- * MBEDTLS_ECDSA_C which does not seem correct.
- */
- #if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C)
- #endif
- #if defined(MBEDTLS_ZLIB_SUPPORT)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #warning "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library"
- #endif
- #if defined(MBEDTLS_DEPRECATED_REMOVED)
- #error "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set"
- #endif
- #endif
- #if defined(MBEDTLS_HAVE_TIME)
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- /*
- * SSL Error codes
- */
- /** The requested feature is not available. */
- #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100
- /** Verification of the message MAC failed. */
- #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
- /** An invalid SSL record was received. */
- #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200
- /** The connection indicated an EOF. */
- #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280
- /** An unknown cipher was received. */
- #define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300
- /** The server has no ciphersuites in common with the client. */
- #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
- /** No RNG was provided to the SSL module. */
- #define MBEDTLS_ERR_SSL_NO_RNG -0x7400
- /** No client certification received from the client, but required by the authentication mode. */
- #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
- /** Our own certificate(s) is/are too large to send in an SSL message. */
- #define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
- /** The own certificate is not set, but needed by the server. */
- #define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
- /** The own private key or pre-shared key is not set, but needed. */
- #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
- /** No CA Chain is set, but required to operate. */
- #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
- /** An unexpected message was received from our peer. */
- #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
- /** A fatal alert message was received from our peer. */
- #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
- /** Verification of our peer failed. */
- #define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800
- /** The peer notified us that the connection is going to be closed. */
- #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
- /** Processing of the ClientHello handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
- /** Processing of the ServerHello handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
- /** Processing of the Certificate handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
- /** Processing of the CertificateRequest handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
- /** Processing of the ServerKeyExchange handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
- /** Processing of the ServerHelloDone handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
- /** Processing of the ClientKeyExchange handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
- /** Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
- /** Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
- /** Processing of the CertificateVerify handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
- /** Processing of the ChangeCipherSpec handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
- /** Processing of the Finished handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80
- /** Memory allocation failed */
- #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00
- /** Hardware acceleration function returned with error */
- #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
- /** Hardware acceleration function skipped / left alone data */
- #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
- /** Processing of the compression / decompression failed */
- #define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00
- /** Handshake protocol not within min/max boundaries */
- #define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
- /** Processing of the NewSessionTicket handshake message failed. */
- #define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
- /** Session ticket has expired. */
- #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
- /** Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */
- #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
- /** Unknown identity received (eg, PSK identity) */
- #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
- /** Internal error (eg, unexpected failure in lower-level module) */
- #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00
- /** A counter would wrap (eg, too many messages exchanged). */
- #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80
- /** Unexpected message at ServerHello in renegotiation. */
- #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
- /** DTLS client must retry for hello verification */
- #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
- /** A buffer is too small to receive or write a message */
- #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00
- /** None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
- #define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980
- /** No data of requested type currently available on underlying transport. */
- #define MBEDTLS_ERR_SSL_WANT_READ -0x6900
- /** Connection requires a write call. */
- #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880
- /** The operation timed out. */
- #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800
- /** The client initiated a reconnect from the same port. */
- #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780
- /** Record header looks valid but is not expected. */
- #define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700
- /** The alert message received indicates a non-fatal error. */
- #define MBEDTLS_ERR_SSL_NON_FATAL -0x6680
- /** Couldn't set the hash for verifying CertificateVerify */
- #define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600
- /** Internal-only message signaling that further message-processing should be done */
- #define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580
- /** The asynchronous operation is not completed yet. */
- #define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500
- /** Internal-only message signaling that a message arrived early. */
- #define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480
- /** An encrypted DTLS-frame with an unexpected CID was received. */
- #define MBEDTLS_ERR_SSL_UNEXPECTED_CID -0x6000
- /** An operation failed due to an unexpected version or configuration. */
- #define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00
- /** A cryptographic operation is in progress. Try again later. */
- #define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000
- /** Invalid value in SSL config */
- #define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80
- /*
- * Various constants
- */
- #define MBEDTLS_SSL_MAJOR_VERSION_3 3
- #define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
- #define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
- #define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
- #define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
- #define MBEDTLS_SSL_MINOR_VERSION_4 4 /*!< TLS v1.3 (experimental) */
- #define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */
- #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */
- #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 /*!< Maximum host name defined in RFC 1035 */
- #define MBEDTLS_SSL_MAX_ALPN_NAME_LEN 255 /*!< Maximum size in bytes of a protocol name in alpn ext., RFC 7301 */
- #define MBEDTLS_SSL_MAX_ALPN_LIST_LEN 65535 /*!< Maximum size in bytes of list in alpn ext., RFC 7301 */
- /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
- * NONE must be zero so that memset()ing structure to zero works */
- #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 /*!< don't use this extension */
- #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 /*!< MaxFragmentLength 2^9 */
- #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 /*!< MaxFragmentLength 2^10 */
- #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 /*!< MaxFragmentLength 2^11 */
- #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 /*!< MaxFragmentLength 2^12 */
- #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 /*!< first invalid value */
- #define MBEDTLS_SSL_IS_CLIENT 0
- #define MBEDTLS_SSL_IS_SERVER 1
- #define MBEDTLS_SSL_IS_NOT_FALLBACK 0
- #define MBEDTLS_SSL_IS_FALLBACK 1
- #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
- #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
- #define MBEDTLS_SSL_CID_DISABLED 0
- #define MBEDTLS_SSL_CID_ENABLED 1
- #define MBEDTLS_SSL_ETM_DISABLED 0
- #define MBEDTLS_SSL_ETM_ENABLED 1
- #define MBEDTLS_SSL_COMPRESS_NULL 0
- #define MBEDTLS_SSL_COMPRESS_DEFLATE 1
- #define MBEDTLS_SSL_VERIFY_NONE 0
- #define MBEDTLS_SSL_VERIFY_OPTIONAL 1
- #define MBEDTLS_SSL_VERIFY_REQUIRED 2
- #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
- #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
- #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
- #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
- #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
- #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
- #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
- #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
- #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
- #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
- #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
- #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
- #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
- #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
- #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
- #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
- #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
- #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
- #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
- #define MBEDTLS_SSL_ARC4_ENABLED 0
- #define MBEDTLS_SSL_ARC4_DISABLED 1
- #define MBEDTLS_SSL_PRESET_DEFAULT 0
- #define MBEDTLS_SSL_PRESET_SUITEB 2
- #define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1
- #define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0
- #define MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED 0
- #define MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED 1
- /*
- * Default range for DTLS retransmission timer value, in milliseconds.
- * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
- */
- #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
- #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- #if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
- #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
- #endif
- /*
- * Maximum fragment length in bytes,
- * determines the size of each of the two internal I/O buffers.
- *
- * Note: the RFC defines the default size of SSL / TLS messages. If you
- * change the value here, other clients / servers may not be able to
- * communicate with you anymore. Only change this value if you control
- * both sides of the connection and have it reduced at both sides, or
- * if you're using the Max Fragment Length extension and you know all your
- * peers are using it too!
- */
- #if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
- #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */
- #endif
- #if !defined(MBEDTLS_SSL_IN_CONTENT_LEN)
- #define MBEDTLS_SSL_IN_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN
- #endif
- #if !defined(MBEDTLS_SSL_OUT_CONTENT_LEN)
- #define MBEDTLS_SSL_OUT_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN
- #endif
- /*
- * Maximum number of heap-allocated bytes for the purpose of
- * DTLS handshake message reassembly and future message buffering.
- */
- #if !defined(MBEDTLS_SSL_DTLS_MAX_BUFFERING)
- #define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
- #endif
- /*
- * Maximum length of CIDs for incoming and outgoing messages.
- */
- #if !defined(MBEDTLS_SSL_CID_IN_LEN_MAX)
- #define MBEDTLS_SSL_CID_IN_LEN_MAX 32
- #endif
- #if !defined(MBEDTLS_SSL_CID_OUT_LEN_MAX)
- #define MBEDTLS_SSL_CID_OUT_LEN_MAX 32
- #endif
- #if !defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY)
- #define MBEDTLS_SSL_CID_PADDING_GRANULARITY 16
- #endif
- #if !defined(MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY)
- #define MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY 1
- #endif
- /* \} name SECTION: Module settings */
- /*
- * Length of the verify data for secure renegotiation
- */
- #if defined(MBEDTLS_SSL_PROTO_SSL3)
- #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
- #else
- #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
- #endif
- /*
- * Signaling ciphersuite values (SCSV)
- */
- #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
- #define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600 /**< RFC 7507 section 2 */
- /*
- * Supported Signature and Hash algorithms (For TLS 1.2)
- * RFC 5246 section 7.4.1.4.1
- */
- #define MBEDTLS_SSL_HASH_NONE 0
- #define MBEDTLS_SSL_HASH_MD5 1
- #define MBEDTLS_SSL_HASH_SHA1 2
- #define MBEDTLS_SSL_HASH_SHA224 3
- #define MBEDTLS_SSL_HASH_SHA256 4
- #define MBEDTLS_SSL_HASH_SHA384 5
- #define MBEDTLS_SSL_HASH_SHA512 6
- #define MBEDTLS_SSL_SIG_ANON 0
- #define MBEDTLS_SSL_SIG_RSA 1
- #define MBEDTLS_SSL_SIG_ECDSA 3
- /*
- * Client Certificate Types
- * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
- */
- #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
- #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
- /*
- * Message, alert and handshake types
- */
- #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
- #define MBEDTLS_SSL_MSG_ALERT 21
- #define MBEDTLS_SSL_MSG_HANDSHAKE 22
- #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
- #define MBEDTLS_SSL_MSG_CID 25
- #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
- #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
- #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
- #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
- #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
- #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
- #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
- #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
- #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
- #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
- #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
- #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
- #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
- #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
- #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
- #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
- #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
- #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
- #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
- #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
- #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
- #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
- #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
- #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
- #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
- #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
- #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
- #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
- #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
- #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
- #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
- #define MBEDTLS_SSL_HS_HELLO_REQUEST 0
- #define MBEDTLS_SSL_HS_CLIENT_HELLO 1
- #define MBEDTLS_SSL_HS_SERVER_HELLO 2
- #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
- #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
- #define MBEDTLS_SSL_HS_CERTIFICATE 11
- #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
- #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
- #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
- #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
- #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
- #define MBEDTLS_SSL_HS_FINISHED 20
- /*
- * TLS extensions
- */
- #define MBEDTLS_TLS_EXT_SERVERNAME 0
- #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
- #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
- #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
- #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
- #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
- #define MBEDTLS_TLS_EXT_SIG_ALG 13
- #define MBEDTLS_TLS_EXT_USE_SRTP 14
- #define MBEDTLS_TLS_EXT_ALPN 16
- #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
- #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
- #define MBEDTLS_TLS_EXT_SESSION_TICKET 35
- /* The value of the CID extension is still TBD as of
- * draft-ietf-tls-dtls-connection-id-05
- * (https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05).
- *
- * A future minor revision of Mbed TLS may change the default value of
- * this option to match evolving standards and usage.
- */
- #if !defined(MBEDTLS_TLS_EXT_CID)
- #define MBEDTLS_TLS_EXT_CID 254 /* TBD */
- #endif
- #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
- #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
- /*
- * Size defines
- */
- #if !defined(MBEDTLS_PSK_MAX_LEN)
- #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
- #endif
- /* Dummy type used only for its size */
- union mbedtls_ssl_premaster_secret
- {
- #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
- unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
- unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
- unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
- unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
- unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
- + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
- unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
- unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
- + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
- #endif
- };
- #define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*
- * SSL state machine
- */
- typedef enum
- {
- MBEDTLS_SSL_HELLO_REQUEST,
- MBEDTLS_SSL_CLIENT_HELLO,
- MBEDTLS_SSL_SERVER_HELLO,
- MBEDTLS_SSL_SERVER_CERTIFICATE,
- MBEDTLS_SSL_SERVER_KEY_EXCHANGE,
- MBEDTLS_SSL_CERTIFICATE_REQUEST,
- MBEDTLS_SSL_SERVER_HELLO_DONE,
- MBEDTLS_SSL_CLIENT_CERTIFICATE,
- MBEDTLS_SSL_CLIENT_KEY_EXCHANGE,
- MBEDTLS_SSL_CERTIFICATE_VERIFY,
- MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC,
- MBEDTLS_SSL_CLIENT_FINISHED,
- MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC,
- MBEDTLS_SSL_SERVER_FINISHED,
- MBEDTLS_SSL_FLUSH_BUFFERS,
- MBEDTLS_SSL_HANDSHAKE_WRAPUP,
- MBEDTLS_SSL_HANDSHAKE_OVER,
- MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET,
- MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT,
- }
- mbedtls_ssl_states;
- /*
- * The tls_prf function types.
- */
- typedef enum
- {
- MBEDTLS_SSL_TLS_PRF_NONE,
- MBEDTLS_SSL_TLS_PRF_SSL3,
- MBEDTLS_SSL_TLS_PRF_TLS1,
- MBEDTLS_SSL_TLS_PRF_SHA384,
- MBEDTLS_SSL_TLS_PRF_SHA256
- }
- mbedtls_tls_prf_types;
- /**
- * \brief Callback type: send data on the network.
- *
- * \note That callback may be either blocking or non-blocking.
- *
- * \param ctx Context for the send callback (typically a file descriptor)
- * \param buf Buffer holding the data to send
- * \param len Length of the data to send
- *
- * \return The callback must return the number of bytes sent if any,
- * or a non-zero error code.
- * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_WRITE
- * must be returned when the operation would block.
- *
- * \note The callback is allowed to send fewer bytes than requested.
- * It must always return the number of bytes actually sent.
- */
- typedef int mbedtls_ssl_send_t( void *ctx,
- const unsigned char *buf,
- size_t len );
- /**
- * \brief Callback type: receive data from the network.
- *
- * \note That callback may be either blocking or non-blocking.
- *
- * \param ctx Context for the receive callback (typically a file
- * descriptor)
- * \param buf Buffer to write the received data to
- * \param len Length of the receive buffer
- *
- * \returns If data has been received, the positive number of bytes received.
- * \returns \c 0 if the connection has been closed.
- * \returns If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ
- * must be returned when the operation would block.
- * \returns Another negative error code on other kinds of failures.
- *
- * \note The callback may receive fewer bytes than the length of the
- * buffer. It must always return the number of bytes actually
- * received and written to the buffer.
- */
- typedef int mbedtls_ssl_recv_t( void *ctx,
- unsigned char *buf,
- size_t len );
- /**
- * \brief Callback type: receive data from the network, with timeout
- *
- * \note That callback must block until data is received, or the
- * timeout delay expires, or the operation is interrupted by a
- * signal.
- *
- * \param ctx Context for the receive callback (typically a file descriptor)
- * \param buf Buffer to write the received data to
- * \param len Length of the receive buffer
- * \param timeout Maximum nomber of millisecondes to wait for data
- * 0 means no timeout (potentially waiting forever)
- *
- * \return The callback must return the number of bytes received,
- * or a non-zero error code:
- * \c MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out,
- * \c MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
- *
- * \note The callback may receive fewer bytes than the length of the
- * buffer. It must always return the number of bytes actually
- * received and written to the buffer.
- */
- typedef int mbedtls_ssl_recv_timeout_t( void *ctx,
- unsigned char *buf,
- size_t len,
- uint32_t timeout );
- /**
- * \brief Callback type: set a pair of timers/delays to watch
- *
- * \param ctx Context pointer
- * \param int_ms Intermediate delay in milliseconds
- * \param fin_ms Final delay in milliseconds
- * 0 cancels the current timer.
- *
- * \note This callback must at least store the necessary information
- * for the associated \c mbedtls_ssl_get_timer_t callback to
- * return correct information.
- *
- * \note If using a event-driven style of programming, an event must
- * be generated when the final delay is passed. The event must
- * cause a call to \c mbedtls_ssl_handshake() with the proper
- * SSL context to be scheduled. Care must be taken to ensure
- * that at most one such call happens at a time.
- *
- * \note Only one timer at a time must be running. Calling this
- * function while a timer is running must cancel it. Cancelled
- * timers must not generate any event.
- */
- typedef void mbedtls_ssl_set_timer_t( void * ctx,
- uint32_t int_ms,
- uint32_t fin_ms );
- /**
- * \brief Callback type: get status of timers/delays
- *
- * \param ctx Context pointer
- *
- * \return This callback must return:
- * -1 if cancelled (fin_ms == 0),
- * 0 if none of the delays have passed,
- * 1 if only the intermediate delay has passed,
- * 2 if the final delay has passed.
- */
- typedef int mbedtls_ssl_get_timer_t( void * ctx );
- /* Defined below */
- typedef struct mbedtls_ssl_session mbedtls_ssl_session;
- typedef struct mbedtls_ssl_context mbedtls_ssl_context;
- typedef struct mbedtls_ssl_config mbedtls_ssl_config;
- /* Defined in ssl_internal.h */
- typedef struct mbedtls_ssl_transform mbedtls_ssl_transform;
- typedef struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params;
- typedef struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t;
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert;
- #endif
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item;
- #endif
- #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * \brief Callback type: start external signature operation.
- *
- * This callback is called during an SSL handshake to start
- * a signature decryption operation using an
- * external processor. The parameter \p cert contains
- * the public key; it is up to the callback function to
- * determine how to access the associated private key.
- *
- * This function typically sends or enqueues a request, and
- * does not wait for the operation to complete. This allows
- * the handshake step to be non-blocking.
- *
- * The parameters \p ssl and \p cert are guaranteed to remain
- * valid throughout the handshake. On the other hand, this
- * function must save the contents of \p hash if the value
- * is needed for later processing, because the \p hash buffer
- * is no longer valid after this function returns.
- *
- * This function may call mbedtls_ssl_set_async_operation_data()
- * to store an operation context for later retrieval
- * by the resume or cancel callback.
- *
- * \note For RSA signatures, this function must produce output
- * that is consistent with PKCS#1 v1.5 in the same way as
- * mbedtls_rsa_pkcs1_sign(). Before the private key operation,
- * apply the padding steps described in RFC 8017, section 9.2
- * "EMSA-PKCS1-v1_5" as follows.
- * - If \p md_alg is #MBEDTLS_MD_NONE, apply the PKCS#1 v1.5
- * encoding, treating \p hash as the DigestInfo to be
- * padded. In other words, apply EMSA-PKCS1-v1_5 starting
- * from step 3, with `T = hash` and `tLen = hash_len`.
- * - If `md_alg != MBEDTLS_MD_NONE`, apply the PKCS#1 v1.5
- * encoding, treating \p hash as the hash to be encoded and
- * padded. In other words, apply EMSA-PKCS1-v1_5 starting
- * from step 2, with `digestAlgorithm` obtained by calling
- * mbedtls_oid_get_oid_by_md() on \p md_alg.
- *
- * \note For ECDSA signatures, the output format is the DER encoding
- * `Ecdsa-Sig-Value` defined in
- * [RFC 4492 section 5.4](https://tools.ietf.org/html/rfc4492#section-5.4).
- *
- * \param ssl The SSL connection instance. It should not be
- * modified other than via
- * mbedtls_ssl_set_async_operation_data().
- * \param cert Certificate containing the public key.
- * In simple cases, this is one of the pointers passed to
- * mbedtls_ssl_conf_own_cert() when configuring the SSL
- * connection. However, if other callbacks are used, this
- * property may not hold. For example, if an SNI callback
- * is registered with mbedtls_ssl_conf_sni(), then
- * this callback determines what certificate is used.
- * \param md_alg Hash algorithm.
- * \param hash Buffer containing the hash. This buffer is
- * no longer valid when the function returns.
- * \param hash_len Size of the \c hash buffer in bytes.
- *
- * \return 0 if the operation was started successfully and the SSL
- * stack should call the resume callback immediately.
- * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation
- * was started successfully and the SSL stack should return
- * immediately without calling the resume callback yet.
- * \return #MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH if the external
- * processor does not support this key. The SSL stack will
- * use the private key object instead.
- * \return Any other error indicates a fatal failure and is
- * propagated up the call chain. The callback should
- * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b>
- * use \c MBEDTLS_ERR_SSL_xxx error codes except as
- * directed in the documentation of this callback.
- */
- typedef int mbedtls_ssl_async_sign_t( mbedtls_ssl_context *ssl,
- mbedtls_x509_crt *cert,
- mbedtls_md_type_t md_alg,
- const unsigned char *hash,
- size_t hash_len );
- /**
- * \brief Callback type: start external decryption operation.
- *
- * This callback is called during an SSL handshake to start
- * an RSA decryption operation using an
- * external processor. The parameter \p cert contains
- * the public key; it is up to the callback function to
- * determine how to access the associated private key.
- *
- * This function typically sends or enqueues a request, and
- * does not wait for the operation to complete. This allows
- * the handshake step to be non-blocking.
- *
- * The parameters \p ssl and \p cert are guaranteed to remain
- * valid throughout the handshake. On the other hand, this
- * function must save the contents of \p input if the value
- * is needed for later processing, because the \p input buffer
- * is no longer valid after this function returns.
- *
- * This function may call mbedtls_ssl_set_async_operation_data()
- * to store an operation context for later retrieval
- * by the resume or cancel callback.
- *
- * \warning RSA decryption as used in TLS is subject to a potential
- * timing side channel attack first discovered by Bleichenbacher
- * in 1998. This attack can be remotely exploitable
- * in practice. To avoid this attack, you must ensure that
- * if the callback performs an RSA decryption, the time it
- * takes to execute and return the result does not depend
- * on whether the RSA decryption succeeded or reported
- * invalid padding.
- *
- * \param ssl The SSL connection instance. It should not be
- * modified other than via
- * mbedtls_ssl_set_async_operation_data().
- * \param cert Certificate containing the public key.
- * In simple cases, this is one of the pointers passed to
- * mbedtls_ssl_conf_own_cert() when configuring the SSL
- * connection. However, if other callbacks are used, this
- * property may not hold. For example, if an SNI callback
- * is registered with mbedtls_ssl_conf_sni(), then
- * this callback determines what certificate is used.
- * \param input Buffer containing the input ciphertext. This buffer
- * is no longer valid when the function returns.
- * \param input_len Size of the \p input buffer in bytes.
- *
- * \return 0 if the operation was started successfully and the SSL
- * stack should call the resume callback immediately.
- * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation
- * was started successfully and the SSL stack should return
- * immediately without calling the resume callback yet.
- * \return #MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH if the external
- * processor does not support this key. The SSL stack will
- * use the private key object instead.
- * \return Any other error indicates a fatal failure and is
- * propagated up the call chain. The callback should
- * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b>
- * use \c MBEDTLS_ERR_SSL_xxx error codes except as
- * directed in the documentation of this callback.
- */
- typedef int mbedtls_ssl_async_decrypt_t( mbedtls_ssl_context *ssl,
- mbedtls_x509_crt *cert,
- const unsigned char *input,
- size_t input_len );
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- /**
- * \brief Callback type: resume external operation.
- *
- * This callback is called during an SSL handshake to resume
- * an external operation started by the
- * ::mbedtls_ssl_async_sign_t or
- * ::mbedtls_ssl_async_decrypt_t callback.
- *
- * This function typically checks the status of a pending
- * request or causes the request queue to make progress, and
- * does not wait for the operation to complete. This allows
- * the handshake step to be non-blocking.
- *
- * This function may call mbedtls_ssl_get_async_operation_data()
- * to retrieve an operation context set by the start callback.
- * It may call mbedtls_ssl_set_async_operation_data() to modify
- * this context.
- *
- * Note that when this function returns a status other than
- * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, it must free any
- * resources associated with the operation.
- *
- * \param ssl The SSL connection instance. It should not be
- * modified other than via
- * mbedtls_ssl_set_async_operation_data().
- * \param output Buffer containing the output (signature or decrypted
- * data) on success.
- * \param output_len On success, number of bytes written to \p output.
- * \param output_size Size of the \p output buffer in bytes.
- *
- * \return 0 if output of the operation is available in the
- * \p output buffer.
- * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation
- * is still in progress. Subsequent requests for progress
- * on the SSL connection will call the resume callback
- * again.
- * \return Any other error means that the operation is aborted.
- * The SSL handshake is aborted. The callback should
- * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b>
- * use \c MBEDTLS_ERR_SSL_xxx error codes except as
- * directed in the documentation of this callback.
- */
- typedef int mbedtls_ssl_async_resume_t( mbedtls_ssl_context *ssl,
- unsigned char *output,
- size_t *output_len,
- size_t output_size );
- /**
- * \brief Callback type: cancel external operation.
- *
- * This callback is called if an SSL connection is closed
- * while an asynchronous operation is in progress. Note that
- * this callback is not called if the
- * ::mbedtls_ssl_async_resume_t callback has run and has
- * returned a value other than
- * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, since in that case
- * the asynchronous operation has already completed.
- *
- * This function may call mbedtls_ssl_get_async_operation_data()
- * to retrieve an operation context set by the start callback.
- *
- * \param ssl The SSL connection instance. It should not be
- * modified.
- */
- typedef void mbedtls_ssl_async_cancel_t( mbedtls_ssl_context *ssl );
- #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
- #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
- !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
- #define MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN 48
- #if defined(MBEDTLS_SHA256_C)
- #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA256
- #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 32
- #elif defined(MBEDTLS_SHA512_C)
- #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA384
- #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 48
- #elif defined(MBEDTLS_SHA1_C)
- #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA1
- #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 20
- #else
- /* This is already checked in check_config.h, but be sure. */
- #error "Bad configuration - need SHA-1, SHA-256 or SHA-512 enabled to compute digest of peer CRT."
- #endif
- #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED &&
- !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
- #if defined(MBEDTLS_SSL_DTLS_SRTP)
- #define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH 255
- #define MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH 4
- /*
- * For code readability use a typedef for DTLS-SRTP profiles
- *
- * Use_srtp extension protection profiles values as defined in
- * http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
- *
- * Reminder: if this list is expanded mbedtls_ssl_check_srtp_profile_value
- * must be updated too.
- */
- #define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80 ( (uint16_t) 0x0001)
- #define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32 ( (uint16_t) 0x0002)
- #define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80 ( (uint16_t) 0x0005)
- #define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32 ( (uint16_t) 0x0006)
- /* This one is not iana defined, but for code readability. */
- #define MBEDTLS_TLS_SRTP_UNSET ( (uint16_t) 0x0000)
- typedef uint16_t mbedtls_ssl_srtp_profile;
- typedef struct mbedtls_dtls_srtp_info_t
- {
- /*! The SRTP profile that was negotiated. */
- mbedtls_ssl_srtp_profile chosen_dtls_srtp_profile;
- /*! The length of mki_value. */
- uint16_t mki_len;
- /*! The mki_value used, with max size of 256 bytes. */
- unsigned char mki_value[MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH];
- }
- mbedtls_dtls_srtp_info;
- #endif /* MBEDTLS_SSL_DTLS_SRTP */
- /*
- * This structure is used for storing current session data.
- *
- * Note: when changing this definition, we need to check and update:
- * - in tests/suites/test_suite_ssl.function:
- * ssl_populate_session() and ssl_serialize_session_save_load()
- * - in library/ssl_tls.c:
- * mbedtls_ssl_session_init() and mbedtls_ssl_session_free()
- * mbedtls_ssl_session_save() and ssl_session_load()
- * ssl_session_copy()
- */
- struct mbedtls_ssl_session
- {
- #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */
- #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
- #if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t start; /*!< starting time */
- #endif
- int ciphersuite; /*!< chosen ciphersuite */
- int compression; /*!< chosen compression */
- size_t id_len; /*!< session id length */
- unsigned char id[32]; /*!< session identifier */
- unsigned char master[48]; /*!< the master secret */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
- mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */
- #else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
- /*! The digest of the peer's end-CRT. This must be kept to detect CRT
- * changes during renegotiation, mitigating the triple handshake attack. */
- unsigned char *peer_cert_digest;
- size_t peer_cert_digest_len;
- mbedtls_md_type_t peer_cert_digest_type;
- #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- uint32_t verify_result; /*!< verification result */
- #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
- unsigned char *ticket; /*!< RFC 5077 session ticket */
- size_t ticket_len; /*!< session ticket length */
- uint32_t ticket_lifetime; /*!< ticket lifetime hint */
- #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
- #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
- int trunc_hmac; /*!< flag for truncated hmac activation */
- #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
- #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
- int encrypt_then_mac; /*!< flag for EtM activation */
- #endif
- };
- /**
- * SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
- */
- struct mbedtls_ssl_config
- {
- /* Group items by size and reorder them to maximize usage of immediate offset access. */
- /*
- * Numerical settings (char)
- */
- unsigned char max_major_ver; /*!< max. major version used */
- unsigned char max_minor_ver; /*!< max. minor version used */
- unsigned char min_major_ver; /*!< min. major version used */
- unsigned char min_minor_ver; /*!< min. minor version used */
- /*
- * Flags (could be bit-fields to save RAM, but separate bytes make
- * the code smaller on architectures with an instruction for direct
- * byte access).
- */
- uint8_t endpoint /*bool*/; /*!< 0: client, 1: server */
- uint8_t transport /*bool*/; /*!< stream (TLS) or datagram (DTLS) */
- uint8_t authmode /*2 bits*/; /*!< MBEDTLS_SSL_VERIFY_XXX */
- /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
- uint8_t allow_legacy_renegotiation /*2 bits*/; /*!< MBEDTLS_LEGACY_XXX */
- #if defined(MBEDTLS_ARC4_C)
- uint8_t arc4_disabled /*bool*/; /*!< blacklist RC4 ciphersuites? */
- #endif
- #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- uint8_t mfl_code /*3 bits*/; /*!< desired fragment length */
- #endif
- #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
- uint8_t encrypt_then_mac /*bool*/; /*!< negotiate encrypt-then-mac? */
- #endif
- #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
- uint8_t extended_ms /*bool*/; /*!< negotiate extended master secret? */
- #endif
- #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
- uint8_t anti_replay /*bool*/; /*!< detect and prevent replay? */
- #endif
- #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
- uint8_t cbc_record_splitting /*bool*/; /*!< do cbc record splitting */
- #endif
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- uint8_t disable_renegotiation /*bool*/; /*!< disable renegotiation? */
- #endif
- #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
- uint8_t trunc_hmac /*bool*/; /*!< negotiate truncated hmac? */
- #endif
- #if defined(MBEDTLS_SSL_SESSION_TICKETS)
- uint8_t session_tickets /*bool*/; /*!< use session tickets? */
- #endif
- #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
- uint8_t fallback /*bool*/; /*!< is this a fallback? */
- #endif
- #if defined(MBEDTLS_SSL_SRV_C)
- uint8_t cert_req_ca_list /*bool*/; /*!< enable sending CA list in
- Certificate Request messages? */
- #endif
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- uint8_t ignore_unexpected_cid /*bool*/; /*!< Determines whether DTLS
- * record with unexpected CID
- * should lead to failure. */
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- #if defined(MBEDTLS_SSL_DTLS_SRTP)
- uint8_t dtls_srtp_mki_support /*bool*/; /*!< support having mki_value
- in the use_srtp extension? */
- #endif
- /*
- * Numerical settings (int or larger)
- */
- uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- uint32_t hs_timeout_min; /*!< initial value of the handshake
- retransmission timeout (ms) */
- uint32_t hs_timeout_max; /*!< maximum value of the handshake
- retransmission timeout (ms) */
- #endif
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- int renego_max_records; /*!< grace period for renegotiation */
- unsigned char renego_period[8]; /*!< value of the record counters
- that triggers renegotiation */
- #endif
- #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
- unsigned int badmac_limit; /*!< limit of records with a bad MAC */
- #endif
- #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
- unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
- #endif
- /*
- * Pointers
- */
- const int *ciphersuite_list[4]; /*!< allowed ciphersuites per version */
- /** Callback for printing debug output */
- void (*f_dbg)(void *, int, const char *, int, const char *);
- void *p_dbg; /*!< context for the debug function */
- /** Callback for getting (pseudo-)random numbers */
- int (*f_rng)(void *, unsigned char *, size_t);
- void *p_rng; /*!< context for the RNG function */
- /** Callback to retrieve a session from the cache */
- int (*f_get_cache)(void *, mbedtls_ssl_session *);
- /** Callback to store a session into the cache */
- int (*f_set_cache)(void *, const mbedtls_ssl_session *);
- void *p_cache; /*!< context for cache callbacks */
- #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
- /** Callback for setting cert according to SNI extension */
- int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
- void *p_sni; /*!< context for SNI callback */
- #endif
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /** Callback to customize X.509 certificate chain verification */
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
- void *p_vrfy; /*!< context for X.509 verify calllback */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
- /** Callback to retrieve PSK key from identity */
- int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
- void *p_psk; /*!< context for PSK callback */
- #endif
- #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
- /** Callback to create & write a cookie for ClientHello veirifcation */
- int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
- const unsigned char *, size_t );
- /** Callback to verify validity of a ClientHello cookie */
- int (*f_cookie_check)( void *, const unsigned char *, size_t,
- const unsigned char *, size_t );
- void *p_cookie; /*!< context for the cookie callbacks */
- #endif
- #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
- /** Callback to create & write a session ticket */
- int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
- unsigned char *, const unsigned char *, size_t *, uint32_t * );
- /** Callback to parse a session ticket into a session structure */
- int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
- void *p_ticket; /*!< context for the ticket callbacks */
- #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
- #if defined(MBEDTLS_SSL_EXPORT_KEYS)
- /** Callback to export key block and master secret */
- int (*f_export_keys)( void *, const unsigned char *,
- const unsigned char *, size_t, size_t, size_t );
- /** Callback to export key block, master secret,
- * tls_prf and random bytes. Should replace f_export_keys */
- int (*f_export_keys_ext)( void *, const unsigned char *,
- const unsigned char *, size_t, size_t, size_t,
- const unsigned char[32], const unsigned char[32],
- mbedtls_tls_prf_types );
- void *p_export_keys; /*!< context for key export callback */
- #endif
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- size_t cid_len; /*!< The length of CIDs for incoming DTLS records. */
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- const mbedtls_x509_crt_profile *cert_profile; /*!< verification profile */
- mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */
- mbedtls_x509_crt *ca_chain; /*!< trusted CAs */
- mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */
- #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
- mbedtls_x509_crt_ca_cb_t f_ca_cb;
- void *p_ca_cb;
- #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- mbedtls_ssl_async_sign_t *f_async_sign_start; /*!< start asynchronous signature operation */
- mbedtls_ssl_async_decrypt_t *f_async_decrypt_start; /*!< start asynchronous decryption operation */
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- mbedtls_ssl_async_resume_t *f_async_resume; /*!< resume asynchronous operation */
- mbedtls_ssl_async_cancel_t *f_async_cancel; /*!< cancel asynchronous operation */
- void *p_async_config_data; /*!< Configuration data set by mbedtls_ssl_conf_async_private_cb(). */
- #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
- #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
- const int *sig_hashes; /*!< allowed signature hashes */
- #endif
- #if defined(MBEDTLS_ECP_C)
- const mbedtls_ecp_group_id *curve_list; /*!< allowed curves */
- #endif
- #if defined(MBEDTLS_DHM_C)
- mbedtls_mpi dhm_P; /*!< prime modulus for DHM */
- mbedtls_mpi dhm_G; /*!< generator for DHM */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_key_id_t psk_opaque; /*!< PSA key slot holding opaque PSK. This field
- * should only be set via
- * mbedtls_ssl_conf_psk_opaque().
- * If either no PSK or a raw PSK have been
- * configured, this has value \c 0.
- */
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- unsigned char *psk; /*!< The raw pre-shared key. This field should
- * only be set via mbedtls_ssl_conf_psk().
- * If either no PSK or an opaque PSK
- * have been configured, this has value NULL. */
- size_t psk_len; /*!< The length of the raw pre-shared key.
- * This field should only be set via
- * mbedtls_ssl_conf_psk().
- * Its value is non-zero if and only if
- * \c psk is not \c NULL. */
- unsigned char *psk_identity; /*!< The PSK identity for PSK negotiation.
- * This field should only be set via
- * mbedtls_ssl_conf_psk().
- * This is set if and only if either
- * \c psk or \c psk_opaque are set. */
- size_t psk_identity_len;/*!< The length of PSK identity.
- * This field should only be set via
- * mbedtls_ssl_conf_psk().
- * Its value is non-zero if and only if
- * \c psk is not \c NULL or \c psk_opaque
- * is not \c 0. */
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
- #if defined(MBEDTLS_SSL_ALPN)
- const char **alpn_list; /*!< ordered list of protocols */
- #endif
- #if defined(MBEDTLS_SSL_DTLS_SRTP)
- /*! ordered list of supported srtp profile */
- const mbedtls_ssl_srtp_profile *dtls_srtp_profile_list;
- /*! number of supported profiles */
- size_t dtls_srtp_profile_list_len;
- #endif /* MBEDTLS_SSL_DTLS_SRTP */
- };
- struct mbedtls_ssl_context
- {
- const mbedtls_ssl_config *conf; /*!< configuration information */
- /*
- * Miscellaneous
- */
- int state; /*!< SSL handshake: current state */
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- int renego_status; /*!< Initial, in progress, pending? */
- int renego_records_seen; /*!< Records since renego request, or with DTLS,
- number of retransmissions of request if
- renego_max_records is < 0 */
- #endif /* MBEDTLS_SSL_RENEGOTIATION */
- int major_ver; /*!< equal to MBEDTLS_SSL_MAJOR_VERSION_3 */
- int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
- #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
- unsigned badmac_seen; /*!< records with a bad MAC received */
- #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /** Callback to customize X.509 certificate chain verification */
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
- void *p_vrfy; /*!< context for X.509 verify callback */
- #endif
- mbedtls_ssl_send_t *f_send; /*!< Callback for network send */
- mbedtls_ssl_recv_t *f_recv; /*!< Callback for network receive */
- mbedtls_ssl_recv_timeout_t *f_recv_timeout;
- /*!< Callback for network receive with timeout */
- void *p_bio; /*!< context for I/O operations */
- /*
- * Session layer
- */
- mbedtls_ssl_session *session_in; /*!< current session data (in) */
- mbedtls_ssl_session *session_out; /*!< current session data (out) */
- mbedtls_ssl_session *session; /*!< negotiated session data */
- mbedtls_ssl_session *session_negotiate; /*!< session data in negotiation */
- mbedtls_ssl_handshake_params *handshake; /*!< params required only during
- the handshake process */
- /*
- * Record layer transformations
- */
- mbedtls_ssl_transform *transform_in; /*!< current transform params (in) */
- mbedtls_ssl_transform *transform_out; /*!< current transform params (in) */
- mbedtls_ssl_transform *transform; /*!< negotiated transform params */
- mbedtls_ssl_transform *transform_negotiate; /*!< transform params in negotiation */
- /*
- * Timers
- */
- void *p_timer; /*!< context for the timer callbacks */
- mbedtls_ssl_set_timer_t *f_set_timer; /*!< set timer callback */
- mbedtls_ssl_get_timer_t *f_get_timer; /*!< get timer callback */
- /*
- * Record layer (incoming data)
- */
- unsigned char *in_buf; /*!< input buffer */
- unsigned char *in_ctr; /*!< 64-bit incoming message counter
- TLS: maintained by us
- DTLS: read from peer */
- unsigned char *in_hdr; /*!< start of record header */
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- unsigned char *in_cid; /*!< The start of the CID;
- * (the end is marked by in_len). */
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- unsigned char *in_len; /*!< two-bytes message length field */
- unsigned char *in_iv; /*!< ivlen-byte IV */
- unsigned char *in_msg; /*!< message contents (in_iv+ivlen) */
- unsigned char *in_offt; /*!< read offset in application data */
- int in_msgtype; /*!< record header: message type */
- size_t in_msglen; /*!< record header: message length */
- size_t in_left; /*!< amount of data read so far */
- #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
- size_t in_buf_len; /*!< length of input buffer */
- #endif
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- uint16_t in_epoch; /*!< DTLS epoch for incoming records */
- size_t next_record_offset; /*!< offset of the next record in datagram
- (equal to in_left if none) */
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
- uint64_t in_window_top; /*!< last validated record seq_num */
- uint64_t in_window; /*!< bitmask for replay detection */
- #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
- size_t in_hslen; /*!< current handshake message length,
- including the handshake header */
- int nb_zero; /*!< # of 0-length encrypted messages */
- int keep_current_message; /*!< drop or reuse current message
- on next call to record layer? */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- uint8_t disable_datagram_packing; /*!< Disable packing multiple records
- * within a single datagram. */
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- /*
- * Record layer (outgoing data)
- */
- unsigned char *out_buf; /*!< output buffer */
- unsigned char *out_ctr; /*!< 64-bit outgoing message counter */
- unsigned char *out_hdr; /*!< start of record header */
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- unsigned char *out_cid; /*!< The start of the CID;
- * (the end is marked by in_len). */
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- unsigned char *out_len; /*!< two-bytes message length field */
- unsigned char *out_iv; /*!< ivlen-byte IV */
- unsigned char *out_msg; /*!< message contents (out_iv+ivlen) */
- int out_msgtype; /*!< record header: message type */
- size_t out_msglen; /*!< record header: message length */
- size_t out_left; /*!< amount of data not yet written */
- #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
- size_t out_buf_len; /*!< length of output buffer */
- #endif
- unsigned char cur_out_ctr[8]; /*!< Outgoing record sequence number. */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- uint16_t mtu; /*!< path mtu, used to fragment outgoing messages */
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- #if defined(MBEDTLS_ZLIB_SUPPORT)
- unsigned char *compress_buf; /*!< zlib data buffer */
- #endif /* MBEDTLS_ZLIB_SUPPORT */
- #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
- signed char split_done; /*!< current record already splitted? */
- #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
- /*
- * PKI layer
- */
- int client_auth; /*!< flag for client auth. */
- /*
- * User settings
- */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- char *hostname; /*!< expected peer CN for verification
- (and SNI if available) */
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- #if defined(MBEDTLS_SSL_ALPN)
- const char *alpn_chosen; /*!< negotiated protocol */
- #endif /* MBEDTLS_SSL_ALPN */
- #if defined(MBEDTLS_SSL_DTLS_SRTP)
- /*
- * use_srtp extension
- */
- mbedtls_dtls_srtp_info dtls_srtp_info;
- #endif /* MBEDTLS_SSL_DTLS_SRTP */
- /*
- * Information for DTLS hello verify
- */
- #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
- unsigned char *cli_id; /*!< transport-level ID of the client */
- size_t cli_id_len; /*!< length of cli_id */
- #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
- /*
- * Secure renegotiation
- */
- /* needed to know when to send extension on server */
- int secure_renegotiation; /*!< does peer support legacy or
- secure renegotiation */
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- size_t verify_data_len; /*!< length of verify data stored */
- char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
- char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
- #endif /* MBEDTLS_SSL_RENEGOTIATION */
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- /* CID configuration to use in subsequent handshakes. */
- /*! The next incoming CID, chosen by the user and applying to
- * all subsequent handshakes. This may be different from the
- * CID currently used in case the user has re-configured the CID
- * after an initial handshake. */
- unsigned char own_cid[ MBEDTLS_SSL_CID_IN_LEN_MAX ];
- uint8_t own_cid_len; /*!< The length of \c own_cid. */
- uint8_t negotiate_cid; /*!< This indicates whether the CID extension should
- * be negotiated in the next handshake or not.
- * Possible values are #MBEDTLS_SSL_CID_ENABLED
- * and #MBEDTLS_SSL_CID_DISABLED. */
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- void *appData;
- };
- #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #define MBEDTLS_SSL_CHANNEL_OUTBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 0 )
- #define MBEDTLS_SSL_CHANNEL_INBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 1 )
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif /* MBEDTLS_DEPRECATED_WARNING */
- MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_init)(
- mbedtls_ssl_context *ssl,
- const unsigned char *key_enc, const unsigned char *key_dec,
- size_t keylen,
- const unsigned char *iv_enc, const unsigned char *iv_dec,
- size_t ivlen,
- const unsigned char *mac_enc, const unsigned char *mac_dec,
- size_t maclen);
- MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_activate)(
- mbedtls_ssl_context *ssl,
- int direction );
- MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_reset)(
- mbedtls_ssl_context *ssl );
- MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_write)(
- mbedtls_ssl_context *ssl );
- MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_read)(
- mbedtls_ssl_context *ssl );
- MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_finish)(
- mbedtls_ssl_context *ssl );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
- /**
- * \brief Return the name of the ciphersuite associated with the
- * given ID
- *
- * \param ciphersuite_id SSL ciphersuite ID
- *
- * \return a string containing the ciphersuite name
- */
- const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
- /**
- * \brief Return the ID of the ciphersuite associated with the
- * given name
- *
- * \param ciphersuite_name SSL ciphersuite name
- *
- * \return the ID with the ciphersuite or 0 if not found
- */
- int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
- /**
- * \brief Initialize an SSL context
- * Just makes the context ready for mbedtls_ssl_setup() or
- * mbedtls_ssl_free()
- *
- * \param ssl SSL context
- */
- void mbedtls_ssl_init( mbedtls_ssl_context *ssl );
- /**
- * \brief Set up an SSL context for use
- *
- * \note No copy of the configuration context is made, it can be
- * shared by many mbedtls_ssl_context structures.
- *
- * \warning The conf structure will be accessed during the session.
- * It must not be modified or freed as long as the session
- * is active.
- *
- * \warning This function must be called exactly once per context.
- * Calling mbedtls_ssl_setup again is not supported, even
- * if no session is active.
- *
- * \param ssl SSL context
- * \param conf SSL configuration to use
- *
- * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED if
- * memory allocation failed
- */
- int mbedtls_ssl_setup( mbedtls_ssl_context *ssl,
- const mbedtls_ssl_config *conf );
- /**
- * \brief Reset an already initialized SSL context for re-use
- * while retaining application-set variables, function
- * pointers and data.
- *
- * \param ssl SSL context
- * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED,
- MBEDTLS_ERR_SSL_HW_ACCEL_FAILED or
- * MBEDTLS_ERR_SSL_COMPRESSION_FAILED
- */
- int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl );
- /**
- * \brief Set the current endpoint type
- *
- * \param conf SSL configuration
- * \param endpoint must be MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
- */
- void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint );
- /**
- * \brief Set the transport type (TLS or DTLS).
- * Default: TLS
- *
- * \note For DTLS, you must either provide a recv callback that
- * doesn't block, or one that handles timeouts, see
- * \c mbedtls_ssl_set_bio(). You also need to provide timer
- * callbacks with \c mbedtls_ssl_set_timer_cb().
- *
- * \param conf SSL configuration
- * \param transport transport type:
- * MBEDTLS_SSL_TRANSPORT_STREAM for TLS,
- * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS.
- */
- void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport );
- /**
- * \brief Set the certificate verification mode
- * Default: NONE on server, REQUIRED on client
- *
- * \param conf SSL configuration
- * \param authmode can be:
- *
- * MBEDTLS_SSL_VERIFY_NONE: peer certificate is not checked
- * (default on server)
- * (insecure on client)
- *
- * MBEDTLS_SSL_VERIFY_OPTIONAL: peer certificate is checked, however the
- * handshake continues even if verification failed;
- * mbedtls_ssl_get_verify_result() can be called after the
- * handshake is complete.
- *
- * MBEDTLS_SSL_VERIFY_REQUIRED: peer *must* present a valid certificate,
- * handshake is aborted if verification failed.
- * (default on client)
- *
- * \note On client, MBEDTLS_SSL_VERIFY_REQUIRED is the recommended mode.
- * With MBEDTLS_SSL_VERIFY_OPTIONAL, the user needs to call mbedtls_ssl_get_verify_result() at
- * the right time(s), which may not be obvious, while REQUIRED always perform
- * the verification as soon as possible. For example, REQUIRED was protecting
- * against the "triple handshake" attack even before it was found.
- */
- void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * \brief Set the verification callback (Optional).
- *
- * If set, the provided verify callback is called for each
- * certificate in the peer's CRT chain, including the trusted
- * root. For more information, please see the documentation of
- * \c mbedtls_x509_crt_verify().
- *
- * \note For per context callbacks and contexts, please use
- * mbedtls_ssl_set_verify() instead.
- *
- * \param conf The SSL configuration to use.
- * \param f_vrfy The verification callback to use during CRT verification.
- * \param p_vrfy The opaque context to be passed to the callback.
- */
- void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy );
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- /**
- * \brief Set the random number generator callback
- *
- * \param conf SSL configuration
- * \param f_rng RNG function
- * \param p_rng RNG parameter
- */
- void mbedtls_ssl_conf_rng( mbedtls_ssl_config *conf,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief Set the debug callback
- *
- * The callback has the following argument:
- * void * opaque context for the callback
- * int debug level
- * const char * file name
- * int line number
- * const char * message
- *
- * \param conf SSL configuration
- * \param f_dbg debug function
- * \param p_dbg debug parameter
- */
- void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf,
- void (*f_dbg)(void *, int, const char *, int, const char *),
- void *p_dbg );
- /**
- * \brief Set the underlying BIO callbacks for write, read and
- * read-with-timeout.
- *
- * \param ssl SSL context
- * \param p_bio parameter (context) shared by BIO callbacks
- * \param f_send write callback
- * \param f_recv read callback
- * \param f_recv_timeout blocking read callback with timeout.
- *
- * \note One of f_recv or f_recv_timeout can be NULL, in which case
- * the other is used. If both are non-NULL, f_recv_timeout is
- * used and f_recv is ignored (as if it were NULL).
- *
- * \note The two most common use cases are:
- * - non-blocking I/O, f_recv != NULL, f_recv_timeout == NULL
- * - blocking I/O, f_recv == NULL, f_recv_timout != NULL
- *
- * \note For DTLS, you need to provide either a non-NULL
- * f_recv_timeout callback, or a f_recv that doesn't block.
- *
- * \note See the documentations of \c mbedtls_ssl_send_t,
- * \c mbedtls_ssl_recv_t and \c mbedtls_ssl_recv_timeout_t for
- * the conventions those callbacks must follow.
- *
- * \note On some platforms, net_sockets.c provides
- * \c mbedtls_net_send(), \c mbedtls_net_recv() and
- * \c mbedtls_net_recv_timeout() that are suitable to be used
- * here.
- */
- void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
- void *p_bio,
- mbedtls_ssl_send_t *f_send,
- mbedtls_ssl_recv_t *f_recv,
- mbedtls_ssl_recv_timeout_t *f_recv_timeout );
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- /**
- * \brief Configure the use of the Connection ID (CID)
- * extension in the next handshake.
- *
- * Reference: draft-ietf-tls-dtls-connection-id-05
- * https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05
- *
- * The DTLS CID extension allows the reliable association of
- * DTLS records to DTLS connections across changes in the
- * underlying transport (changed IP and Port metadata) by
- * adding explicit connection identifiers (CIDs) to the
- * headers of encrypted DTLS records. The desired CIDs are
- * configured by the application layer and are exchanged in
- * new `ClientHello` / `ServerHello` extensions during the
- * handshake, where each side indicates the CID it wants the
- * peer to use when writing encrypted messages. The CIDs are
- * put to use once records get encrypted: the stack discards
- * any incoming records that don't include the configured CID
- * in their header, and adds the peer's requested CID to the
- * headers of outgoing messages.
- *
- * This API enables or disables the use of the CID extension
- * in the next handshake and sets the value of the CID to
- * be used for incoming messages.
- *
- * \param ssl The SSL context to configure. This must be initialized.
- * \param enable This value determines whether the CID extension should
- * be used or not. Possible values are:
- * - MBEDTLS_SSL_CID_ENABLED to enable the use of the CID.
- * - MBEDTLS_SSL_CID_DISABLED (default) to disable the use
- * of the CID.
- * \param own_cid The address of the readable buffer holding the CID we want
- * the peer to use when sending encrypted messages to us.
- * This may be \c NULL if \p own_cid_len is \c 0.
- * This parameter is unused if \p enabled is set to
- * MBEDTLS_SSL_CID_DISABLED.
- * \param own_cid_len The length of \p own_cid.
- * This parameter is unused if \p enabled is set to
- * MBEDTLS_SSL_CID_DISABLED.
- *
- * \note The value of \p own_cid_len must match the value of the
- * \c len parameter passed to mbedtls_ssl_conf_cid()
- * when configuring the ::mbedtls_ssl_config that \p ssl
- * is bound to.
- *
- * \note This CID configuration applies to subsequent handshakes
- * performed on the SSL context \p ssl, but does not trigger
- * one. You still have to call `mbedtls_ssl_handshake()`
- * (for the initial handshake) or `mbedtls_ssl_renegotiate()`
- * (for a renegotiation handshake) explicitly after a
- * successful call to this function to run the handshake.
- *
- * \note This call cannot guarantee that the use of the CID
- * will be successfully negotiated in the next handshake,
- * because the peer might not support it. Specifically:
- * - On the Client, enabling the use of the CID through
- * this call implies that the `ClientHello` in the next
- * handshake will include the CID extension, thereby
- * offering the use of the CID to the server. Only if
- * the `ServerHello` contains the CID extension, too,
- * the CID extension will actually be put to use.
- * - On the Server, enabling the use of the CID through
- * this call implies that that the server will look for
- * the CID extension in a `ClientHello` from the client,
- * and, if present, reply with a CID extension in its
- * `ServerHello`.
- *
- * \note To check whether the use of the CID was negotiated
- * after the subsequent handshake has completed, please
- * use the API mbedtls_ssl_get_peer_cid().
- *
- * \warning If the use of the CID extension is enabled in this call
- * and the subsequent handshake negotiates its use, Mbed TLS
- * will silently drop every packet whose CID does not match
- * the CID configured in \p own_cid. It is the responsibility
- * of the user to adapt the underlying transport to take care
- * of CID-based demultiplexing before handing datagrams to
- * Mbed TLS.
- *
- * \return \c 0 on success. In this case, the CID configuration
- * applies to the next handshake.
- * \return A negative error code on failure.
- */
- int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl,
- int enable,
- unsigned char const *own_cid,
- size_t own_cid_len );
- /**
- * \brief Get information about the use of the CID extension
- * in the current connection.
- *
- * \param ssl The SSL context to query.
- * \param enabled The address at which to store whether the CID extension
- * is currently in use or not. If the CID is in use,
- * `*enabled` is set to MBEDTLS_SSL_CID_ENABLED;
- * otherwise, it is set to MBEDTLS_SSL_CID_DISABLED.
- * \param peer_cid The address of the buffer in which to store the CID
- * chosen by the peer (if the CID extension is used).
- * This may be \c NULL in case the value of peer CID
- * isn't needed. If it is not \c NULL, \p peer_cid_len
- * must not be \c NULL.
- * \param peer_cid_len The address at which to store the size of the CID
- * chosen by the peer (if the CID extension is used).
- * This is also the number of Bytes in \p peer_cid that
- * have been written.
- * This may be \c NULL in case the length of the peer CID
- * isn't needed. If it is \c NULL, \p peer_cid must be
- * \c NULL, too.
- *
- * \note This applies to the state of the CID negotiated in
- * the last complete handshake. If a handshake is in
- * progress, this function will attempt to complete
- * the handshake first.
- *
- * \note If CID extensions have been exchanged but both client
- * and server chose to use an empty CID, this function
- * sets `*enabled` to #MBEDTLS_SSL_CID_DISABLED
- * (the rationale for this is that the resulting
- * communication is the same as if the CID extensions
- * hadn't been used).
- *
- * \return \c 0 on success.
- * \return A negative error code on failure.
- */
- int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl,
- int *enabled,
- unsigned char peer_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ],
- size_t *peer_cid_len );
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- /**
- * \brief Set the Maximum Tranport Unit (MTU).
- * Special value: 0 means unset (no limit).
- * This represents the maximum size of a datagram payload
- * handled by the transport layer (usually UDP) as determined
- * by the network link and stack. In practice, this controls
- * the maximum size datagram the DTLS layer will pass to the
- * \c f_send() callback set using \c mbedtls_ssl_set_bio().
- *
- * \note The limit on datagram size is converted to a limit on
- * record payload by subtracting the current overhead of
- * encapsulation and encryption/authentication if any.
- *
- * \note This can be called at any point during the connection, for
- * example when a Path Maximum Transfer Unit (PMTU)
- * estimate becomes available from other sources,
- * such as lower (or higher) protocol layers.
- *
- * \note This setting only controls the size of the packets we send,
- * and does not restrict the size of the datagrams we're
- * willing to receive. Client-side, you can request the
- * server to use smaller records with \c
- * mbedtls_ssl_conf_max_frag_len().
- *
- * \note If both a MTU and a maximum fragment length have been
- * configured (or negotiated with the peer), the resulting
- * lower limit on record payload (see first note) is used.
- *
- * \note This can only be used to decrease the maximum size
- * of datagrams (hence records, see first note) sent. It
- * cannot be used to increase the maximum size of records over
- * the limit set by #MBEDTLS_SSL_OUT_CONTENT_LEN.
- *
- * \note Values lower than the current record layer expansion will
- * result in an error when trying to send data.
- *
- * \note Using record compression together with a non-zero MTU value
- * will result in an error when trying to send data.
- *
- * \param ssl SSL context
- * \param mtu Value of the path MTU in bytes
- */
- void mbedtls_ssl_set_mtu( mbedtls_ssl_context *ssl, uint16_t mtu );
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * \brief Set a connection-specific verification callback (optional).
- *
- * If set, the provided verify callback is called for each
- * certificate in the peer's CRT chain, including the trusted
- * root. For more information, please see the documentation of
- * \c mbedtls_x509_crt_verify().
- *
- * \note This call is analogous to mbedtls_ssl_conf_verify() but
- * binds the verification callback and context to an SSL context
- * as opposed to an SSL configuration.
- * If mbedtls_ssl_conf_verify() and mbedtls_ssl_set_verify()
- * are both used, mbedtls_ssl_set_verify() takes precedence.
- *
- * \param ssl The SSL context to use.
- * \param f_vrfy The verification callback to use during CRT verification.
- * \param p_vrfy The opaque context to be passed to the callback.
- */
- void mbedtls_ssl_set_verify( mbedtls_ssl_context *ssl,
- int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
- void *p_vrfy );
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- /**
- * \brief Set the timeout period for mbedtls_ssl_read()
- * (Default: no timeout.)
- *
- * \param conf SSL configuration context
- * \param timeout Timeout value in milliseconds.
- * Use 0 for no timeout (default).
- *
- * \note With blocking I/O, this will only work if a non-NULL
- * \c f_recv_timeout was set with \c mbedtls_ssl_set_bio().
- * With non-blocking I/O, this will only work if timer
- * callbacks were set with \c mbedtls_ssl_set_timer_cb().
- *
- * \note With non-blocking I/O, you may also skip this function
- * altogether and handle timeouts at the application layer.
- */
- void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
- #if defined(MBEDTLS_SSL_RECORD_CHECKING)
- /**
- * \brief Check whether a buffer contains a valid and authentic record
- * that has not been seen before. (DTLS only).
- *
- * This function does not change the user-visible state
- * of the SSL context. Its sole purpose is to provide
- * an indication of the legitimacy of an incoming record.
- *
- * This can be useful e.g. in distributed server environments
- * using the DTLS Connection ID feature, in which connections
- * might need to be passed between service instances on a change
- * of peer address, but where such disruptive operations should
- * only happen after the validity of incoming records has been
- * confirmed.
- *
- * \param ssl The SSL context to use.
- * \param buf The address of the buffer holding the record to be checked.
- * This must be a read/write buffer of length \p buflen Bytes.
- * \param buflen The length of \p buf in Bytes.
- *
- * \note This routine only checks whether the provided buffer begins
- * with a valid and authentic record that has not been seen
- * before, but does not check potential data following the
- * initial record. In particular, it is possible to pass DTLS
- * datagrams containing multiple records, in which case only
- * the first record is checked.
- *
- * \note This function modifies the input buffer \p buf. If you need
- * to preserve the original record, you have to maintain a copy.
- *
- * \return \c 0 if the record is valid and authentic and has not been
- * seen before.
- * \return MBEDTLS_ERR_SSL_INVALID_MAC if the check completed
- * successfully but the record was found to be not authentic.
- * \return MBEDTLS_ERR_SSL_INVALID_RECORD if the check completed
- * successfully but the record was found to be invalid for
- * a reason different from authenticity checking.
- * \return MBEDTLS_ERR_SSL_UNEXPECTED_RECORD if the check completed
- * successfully but the record was found to be unexpected
- * in the state of the SSL context, including replayed records.
- * \return Another negative error code on different kinds of failure.
- * In this case, the SSL context becomes unusable and needs
- * to be freed or reset before reuse.
- */
- int mbedtls_ssl_check_record( mbedtls_ssl_context const *ssl,
- unsigned char *buf,
- size_t buflen );
- #endif /* MBEDTLS_SSL_RECORD_CHECKING */
- /**
- * \brief Set the timer callbacks (Mandatory for DTLS.)
- *
- * \param ssl SSL context
- * \param p_timer parameter (context) shared by timer callbacks
- * \param f_set_timer set timer callback
- * \param f_get_timer get timer callback. Must return:
- *
- * \note See the documentation of \c mbedtls_ssl_set_timer_t and
- * \c mbedtls_ssl_get_timer_t for the conventions this pair of
- * callbacks must follow.
- *
- * \note On some platforms, timing.c provides
- * \c mbedtls_timing_set_delay() and
- * \c mbedtls_timing_get_delay() that are suitable for using
- * here, except if using an event-driven style.
- *
- * \note See also the "DTLS tutorial" article in our knowledge base.
- * https://tls.mbed.org/kb/how-to/dtls-tutorial
- */
- void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *ssl,
- void *p_timer,
- mbedtls_ssl_set_timer_t *f_set_timer,
- mbedtls_ssl_get_timer_t *f_get_timer );
- /**
- * \brief Callback type: generate and write session ticket
- *
- * \note This describes what a callback implementation should do.
- * This callback should generate an encrypted and
- * authenticated ticket for the session and write it to the
- * output buffer. Here, ticket means the opaque ticket part
- * of the NewSessionTicket structure of RFC 5077.
- *
- * \param p_ticket Context for the callback
- * \param session SSL session to be written in the ticket
- * \param start Start of the output buffer
- * \param end End of the output buffer
- * \param tlen On exit, holds the length written
- * \param lifetime On exit, holds the lifetime of the ticket in seconds
- *
- * \return 0 if successful, or
- * a specific MBEDTLS_ERR_XXX code.
- */
- typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
- const mbedtls_ssl_session *session,
- unsigned char *start,
- const unsigned char *end,
- size_t *tlen,
- uint32_t *lifetime );
- #if defined(MBEDTLS_SSL_EXPORT_KEYS)
- /**
- * \brief Callback type: Export key block and master secret
- *
- * \note This is required for certain uses of TLS, e.g. EAP-TLS
- * (RFC 5216) and Thread. The key pointers are ephemeral and
- * therefore must not be stored. The master secret and keys
- * should not be used directly except as an input to a key
- * derivation function.
- *
- * \param p_expkey Context for the callback
- * \param ms Pointer to master secret (fixed length: 48 bytes)
- * \param kb Pointer to key block, see RFC 5246 section 6.3
- * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
- * \param maclen MAC length
- * \param keylen Key length
- * \param ivlen IV length
- *
- * \return 0 if successful, or
- * a specific MBEDTLS_ERR_XXX code.
- */
- typedef int mbedtls_ssl_export_keys_t( void *p_expkey,
- const unsigned char *ms,
- const unsigned char *kb,
- size_t maclen,
- size_t keylen,
- size_t ivlen );
- /**
- * \brief Callback type: Export key block, master secret,
- * handshake randbytes and the tls_prf function
- * used to derive keys.
- *
- * \note This is required for certain uses of TLS, e.g. EAP-TLS
- * (RFC 5216) and Thread. The key pointers are ephemeral and
- * therefore must not be stored. The master secret and keys
- * should not be used directly except as an input to a key
- * derivation function.
- *
- * \param p_expkey Context for the callback.
- * \param ms Pointer to master secret (fixed length: 48 bytes).
- * \param kb Pointer to key block, see RFC 5246 section 6.3.
- * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
- * \param maclen MAC length.
- * \param keylen Key length.
- * \param ivlen IV length.
- * \param client_random The client random bytes.
- * \param server_random The server random bytes.
- * \param tls_prf_type The tls_prf enum type.
- *
- * \return 0 if successful, or
- * a specific MBEDTLS_ERR_XXX code.
- */
- typedef int mbedtls_ssl_export_keys_ext_t( void *p_expkey,
- const unsigned char *ms,
- const unsigned char *kb,
- size_t maclen,
- size_t keylen,
- size_t ivlen,
- const unsigned char client_random[32],
- const unsigned char server_random[32],
- mbedtls_tls_prf_types tls_prf_type );
- #endif /* MBEDTLS_SSL_EXPORT_KEYS */
- /**
- * \brief Callback type: parse and load session ticket
- *
- * \note This describes what a callback implementation should do.
- * This callback should parse a session ticket as generated
- * by the corresponding mbedtls_ssl_ticket_write_t function,
- * and, if the ticket is authentic and valid, load the
- * session.
- *
- * \note The implementation is allowed to modify the first len
- * bytes of the input buffer, eg to use it as a temporary
- * area for the decrypted ticket contents.
- *
- * \param p_ticket Context for the callback
- * \param session SSL session to be loaded
- * \param buf Start of the buffer containing the ticket
- * \param len Length of the ticket.
- *
- * \return 0 if successful, or
- * MBEDTLS_ERR_SSL_INVALID_MAC if not authentic, or
- * MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED if expired, or
- * any other non-zero code for other failures.
- */
- typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
- mbedtls_ssl_session *session,
- unsigned char *buf,
- size_t len );
- #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
- /**
- * \brief Configure SSL session ticket callbacks (server only).
- * (Default: none.)
- *
- * \note On server, session tickets are enabled by providing
- * non-NULL callbacks.
- *
- * \note On client, use \c mbedtls_ssl_conf_session_tickets().
- *
- * \param conf SSL configuration context
- * \param f_ticket_write Callback for writing a ticket
- * \param f_ticket_parse Callback for parsing a ticket
- * \param p_ticket Context shared by the two callbacks
- */
- void mbedtls_ssl_conf_session_tickets_cb( mbedtls_ssl_config *conf,
- mbedtls_ssl_ticket_write_t *f_ticket_write,
- mbedtls_ssl_ticket_parse_t *f_ticket_parse,
- void *p_ticket );
- #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
- #if defined(MBEDTLS_SSL_EXPORT_KEYS)
- /**
- * \brief Configure key export callback.
- * (Default: none.)
- *
- * \note See \c mbedtls_ssl_export_keys_t.
- *
- * \param conf SSL configuration context
- * \param f_export_keys Callback for exporting keys
- * \param p_export_keys Context for the callback
- */
- void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf,
- mbedtls_ssl_export_keys_t *f_export_keys,
- void *p_export_keys );
- /**
- * \brief Configure extended key export callback.
- * (Default: none.)
- *
- * \note See \c mbedtls_ssl_export_keys_ext_t.
- * \warning Exported key material must not be used for any purpose
- * before the (D)TLS handshake is completed
- *
- * \param conf SSL configuration context
- * \param f_export_keys_ext Callback for exporting keys
- * \param p_export_keys Context for the callback
- */
- void mbedtls_ssl_conf_export_keys_ext_cb( mbedtls_ssl_config *conf,
- mbedtls_ssl_export_keys_ext_t *f_export_keys_ext,
- void *p_export_keys );
- #endif /* MBEDTLS_SSL_EXPORT_KEYS */
- #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
- /**
- * \brief Configure asynchronous private key operation callbacks.
- *
- * \param conf SSL configuration context
- * \param f_async_sign Callback to start a signature operation. See
- * the description of ::mbedtls_ssl_async_sign_t
- * for more information. This may be \c NULL if the
- * external processor does not support any signature
- * operation; in this case the private key object
- * associated with the certificate will be used.
- * \param f_async_decrypt Callback to start a decryption operation. See
- * the description of ::mbedtls_ssl_async_decrypt_t
- * for more information. This may be \c NULL if the
- * external processor does not support any decryption
- * operation; in this case the private key object
- * associated with the certificate will be used.
- * \param f_async_resume Callback to resume an asynchronous operation. See
- * the description of ::mbedtls_ssl_async_resume_t
- * for more information. This may not be \c NULL unless
- * \p f_async_sign and \p f_async_decrypt are both
- * \c NULL.
- * \param f_async_cancel Callback to cancel an asynchronous operation. See
- * the description of ::mbedtls_ssl_async_cancel_t
- * for more information. This may be \c NULL if
- * no cleanup is needed.
- * \param config_data A pointer to configuration data which can be
- * retrieved with
- * mbedtls_ssl_conf_get_async_config_data(). The
- * library stores this value without dereferencing it.
- */
- void mbedtls_ssl_conf_async_private_cb( mbedtls_ssl_config *conf,
- mbedtls_ssl_async_sign_t *f_async_sign,
- mbedtls_ssl_async_decrypt_t *f_async_decrypt,
- mbedtls_ssl_async_resume_t *f_async_resume,
- mbedtls_ssl_async_cancel_t *f_async_cancel,
- void *config_data );
- /**
- * \brief Retrieve the configuration data set by
- * mbedtls_ssl_conf_async_private_cb().
- *
- * \param conf SSL configuration context
- * \return The configuration data set by
- * mbedtls_ssl_conf_async_private_cb().
- */
- void *mbedtls_ssl_conf_get_async_config_data( const mbedtls_ssl_config *conf );
- /**
- * \brief Retrieve the asynchronous operation user context.
- *
- * \note This function may only be called while a handshake
- * is in progress.
- *
- * \param ssl The SSL context to access.
- *
- * \return The asynchronous operation user context that was last
- * set during the current handshake. If
- * mbedtls_ssl_set_async_operation_data() has not yet been
- * called during the current handshake, this function returns
- * \c NULL.
- */
- void *mbedtls_ssl_get_async_operation_data( const mbedtls_ssl_context *ssl );
- /**
- * \brief Retrieve the asynchronous operation user context.
- *
- * \note This function may only be called while a handshake
- * is in progress.
- *
- * \param ssl The SSL context to access.
- * \param ctx The new value of the asynchronous operation user context.
- * Call mbedtls_ssl_get_async_operation_data() later during the
- * same handshake to retrieve this value.
- */
- void mbedtls_ssl_set_async_operation_data( mbedtls_ssl_context *ssl,
- void *ctx );
- #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
- /**
- * \brief Callback type: generate a cookie
- *
- * \param ctx Context for the callback
- * \param p Buffer to write to,
- * must be updated to point right after the cookie
- * \param end Pointer to one past the end of the output buffer
- * \param info Client ID info that was passed to
- * \c mbedtls_ssl_set_client_transport_id()
- * \param ilen Length of info in bytes
- *
- * \return The callback must return 0 on success,
- * or a negative error code.
- */
- typedef int mbedtls_ssl_cookie_write_t( void *ctx,
- unsigned char **p, unsigned char *end,
- const unsigned char *info, size_t ilen );
- /**
- * \brief Callback type: verify a cookie
- *
- * \param ctx Context for the callback
- * \param cookie Cookie to verify
- * \param clen Length of cookie
- * \param info Client ID info that was passed to
- * \c mbedtls_ssl_set_client_transport_id()
- * \param ilen Length of info in bytes
- *
- * \return The callback must return 0 if cookie is valid,
- * or a negative error code.
- */
- typedef int mbedtls_ssl_cookie_check_t( void *ctx,
- const unsigned char *cookie, size_t clen,
- const unsigned char *info, size_t ilen );
- #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
- /**
- * \brief Register callbacks for DTLS cookies
- * (Server only. DTLS only.)
- *
- * Default: dummy callbacks that fail, in order to force you to
- * register working callbacks (and initialize their context).
- *
- * To disable HelloVerifyRequest, register NULL callbacks.
- *
- * \warning Disabling hello verification allows your server to be used
- * for amplification in DoS attacks against other hosts.
- * Only disable if you known this can't happen in your
- * particular environment.
- *
- * \note See comments on \c mbedtls_ssl_handshake() about handling
- * the MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED that is expected
- * on the first handshake attempt when this is enabled.
- *
- * \note This is also necessary to handle client reconnection from
- * the same port as described in RFC 6347 section 4.2.8 (only
- * the variant with cookies is supported currently). See
- * comments on \c mbedtls_ssl_read() for details.
- *
- * \param conf SSL configuration
- * \param f_cookie_write Cookie write callback
- * \param f_cookie_check Cookie check callback
- * \param p_cookie Context for both callbacks
- */
- void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf,
- mbedtls_ssl_cookie_write_t *f_cookie_write,
- mbedtls_ssl_cookie_check_t *f_cookie_check,
- void *p_cookie );
- /**
- * \brief Set client's transport-level identification info.
- * (Server only. DTLS only.)
- *
- * This is usually the IP address (and port), but could be
- * anything identify the client depending on the underlying
- * network stack. Used for HelloVerifyRequest with DTLS.
- * This is *not* used to route the actual packets.
- *
- * \param ssl SSL context
- * \param info Transport-level info identifying the client (eg IP + port)
- * \param ilen Length of info in bytes
- *
- * \note An internal copy is made, so the info buffer can be reused.
- *
- * \return 0 on success,
- * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used on client,
- * MBEDTLS_ERR_SSL_ALLOC_FAILED if out of memory.
- */
- int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl,
- const unsigned char *info,
- size_t ilen );
- #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
- #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
- /**
- * \brief Enable or disable anti-replay protection for DTLS.
- * (DTLS only, no effect on TLS.)
- * Default: enabled.
- *
- * \param conf SSL configuration
- * \param mode MBEDTLS_SSL_ANTI_REPLAY_ENABLED or MBEDTLS_SSL_ANTI_REPLAY_DISABLED.
- *
- * \warning Disabling this is a security risk unless the application
- * protocol handles duplicated packets in a safe way. You
- * should not disable this without careful consideration.
- * However, if your application already detects duplicated
- * packets and needs information about them to adjust its
- * transmission strategy, then you'll want to disable this.
- */
- void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
- #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
- #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
- /**
- * \brief Set a limit on the number of records with a bad MAC
- * before terminating the connection.
- * (DTLS only, no effect on TLS.)
- * Default: 0 (disabled).
- *
- * \param conf SSL configuration
- * \param limit Limit, or 0 to disable.
- *
- * \note If the limit is N, then the connection is terminated when
- * the Nth non-authentic record is seen.
- *
- * \note Records with an invalid header are not counted, only the
- * ones going through the authentication-decryption phase.
- *
- * \note This is a security trade-off related to the fact that it's
- * often relatively easy for an active attacker ot inject UDP
- * datagrams. On one hand, setting a low limit here makes it
- * easier for such an attacker to forcibly terminated a
- * connection. On the other hand, a high limit or no limit
- * might make us waste resources checking authentication on
- * many bogus packets.
- */
- void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
- #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- /**
- * \brief Allow or disallow packing of multiple handshake records
- * within a single datagram.
- *
- * \param ssl The SSL context to configure.
- * \param allow_packing This determines whether datagram packing may
- * be used or not. A value of \c 0 means that every
- * record will be sent in a separate datagram; a
- * value of \c 1 means that, if space permits,
- * multiple handshake messages (including CCS) belonging to
- * a single flight may be packed within a single datagram.
- *
- * \note This is enabled by default and should only be disabled
- * for test purposes, or if datagram packing causes
- * interoperability issues with peers that don't support it.
- *
- * \note Allowing datagram packing reduces the network load since
- * there's less overhead if multiple messages share the same
- * datagram. Also, it increases the handshake efficiency
- * since messages belonging to a single datagram will not
- * be reordered in transit, and so future message buffering
- * or flight retransmission (if no buffering is used) as
- * means to deal with reordering are needed less frequently.
- *
- * \note Application records are not affected by this option and
- * are currently always sent in separate datagrams.
- *
- */
- void mbedtls_ssl_set_datagram_packing( mbedtls_ssl_context *ssl,
- unsigned allow_packing );
- /**
- * \brief Set retransmit timeout values for the DTLS handshake.
- * (DTLS only, no effect on TLS.)
- *
- * \param conf SSL configuration
- * \param min Initial timeout value in milliseconds.
- * Default: 1000 (1 second).
- * \param max Maximum timeout value in milliseconds.
- * Default: 60000 (60 seconds).
- *
- * \note Default values are from RFC 6347 section 4.2.4.1.
- *
- * \note The 'min' value should typically be slightly above the
- * expected round-trip time to your peer, plus whatever time
- * it takes for the peer to process the message. For example,
- * if your RTT is about 600ms and you peer needs up to 1s to
- * do the cryptographic operations in the handshake, then you
- * should set 'min' slightly above 1600. Lower values of 'min'
- * might cause spurious resends which waste network resources,
- * while larger value of 'min' will increase overall latency
- * on unreliable network links.
- *
- * \note The more unreliable your network connection is, the larger
- * your max / min ratio needs to be in order to achieve
- * reliable handshakes.
- *
- * \note Messages are retransmitted up to log2(ceil(max/min)) times.
- * For example, if min = 1s and max = 5s, the retransmit plan
- * goes: send ... 1s -> resend ... 2s -> resend ... 4s ->
- * resend ... 5s -> give up and return a timeout error.
- */
- void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- #if defined(MBEDTLS_SSL_SRV_C)
- /**
- * \brief Set the session cache callbacks (server-side only)
- * If not set, no session resuming is done (except if session
- * tickets are enabled too).
- *
- * The session cache has the responsibility to check for stale
- * entries based on timeout. See RFC 5246 for recommendations.
- *
- * Warning: session.peer_cert is cleared by the SSL/TLS layer on
- * connection shutdown, so do not cache the pointer! Either set
- * it to NULL or make a full copy of the certificate.
- *
- * The get callback is called once during the initial handshake
- * to enable session resuming. The get function has the
- * following parameters: (void *parameter, mbedtls_ssl_session *session)
- * If a valid entry is found, it should fill the master of
- * the session object with the cached values and return 0,
- * return 1 otherwise. Optionally peer_cert can be set as well
- * if it is properly present in cache entry.
- *
- * The set callback is called once during the initial handshake
- * to enable session resuming after the entire handshake has
- * been finished. The set function has the following parameters:
- * (void *parameter, const mbedtls_ssl_session *session). The function
- * should create a cache entry for future retrieval based on
- * the data in the session structure and should keep in mind
- * that the mbedtls_ssl_session object presented (and all its referenced
- * data) is cleared by the SSL/TLS layer when the connection is
- * terminated. It is recommended to add metadata to determine if
- * an entry is still valid in the future. Return 0 if
- * successfully cached, return 1 otherwise.
- *
- * \param conf SSL configuration
- * \param p_cache parmater (context) for both callbacks
- * \param f_get_cache session get callback
- * \param f_set_cache session set callback
- */
- void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf,
- void *p_cache,
- int (*f_get_cache)(void *, mbedtls_ssl_session *),
- int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
- #endif /* MBEDTLS_SSL_SRV_C */
- #if defined(MBEDTLS_SSL_CLI_C)
- /**
- * \brief Request resumption of session (client-side only)
- * Session data is copied from presented session structure.
- *
- * \param ssl SSL context
- * \param session session context
- *
- * \return 0 if successful,
- * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
- * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
- * arguments are otherwise invalid
- *
- * \sa mbedtls_ssl_get_session()
- */
- int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session );
- #endif /* MBEDTLS_SSL_CLI_C */
- /**
- * \brief Load serialized session data into a session structure.
- * On client, this can be used for loading saved sessions
- * before resuming them with mbedstls_ssl_set_session().
- * On server, this can be used for alternative implementations
- * of session cache or session tickets.
- *
- * \warning If a peer certificate chain is associated with the session,
- * the serialized state will only contain the peer's
- * end-entity certificate and the result of the chain
- * verification (unless verification was disabled), but not
- * the rest of the chain.
- *
- * \see mbedtls_ssl_session_save()
- * \see mbedtls_ssl_set_session()
- *
- * \param session The session structure to be populated. It must have been
- * initialised with mbedtls_ssl_session_init() but not
- * populated yet.
- * \param buf The buffer holding the serialized session data. It must be a
- * readable buffer of at least \p len bytes.
- * \param len The size of the serialized data in bytes.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed.
- * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid.
- * \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data
- * was generated in a different version or configuration of
- * Mbed TLS.
- * \return Another negative value for other kinds of errors (for
- * example, unsupported features in the embedded certificate).
- */
- int mbedtls_ssl_session_load( mbedtls_ssl_session *session,
- const unsigned char *buf,
- size_t len );
- /**
- * \brief Save session structure as serialized data in a buffer.
- * On client, this can be used for saving session data,
- * potentially in non-volatile storage, for resuming later.
- * On server, this can be used for alternative implementations
- * of session cache or session tickets.
- *
- * \see mbedtls_ssl_session_load()
- * \see mbedtls_ssl_get_session_pointer()
- *
- * \param session The session structure to be saved.
- * \param buf The buffer to write the serialized data to. It must be a
- * writeable buffer of at least \p len bytes, or may be \c
- * NULL if \p len is \c 0.
- * \param buf_len The number of bytes available for writing in \p buf.
- * \param olen The size in bytes of the data that has been or would have
- * been written. It must point to a valid \c size_t.
- *
- * \note \p olen is updated to the correct value regardless of
- * whether \p buf_len was large enough. This makes it possible
- * to determine the necessary size by calling this function
- * with \p buf set to \c NULL and \p buf_len to \c 0.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small.
- */
- int mbedtls_ssl_session_save( const mbedtls_ssl_session *session,
- unsigned char *buf,
- size_t buf_len,
- size_t *olen );
- /**
- * \brief Get a pointer to the current session structure, for example
- * to serialize it.
- *
- * \warning Ownership of the session remains with the SSL context, and
- * the returned pointer is only guaranteed to be valid until
- * the next API call operating on the same \p ssl context.
- *
- * \see mbedtls_ssl_session_save()
- *
- * \param ssl The SSL context.
- *
- * \return A pointer to the current session if successful.
- * \return \c NULL if no session is active.
- */
- const mbedtls_ssl_session *mbedtls_ssl_get_session_pointer( const mbedtls_ssl_context *ssl );
- /**
- * \brief Set the list of allowed ciphersuites and the preference
- * order. First in the list has the highest preference.
- * (Overrides all version-specific lists)
- *
- * The ciphersuites array is not copied, and must remain
- * valid for the lifetime of the ssl_config.
- *
- * Note: The server uses its own preferences
- * over the preference of the client unless
- * MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE is defined!
- *
- * \param conf SSL configuration
- * \param ciphersuites 0-terminated list of allowed ciphersuites
- */
- void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
- const int *ciphersuites );
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- #define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0
- #define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1
- /**
- * \brief Specify the length of Connection IDs for incoming
- * encrypted DTLS records, as well as the behaviour
- * on unexpected CIDs.
- *
- * By default, the CID length is set to \c 0,
- * and unexpected CIDs are silently ignored.
- *
- * \param conf The SSL configuration to modify.
- * \param len The length in Bytes of the CID fields in encrypted
- * DTLS records using the CID mechanism. This must
- * not be larger than #MBEDTLS_SSL_CID_OUT_LEN_MAX.
- * \param ignore_other_cids This determines the stack's behaviour when
- * receiving a record with an unexpected CID.
- * Possible values are:
- * - #MBEDTLS_SSL_UNEXPECTED_CID_IGNORE
- * In this case, the record is silently ignored.
- * - #MBEDTLS_SSL_UNEXPECTED_CID_FAIL
- * In this case, the stack fails with the specific
- * error code #MBEDTLS_ERR_SSL_UNEXPECTED_CID.
- *
- * \note The CID specification allows implementations to either
- * use a common length for all incoming connection IDs or
- * allow variable-length incoming IDs. Mbed TLS currently
- * requires a common length for all connections sharing the
- * same SSL configuration; this allows simpler parsing of
- * record headers.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if \p own_cid_len
- * is too large.
- */
- int mbedtls_ssl_conf_cid( mbedtls_ssl_config *conf, size_t len,
- int ignore_other_cids );
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- /**
- * \brief Set the list of allowed ciphersuites and the
- * preference order for a specific version of the protocol.
- * (Only useful on the server side)
- *
- * The ciphersuites array is not copied, and must remain
- * valid for the lifetime of the ssl_config.
- *
- * \param conf SSL configuration
- * \param ciphersuites 0-terminated list of allowed ciphersuites
- * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3
- * supported)
- * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
- * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
- * MBEDTLS_SSL_MINOR_VERSION_3 supported)
- *
- * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0
- * and MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
- */
- void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
- const int *ciphersuites,
- int major, int minor );
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * \brief Set the X.509 security profile used for verification
- *
- * \note The restrictions are enforced for all certificates in the
- * chain. However, signatures in the handshake are not covered
- * by this setting but by \b mbedtls_ssl_conf_sig_hashes().
- *
- * \param conf SSL configuration
- * \param profile Profile to use
- */
- void mbedtls_ssl_conf_cert_profile( mbedtls_ssl_config *conf,
- const mbedtls_x509_crt_profile *profile );
- /**
- * \brief Set the data required to verify peer certificate
- *
- * \note See \c mbedtls_x509_crt_verify() for notes regarding the
- * parameters ca_chain (maps to trust_ca for that function)
- * and ca_crl.
- *
- * \param conf SSL configuration
- * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
- * \param ca_crl trusted CA CRLs
- */
- void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf,
- mbedtls_x509_crt *ca_chain,
- mbedtls_x509_crl *ca_crl );
- #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
- /**
- * \brief Set the trusted certificate callback.
- *
- * This API allows to register the set of trusted certificates
- * through a callback, instead of a linked list as configured
- * by mbedtls_ssl_conf_ca_chain().
- *
- * This is useful for example in contexts where a large number
- * of CAs are used, and the inefficiency of maintaining them
- * in a linked list cannot be tolerated. It is also useful when
- * the set of trusted CAs needs to be modified frequently.
- *
- * See the documentation of `mbedtls_x509_crt_ca_cb_t` for
- * more information.
- *
- * \param conf The SSL configuration to register the callback with.
- * \param f_ca_cb The trusted certificate callback to use when verifying
- * certificate chains.
- * \param p_ca_cb The context to be passed to \p f_ca_cb (for example,
- * a reference to a trusted CA database).
- *
- * \note This API is incompatible with mbedtls_ssl_conf_ca_chain():
- * Any call to this function overwrites the values set through
- * earlier calls to mbedtls_ssl_conf_ca_chain() or
- * mbedtls_ssl_conf_ca_cb().
- *
- * \note This API is incompatible with CA indication in
- * CertificateRequest messages: A server-side SSL context which
- * is bound to an SSL configuration that uses a CA callback
- * configured via mbedtls_ssl_conf_ca_cb(), and which requires
- * client authentication, will send an empty CA list in the
- * corresponding CertificateRequest message.
- *
- * \note This API is incompatible with mbedtls_ssl_set_hs_ca_chain():
- * If an SSL context is bound to an SSL configuration which uses
- * CA callbacks configured via mbedtls_ssl_conf_ca_cb(), then
- * calls to mbedtls_ssl_set_hs_ca_chain() have no effect.
- *
- * \note The use of this API disables the use of restartable ECC
- * during X.509 CRT signature verification (but doesn't affect
- * other uses).
- *
- * \warning This API is incompatible with the use of CRLs. Any call to
- * mbedtls_ssl_conf_ca_cb() unsets CRLs configured through
- * earlier calls to mbedtls_ssl_conf_ca_chain().
- *
- * \warning In multi-threaded environments, the callback \p f_ca_cb
- * must be thread-safe, and it is the user's responsibility
- * to guarantee this (for example through a mutex
- * contained in the callback context pointed to by \p p_ca_cb).
- */
- void mbedtls_ssl_conf_ca_cb( mbedtls_ssl_config *conf,
- mbedtls_x509_crt_ca_cb_t f_ca_cb,
- void *p_ca_cb );
- #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
- /**
- * \brief Set own certificate chain and private key
- *
- * \note own_cert should contain in order from the bottom up your
- * certificate chain. The top certificate (self-signed)
- * can be omitted.
- *
- * \note On server, this function can be called multiple times to
- * provision more than one cert/key pair (eg one ECDSA, one
- * RSA with SHA-256, one RSA with SHA-1). An adequate
- * certificate will be selected according to the client's
- * advertised capabilities. In case multiple certificates are
- * adequate, preference is given to the one set by the first
- * call to this function, then second, etc.
- *
- * \note On client, only the first call has any effect. That is,
- * only one client certificate can be provisioned. The
- * server's preferences in its CertficateRequest message will
- * be ignored and our only cert will be sent regardless of
- * whether it matches those preferences - the server can then
- * decide what it wants to do with it.
- *
- * \note The provided \p pk_key needs to match the public key in the
- * first certificate in \p own_cert, or all handshakes using
- * that certificate will fail. It is your responsibility
- * to ensure that; this function will not perform any check.
- * You may use mbedtls_pk_check_pair() in order to perform
- * this check yourself, but be aware that this function can
- * be computationally expensive on some key types.
- *
- * \param conf SSL configuration
- * \param own_cert own public certificate chain
- * \param pk_key own private key
- *
- * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
- */
- int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf,
- mbedtls_x509_crt *own_cert,
- mbedtls_pk_context *pk_key );
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
- /**
- * \brief Configure a pre-shared key (PSK) and identity
- * to be used in PSK-based ciphersuites.
- *
- * \note This is mainly useful for clients. Servers will usually
- * want to use \c mbedtls_ssl_conf_psk_cb() instead.
- *
- * \note A PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback
- * takes precedence over a PSK configured by this function.
- *
- * \warning Currently, clients can only register a single pre-shared key.
- * Calling this function or mbedtls_ssl_conf_psk_opaque() more
- * than once will overwrite values configured in previous calls.
- * Support for setting multiple PSKs on clients and selecting
- * one based on the identity hint is not a planned feature,
- * but feedback is welcomed.
- *
- * \param conf The SSL configuration to register the PSK with.
- * \param psk The pointer to the pre-shared key to use.
- * \param psk_len The length of the pre-shared key in bytes.
- * \param psk_identity The pointer to the pre-shared key identity.
- * \param psk_identity_len The length of the pre-shared key identity
- * in bytes.
- *
- * \note The PSK and its identity are copied internally and
- * hence need not be preserved by the caller for the lifetime
- * of the SSL configuration.
- *
- * \return \c 0 if successful.
- * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
- */
- int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
- const unsigned char *psk, size_t psk_len,
- const unsigned char *psk_identity, size_t psk_identity_len );
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- /**
- * \brief Configure an opaque pre-shared key (PSK) and identity
- * to be used in PSK-based ciphersuites.
- *
- * \note This is mainly useful for clients. Servers will usually
- * want to use \c mbedtls_ssl_conf_psk_cb() instead.
- *
- * \note An opaque PSK set by \c mbedtls_ssl_set_hs_psk_opaque() in
- * the PSK callback takes precedence over an opaque PSK
- * configured by this function.
- *
- * \warning Currently, clients can only register a single pre-shared key.
- * Calling this function or mbedtls_ssl_conf_psk() more than
- * once will overwrite values configured in previous calls.
- * Support for setting multiple PSKs on clients and selecting
- * one based on the identity hint is not a planned feature,
- * but feedback is welcomed.
- *
- * \param conf The SSL configuration to register the PSK with.
- * \param psk The identifier of the key slot holding the PSK.
- * Until \p conf is destroyed or this function is successfully
- * called again, the key slot \p psk must be populated with a
- * key of type PSA_ALG_CATEGORY_KEY_DERIVATION whose policy
- * allows its use for the key derivation algorithm applied
- * in the handshake.
- * \param psk_identity The pointer to the pre-shared key identity.
- * \param psk_identity_len The length of the pre-shared key identity
- * in bytes.
- *
- * \note The PSK identity hint is copied internally and hence need
- * not be preserved by the caller for the lifetime of the
- * SSL configuration.
- *
- * \return \c 0 if successful.
- * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
- */
- int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf,
- psa_key_id_t psk,
- const unsigned char *psk_identity,
- size_t psk_identity_len );
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- /**
- * \brief Set the pre-shared Key (PSK) for the current handshake.
- *
- * \note This should only be called inside the PSK callback,
- * i.e. the function passed to \c mbedtls_ssl_conf_psk_cb().
- *
- * \note A PSK set by this function takes precedence over a PSK
- * configured by \c mbedtls_ssl_conf_psk().
- *
- * \param ssl The SSL context to configure a PSK for.
- * \param psk The pointer to the pre-shared key.
- * \param psk_len The length of the pre-shared key in bytes.
- *
- * \return \c 0 if successful.
- * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
- */
- int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
- const unsigned char *psk, size_t psk_len );
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- /**
- * \brief Set an opaque pre-shared Key (PSK) for the current handshake.
- *
- * \note This should only be called inside the PSK callback,
- * i.e. the function passed to \c mbedtls_ssl_conf_psk_cb().
- *
- * \note An opaque PSK set by this function takes precedence over an
- * opaque PSK configured by \c mbedtls_ssl_conf_psk_opaque().
- *
- * \param ssl The SSL context to configure a PSK for.
- * \param psk The identifier of the key slot holding the PSK.
- * For the duration of the current handshake, the key slot
- * must be populated with a key of type
- * PSA_ALG_CATEGORY_KEY_DERIVATION whose policy allows its
- * use for the key derivation algorithm
- * applied in the handshake.
- *
- * \return \c 0 if successful.
- * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
- */
- int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl,
- psa_key_id_t psk );
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- /**
- * \brief Set the PSK callback (server-side only).
- *
- * If set, the PSK callback is called for each
- * handshake where a PSK-based ciphersuite was negotiated.
- * The caller provides the identity received and wants to
- * receive the actual PSK data and length.
- *
- * The callback has the following parameters:
- * - \c void*: The opaque pointer \p p_psk.
- * - \c mbedtls_ssl_context*: The SSL context to which
- * the operation applies.
- * - \c const unsigned char*: The PSK identity
- * selected by the client.
- * - \c size_t: The length of the PSK identity
- * selected by the client.
- *
- * If a valid PSK identity is found, the callback should use
- * \c mbedtls_ssl_set_hs_psk() or
- * \c mbedtls_ssl_set_hs_psk_opaque()
- * on the SSL context to set the correct PSK and return \c 0.
- * Any other return value will result in a denied PSK identity.
- *
- * \note A dynamic PSK (i.e. set by the PSK callback) takes
- * precedence over a static PSK (i.e. set by
- * \c mbedtls_ssl_conf_psk() or
- * \c mbedtls_ssl_conf_psk_opaque()).
- * This means that if you set a PSK callback using this
- * function, you don't need to set a PSK using
- * \c mbedtls_ssl_conf_psk() or
- * \c mbedtls_ssl_conf_psk_opaque()).
- *
- * \param conf The SSL configuration to register the callback with.
- * \param f_psk The callback for selecting and setting the PSK based
- * in the PSK identity chosen by the client.
- * \param p_psk A pointer to an opaque structure to be passed to
- * the callback, for example a PSK store.
- */
- void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf,
- int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
- size_t),
- void *p_psk );
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
- #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief Set the Diffie-Hellman public P and G values,
- * read as hexadecimal strings (server-side only)
- * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG])
- *
- * \param conf SSL configuration
- * \param dhm_P Diffie-Hellman-Merkle modulus
- * \param dhm_G Diffie-Hellman-Merkle generator
- *
- * \deprecated Superseded by \c mbedtls_ssl_conf_dh_param_bin.
- *
- * \return 0 if successful
- */
- MBEDTLS_DEPRECATED int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf,
- const char *dhm_P,
- const char *dhm_G );
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief Set the Diffie-Hellman public P and G values
- * from big-endian binary presentations.
- * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]_BIN)
- *
- * \param conf SSL configuration
- * \param dhm_P Diffie-Hellman-Merkle modulus in big-endian binary form
- * \param P_len Length of DHM modulus
- * \param dhm_G Diffie-Hellman-Merkle generator in big-endian binary form
- * \param G_len Length of DHM generator
- *
- * \return 0 if successful
- */
- int mbedtls_ssl_conf_dh_param_bin( mbedtls_ssl_config *conf,
- const unsigned char *dhm_P, size_t P_len,
- const unsigned char *dhm_G, size_t G_len );
- /**
- * \brief Set the Diffie-Hellman public P and G values,
- * read from existing context (server-side only)
- *
- * \param conf SSL configuration
- * \param dhm_ctx Diffie-Hellman-Merkle context
- *
- * \return 0 if successful
- */
- int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx );
- #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
- #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
- /**
- * \brief Set the minimum length for Diffie-Hellman parameters.
- * (Client-side only.)
- * (Default: 1024 bits.)
- *
- * \param conf SSL configuration
- * \param bitlen Minimum bit length of the DHM prime
- */
- void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
- unsigned int bitlen );
- #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
- #if defined(MBEDTLS_ECP_C)
- /**
- * \brief Set the allowed curves in order of preference.
- * (Default: all defined curves in order of decreasing size,
- * except that Montgomery curves come last. This order
- * is likely to change in a future version.)
- *
- * On server: this only affects selection of the ECDHE curve;
- * the curves used for ECDH and ECDSA are determined by the
- * list of available certificates instead.
- *
- * On client: this affects the list of curves offered for any
- * use. The server can override our preference order.
- *
- * Both sides: limits the set of curves accepted for use in
- * ECDHE and in the peer's end-entity certificate.
- *
- * \note This has no influence on which curves are allowed inside the
- * certificate chains, see \c mbedtls_ssl_conf_cert_profile()
- * for that. For the end-entity certificate however, the key
- * will be accepted only if it is allowed both by this list
- * and by the cert profile.
- *
- * \note This list should be ordered by decreasing preference
- * (preferred curve first).
- *
- * \param conf SSL configuration
- * \param curves Ordered list of allowed curves,
- * terminated by MBEDTLS_ECP_DP_NONE.
- */
- void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf,
- const mbedtls_ecp_group_id *curves );
- #endif /* MBEDTLS_ECP_C */
- #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
- /**
- * \brief Set the allowed hashes for signatures during the handshake.
- * (Default: all SHA-2 hashes, largest first. Also SHA-1 if
- * the compile-time option
- * `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE` is enabled.)
- *
- * \note This only affects which hashes are offered and can be used
- * for signatures during the handshake. Hashes for message
- * authentication and the TLS PRF are controlled by the
- * ciphersuite, see \c mbedtls_ssl_conf_ciphersuites(). Hashes
- * used for certificate signature are controlled by the
- * verification profile, see \c mbedtls_ssl_conf_cert_profile().
- *
- * \note This list should be ordered by decreasing preference
- * (preferred hash first).
- *
- * \param conf SSL configuration
- * \param hashes Ordered list of allowed signature hashes,
- * terminated by \c MBEDTLS_MD_NONE.
- */
- void mbedtls_ssl_conf_sig_hashes( mbedtls_ssl_config *conf,
- const int *hashes );
- #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * \brief Set or reset the hostname to check against the received
- * server certificate. It sets the ServerName TLS extension,
- * too, if that extension is enabled. (client-side only)
- *
- * \param ssl SSL context
- * \param hostname the server hostname, may be NULL to clear hostname
- * \note Maximum hostname length MBEDTLS_SSL_MAX_HOST_NAME_LEN.
- *
- * \return 0 if successful, MBEDTLS_ERR_SSL_ALLOC_FAILED on
- * allocation failure, MBEDTLS_ERR_SSL_BAD_INPUT_DATA on
- * too long input hostname.
- *
- * Hostname set to the one provided on success (cleared
- * when NULL). On allocation failure hostname is cleared.
- * On too long input failure, old hostname is unchanged.
- */
- int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
- /**
- * \brief Set own certificate and key for the current handshake
- *
- * \note Same as \c mbedtls_ssl_conf_own_cert() but for use within
- * the SNI callback.
- *
- * \param ssl SSL context
- * \param own_cert own public certificate chain
- * \param pk_key own private key
- *
- * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
- */
- int mbedtls_ssl_set_hs_own_cert( mbedtls_ssl_context *ssl,
- mbedtls_x509_crt *own_cert,
- mbedtls_pk_context *pk_key );
- /**
- * \brief Set the data required to verify peer certificate for the
- * current handshake
- *
- * \note Same as \c mbedtls_ssl_conf_ca_chain() but for use within
- * the SNI callback.
- *
- * \param ssl SSL context
- * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
- * \param ca_crl trusted CA CRLs
- */
- void mbedtls_ssl_set_hs_ca_chain( mbedtls_ssl_context *ssl,
- mbedtls_x509_crt *ca_chain,
- mbedtls_x509_crl *ca_crl );
- /**
- * \brief Set authmode for the current handshake.
- *
- * \note Same as \c mbedtls_ssl_conf_authmode() but for use within
- * the SNI callback.
- *
- * \param ssl SSL context
- * \param authmode MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL or
- * MBEDTLS_SSL_VERIFY_REQUIRED
- */
- void mbedtls_ssl_set_hs_authmode( mbedtls_ssl_context *ssl,
- int authmode );
- /**
- * \brief Set server side ServerName TLS extension callback
- * (optional, server-side only).
- *
- * If set, the ServerName callback is called whenever the
- * server receives a ServerName TLS extension from the client
- * during a handshake. The ServerName callback has the
- * following parameters: (void *parameter, mbedtls_ssl_context *ssl,
- * const unsigned char *hostname, size_t len). If a suitable
- * certificate is found, the callback must set the
- * certificate(s) and key(s) to use with \c
- * mbedtls_ssl_set_hs_own_cert() (can be called repeatedly),
- * and may optionally adjust the CA and associated CRL with \c
- * mbedtls_ssl_set_hs_ca_chain() as well as the client
- * authentication mode with \c mbedtls_ssl_set_hs_authmode(),
- * then must return 0. If no matching name is found, the
- * callback must either set a default cert, or
- * return non-zero to abort the handshake at this point.
- *
- * \param conf SSL configuration
- * \param f_sni verification function
- * \param p_sni verification parameter
- */
- void mbedtls_ssl_conf_sni( mbedtls_ssl_config *conf,
- int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
- size_t),
- void *p_sni );
- #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
- #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- /**
- * \brief Set the EC J-PAKE password for current handshake.
- *
- * \note An internal copy is made, and destroyed as soon as the
- * handshake is completed, or when the SSL context is reset or
- * freed.
- *
- * \note The SSL context needs to be already set up. The right place
- * to call this function is between \c mbedtls_ssl_setup() or
- * \c mbedtls_ssl_reset() and \c mbedtls_ssl_handshake().
- *
- * \param ssl SSL context
- * \param pw EC J-PAKE password (pre-shared secret)
- * \param pw_len length of pw in bytes
- *
- * \return 0 on success, or a negative error code.
- */
- int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
- const unsigned char *pw,
- size_t pw_len );
- #endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
- #if defined(MBEDTLS_SSL_ALPN)
- /**
- * \brief Set the supported Application Layer Protocols.
- *
- * \param conf SSL configuration
- * \param protos Pointer to a NULL-terminated list of supported protocols,
- * in decreasing preference order. The pointer to the list is
- * recorded by the library for later reference as required, so
- * the lifetime of the table must be atleast as long as the
- * lifetime of the SSL configuration structure.
- *
- * \return 0 on success, or MBEDTLS_ERR_SSL_BAD_INPUT_DATA.
- */
- int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
- /**
- * \brief Get the name of the negotiated Application Layer Protocol.
- * This function should be called after the handshake is
- * completed.
- *
- * \param ssl SSL context
- *
- * \return Protcol name, or NULL if no protocol was negotiated.
- */
- const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
- #endif /* MBEDTLS_SSL_ALPN */
- #if defined(MBEDTLS_SSL_DTLS_SRTP)
- #if defined(MBEDTLS_DEBUG_C)
- static inline const char *mbedtls_ssl_get_srtp_profile_as_string( mbedtls_ssl_srtp_profile profile )
- {
- switch( profile )
- {
- case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
- return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" );
- case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
- return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" );
- case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
- return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" );
- case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
- return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" );
- default: break;
- }
- return( "" );
- }
- #endif /* MBEDTLS_DEBUG_C */
- /**
- * \brief Manage support for mki(master key id) value
- * in use_srtp extension.
- * MKI is an optional part of SRTP used for key management
- * and re-keying. See RFC3711 section 3.1 for details.
- * The default value is
- * #MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED.
- *
- * \param conf The SSL configuration to manage mki support.
- * \param support_mki_value Enable or disable mki usage. Values are
- * #MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED
- * or #MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED.
- */
- void mbedtls_ssl_conf_srtp_mki_value_supported( mbedtls_ssl_config *conf,
- int support_mki_value );
- /**
- * \brief Set the supported DTLS-SRTP protection profiles.
- *
- * \param conf SSL configuration
- * \param profiles Pointer to a List of MBEDTLS_TLS_SRTP_UNSET terminated
- * supported protection profiles
- * in decreasing preference order.
- * The pointer to the list is recorded by the library
- * for later reference as required, so the lifetime
- * of the table must be at least as long as the lifetime
- * of the SSL configuration structure.
- * The list must not hold more than
- * MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH elements
- * (excluding the terminating MBEDTLS_TLS_SRTP_UNSET).
- *
- * \return 0 on success
- * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA when the list of
- * protection profiles is incorrect.
- */
- int mbedtls_ssl_conf_dtls_srtp_protection_profiles
- ( mbedtls_ssl_config *conf,
- const mbedtls_ssl_srtp_profile *profiles );
- /**
- * \brief Set the mki_value for the current DTLS-SRTP session.
- *
- * \param ssl SSL context to use.
- * \param mki_value The MKI value to set.
- * \param mki_len The length of the MKI value.
- *
- * \note This function is relevant on client side only.
- * The server discovers the mki value during handshake.
- * A mki value set on server side using this function
- * is ignored.
- *
- * \return 0 on success
- * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA
- * \return #MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
- */
- int mbedtls_ssl_dtls_srtp_set_mki_value( mbedtls_ssl_context *ssl,
- unsigned char *mki_value,
- uint16_t mki_len );
- /**
- * \brief Get the negotiated DTLS-SRTP informations:
- * Protection profile and MKI value.
- *
- * \warning This function must be called after the handshake is
- * completed. The value returned by this function must
- * not be trusted or acted upon before the handshake completes.
- *
- * \param ssl The SSL context to query.
- * \param dtls_srtp_info The negotiated DTLS-SRTP informations:
- * - Protection profile in use.
- * A direct mapping of the iana defined value for protection
- * profile on an uint16_t.
- http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
- * #MBEDTLS_TLS_SRTP_UNSET if the use of SRTP was not negotiated
- * or peer's Hello packet was not parsed yet.
- * - mki size and value( if size is > 0 ).
- */
- void mbedtls_ssl_get_dtls_srtp_negotiation_result( const mbedtls_ssl_context *ssl,
- mbedtls_dtls_srtp_info *dtls_srtp_info );
- #endif /* MBEDTLS_SSL_DTLS_SRTP */
- /**
- * \brief Set the maximum supported version sent from the client side
- * and/or accepted at the server side
- * (Default: MBEDTLS_SSL_MAX_MAJOR_VERSION, MBEDTLS_SSL_MAX_MINOR_VERSION)
- *
- * \note This ignores ciphersuites from higher versions.
- *
- * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
- * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
- *
- * \param conf SSL configuration
- * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
- * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
- * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
- * MBEDTLS_SSL_MINOR_VERSION_3 supported)
- */
- void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
- /**
- * \brief Set the minimum accepted SSL/TLS protocol version
- * (Default: TLS 1.0)
- *
- * \note Input outside of the SSL_MAX_XXXXX_VERSION and
- * SSL_MIN_XXXXX_VERSION range is ignored.
- *
- * \note MBEDTLS_SSL_MINOR_VERSION_0 (SSL v3) should be avoided.
- *
- * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
- * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
- *
- * \param conf SSL configuration
- * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
- * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
- * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
- * MBEDTLS_SSL_MINOR_VERSION_3 supported)
- */
- void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
- #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
- /**
- * \brief Set the fallback flag (client-side only).
- * (Default: MBEDTLS_SSL_IS_NOT_FALLBACK).
- *
- * \note Set to MBEDTLS_SSL_IS_FALLBACK when preparing a fallback
- * connection, that is a connection with max_version set to a
- * lower value than the value you're willing to use. Such
- * fallback connections are not recommended but are sometimes
- * necessary to interoperate with buggy (version-intolerant)
- * servers.
- *
- * \warning You should NOT set this to MBEDTLS_SSL_IS_FALLBACK for
- * non-fallback connections! This would appear to work for a
- * while, then cause failures when the server is upgraded to
- * support a newer TLS version.
- *
- * \param conf SSL configuration
- * \param fallback MBEDTLS_SSL_IS_NOT_FALLBACK or MBEDTLS_SSL_IS_FALLBACK
- */
- void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
- #endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
- #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
- /**
- * \brief Enable or disable Encrypt-then-MAC
- * (Default: MBEDTLS_SSL_ETM_ENABLED)
- *
- * \note This should always be enabled, it is a security
- * improvement, and should not cause any interoperability
- * issue (used only if the peer supports it too).
- *
- * \param conf SSL configuration
- * \param etm MBEDTLS_SSL_ETM_ENABLED or MBEDTLS_SSL_ETM_DISABLED
- */
- void mbedtls_ssl_conf_encrypt_then_mac( mbedtls_ssl_config *conf, char etm );
- #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
- #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
- /**
- * \brief Enable or disable Extended Master Secret negotiation.
- * (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED)
- *
- * \note This should always be enabled, it is a security fix to the
- * protocol, and should not cause any interoperability issue
- * (used only if the peer supports it too).
- *
- * \param conf SSL configuration
- * \param ems MBEDTLS_SSL_EXTENDED_MS_ENABLED or MBEDTLS_SSL_EXTENDED_MS_DISABLED
- */
- void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems );
- #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
- #if defined(MBEDTLS_ARC4_C)
- /**
- * \brief Disable or enable support for RC4
- * (Default: MBEDTLS_SSL_ARC4_DISABLED)
- *
- * \warning Use of RC4 in DTLS/TLS has been prohibited by RFC 7465
- * for security reasons. Use at your own risk.
- *
- * \note This function is deprecated and will be removed in
- * a future version of the library.
- * RC4 is disabled by default at compile time and needs to be
- * actively enabled for use with legacy systems.
- *
- * \param conf SSL configuration
- * \param arc4 MBEDTLS_SSL_ARC4_ENABLED or MBEDTLS_SSL_ARC4_DISABLED
- */
- void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
- #endif /* MBEDTLS_ARC4_C */
- #if defined(MBEDTLS_SSL_SRV_C)
- /**
- * \brief Whether to send a list of acceptable CAs in
- * CertificateRequest messages.
- * (Default: do send)
- *
- * \param conf SSL configuration
- * \param cert_req_ca_list MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED or
- * MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED
- */
- void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf,
- char cert_req_ca_list );
- #endif /* MBEDTLS_SSL_SRV_C */
- #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- /**
- * \brief Set the maximum fragment length to emit and/or negotiate.
- * (Typical: the smaller of #MBEDTLS_SSL_IN_CONTENT_LEN and
- * #MBEDTLS_SSL_OUT_CONTENT_LEN, usually `2^14` bytes)
- * (Server: set maximum fragment length to emit,
- * usually negotiated by the client during handshake)
- * (Client: set maximum fragment length to emit *and*
- * negotiate with the server during handshake)
- * (Default: #MBEDTLS_SSL_MAX_FRAG_LEN_NONE)
- *
- * \note On the client side, the maximum fragment length extension
- * *will not* be used, unless the maximum fragment length has
- * been set via this function to a value different than
- * #MBEDTLS_SSL_MAX_FRAG_LEN_NONE.
- *
- * \note With TLS, this currently only affects ApplicationData (sent
- * with \c mbedtls_ssl_read()), not handshake messages.
- * With DTLS, this affects both ApplicationData and handshake.
- *
- * \note This sets the maximum length for a record's payload,
- * excluding record overhead that will be added to it, see
- * \c mbedtls_ssl_get_record_expansion().
- *
- * \note For DTLS, it is also possible to set a limit for the total
- * size of daragrams passed to the transport layer, including
- * record overhead, see \c mbedtls_ssl_set_mtu().
- *
- * \param conf SSL configuration
- * \param mfl_code Code for maximum fragment length (allowed values:
- * MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_1024,
- * MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096)
- *
- * \return 0 if successful or MBEDTLS_ERR_SSL_BAD_INPUT_DATA
- */
- int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
- #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
- #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
- /**
- * \brief Activate negotiation of truncated HMAC
- * (Default: MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
- *
- * \param conf SSL configuration
- * \param truncate Enable or disable (MBEDTLS_SSL_TRUNC_HMAC_ENABLED or
- * MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
- */
- void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
- #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
- #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
- /**
- * \brief Enable / Disable 1/n-1 record splitting
- * (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED)
- *
- * \note Only affects SSLv3 and TLS 1.0, not higher versions.
- * Does not affect non-CBC ciphersuites in any version.
- *
- * \param conf SSL configuration
- * \param split MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED or
- * MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED
- */
- void mbedtls_ssl_conf_cbc_record_splitting( mbedtls_ssl_config *conf, char split );
- #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
- #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
- /**
- * \brief Enable / Disable session tickets (client only).
- * (Default: MBEDTLS_SSL_SESSION_TICKETS_ENABLED.)
- *
- * \note On server, use \c mbedtls_ssl_conf_session_tickets_cb().
- *
- * \param conf SSL configuration
- * \param use_tickets Enable or disable (MBEDTLS_SSL_SESSION_TICKETS_ENABLED or
- * MBEDTLS_SSL_SESSION_TICKETS_DISABLED)
- */
- void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
- #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- /**
- * \brief Enable / Disable renegotiation support for connection when
- * initiated by peer
- * (Default: MBEDTLS_SSL_RENEGOTIATION_DISABLED)
- *
- * \warning It is recommended to always disable renegotation unless you
- * know you need it and you know what you're doing. In the
- * past, there have been several issues associated with
- * renegotiation or a poor understanding of its properties.
- *
- * \note Server-side, enabling renegotiation also makes the server
- * susceptible to a resource DoS by a malicious client.
- *
- * \param conf SSL configuration
- * \param renegotiation Enable or disable (MBEDTLS_SSL_RENEGOTIATION_ENABLED or
- * MBEDTLS_SSL_RENEGOTIATION_DISABLED)
- */
- void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
- #endif /* MBEDTLS_SSL_RENEGOTIATION */
- /**
- * \brief Prevent or allow legacy renegotiation.
- * (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION)
- *
- * MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION allows connections to
- * be established even if the peer does not support
- * secure renegotiation, but does not allow renegotiation
- * to take place if not secure.
- * (Interoperable and secure option)
- *
- * MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations
- * with non-upgraded peers. Allowing legacy renegotiation
- * makes the connection vulnerable to specific man in the
- * middle attacks. (See RFC 5746)
- * (Most interoperable and least secure option)
- *
- * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE breaks off connections
- * if peer does not support secure renegotiation. Results
- * in interoperability issues with non-upgraded peers
- * that do not support renegotiation altogether.
- * (Most secure option, interoperability issues)
- *
- * \param conf SSL configuration
- * \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION,
- * SSL_ALLOW_LEGACY_RENEGOTIATION or
- * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE)
- */
- void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy );
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- /**
- * \brief Enforce renegotiation requests.
- * (Default: enforced, max_records = 16)
- *
- * When we request a renegotiation, the peer can comply or
- * ignore the request. This function allows us to decide
- * whether to enforce our renegotiation requests by closing
- * the connection if the peer doesn't comply.
- *
- * However, records could already be in transit from the peer
- * when the request is emitted. In order to increase
- * reliability, we can accept a number of records before the
- * expected handshake records.
- *
- * The optimal value is highly dependent on the specific usage
- * scenario.
- *
- * \note With DTLS and server-initiated renegotiation, the
- * HelloRequest is retransmited every time mbedtls_ssl_read() times
- * out or receives Application Data, until:
- * - max_records records have beens seen, if it is >= 0, or
- * - the number of retransmits that would happen during an
- * actual handshake has been reached.
- * Please remember the request might be lost a few times
- * if you consider setting max_records to a really low value.
- *
- * \warning On client, the grace period can only happen during
- * mbedtls_ssl_read(), as opposed to mbedtls_ssl_write() and mbedtls_ssl_renegotiate()
- * which always behave as if max_record was 0. The reason is,
- * if we receive application data from the server, we need a
- * place to write it, which only happens during mbedtls_ssl_read().
- *
- * \param conf SSL configuration
- * \param max_records Use MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED if you don't want to
- * enforce renegotiation, or a non-negative value to enforce
- * it but allow for a grace period of max_records records.
- */
- void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
- /**
- * \brief Set record counter threshold for periodic renegotiation.
- * (Default: 2^48 - 1)
- *
- * Renegotiation is automatically triggered when a record
- * counter (outgoing or incoming) crosses the defined
- * threshold. The default value is meant to prevent the
- * connection from being closed when the counter is about to
- * reached its maximal value (it is not allowed to wrap).
- *
- * Lower values can be used to enforce policies such as "keys
- * must be refreshed every N packets with cipher X".
- *
- * The renegotiation period can be disabled by setting
- * conf->disable_renegotiation to
- * MBEDTLS_SSL_RENEGOTIATION_DISABLED.
- *
- * \note When the configured transport is
- * MBEDTLS_SSL_TRANSPORT_DATAGRAM the maximum renegotiation
- * period is 2^48 - 1, and for MBEDTLS_SSL_TRANSPORT_STREAM,
- * the maximum renegotiation period is 2^64 - 1.
- *
- * \param conf SSL configuration
- * \param period The threshold value: a big-endian 64-bit number.
- */
- void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf,
- const unsigned char period[8] );
- #endif /* MBEDTLS_SSL_RENEGOTIATION */
- /**
- * \brief Check if there is data already read from the
- * underlying transport but not yet processed.
- *
- * \param ssl SSL context
- *
- * \return 0 if nothing's pending, 1 otherwise.
- *
- * \note This is different in purpose and behaviour from
- * \c mbedtls_ssl_get_bytes_avail in that it considers
- * any kind of unprocessed data, not only unread
- * application data. If \c mbedtls_ssl_get_bytes
- * returns a non-zero value, this function will
- * also signal pending data, but the converse does
- * not hold. For example, in DTLS there might be
- * further records waiting to be processed from
- * the current underlying transport's datagram.
- *
- * \note If this function returns 1 (data pending), this
- * does not imply that a subsequent call to
- * \c mbedtls_ssl_read will provide any data;
- * e.g., the unprocessed data might turn out
- * to be an alert or a handshake message.
- *
- * \note This function is useful in the following situation:
- * If the SSL/TLS module successfully returns from an
- * operation - e.g. a handshake or an application record
- * read - and you're awaiting incoming data next, you
- * must not immediately idle on the underlying transport
- * to have data ready, but you need to check the value
- * of this function first. The reason is that the desired
- * data might already be read but not yet processed.
- * If, in contrast, a previous call to the SSL/TLS module
- * returned MBEDTLS_ERR_SSL_WANT_READ, it is not necessary
- * to call this function, as the latter error code entails
- * that all internal data has been processed.
- *
- */
- int mbedtls_ssl_check_pending( const mbedtls_ssl_context *ssl );
- /**
- * \brief Return the number of application data bytes
- * remaining to be read from the current record.
- *
- * \param ssl SSL context
- *
- * \return How many bytes are available in the application
- * data record read buffer.
- *
- * \note When working over a datagram transport, this is
- * useful to detect the current datagram's boundary
- * in case \c mbedtls_ssl_read has written the maximal
- * amount of data fitting into the input buffer.
- *
- */
- size_t mbedtls_ssl_get_bytes_avail( const mbedtls_ssl_context *ssl );
- /**
- * \brief Return the result of the certificate verification
- *
- * \param ssl The SSL context to use.
- *
- * \return \c 0 if the certificate verification was successful.
- * \return \c -1u if the result is not available. This may happen
- * e.g. if the handshake aborts early, or a verification
- * callback returned a fatal error.
- * \return A bitwise combination of \c MBEDTLS_X509_BADCERT_XXX
- * and \c MBEDTLS_X509_BADCRL_XXX failure flags; see x509.h.
- */
- uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
- /**
- * \brief Return the name of the current ciphersuite
- *
- * \param ssl SSL context
- *
- * \return a string containing the ciphersuite name
- */
- const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
- /**
- * \brief Return the current SSL version (SSLv3/TLSv1/etc)
- *
- * \param ssl SSL context
- *
- * \return a string containing the SSL version
- */
- const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
- /**
- * \brief Return the (maximum) number of bytes added by the record
- * layer: header + encryption/MAC overhead (inc. padding)
- *
- * \note This function is not available (always returns an error)
- * when record compression is enabled.
- *
- * \param ssl SSL context
- *
- * \return Current maximum record expansion in bytes, or
- * MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if compression is
- * enabled, which makes expansion much less predictable
- */
- int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl );
- #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- /**
- * \brief Return the maximum fragment length (payload, in bytes) for
- * the output buffer. For the client, this is the configured
- * value. For the server, it is the minimum of two - the
- * configured value and the negotiated one.
- *
- * \sa mbedtls_ssl_conf_max_frag_len()
- * \sa mbedtls_ssl_get_max_record_payload()
- *
- * \param ssl SSL context
- *
- * \return Current maximum fragment length for the output buffer.
- */
- size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl );
- /**
- * \brief Return the maximum fragment length (payload, in bytes) for
- * the input buffer. This is the negotiated maximum fragment
- * length, or, if there is none, MBEDTLS_SSL_MAX_CONTENT_LEN.
- * If it is not defined either, the value is 2^14. This function
- * works as its predecessor, \c mbedtls_ssl_get_max_frag_len().
- *
- * \sa mbedtls_ssl_conf_max_frag_len()
- * \sa mbedtls_ssl_get_max_record_payload()
- *
- * \param ssl SSL context
- *
- * \return Current maximum fragment length for the output buffer.
- */
- size_t mbedtls_ssl_get_input_max_frag_len( const mbedtls_ssl_context *ssl );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function is a deprecated approach to getting the max
- * fragment length. Its an alias for
- * \c mbedtls_ssl_get_output_max_frag_len(), as the behaviour
- * is the same. See \c mbedtls_ssl_get_output_max_frag_len() for
- * more detail.
- *
- * \sa mbedtls_ssl_get_input_max_frag_len()
- * \sa mbedtls_ssl_get_output_max_frag_len()
- *
- * \param ssl SSL context
- *
- * \return Current maximum fragment length for the output buffer.
- */
- MBEDTLS_DEPRECATED size_t mbedtls_ssl_get_max_frag_len(
- const mbedtls_ssl_context *ssl );
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
- /**
- * \brief Return the current maximum outgoing record payload in bytes.
- * This takes into account the config.h setting \c
- * MBEDTLS_SSL_OUT_CONTENT_LEN, the configured and negotiated
- * max fragment length extension if used, and for DTLS the
- * path MTU as configured and current record expansion.
- *
- * \note With DTLS, \c mbedtls_ssl_write() will return an error if
- * called with a larger length value.
- * With TLS, \c mbedtls_ssl_write() will fragment the input if
- * necessary and return the number of bytes written; it is up
- * to the caller to call \c mbedtls_ssl_write() again in
- * order to send the remaining bytes if any.
- *
- * \note This function is not available (always returns an error)
- * when record compression is enabled.
- *
- * \sa mbedtls_ssl_set_mtu()
- * \sa mbedtls_ssl_get_output_max_frag_len()
- * \sa mbedtls_ssl_get_input_max_frag_len()
- * \sa mbedtls_ssl_get_record_expansion()
- *
- * \param ssl SSL context
- *
- * \return Current maximum payload for an outgoing record,
- * or a negative error code.
- */
- int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl );
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * \brief Return the peer certificate from the current connection.
- *
- * \param ssl The SSL context to use. This must be initialized and setup.
- *
- * \return The current peer certificate, if available.
- * The returned certificate is owned by the SSL context and
- * is valid only until the next call to the SSL API.
- * \return \c NULL if no peer certificate is available. This might
- * be because the chosen ciphersuite doesn't use CRTs
- * (PSK-based ciphersuites, for example), or because
- * #MBEDTLS_SSL_KEEP_PEER_CERTIFICATE has been disabled,
- * allowing the stack to free the peer's CRT to save memory.
- *
- * \note For one-time inspection of the peer's certificate during
- * the handshake, consider registering an X.509 CRT verification
- * callback through mbedtls_ssl_conf_verify() instead of calling
- * this function. Using mbedtls_ssl_conf_verify() also comes at
- * the benefit of allowing you to influence the verification
- * process, for example by masking expected and tolerated
- * verification failures.
- *
- * \warning You must not use the pointer returned by this function
- * after any further call to the SSL API, including
- * mbedtls_ssl_read() and mbedtls_ssl_write(); this is
- * because the pointer might change during renegotiation,
- * which happens transparently to the user.
- * If you want to use the certificate across API calls,
- * you must make a copy.
- */
- const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl );
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- #if defined(MBEDTLS_SSL_CLI_C)
- /**
- * \brief Save session in order to resume it later (client-side only)
- * Session data is copied to presented session structure.
- *
- *
- * \param ssl SSL context
- * \param session session context
- *
- * \return 0 if successful,
- * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
- * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
- * arguments are otherwise invalid.
- *
- * \note Only the server certificate is copied, and not the full chain,
- * so you should not attempt to validate the certificate again
- * by calling \c mbedtls_x509_crt_verify() on it.
- * Instead, you should use the results from the verification
- * in the original handshake by calling \c mbedtls_ssl_get_verify_result()
- * after loading the session again into a new SSL context
- * using \c mbedtls_ssl_set_session().
- *
- * \note Once the session object is not needed anymore, you should
- * free it by calling \c mbedtls_ssl_session_free().
- *
- * \sa mbedtls_ssl_set_session()
- */
- int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session );
- #endif /* MBEDTLS_SSL_CLI_C */
- /**
- * \brief Perform the SSL handshake
- *
- * \param ssl SSL context
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE
- * if the handshake is incomplete and waiting for data to
- * be available for reading from or writing to the underlying
- * transport - in this case you must call this function again
- * when the underlying transport is ready for the operation.
- * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous
- * operation is in progress (see
- * mbedtls_ssl_conf_async_private_cb()) - in this case you
- * must call this function again when the operation is ready.
- * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic
- * operation is in progress (see mbedtls_ecp_set_max_ops()) -
- * in this case you must call this function again to complete
- * the handshake when you're done attending other tasks.
- * \return #MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED if DTLS is in use
- * and the client did not demonstrate reachability yet - in
- * this case you must stop using the context (see below).
- * \return Another SSL error code - in this case you must stop using
- * the context (see below).
- *
- * \warning If this function returns something other than
- * \c 0,
- * #MBEDTLS_ERR_SSL_WANT_READ,
- * #MBEDTLS_ERR_SSL_WANT_WRITE,
- * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
- * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS,
- * you must stop using the SSL context for reading or writing,
- * and either free it or call \c mbedtls_ssl_session_reset()
- * on it before re-using it for a new connection; the current
- * connection must be closed.
- *
- * \note If DTLS is in use, then you may choose to handle
- * #MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED specially for logging
- * purposes, as it is an expected return value rather than an
- * actual error, but you still need to reset/free the context.
- *
- * \note Remarks regarding event-driven DTLS:
- * If the function returns #MBEDTLS_ERR_SSL_WANT_READ, no datagram
- * from the underlying transport layer is currently being processed,
- * and it is safe to idle until the timer or the underlying transport
- * signal a new event. This is not true for a successful handshake,
- * in which case the datagram of the underlying transport that is
- * currently being processed might or might not contain further
- * DTLS records.
- */
- int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl );
- /**
- * \brief Perform a single step of the SSL handshake
- *
- * \note The state of the context (ssl->state) will be at
- * the next state after this function returns \c 0. Do not
- * call this function if state is MBEDTLS_SSL_HANDSHAKE_OVER.
- *
- * \param ssl SSL context
- *
- * \return See mbedtls_ssl_handshake().
- *
- * \warning If this function returns something other than \c 0,
- * #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE,
- * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
- * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, you must stop using
- * the SSL context for reading or writing, and either free it
- * or call \c mbedtls_ssl_session_reset() on it before
- * re-using it for a new connection; the current connection
- * must be closed.
- */
- int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl );
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- /**
- * \brief Initiate an SSL renegotiation on the running connection.
- * Client: perform the renegotiation right now.
- * Server: request renegotiation, which will be performed
- * during the next call to mbedtls_ssl_read() if honored by
- * client.
- *
- * \param ssl SSL context
- *
- * \return 0 if successful, or any mbedtls_ssl_handshake() return
- * value except #MBEDTLS_ERR_SSL_CLIENT_RECONNECT that can't
- * happen during a renegotiation.
- *
- * \warning If this function returns something other than \c 0,
- * #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE,
- * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
- * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, you must stop using
- * the SSL context for reading or writing, and either free it
- * or call \c mbedtls_ssl_session_reset() on it before
- * re-using it for a new connection; the current connection
- * must be closed.
- *
- */
- int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl );
- #endif /* MBEDTLS_SSL_RENEGOTIATION */
- /**
- * \brief Read at most 'len' application data bytes
- *
- * \param ssl SSL context
- * \param buf buffer that will hold the data
- * \param len maximum number of bytes to read
- *
- * \return The (positive) number of bytes read if successful.
- * \return \c 0 if the read end of the underlying transport was closed
- * without sending a CloseNotify beforehand, which might happen
- * because of various reasons (internal error of an underlying
- * stack, non-conformant peer not sending a CloseNotify and
- * such) - in this case you must stop using the context
- * (see below).
- * \return #MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY if the underlying
- * transport is still functional, but the peer has
- * acknowledged to not send anything anymore.
- * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE
- * if the handshake is incomplete and waiting for data to
- * be available for reading from or writing to the underlying
- * transport - in this case you must call this function again
- * when the underlying transport is ready for the operation.
- * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous
- * operation is in progress (see
- * mbedtls_ssl_conf_async_private_cb()) - in this case you
- * must call this function again when the operation is ready.
- * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic
- * operation is in progress (see mbedtls_ecp_set_max_ops()) -
- * in this case you must call this function again to complete
- * the handshake when you're done attending other tasks.
- * \return #MBEDTLS_ERR_SSL_CLIENT_RECONNECT if we're at the server
- * side of a DTLS connection and the client is initiating a
- * new connection using the same source port. See below.
- * \return Another SSL error code - in this case you must stop using
- * the context (see below).
- *
- * \warning If this function returns something other than
- * a positive value,
- * #MBEDTLS_ERR_SSL_WANT_READ,
- * #MBEDTLS_ERR_SSL_WANT_WRITE,
- * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS,
- * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS or
- * #MBEDTLS_ERR_SSL_CLIENT_RECONNECT,
- * you must stop using the SSL context for reading or writing,
- * and either free it or call \c mbedtls_ssl_session_reset()
- * on it before re-using it for a new connection; the current
- * connection must be closed.
- *
- * \note When this function returns #MBEDTLS_ERR_SSL_CLIENT_RECONNECT
- * (which can only happen server-side), it means that a client
- * is initiating a new connection using the same source port.
- * You can either treat that as a connection close and wait
- * for the client to resend a ClientHello, or directly
- * continue with \c mbedtls_ssl_handshake() with the same
- * context (as it has been reset internally). Either way, you
- * must make sure this is seen by the application as a new
- * connection: application state, if any, should be reset, and
- * most importantly the identity of the client must be checked
- * again. WARNING: not validating the identity of the client
- * again, or not transmitting the new identity to the
- * application layer, would allow authentication bypass!
- *
- * \note Remarks regarding event-driven DTLS:
- * - If the function returns #MBEDTLS_ERR_SSL_WANT_READ, no datagram
- * from the underlying transport layer is currently being processed,
- * and it is safe to idle until the timer or the underlying transport
- * signal a new event.
- * - This function may return MBEDTLS_ERR_SSL_WANT_READ even if data was
- * initially available on the underlying transport, as this data may have
- * been only e.g. duplicated messages or a renegotiation request.
- * Therefore, you must be prepared to receive MBEDTLS_ERR_SSL_WANT_READ even
- * when reacting to an incoming-data event from the underlying transport.
- * - On success, the datagram of the underlying transport that is currently
- * being processed may contain further DTLS records. You should call
- * \c mbedtls_ssl_check_pending to check for remaining records.
- *
- */
- int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
- /**
- * \brief Try to write exactly 'len' application data bytes
- *
- * \warning This function will do partial writes in some cases. If the
- * return value is non-negative but less than length, the
- * function must be called again with updated arguments:
- * buf + ret, len - ret (if ret is the return value) until
- * it returns a value equal to the last 'len' argument.
- *
- * \param ssl SSL context
- * \param buf buffer holding the data
- * \param len how many bytes must be written
- *
- * \return The (non-negative) number of bytes actually written if
- * successful (may be less than \p len).
- * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE
- * if the handshake is incomplete and waiting for data to
- * be available for reading from or writing to the underlying
- * transport - in this case you must call this function again
- * when the underlying transport is ready for the operation.
- * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous
- * operation is in progress (see
- * mbedtls_ssl_conf_async_private_cb()) - in this case you
- * must call this function again when the operation is ready.
- * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic
- * operation is in progress (see mbedtls_ecp_set_max_ops()) -
- * in this case you must call this function again to complete
- * the handshake when you're done attending other tasks.
- * \return Another SSL error code - in this case you must stop using
- * the context (see below).
- *
- * \warning If this function returns something other than
- * a non-negative value,
- * #MBEDTLS_ERR_SSL_WANT_READ,
- * #MBEDTLS_ERR_SSL_WANT_WRITE,
- * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
- * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS,
- * you must stop using the SSL context for reading or writing,
- * and either free it or call \c mbedtls_ssl_session_reset()
- * on it before re-using it for a new connection; the current
- * connection must be closed.
- *
- * \note When this function returns #MBEDTLS_ERR_SSL_WANT_WRITE/READ,
- * it must be called later with the *same* arguments,
- * until it returns a value greater that or equal to 0. When
- * the function returns #MBEDTLS_ERR_SSL_WANT_WRITE there may be
- * some partial data in the output buffer, however this is not
- * yet sent.
- *
- * \note If the requested length is greater than the maximum
- * fragment length (either the built-in limit or the one set
- * or negotiated with the peer), then:
- * - with TLS, less bytes than requested are written.
- * - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned.
- * \c mbedtls_ssl_get_output_max_frag_len() may be used to
- * query the active maximum fragment length.
- *
- * \note Attempting to write 0 bytes will result in an empty TLS
- * application record being sent.
- */
- int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
- /**
- * \brief Send an alert message
- *
- * \param ssl SSL context
- * \param level The alert level of the message
- * (MBEDTLS_SSL_ALERT_LEVEL_WARNING or MBEDTLS_SSL_ALERT_LEVEL_FATAL)
- * \param message The alert message (SSL_ALERT_MSG_*)
- *
- * \return 0 if successful, or a specific SSL error code.
- *
- * \note If this function returns something other than 0 or
- * MBEDTLS_ERR_SSL_WANT_READ/WRITE, you must stop using
- * the SSL context for reading or writing, and either free it or
- * call \c mbedtls_ssl_session_reset() on it before re-using it
- * for a new connection; the current connection must be closed.
- */
- int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl,
- unsigned char level,
- unsigned char message );
- /**
- * \brief Notify the peer that the connection is being closed
- *
- * \param ssl SSL context
- *
- * \return 0 if successful, or a specific SSL error code.
- *
- * \note If this function returns something other than 0 or
- * MBEDTLS_ERR_SSL_WANT_READ/WRITE, you must stop using
- * the SSL context for reading or writing, and either free it or
- * call \c mbedtls_ssl_session_reset() on it before re-using it
- * for a new connection; the current connection must be closed.
- */
- int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl );
- /**
- * \brief Free referenced items in an SSL context and clear memory
- *
- * \param ssl SSL context
- */
- void mbedtls_ssl_free( mbedtls_ssl_context *ssl );
- #if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
- /**
- * \brief Save an active connection as serialized data in a buffer.
- * This allows the freeing or re-using of the SSL context
- * while still picking up the connection later in a way that
- * it entirely transparent to the peer.
- *
- * \see mbedtls_ssl_context_load()
- *
- * \note This feature is currently only available under certain
- * conditions, see the documentation of the return value
- * #MBEDTLS_ERR_SSL_BAD_INPUT_DATA for details.
- *
- * \note When this function succeeds, it calls
- * mbedtls_ssl_session_reset() on \p ssl which as a result is
- * no longer associated with the connection that has been
- * serialized. This avoids creating copies of the connection
- * state. You're then free to either re-use the context
- * structure for a different connection, or call
- * mbedtls_ssl_free() on it. See the documentation of
- * mbedtls_ssl_session_reset() for more details.
- *
- * \param ssl The SSL context to save. On success, it is no longer
- * associated with the connection that has been serialized.
- * \param buf The buffer to write the serialized data to. It must be a
- * writeable buffer of at least \p buf_len bytes, or may be \c
- * NULL if \p buf_len is \c 0.
- * \param buf_len The number of bytes available for writing in \p buf.
- * \param olen The size in bytes of the data that has been or would have
- * been written. It must point to a valid \c size_t.
- *
- * \note \p olen is updated to the correct value regardless of
- * whether \p buf_len was large enough. This makes it possible
- * to determine the necessary size by calling this function
- * with \p buf set to \c NULL and \p buf_len to \c 0. However,
- * the value of \p olen is only guaranteed to be correct when
- * the function returns #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL or
- * \c 0. If the return value is different, then the value of
- * \p olen is undefined.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small.
- * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed
- * while reseting the context.
- * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if a handshake is in
- * progress, or there is pending data for reading or sending,
- * or the connection does not use DTLS 1.2 with an AEAD
- * ciphersuite, or renegotiation is enabled.
- */
- int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl,
- unsigned char *buf,
- size_t buf_len,
- size_t *olen );
- /**
- * \brief Load serialized connection data to an SSL context.
- *
- * \see mbedtls_ssl_context_save()
- *
- * \warning The same serialized data must never be loaded into more
- * that one context. In order to ensure that, after
- * successfully loading serialized data to an SSL context, you
- * should immediately destroy or invalidate all copies of the
- * serialized data that was loaded. Loading the same data in
- * more than one context would cause severe security failures
- * including but not limited to loss of confidentiality.
- *
- * \note Before calling this function, the SSL context must be
- * prepared in one of the two following ways. The first way is
- * to take a context freshly initialised with
- * mbedtls_ssl_init() and call mbedtls_ssl_setup() on it with
- * the same ::mbedtls_ssl_config structure that was used in
- * the original connection. The second way is to
- * call mbedtls_ssl_session_reset() on a context that was
- * previously prepared as above but used in the meantime.
- * Either way, you must not use the context to perform a
- * handshake between calling mbedtls_ssl_setup() or
- * mbedtls_ssl_session_reset() and calling this function. You
- * may however call other setter functions in that time frame
- * as indicated in the note below.
- *
- * \note Before or after calling this function successfully, you
- * also need to configure some connection-specific callbacks
- * and settings before you can use the connection again
- * (unless they were already set before calling
- * mbedtls_ssl_session_reset() and the values are suitable for
- * the present connection). Specifically, you want to call
- * at least mbedtls_ssl_set_bio() and
- * mbedtls_ssl_set_timer_cb(). All other SSL setter functions
- * are not necessary to call, either because they're only used
- * in handshakes, or because the setting is already saved. You
- * might choose to call them anyway, for example in order to
- * share code between the cases of establishing a new
- * connection and the case of loading an already-established
- * connection.
- *
- * \note If you have new information about the path MTU, you want to
- * call mbedtls_ssl_set_mtu() after calling this function, as
- * otherwise this function would overwrite your
- * newly-configured value with the value that was active when
- * the context was saved.
- *
- * \note When this function returns an error code, it calls
- * mbedtls_ssl_free() on \p ssl. In this case, you need to
- * prepare the context with the usual sequence starting with a
- * call to mbedtls_ssl_init() if you want to use it again.
- *
- * \param ssl The SSL context structure to be populated. It must have
- * been prepared as described in the note above.
- * \param buf The buffer holding the serialized connection data. It must
- * be a readable buffer of at least \p len bytes.
- * \param len The size of the serialized data in bytes.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed.
- * \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data
- * comes from a different Mbed TLS version or build.
- * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid.
- */
- int mbedtls_ssl_context_load( mbedtls_ssl_context *ssl,
- const unsigned char *buf,
- size_t len );
- #endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
- /**
- * \brief Initialize an SSL configuration context
- * Just makes the context ready for
- * mbedtls_ssl_config_defaults() or mbedtls_ssl_config_free().
- *
- * \note You need to call mbedtls_ssl_config_defaults() unless you
- * manually set all of the relevant fields yourself.
- *
- * \param conf SSL configuration context
- */
- void mbedtls_ssl_config_init( mbedtls_ssl_config *conf );
- /**
- * \brief Load reasonnable default SSL configuration values.
- * (You need to call mbedtls_ssl_config_init() first.)
- *
- * \param conf SSL configuration context
- * \param endpoint MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
- * \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or
- * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS
- * \param preset a MBEDTLS_SSL_PRESET_XXX value
- *
- * \note See \c mbedtls_ssl_conf_transport() for notes on DTLS.
- *
- * \return 0 if successful, or
- * MBEDTLS_ERR_XXX_ALLOC_FAILED on memory allocation error.
- */
- int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
- int endpoint, int transport, int preset );
- /**
- * \brief Free an SSL configuration context
- *
- * \param conf SSL configuration context
- */
- void mbedtls_ssl_config_free( mbedtls_ssl_config *conf );
- /**
- * \brief Initialize SSL session structure
- *
- * \param session SSL session
- */
- void mbedtls_ssl_session_init( mbedtls_ssl_session *session );
- /**
- * \brief Free referenced items in an SSL session including the
- * peer certificate and clear memory
- *
- * \note A session object can be freed even if the SSL context
- * that was used to retrieve the session is still in use.
- *
- * \param session SSL session
- */
- void mbedtls_ssl_session_free( mbedtls_ssl_session *session );
- /**
- * \brief TLS-PRF function for key derivation.
- *
- * \param prf The tls_prf type function type to be used.
- * \param secret Secret for the key derivation function.
- * \param slen Length of the secret.
- * \param label String label for the key derivation function,
- * terminated with null character.
- * \param random Random bytes.
- * \param rlen Length of the random bytes buffer.
- * \param dstbuf The buffer holding the derived key.
- * \param dlen Length of the output buffer.
- *
- * \return 0 on success. An SSL specific error on failure.
- */
- int mbedtls_ssl_tls_prf( const mbedtls_tls_prf_types prf,
- const unsigned char *secret, size_t slen,
- const char *label,
- const unsigned char *random, size_t rlen,
- unsigned char *dstbuf, size_t dlen );
- #ifdef __cplusplus
- }
- #endif
- #endif /* ssl.h */
- /********* Start of file include/mbedtls/ssl_cookie.h ************/
- /**
- * \file ssl_cookie.h
- *
- * \brief DTLS cookie callbacks implementation
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SSL_COOKIE_H
- #define MBEDTLS_SSL_COOKIE_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_THREADING_C)
- #endif
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- #ifndef MBEDTLS_SSL_COOKIE_TIMEOUT
- #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
- #endif
- /* \} name SECTION: Module settings */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Context for the default cookie functions.
- */
- typedef struct mbedtls_ssl_cookie_ctx
- {
- mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */
- #if !defined(MBEDTLS_HAVE_TIME)
- unsigned long serial; /*!< serial number for expiration */
- #endif
- unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME,
- or in number of tickets issued */
- #if defined(MBEDTLS_THREADING_C)
- mbedtls_threading_mutex_t mutex;
- #endif
- } mbedtls_ssl_cookie_ctx;
- /**
- * \brief Initialize cookie context
- */
- void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx );
- /**
- * \brief Setup cookie context (generate keys)
- */
- int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- /**
- * \brief Set expiration delay for cookies
- * (Default MBEDTLS_SSL_COOKIE_TIMEOUT)
- *
- * \param ctx Cookie contex
- * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies
- * issued in the meantime.
- * 0 to disable expiration (NOT recommended)
- */
- void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay );
- /**
- * \brief Free cookie context
- */
- void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx );
- /**
- * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t
- */
- mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write;
- /**
- * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t
- */
- mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check;
- #ifdef __cplusplus
- }
- #endif
- #endif /* ssl_cookie.h */
- /********* Start of file include/mbedtls/ssl_internal.h ************/
- /**
- * \file ssl_internal.h
- *
- * \brief Internal functions shared by the SSL modules
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SSL_INTERNAL_H
- #define MBEDTLS_SSL_INTERNAL_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- #endif
- #if defined(MBEDTLS_MD5_C)
- #endif
- #if defined(MBEDTLS_SHA1_C)
- #endif
- #if defined(MBEDTLS_SHA256_C)
- #endif
- #if defined(MBEDTLS_SHA512_C)
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- #endif
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
- #define inline __inline
- #endif
- /* Determine minimum supported version */
- #define MBEDTLS_SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
- #if defined(MBEDTLS_SSL_PROTO_SSL3)
- #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
- #else
- #if defined(MBEDTLS_SSL_PROTO_TLS1)
- #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
- #else
- #if defined(MBEDTLS_SSL_PROTO_TLS1_1)
- #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
- #else
- #if defined(MBEDTLS_SSL_PROTO_TLS1_2)
- #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
- #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
- #endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
- #endif /* MBEDTLS_SSL_PROTO_TLS1 */
- #endif /* MBEDTLS_SSL_PROTO_SSL3 */
- #define MBEDTLS_SSL_MIN_VALID_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
- #define MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
- /* Determine maximum supported version */
- #define MBEDTLS_SSL_MAX_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
- #if defined(MBEDTLS_SSL_PROTO_TLS1_2)
- #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
- #else
- #if defined(MBEDTLS_SSL_PROTO_TLS1_1)
- #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
- #else
- #if defined(MBEDTLS_SSL_PROTO_TLS1)
- #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
- #else
- #if defined(MBEDTLS_SSL_PROTO_SSL3)
- #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
- #endif /* MBEDTLS_SSL_PROTO_SSL3 */
- #endif /* MBEDTLS_SSL_PROTO_TLS1 */
- #endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
- #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
- /* Shorthand for restartable ECC */
- #if defined(MBEDTLS_ECP_RESTARTABLE) && \
- defined(MBEDTLS_SSL_CLI_C) && \
- defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
- defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
- #define MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED
- #endif
- #define MBEDTLS_SSL_INITIAL_HANDSHAKE 0
- #define MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS 1 /* In progress */
- #define MBEDTLS_SSL_RENEGOTIATION_DONE 2 /* Done or aborted */
- #define MBEDTLS_SSL_RENEGOTIATION_PENDING 3 /* Requested (server only) */
- /*
- * DTLS retransmission states, see RFC 6347 4.2.4
- *
- * The SENDING state is merged in PREPARING for initial sends,
- * but is distinct for resends.
- *
- * Note: initial state is wrong for server, but is not used anyway.
- */
- #define MBEDTLS_SSL_RETRANS_PREPARING 0
- #define MBEDTLS_SSL_RETRANS_SENDING 1
- #define MBEDTLS_SSL_RETRANS_WAITING 2
- #define MBEDTLS_SSL_RETRANS_FINISHED 3
- /*
- * Allow extra bytes for record, authentication and encryption overhead:
- * counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256)
- * and allow for a maximum of 1024 of compression expansion if
- * enabled.
- */
- #if defined(MBEDTLS_ZLIB_SUPPORT)
- #define MBEDTLS_SSL_COMPRESSION_ADD 1024
- #else
- #define MBEDTLS_SSL_COMPRESSION_ADD 0
- #endif
- /* This macro determines whether CBC is supported. */
- #if defined(MBEDTLS_CIPHER_MODE_CBC) && \
- ( defined(MBEDTLS_AES_C) || \
- defined(MBEDTLS_CAMELLIA_C) || \
- defined(MBEDTLS_ARIA_C) || \
- defined(MBEDTLS_DES_C) )
- #define MBEDTLS_SSL_SOME_SUITES_USE_CBC
- #endif
- /* This macro determines whether the CBC construct used in TLS 1.0-1.2 (as
- * opposed to the very different CBC construct used in SSLv3) is supported. */
- #if defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC) && \
- ( defined(MBEDTLS_SSL_PROTO_TLS1) || \
- defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
- defined(MBEDTLS_SSL_PROTO_TLS1_2) )
- #define MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC
- #endif
- #if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER) || \
- defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC)
- #define MBEDTLS_SSL_SOME_MODES_USE_MAC
- #endif
- #if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
- /* Ciphersuites using HMAC */
- #if defined(MBEDTLS_SHA512_C)
- #define MBEDTLS_SSL_MAC_ADD 48 /* SHA-384 used for HMAC */
- #elif defined(MBEDTLS_SHA256_C)
- #define MBEDTLS_SSL_MAC_ADD 32 /* SHA-256 used for HMAC */
- #else
- #define MBEDTLS_SSL_MAC_ADD 20 /* SHA-1 used for HMAC */
- #endif
- #else /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
- /* AEAD ciphersuites: GCM and CCM use a 128 bits tag */
- #define MBEDTLS_SSL_MAC_ADD 16
- #endif
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- #define MBEDTLS_SSL_PADDING_ADD 256
- #else
- #define MBEDTLS_SSL_PADDING_ADD 0
- #endif
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- #define MBEDTLS_SSL_MAX_CID_EXPANSION MBEDTLS_SSL_CID_PADDING_GRANULARITY
- #else
- #define MBEDTLS_SSL_MAX_CID_EXPANSION 0
- #endif
- #define MBEDTLS_SSL_PAYLOAD_OVERHEAD ( MBEDTLS_SSL_COMPRESSION_ADD + \
- MBEDTLS_MAX_IV_LENGTH + \
- MBEDTLS_SSL_MAC_ADD + \
- MBEDTLS_SSL_PADDING_ADD + \
- MBEDTLS_SSL_MAX_CID_EXPANSION \
- )
- #define MBEDTLS_SSL_IN_PAYLOAD_LEN ( MBEDTLS_SSL_PAYLOAD_OVERHEAD + \
- ( MBEDTLS_SSL_IN_CONTENT_LEN ) )
- #define MBEDTLS_SSL_OUT_PAYLOAD_LEN ( MBEDTLS_SSL_PAYLOAD_OVERHEAD + \
- ( MBEDTLS_SSL_OUT_CONTENT_LEN ) )
- /* The maximum number of buffered handshake messages. */
- #define MBEDTLS_SSL_MAX_BUFFERED_HS 4
- /* Maximum length we can advertise as our max content length for
- RFC 6066 max_fragment_length extension negotiation purposes
- (the lesser of both sizes, if they are unequal.)
- */
- #define MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ( \
- (MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN) \
- ? ( MBEDTLS_SSL_OUT_CONTENT_LEN ) \
- : ( MBEDTLS_SSL_IN_CONTENT_LEN ) \
- )
- /* Maximum size in bytes of list in sig-hash algorithm ext., RFC 5246 */
- #define MBEDTLS_SSL_MAX_SIG_HASH_ALG_LIST_LEN 65534
- /* Maximum size in bytes of list in supported elliptic curve ext., RFC 4492 */
- #define MBEDTLS_SSL_MAX_CURVE_LIST_LEN 65535
- /*
- * Check that we obey the standard's message size bounds
- */
- #if MBEDTLS_SSL_MAX_CONTENT_LEN > 16384
- #error "Bad configuration - record content too large."
- #endif
- #if MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN
- #error "Bad configuration - incoming record content should not be larger than MBEDTLS_SSL_MAX_CONTENT_LEN."
- #endif
- #if MBEDTLS_SSL_OUT_CONTENT_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN
- #error "Bad configuration - outgoing record content should not be larger than MBEDTLS_SSL_MAX_CONTENT_LEN."
- #endif
- #if MBEDTLS_SSL_IN_PAYLOAD_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN + 2048
- #error "Bad configuration - incoming protected record payload too large."
- #endif
- #if MBEDTLS_SSL_OUT_PAYLOAD_LEN > MBEDTLS_SSL_MAX_CONTENT_LEN + 2048
- #error "Bad configuration - outgoing protected record payload too large."
- #endif
- /* Calculate buffer sizes */
- /* Note: Even though the TLS record header is only 5 bytes
- long, we're internally using 8 bytes to store the
- implicit sequence number. */
- #define MBEDTLS_SSL_HEADER_LEN 13
- #if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- #define MBEDTLS_SSL_IN_BUFFER_LEN \
- ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_IN_PAYLOAD_LEN ) )
- #else
- #define MBEDTLS_SSL_IN_BUFFER_LEN \
- ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_IN_PAYLOAD_LEN ) \
- + ( MBEDTLS_SSL_CID_IN_LEN_MAX ) )
- #endif
- #if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- #define MBEDTLS_SSL_OUT_BUFFER_LEN \
- ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_OUT_PAYLOAD_LEN ) )
- #else
- #define MBEDTLS_SSL_OUT_BUFFER_LEN \
- ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_OUT_PAYLOAD_LEN ) \
- + ( MBEDTLS_SSL_CID_OUT_LEN_MAX ) )
- #endif
- #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
- static inline size_t mbedtls_ssl_get_output_buflen( const mbedtls_ssl_context *ctx )
- {
- #if defined (MBEDTLS_SSL_DTLS_CONNECTION_ID)
- return mbedtls_ssl_get_output_max_frag_len( ctx )
- + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
- + MBEDTLS_SSL_CID_OUT_LEN_MAX;
- #else
- return mbedtls_ssl_get_output_max_frag_len( ctx )
- + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
- #endif
- }
- static inline size_t mbedtls_ssl_get_input_buflen( const mbedtls_ssl_context *ctx )
- {
- #if defined (MBEDTLS_SSL_DTLS_CONNECTION_ID)
- return mbedtls_ssl_get_input_max_frag_len( ctx )
- + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
- + MBEDTLS_SSL_CID_IN_LEN_MAX;
- #else
- return mbedtls_ssl_get_input_max_frag_len( ctx )
- + MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
- #endif
- }
- #endif
- #ifdef MBEDTLS_ZLIB_SUPPORT
- /* Compression buffer holds both IN and OUT buffers, so should be size of the larger */
- #define MBEDTLS_SSL_COMPRESS_BUFFER_LEN ( \
- ( MBEDTLS_SSL_IN_BUFFER_LEN > MBEDTLS_SSL_OUT_BUFFER_LEN ) \
- ? MBEDTLS_SSL_IN_BUFFER_LEN \
- : MBEDTLS_SSL_OUT_BUFFER_LEN \
- )
- #endif
- /*
- * TLS extension flags (for extensions with outgoing ServerHello content
- * that need it (e.g. for RENEGOTIATION_INFO the server already knows because
- * of state of the renegotiation flag, so no indicator is required)
- */
- #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
- #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK (1 << 1)
- /**
- * \brief This function checks if the remaining size in a buffer is
- * greater or equal than a needed space.
- *
- * \param cur Pointer to the current position in the buffer.
- * \param end Pointer to one past the end of the buffer.
- * \param need Needed space in bytes.
- *
- * \return Zero if the needed space is available in the buffer, non-zero
- * otherwise.
- */
- static inline int mbedtls_ssl_chk_buf_ptr( const uint8_t *cur,
- const uint8_t *end, size_t need )
- {
- return( ( cur > end ) || ( need > (size_t)( end - cur ) ) );
- }
- /**
- * \brief This macro checks if the remaining size in a buffer is
- * greater or equal than a needed space. If it is not the case,
- * it returns an SSL_BUFFER_TOO_SMALL error.
- *
- * \param cur Pointer to the current position in the buffer.
- * \param end Pointer to one past the end of the buffer.
- * \param need Needed space in bytes.
- *
- */
- #define MBEDTLS_SSL_CHK_BUF_PTR( cur, end, need ) \
- do { \
- if( mbedtls_ssl_chk_buf_ptr( ( cur ), ( end ), ( need ) ) != 0 ) \
- { \
- return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); \
- } \
- } while( 0 )
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
- defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
- /*
- * Abstraction for a grid of allowed signature-hash-algorithm pairs.
- */
- struct mbedtls_ssl_sig_hash_set_t
- {
- /* At the moment, we only need to remember a single suitable
- * hash algorithm per signature algorithm. As long as that's
- * the case - and we don't need a general lookup function -
- * we can implement the sig-hash-set as a map from signatures
- * to hash algorithms. */
- mbedtls_md_type_t rsa;
- mbedtls_md_type_t ecdsa;
- };
- #endif /* MBEDTLS_SSL_PROTO_TLS1_2 &&
- MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
- typedef int mbedtls_ssl_tls_prf_cb( const unsigned char *secret, size_t slen,
- const char *label,
- const unsigned char *random, size_t rlen,
- unsigned char *dstbuf, size_t dlen );
- /* cipher.h exports the maximum IV, key and block length from
- * all ciphers enabled in the config, regardless of whether those
- * ciphers are actually usable in SSL/TLS. Notably, XTS is enabled
- * in the default configuration and uses 64 Byte keys, but it is
- * not used for record protection in SSL/TLS.
- *
- * In order to prevent unnecessary inflation of key structures,
- * we introduce SSL-specific variants of the max-{key,block,IV}
- * macros here which are meant to only take those ciphers into
- * account which can be negotiated in SSL/TLS.
- *
- * Since the current definitions of MBEDTLS_MAX_{KEY|BLOCK|IV}_LENGTH
- * in cipher.h are rough overapproximations of the real maxima, here
- * we content ourselves with replicating those overapproximations
- * for the maximum block and IV length, and excluding XTS from the
- * computation of the maximum key length. */
- #define MBEDTLS_SSL_MAX_BLOCK_LENGTH 16
- #define MBEDTLS_SSL_MAX_IV_LENGTH 16
- #define MBEDTLS_SSL_MAX_KEY_LENGTH 32
- /**
- * \brief The data structure holding the cryptographic material (key and IV)
- * used for record protection in TLS 1.3.
- */
- struct mbedtls_ssl_key_set
- {
- /*! The key for client->server records. */
- unsigned char client_write_key[ MBEDTLS_SSL_MAX_KEY_LENGTH ];
- /*! The key for server->client records. */
- unsigned char server_write_key[ MBEDTLS_SSL_MAX_KEY_LENGTH ];
- /*! The IV for client->server records. */
- unsigned char client_write_iv[ MBEDTLS_SSL_MAX_IV_LENGTH ];
- /*! The IV for server->client records. */
- unsigned char server_write_iv[ MBEDTLS_SSL_MAX_IV_LENGTH ];
- size_t key_len; /*!< The length of client_write_key and
- * server_write_key, in Bytes. */
- size_t iv_len; /*!< The length of client_write_iv and
- * server_write_iv, in Bytes. */
- };
- typedef struct mbedtls_ssl_key_set mbedtls_ssl_key_set;
- /*
- * This structure contains the parameters only needed during handshake.
- */
- struct mbedtls_ssl_handshake_params
- {
- /*
- * Handshake specific crypto variables
- */
- uint8_t max_major_ver; /*!< max. major version client*/
- uint8_t max_minor_ver; /*!< max. minor version client*/
- uint8_t resume; /*!< session resume indicator*/
- uint8_t cli_exts; /*!< client extension presence*/
- #if defined(MBEDTLS_X509_CRT_PARSE_C) && \
- defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
- uint8_t sni_authmode; /*!< authmode from SNI callback */
- #endif
- #if defined(MBEDTLS_SSL_SESSION_TICKETS)
- uint8_t new_session_ticket; /*!< use NewSessionTicket? */
- #endif /* MBEDTLS_SSL_SESSION_TICKETS */
- #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
- uint8_t extended_ms; /*!< use Extended Master Secret? */
- #endif
- #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
- uint8_t async_in_progress; /*!< an asynchronous operation is in progress */
- #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- unsigned char retransmit_state; /*!< Retransmission state */
- #endif
- #if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
- uint8_t ecrs_enabled; /*!< Handshake supports EC restart? */
- enum { /* this complements ssl->state with info on intra-state operations */
- ssl_ecrs_none = 0, /*!< nothing going on (yet) */
- ssl_ecrs_crt_verify, /*!< Certificate: crt_verify() */
- ssl_ecrs_ske_start_processing, /*!< ServerKeyExchange: pk_verify() */
- ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */
- ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */
- } ecrs_state; /*!< current (or last) operation */
- mbedtls_x509_crt *ecrs_peer_cert; /*!< The peer's CRT chain. */
- size_t ecrs_n; /*!< place for saving a length */
- #endif
- #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
- defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
- mbedtls_ssl_sig_hash_set_t hash_algs; /*!< Set of suitable sig-hash pairs */
- #endif
- size_t pmslen; /*!< premaster length */
- mbedtls_ssl_ciphersuite_t const *ciphersuite_info;
- void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
- void (*calc_verify)(const mbedtls_ssl_context *, unsigned char *, size_t *);
- void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
- mbedtls_ssl_tls_prf_cb *tls_prf;
- #if defined(MBEDTLS_DHM_C)
- mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
- #endif
- /* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due
- * to guards also being in ssl_srv.c and ssl_cli.c. There is a gap
- * in functionality that access to ecdh_ctx structure is needed for
- * MBEDTLS_ECDSA_C which does not seem correct.
- */
- #if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C)
- mbedtls_ecdh_context ecdh_ctx; /*!< ECDH key exchange */
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_key_type_t ecdh_psa_type;
- uint16_t ecdh_bits;
- psa_key_id_t ecdh_psa_privkey;
- unsigned char ecdh_psa_peerkey[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
- size_t ecdh_psa_peerkey_len;
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- #endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C */
- #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- mbedtls_ecjpake_context ecjpake_ctx; /*!< EC J-PAKE key exchange */
- #if defined(MBEDTLS_SSL_CLI_C)
- unsigned char *ecjpake_cache; /*!< Cache for ClientHello ext */
- size_t ecjpake_cache_len; /*!< Length of cached data */
- #endif
- #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
- #if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
- defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
- const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_key_id_t psk_opaque; /*!< Opaque PSK from the callback */
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- unsigned char *psk; /*!< PSK from the callback */
- size_t psk_len; /*!< Length of PSK from callback */
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
- #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
- mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */
- mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
- mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
- #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- #if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
- mbedtls_x509_crt_restart_ctx ecrs_ctx; /*!< restart context */
- #endif
- #if defined(MBEDTLS_X509_CRT_PARSE_C) && \
- !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
- mbedtls_pk_context peer_pubkey; /*!< The public key from the peer. */
- #endif /* MBEDTLS_X509_CRT_PARSE_C && !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- struct
- {
- size_t total_bytes_buffered; /*!< Cumulative size of heap allocated
- * buffers used for message buffering. */
- uint8_t seen_ccs; /*!< Indicates if a CCS message has
- * been seen in the current flight. */
- struct mbedtls_ssl_hs_buffer
- {
- unsigned is_valid : 1;
- unsigned is_fragmented : 1;
- unsigned is_complete : 1;
- unsigned char *data;
- size_t data_len;
- } hs[MBEDTLS_SSL_MAX_BUFFERED_HS];
- struct
- {
- unsigned char *data;
- size_t len;
- unsigned epoch;
- } future_record;
- } buffering;
- unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
- unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
- unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie
- Srv: unused */
- unsigned char verify_cookie_len; /*!< Cli: cookie length
- Srv: flag for sending a cookie */
- uint32_t retransmit_timeout; /*!< Current value of timeout */
- mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */
- mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */
- unsigned char *cur_msg_p; /*!< Position in current message */
- unsigned int in_flight_start_seq; /*!< Minimum message sequence in the
- flight being received */
- mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for
- resending messages */
- unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter
- for resending messages */
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- /* The state of CID configuration in this handshake. */
- uint8_t cid_in_use; /*!< This indicates whether the use of the CID extension
- * has been negotiated. Possible values are
- * #MBEDTLS_SSL_CID_ENABLED and
- * #MBEDTLS_SSL_CID_DISABLED. */
- unsigned char peer_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ]; /*! The peer's CID */
- uint8_t peer_cid_len; /*!< The length of
- * \c peer_cid. */
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- uint16_t mtu; /*!< Handshake mtu, used to fragment outgoing messages */
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- /*
- * Checksum contexts
- */
- #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
- defined(MBEDTLS_SSL_PROTO_TLS1_1)
- mbedtls_md5_context fin_md5;
- mbedtls_sha1_context fin_sha1;
- #endif
- #if defined(MBEDTLS_SSL_PROTO_TLS1_2)
- #if defined(MBEDTLS_SHA256_C)
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_hash_operation_t fin_sha256_psa;
- #else
- mbedtls_sha256_context fin_sha256;
- #endif
- #endif
- #if defined(MBEDTLS_SHA512_C)
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_hash_operation_t fin_sha384_psa;
- #else
- mbedtls_sha512_context fin_sha512;
- #endif
- #endif
- #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
- unsigned char randbytes[64]; /*!< random bytes */
- unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
- /*!< premaster secret */
- #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
- /** Asynchronous operation context. This field is meant for use by the
- * asynchronous operation callbacks (mbedtls_ssl_config::f_async_sign_start,
- * mbedtls_ssl_config::f_async_decrypt_start,
- * mbedtls_ssl_config::f_async_resume, mbedtls_ssl_config::f_async_cancel).
- * The library does not use it internally. */
- void *user_async_ctx;
- #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
- };
- typedef struct mbedtls_ssl_hs_buffer mbedtls_ssl_hs_buffer;
- /*
- * Representation of decryption/encryption transformations on records
- *
- * There are the following general types of record transformations:
- * - Stream transformations (TLS versions <= 1.2 only)
- * Transformation adding a MAC and applying a stream-cipher
- * to the authenticated message.
- * - CBC block cipher transformations ([D]TLS versions <= 1.2 only)
- * In addition to the distinction of the order of encryption and
- * authentication, there's a fundamental difference between the
- * handling in SSL3 & TLS 1.0 and TLS 1.1 and TLS 1.2: For SSL3
- * and TLS 1.0, the final IV after processing a record is used
- * as the IV for the next record. No explicit IV is contained
- * in an encrypted record. The IV for the first record is extracted
- * at key extraction time. In contrast, for TLS 1.1 and 1.2, no
- * IV is generated at key extraction time, but every encrypted
- * record is explicitly prefixed by the IV with which it was encrypted.
- * - AEAD transformations ([D]TLS versions >= 1.2 only)
- * These come in two fundamentally different versions, the first one
- * used in TLS 1.2, excluding ChaChaPoly ciphersuites, and the second
- * one used for ChaChaPoly ciphersuites in TLS 1.2 as well as for TLS 1.3.
- * In the first transformation, the IV to be used for a record is obtained
- * as the concatenation of an explicit, static 4-byte IV and the 8-byte
- * record sequence number, and explicitly prepending this sequence number
- * to the encrypted record. In contrast, in the second transformation
- * the IV is obtained by XOR'ing a static IV obtained at key extraction
- * time with the 8-byte record sequence number, without prepending the
- * latter to the encrypted record.
- *
- * Additionally, DTLS 1.2 + CID as well as TLS 1.3 use an inner plaintext
- * which allows to add flexible length padding and to hide a record's true
- * content type.
- *
- * In addition to type and version, the following parameters are relevant:
- * - The symmetric cipher algorithm to be used.
- * - The (static) encryption/decryption keys for the cipher.
- * - For stream/CBC, the type of message digest to be used.
- * - For stream/CBC, (static) encryption/decryption keys for the digest.
- * - For AEAD transformations, the size (potentially 0) of an explicit,
- * random initialization vector placed in encrypted records.
- * - For some transformations (currently AEAD and CBC in SSL3 and TLS 1.0)
- * an implicit IV. It may be static (e.g. AEAD) or dynamic (e.g. CBC)
- * and (if present) is combined with the explicit IV in a transformation-
- * dependent way (e.g. appending in TLS 1.2 and XOR'ing in TLS 1.3).
- * - For stream/CBC, a flag determining the order of encryption and MAC.
- * - The details of the transformation depend on the SSL/TLS version.
- * - The length of the authentication tag.
- *
- * Note: Except for CBC in SSL3 and TLS 1.0, these parameters are
- * constant across multiple encryption/decryption operations.
- * For CBC, the implicit IV needs to be updated after each
- * operation.
- *
- * The struct below refines this abstract view as follows:
- * - The cipher underlying the transformation is managed in
- * cipher contexts cipher_ctx_{enc/dec}, which must have the
- * same cipher type. The mode of these cipher contexts determines
- * the type of the transformation in the sense above: e.g., if
- * the type is MBEDTLS_CIPHER_AES_256_CBC resp. MBEDTLS_CIPHER_AES_192_GCM
- * then the transformation has type CBC resp. AEAD.
- * - The cipher keys are never stored explicitly but
- * are maintained within cipher_ctx_{enc/dec}.
- * - For stream/CBC transformations, the message digest contexts
- * used for the MAC's are stored in md_ctx_{enc/dec}. These contexts
- * are unused for AEAD transformations.
- * - For stream/CBC transformations and versions > SSL3, the
- * MAC keys are not stored explicitly but maintained within
- * md_ctx_{enc/dec}.
- * - For stream/CBC transformations and version SSL3, the MAC
- * keys are stored explicitly in mac_enc, mac_dec and have
- * a fixed size of 20 bytes. These fields are unused for
- * AEAD transformations or transformations >= TLS 1.0.
- * - For transformations using an implicit IV maintained within
- * the transformation context, its contents are stored within
- * iv_{enc/dec}.
- * - The value of ivlen indicates the length of the IV.
- * This is redundant in case of stream/CBC transformations
- * which always use 0 resp. the cipher's block length as the
- * IV length, but is needed for AEAD ciphers and may be
- * different from the underlying cipher's block length
- * in this case.
- * - The field fixed_ivlen is nonzero for AEAD transformations only
- * and indicates the length of the static part of the IV which is
- * constant throughout the communication, and which is stored in
- * the first fixed_ivlen bytes of the iv_{enc/dec} arrays.
- * Note: For CBC in SSL3 and TLS 1.0, the fields iv_{enc/dec}
- * still store IV's for continued use across multiple transformations,
- * so it is not true that fixed_ivlen == 0 means that iv_{enc/dec} are
- * not being used!
- * - minor_ver denotes the SSL/TLS version
- * - For stream/CBC transformations, maclen denotes the length of the
- * authentication tag, while taglen is unused and 0.
- * - For AEAD transformations, taglen denotes the length of the
- * authentication tag, while maclen is unused and 0.
- * - For CBC transformations, encrypt_then_mac determines the
- * order of encryption and authentication. This field is unused
- * in other transformations.
- *
- */
- struct mbedtls_ssl_transform
- {
- /*
- * Session specific crypto layer
- */
- size_t minlen; /*!< min. ciphertext length */
- size_t ivlen; /*!< IV length */
- size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
- size_t maclen; /*!< MAC(CBC) len */
- size_t taglen; /*!< TAG(AEAD) len */
- unsigned char iv_enc[16]; /*!< IV (encryption) */
- unsigned char iv_dec[16]; /*!< IV (decryption) */
- #if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
- #if defined(MBEDTLS_SSL_PROTO_SSL3)
- /* Needed only for SSL v3.0 secret */
- unsigned char mac_enc[20]; /*!< SSL v3.0 secret (enc) */
- unsigned char mac_dec[20]; /*!< SSL v3.0 secret (dec) */
- #endif /* MBEDTLS_SSL_PROTO_SSL3 */
- mbedtls_md_context_t md_ctx_enc; /*!< MAC (encryption) */
- mbedtls_md_context_t md_ctx_dec; /*!< MAC (decryption) */
- #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
- int encrypt_then_mac; /*!< flag for EtM activation */
- #endif
- #endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
- mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
- mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
- int minor_ver;
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- uint8_t in_cid_len;
- uint8_t out_cid_len;
- unsigned char in_cid [ MBEDTLS_SSL_CID_OUT_LEN_MAX ];
- unsigned char out_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ];
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- /*
- * Session specific compression layer
- */
- #if defined(MBEDTLS_ZLIB_SUPPORT)
- z_stream ctx_deflate; /*!< compression context */
- z_stream ctx_inflate; /*!< decompression context */
- #endif
- #if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
- /* We need the Hello random bytes in order to re-derive keys from the
- * Master Secret and other session info, see ssl_populate_transform() */
- unsigned char randbytes[64]; /*!< ServerHello.random+ClientHello.random */
- #endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
- };
- /*
- * Return 1 if the transform uses an AEAD cipher, 0 otherwise.
- * Equivalently, return 0 if a separate MAC is used, 1 otherwise.
- */
- static inline int mbedtls_ssl_transform_uses_aead(
- const mbedtls_ssl_transform *transform )
- {
- #if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
- return( transform->maclen == 0 && transform->taglen != 0 );
- #else
- (void) transform;
- return( 1 );
- #endif
- }
- /*
- * Internal representation of record frames
- *
- * Instances come in two flavors:
- * (1) Encrypted
- * These always have data_offset = 0
- * (2) Unencrypted
- * These have data_offset set to the amount of
- * pre-expansion during record protection. Concretely,
- * this is the length of the fixed part of the explicit IV
- * used for encryption, or 0 if no explicit IV is used
- * (e.g. for CBC in TLS 1.0, or stream ciphers).
- *
- * The reason for the data_offset in the unencrypted case
- * is to allow for in-place conversion of an unencrypted to
- * an encrypted record. If the offset wasn't included, the
- * encrypted content would need to be shifted afterwards to
- * make space for the fixed IV.
- *
- */
- #if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX
- #define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_OUT_LEN_MAX
- #else
- #define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_IN_LEN_MAX
- #endif
- typedef struct
- {
- uint8_t ctr[8]; /* In TLS: The implicit record sequence number.
- * In DTLS: The 2-byte epoch followed by
- * the 6-byte sequence number.
- * This is stored as a raw big endian byte array
- * as opposed to a uint64_t because we rarely
- * need to perform arithmetic on this, but do
- * need it as a Byte array for the purpose of
- * MAC computations. */
- uint8_t type; /* The record content type. */
- uint8_t ver[2]; /* SSL/TLS version as present on the wire.
- * Convert to internal presentation of versions
- * using mbedtls_ssl_read_version() and
- * mbedtls_ssl_write_version().
- * Keep wire-format for MAC computations. */
- unsigned char *buf; /* Memory buffer enclosing the record content */
- size_t buf_len; /* Buffer length */
- size_t data_offset; /* Offset of record content */
- size_t data_len; /* Length of record content */
- #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
- uint8_t cid_len; /* Length of the CID (0 if not present) */
- unsigned char cid[ MBEDTLS_SSL_CID_LEN_MAX ]; /* The CID */
- #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
- } mbedtls_record;
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /*
- * List of certificate + private key pairs
- */
- struct mbedtls_ssl_key_cert
- {
- mbedtls_x509_crt *cert; /*!< cert */
- mbedtls_pk_context *key; /*!< private key */
- mbedtls_ssl_key_cert *next; /*!< next key/cert pair */
- };
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- /*
- * List of handshake messages kept around for resending
- */
- struct mbedtls_ssl_flight_item
- {
- unsigned char *p; /*!< message, including handshake headers */
- size_t len; /*!< length of p */
- unsigned char type; /*!< type of the message: handshake or CCS */
- mbedtls_ssl_flight_item *next; /*!< next handshake message(s) */
- };
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
- defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
- /* Find an entry in a signature-hash set matching a given hash algorithm. */
- mbedtls_md_type_t mbedtls_ssl_sig_hash_set_find( mbedtls_ssl_sig_hash_set_t *set,
- mbedtls_pk_type_t sig_alg );
- /* Add a signature-hash-pair to a signature-hash set */
- void mbedtls_ssl_sig_hash_set_add( mbedtls_ssl_sig_hash_set_t *set,
- mbedtls_pk_type_t sig_alg,
- mbedtls_md_type_t md_alg );
- /* Allow exactly one hash algorithm for each signature. */
- void mbedtls_ssl_sig_hash_set_const_hash( mbedtls_ssl_sig_hash_set_t *set,
- mbedtls_md_type_t md_alg );
- /* Setup an empty signature-hash set */
- static inline void mbedtls_ssl_sig_hash_set_init( mbedtls_ssl_sig_hash_set_t *set )
- {
- mbedtls_ssl_sig_hash_set_const_hash( set, MBEDTLS_MD_NONE );
- }
- #endif /* MBEDTLS_SSL_PROTO_TLS1_2) &&
- MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
- /**
- * \brief Free referenced items in an SSL transform context and clear
- * memory
- *
- * \param transform SSL transform context
- */
- void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform );
- /**
- * \brief Free referenced items in an SSL handshake context and clear
- * memory
- *
- * \param ssl SSL context
- */
- void mbedtls_ssl_handshake_free( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_handshake_client_step( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_handshake_server_step( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_handshake_wrapup( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_send_fatal_handshake_failure( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_update_handshake_status( mbedtls_ssl_context *ssl );
- /**
- * \brief Update record layer
- *
- * This function roughly separates the implementation
- * of the logic of (D)TLS from the implementation
- * of the secure transport.
- *
- * \param ssl The SSL context to use.
- * \param update_hs_digest This indicates if the handshake digest
- * should be automatically updated in case
- * a handshake message is found.
- *
- * \return 0 or non-zero error code.
- *
- * \note A clarification on what is called 'record layer' here
- * is in order, as many sensible definitions are possible:
- *
- * The record layer takes as input an untrusted underlying
- * transport (stream or datagram) and transforms it into
- * a serially multiplexed, secure transport, which
- * conceptually provides the following:
- *
- * (1) Three datagram based, content-agnostic transports
- * for handshake, alert and CCS messages.
- * (2) One stream- or datagram-based transport
- * for application data.
- * (3) Functionality for changing the underlying transform
- * securing the contents.
- *
- * The interface to this functionality is given as follows:
- *
- * a Updating
- * [Currently implemented by mbedtls_ssl_read_record]
- *
- * Check if and on which of the four 'ports' data is pending:
- * Nothing, a controlling datagram of type (1), or application
- * data (2). In any case data is present, internal buffers
- * provide access to the data for the user to process it.
- * Consumption of type (1) datagrams is done automatically
- * on the next update, invalidating that the internal buffers
- * for previous datagrams, while consumption of application
- * data (2) is user-controlled.
- *
- * b Reading of application data
- * [Currently manual adaption of ssl->in_offt pointer]
- *
- * As mentioned in the last paragraph, consumption of data
- * is different from the automatic consumption of control
- * datagrams (1) because application data is treated as a stream.
- *
- * c Tracking availability of application data
- * [Currently manually through decreasing ssl->in_msglen]
- *
- * For efficiency and to retain datagram semantics for
- * application data in case of DTLS, the record layer
- * provides functionality for checking how much application
- * data is still available in the internal buffer.
- *
- * d Changing the transformation securing the communication.
- *
- * Given an opaque implementation of the record layer in the
- * above sense, it should be possible to implement the logic
- * of (D)TLS on top of it without the need to know anything
- * about the record layer's internals. This is done e.g.
- * in all the handshake handling functions, and in the
- * application data reading function mbedtls_ssl_read.
- *
- * \note The above tries to give a conceptual picture of the
- * record layer, but the current implementation deviates
- * from it in some places. For example, our implementation of
- * the update functionality through mbedtls_ssl_read_record
- * discards datagrams depending on the current state, which
- * wouldn't fall under the record layer's responsibility
- * following the above definition.
- *
- */
- int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl,
- unsigned update_hs_digest );
- int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want );
- int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush );
- int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_write_change_cipher_spec( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl,
- const mbedtls_ssl_ciphersuite_t *ciphersuite_info );
- #if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
- int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exchange_type_t key_ex );
- /**
- * Get the first defined PSK by order of precedence:
- * 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback
- * 2. static PSK configured by \c mbedtls_ssl_conf_psk()
- * Return a code and update the pair (PSK, PSK length) passed to this function
- */
- static inline int mbedtls_ssl_get_psk( const mbedtls_ssl_context *ssl,
- const unsigned char **psk, size_t *psk_len )
- {
- if( ssl->handshake->psk != NULL && ssl->handshake->psk_len > 0 )
- {
- *psk = ssl->handshake->psk;
- *psk_len = ssl->handshake->psk_len;
- }
- else if( ssl->conf->psk != NULL && ssl->conf->psk_len > 0 )
- {
- *psk = ssl->conf->psk;
- *psk_len = ssl->conf->psk_len;
- }
- else
- {
- *psk = NULL;
- *psk_len = 0;
- return( MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED );
- }
- return( 0 );
- }
- #if defined(MBEDTLS_USE_PSA_CRYPTO)
- /**
- * Get the first defined opaque PSK by order of precedence:
- * 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk_opaque() in the PSK
- * callback
- * 2. static PSK configured by \c mbedtls_ssl_conf_psk_opaque()
- * Return an opaque PSK
- */
- static inline psa_key_id_t mbedtls_ssl_get_opaque_psk(
- const mbedtls_ssl_context *ssl )
- {
- if( ! mbedtls_svc_key_id_is_null( ssl->handshake->psk_opaque ) )
- return( ssl->handshake->psk_opaque );
- if( ! mbedtls_svc_key_id_is_null( ssl->conf->psk_opaque ) )
- return( ssl->conf->psk_opaque );
- return( MBEDTLS_SVC_KEY_ID_INIT );
- }
- #endif /* MBEDTLS_USE_PSA_CRYPTO */
- #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
- #if defined(MBEDTLS_PK_C)
- unsigned char mbedtls_ssl_sig_from_pk( mbedtls_pk_context *pk );
- unsigned char mbedtls_ssl_sig_from_pk_alg( mbedtls_pk_type_t type );
- mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig( unsigned char sig );
- #endif
- mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash( unsigned char hash );
- unsigned char mbedtls_ssl_hash_from_md_alg( int md );
- int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md );
- #if defined(MBEDTLS_ECP_C)
- int mbedtls_ssl_check_curve( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id );
- #endif
- #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
- int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl,
- mbedtls_md_type_t md );
- #endif
- #if defined(MBEDTLS_SSL_DTLS_SRTP)
- static inline mbedtls_ssl_srtp_profile mbedtls_ssl_check_srtp_profile_value
- ( const uint16_t srtp_profile_value )
- {
- switch( srtp_profile_value )
- {
- case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
- case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
- case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
- case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
- return srtp_profile_value;
- default: break;
- }
- return( MBEDTLS_TLS_SRTP_UNSET );
- }
- #endif
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl )
- {
- mbedtls_ssl_key_cert *key_cert;
- if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
- key_cert = ssl->handshake->key_cert;
- else
- key_cert = ssl->conf->key_cert;
- return( key_cert == NULL ? NULL : key_cert->key );
- }
- static inline mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl )
- {
- mbedtls_ssl_key_cert *key_cert;
- if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
- key_cert = ssl->handshake->key_cert;
- else
- key_cert = ssl->conf->key_cert;
- return( key_cert == NULL ? NULL : key_cert->cert );
- }
- /*
- * Check usage of a certificate wrt extensions:
- * keyUsage, extendedKeyUsage (later), and nSCertType (later).
- *
- * Warning: cert_endpoint is the endpoint of the cert (ie, of our peer when we
- * check a cert we received from them)!
- *
- * Return 0 if everything is OK, -1 if not.
- */
- int mbedtls_ssl_check_cert_usage( const mbedtls_x509_crt *cert,
- const mbedtls_ssl_ciphersuite_t *ciphersuite,
- int cert_endpoint,
- uint32_t *flags );
- #endif /* MBEDTLS_X509_CRT_PARSE_C */
- void mbedtls_ssl_write_version( int major, int minor, int transport,
- unsigned char ver[2] );
- void mbedtls_ssl_read_version( int *major, int *minor, int transport,
- const unsigned char ver[2] );
- static inline size_t mbedtls_ssl_in_hdr_len( const mbedtls_ssl_context *ssl )
- {
- #if !defined(MBEDTLS_SSL_PROTO_DTLS)
- ((void) ssl);
- #endif
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
- {
- return( 13 );
- }
- else
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- {
- return( 5 );
- }
- }
- static inline size_t mbedtls_ssl_out_hdr_len( const mbedtls_ssl_context *ssl )
- {
- return( (size_t) ( ssl->out_iv - ssl->out_hdr ) );
- }
- static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl )
- {
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
- return( 12 );
- #else
- ((void) ssl);
- #endif
- return( 4 );
- }
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- void mbedtls_ssl_send_flight_completed( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_recv_flight_completed( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_resend( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_flight_transmit( mbedtls_ssl_context *ssl );
- #endif
- /* Visible for testing purposes only */
- #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
- int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context const *ssl );
- void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
- #endif
- int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst,
- const mbedtls_ssl_session *src );
- #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
- defined(MBEDTLS_SSL_PROTO_TLS1_1)
- int mbedtls_ssl_get_key_exchange_md_ssl_tls( mbedtls_ssl_context *ssl,
- unsigned char *output,
- unsigned char *data, size_t data_len );
- #endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
- MBEDTLS_SSL_PROTO_TLS1_1 */
- #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
- defined(MBEDTLS_SSL_PROTO_TLS1_2)
- /* The hash buffer must have at least MBEDTLS_MD_MAX_SIZE bytes of length. */
- int mbedtls_ssl_get_key_exchange_md_tls1_2( mbedtls_ssl_context *ssl,
- unsigned char *hash, size_t *hashlen,
- unsigned char *data, size_t data_len,
- mbedtls_md_type_t md_alg );
- #endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
- MBEDTLS_SSL_PROTO_TLS1_2 */
- #ifdef __cplusplus
- }
- #endif
- void mbedtls_ssl_transform_init( mbedtls_ssl_transform *transform );
- int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
- mbedtls_ssl_transform *transform,
- mbedtls_record *rec,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng );
- int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
- mbedtls_ssl_transform *transform,
- mbedtls_record *rec );
- /* Length of the "epoch" field in the record header */
- static inline size_t mbedtls_ssl_ep_len( const mbedtls_ssl_context *ssl )
- {
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
- return( 2 );
- #else
- ((void) ssl);
- #endif
- return( 0 );
- }
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- int mbedtls_ssl_resend_hello_request( mbedtls_ssl_context *ssl );
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- void mbedtls_ssl_set_timer( mbedtls_ssl_context *ssl, uint32_t millisecs );
- int mbedtls_ssl_check_timer( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_reset_in_out_pointers( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_update_out_pointers( mbedtls_ssl_context *ssl,
- mbedtls_ssl_transform *transform );
- void mbedtls_ssl_update_in_pointers( mbedtls_ssl_context *ssl );
- int mbedtls_ssl_session_reset_int( mbedtls_ssl_context *ssl, int partial );
- #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
- void mbedtls_ssl_dtls_replay_reset( mbedtls_ssl_context *ssl );
- #endif
- void mbedtls_ssl_handshake_wrapup_free_hs_transform( mbedtls_ssl_context *ssl );
- #if defined(MBEDTLS_SSL_RENEGOTIATION)
- int mbedtls_ssl_start_renegotiation( mbedtls_ssl_context *ssl );
- #endif /* MBEDTLS_SSL_RENEGOTIATION */
- #if defined(MBEDTLS_SSL_PROTO_DTLS)
- size_t mbedtls_ssl_get_current_mtu( const mbedtls_ssl_context *ssl );
- void mbedtls_ssl_buffering_free( mbedtls_ssl_context *ssl );
- void mbedtls_ssl_flight_free( mbedtls_ssl_flight_item *flight );
- #endif /* MBEDTLS_SSL_PROTO_DTLS */
- #endif /* ssl_internal.h */
- /********* Start of file include/mbedtls/ssl_cache.h ************/
- /**
- * \file ssl_cache.h
- *
- * \brief SSL session cache implementation
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SSL_CACHE_H
- #define MBEDTLS_SSL_CACHE_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_THREADING_C)
- #endif
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT)
- #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */
- #endif
- #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES)
- #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */
- #endif
- /* \} name SECTION: Module settings */
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct mbedtls_ssl_cache_context mbedtls_ssl_cache_context;
- typedef struct mbedtls_ssl_cache_entry mbedtls_ssl_cache_entry;
- /**
- * \brief This structure is used for storing cache entries
- */
- struct mbedtls_ssl_cache_entry
- {
- #if defined(MBEDTLS_HAVE_TIME)
- mbedtls_time_t timestamp; /*!< entry timestamp */
- #endif
- mbedtls_ssl_session session; /*!< entry session */
- #if defined(MBEDTLS_X509_CRT_PARSE_C) && \
- defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
- mbedtls_x509_buf peer_cert; /*!< entry peer_cert */
- #endif
- mbedtls_ssl_cache_entry *next; /*!< chain pointer */
- };
- /**
- * \brief Cache context
- */
- struct mbedtls_ssl_cache_context
- {
- mbedtls_ssl_cache_entry *chain; /*!< start of the chain */
- int timeout; /*!< cache entry timeout */
- int max_entries; /*!< maximum entries */
- #if defined(MBEDTLS_THREADING_C)
- mbedtls_threading_mutex_t mutex; /*!< mutex */
- #endif
- };
- /**
- * \brief Initialize an SSL cache context
- *
- * \param cache SSL cache context
- */
- void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache );
- /**
- * \brief Cache get callback implementation
- * (Thread-safe if MBEDTLS_THREADING_C is enabled)
- *
- * \param data SSL cache context
- * \param session session to retrieve entry for
- */
- int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session );
- /**
- * \brief Cache set callback implementation
- * (Thread-safe if MBEDTLS_THREADING_C is enabled)
- *
- * \param data SSL cache context
- * \param session session to store entry for
- */
- int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session );
- #if defined(MBEDTLS_HAVE_TIME)
- /**
- * \brief Set the cache timeout
- * (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day))
- *
- * A timeout of 0 indicates no timeout.
- *
- * \param cache SSL cache context
- * \param timeout cache entry timeout in seconds
- */
- void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout );
- #endif /* MBEDTLS_HAVE_TIME */
- /**
- * \brief Set the maximum number of cache entries
- * (Default: MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES (50))
- *
- * \param cache SSL cache context
- * \param max cache entry maximum
- */
- void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max );
- /**
- * \brief Free referenced items in a cache context and clear memory
- *
- * \param cache SSL cache context
- */
- void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache );
- #ifdef __cplusplus
- }
- #endif
- #endif /* ssl_cache.h */
- /********* Start of file include/mbedtls/ssl_ticket.h ************/
- /**
- * \file ssl_ticket.h
- *
- * \brief TLS server ticket callbacks implementation
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_SSL_TICKET_H
- #define MBEDTLS_SSL_TICKET_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /*
- * This implementation of the session ticket callbacks includes key
- * management, rotating the keys periodically in order to preserve forward
- * secrecy, when MBEDTLS_HAVE_TIME is defined.
- */
- #if defined(MBEDTLS_THREADING_C)
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Information for session ticket protection
- */
- typedef struct mbedtls_ssl_ticket_key
- {
- unsigned char name[4]; /*!< random key identifier */
- uint32_t generation_time; /*!< key generation timestamp (seconds) */
- mbedtls_cipher_context_t ctx; /*!< context for auth enc/decryption */
- }
- mbedtls_ssl_ticket_key;
- /**
- * \brief Context for session ticket handling functions
- */
- typedef struct mbedtls_ssl_ticket_context
- {
- mbedtls_ssl_ticket_key keys[2]; /*!< ticket protection keys */
- unsigned char active; /*!< index of the currently active key */
- uint32_t ticket_lifetime; /*!< lifetime of tickets in seconds */
- /** Callback for getting (pseudo-)random numbers */
- int (*f_rng)(void *, unsigned char *, size_t);
- void *p_rng; /*!< context for the RNG function */
- #if defined(MBEDTLS_THREADING_C)
- mbedtls_threading_mutex_t mutex;
- #endif
- }
- mbedtls_ssl_ticket_context;
- /**
- * \brief Initialize a ticket context.
- * (Just make it ready for mbedtls_ssl_ticket_setup()
- * or mbedtls_ssl_ticket_free().)
- *
- * \param ctx Context to be initialized
- */
- void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );
- /**
- * \brief Prepare context to be actually used
- *
- * \param ctx Context to be set up
- * \param f_rng RNG callback function
- * \param p_rng RNG callback context
- * \param cipher AEAD cipher to use for ticket protection.
- * Recommended value: MBEDTLS_CIPHER_AES_256_GCM.
- * \param lifetime Tickets lifetime in seconds
- * Recommended value: 86400 (one day).
- *
- * \note It is highly recommended to select a cipher that is at
- * least as strong as the strongest ciphersuite
- * supported. Usually that means a 256-bit key.
- *
- * \note The lifetime of the keys is twice the lifetime of tickets.
- * It is recommended to pick a reasonnable lifetime so as not
- * to negate the benefits of forward secrecy.
- *
- * \return 0 if successful,
- * or a specific MBEDTLS_ERR_XXX error code
- */
- int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- mbedtls_cipher_type_t cipher,
- uint32_t lifetime );
- /**
- * \brief Implementation of the ticket write callback
- *
- * \note See \c mbedtls_ssl_ticket_write_t for description
- */
- mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write;
- /**
- * \brief Implementation of the ticket parse callback
- *
- * \note See \c mbedtls_ssl_ticket_parse_t for description
- */
- mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse;
- /**
- * \brief Free a context's content and zeroize it.
- *
- * \param ctx Context to be cleaned up
- */
- void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx );
- #ifdef __cplusplus
- }
- #endif
- #endif /* ssl_ticket.h */
- /********* Start of file include/mbedtls/debug.h ************/
- /**
- * \file debug.h
- *
- * \brief Functions for controlling and providing debug output from the library.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_DEBUG_H
- #define MBEDTLS_DEBUG_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_ECP_C)
- #endif
- #if defined(MBEDTLS_DEBUG_C)
- #define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
- #define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
- mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
- MBEDTLS_DEBUG_STRIP_PARENS args )
- #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
- mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
- #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
- mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
- #if defined(MBEDTLS_BIGNUM_C)
- #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
- mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
- #endif
- #if defined(MBEDTLS_ECP_C)
- #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
- mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
- #endif
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
- mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
- #endif
- #if defined(MBEDTLS_ECDH_C)
- #define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
- mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
- #endif
- #else /* MBEDTLS_DEBUG_C */
- #define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
- #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
- #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
- #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
- #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
- #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
- #define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 )
- #endif /* MBEDTLS_DEBUG_C */
- /**
- * \def MBEDTLS_PRINTF_ATTRIBUTE
- *
- * Mark a function as having printf attributes, and thus enable checking
- * via -wFormat and other flags. This does nothing on builds with compilers
- * that do not support the format attribute
- *
- * Module: library/debug.c
- * Caller:
- *
- * This module provides debugging functions.
- */
- #if defined(__has_attribute)
- #if __has_attribute(format)
- #if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1
- #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
- __attribute__((__format__ (gnu_printf, string_index, first_to_check)))
- #else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */
- #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
- __attribute__((format(printf, string_index, first_to_check)))
- #endif
- #else /* __has_attribute(format) */
- #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
- #endif /* __has_attribute(format) */
- #else /* defined(__has_attribute) */
- #define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
- #endif
- /**
- * \def MBEDTLS_PRINTF_SIZET
- *
- * MBEDTLS_PRINTF_xxx: Due to issues with older window compilers
- * and MinGW we need to define the printf specifier for size_t
- * and long long per platform.
- *
- * Module: library/debug.c
- * Caller:
- *
- * This module provides debugging functions.
- */
- #if (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800)
- #include <inttypes.h>
- #define MBEDTLS_PRINTF_SIZET PRIuPTR
- #define MBEDTLS_PRINTF_LONGLONG "I64d"
- #else /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
- #define MBEDTLS_PRINTF_SIZET "zu"
- #define MBEDTLS_PRINTF_LONGLONG "lld"
- #endif /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Set the threshold error level to handle globally all debug output.
- * Debug messages that have a level over the threshold value are
- * discarded.
- * (Default value: 0 = No debug )
- *
- * \param threshold theshold level of messages to filter on. Messages at a
- * higher level will be discarded.
- * - Debug levels
- * - 0 No debug
- * - 1 Error
- * - 2 State change
- * - 3 Informational
- * - 4 Verbose
- */
- void mbedtls_debug_set_threshold( int threshold );
- /**
- * \brief Print a message to the debug output. This function is always used
- * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
- * context, file and line number parameters.
- *
- * \param ssl SSL context
- * \param level error level of the debug message
- * \param file file the message has occurred in
- * \param line line number the message has occurred at
- * \param format format specifier, in printf format
- * \param ... variables used by the format specifier
- *
- * \attention This function is intended for INTERNAL usage within the
- * library only.
- */
- void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
- const char *file, int line,
- const char *format, ... ) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
- /**
- * \brief Print the return value of a function to the debug output. This
- * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
- * which supplies the ssl context, file and line number parameters.
- *
- * \param ssl SSL context
- * \param level error level of the debug message
- * \param file file the error has occurred in
- * \param line line number the error has occurred in
- * \param text the name of the function that returned the error
- * \param ret the return code value
- *
- * \attention This function is intended for INTERNAL usage within the
- * library only.
- */
- void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
- const char *file, int line,
- const char *text, int ret );
- /**
- * \brief Output a buffer of size len bytes to the debug output. This function
- * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
- * which supplies the ssl context, file and line number parameters.
- *
- * \param ssl SSL context
- * \param level error level of the debug message
- * \param file file the error has occurred in
- * \param line line number the error has occurred in
- * \param text a name or label for the buffer being dumped. Normally the
- * variable or buffer name
- * \param buf the buffer to be outputted
- * \param len length of the buffer
- *
- * \attention This function is intended for INTERNAL usage within the
- * library only.
- */
- void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
- const char *file, int line, const char *text,
- const unsigned char *buf, size_t len );
- #if defined(MBEDTLS_BIGNUM_C)
- /**
- * \brief Print a MPI variable to the debug output. This function is always
- * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
- * ssl context, file and line number parameters.
- *
- * \param ssl SSL context
- * \param level error level of the debug message
- * \param file file the error has occurred in
- * \param line line number the error has occurred in
- * \param text a name or label for the MPI being output. Normally the
- * variable name
- * \param X the MPI variable
- *
- * \attention This function is intended for INTERNAL usage within the
- * library only.
- */
- void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
- const char *file, int line,
- const char *text, const mbedtls_mpi *X );
- #endif
- #if defined(MBEDTLS_ECP_C)
- /**
- * \brief Print an ECP point to the debug output. This function is always
- * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
- * ssl context, file and line number parameters.
- *
- * \param ssl SSL context
- * \param level error level of the debug message
- * \param file file the error has occurred in
- * \param line line number the error has occurred in
- * \param text a name or label for the ECP point being output. Normally the
- * variable name
- * \param X the ECP point
- *
- * \attention This function is intended for INTERNAL usage within the
- * library only.
- */
- void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
- const char *file, int line,
- const char *text, const mbedtls_ecp_point *X );
- #endif
- #if defined(MBEDTLS_X509_CRT_PARSE_C)
- /**
- * \brief Print a X.509 certificate structure to the debug output. This
- * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
- * which supplies the ssl context, file and line number parameters.
- *
- * \param ssl SSL context
- * \param level error level of the debug message
- * \param file file the error has occurred in
- * \param line line number the error has occurred in
- * \param text a name or label for the certificate being output
- * \param crt X.509 certificate structure
- *
- * \attention This function is intended for INTERNAL usage within the
- * library only.
- */
- void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
- const char *file, int line,
- const char *text, const mbedtls_x509_crt *crt );
- #endif
- #if defined(MBEDTLS_ECDH_C)
- typedef enum
- {
- MBEDTLS_DEBUG_ECDH_Q,
- MBEDTLS_DEBUG_ECDH_QP,
- MBEDTLS_DEBUG_ECDH_Z,
- } mbedtls_debug_ecdh_attr;
- /**
- * \brief Print a field of the ECDH structure in the SSL context to the debug
- * output. This function is always used through the
- * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file
- * and line number parameters.
- *
- * \param ssl SSL context
- * \param level error level of the debug message
- * \param file file the error has occurred in
- * \param line line number the error has occurred in
- * \param ecdh the ECDH context
- * \param attr the identifier of the attribute being output
- *
- * \attention This function is intended for INTERNAL usage within the
- * library only.
- */
- void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
- const char *file, int line,
- const mbedtls_ecdh_context *ecdh,
- mbedtls_debug_ecdh_attr attr );
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* debug.h */
- /********* Start of file include/mbedtls/blowfish.h ************/
- /**
- * \file blowfish.h
- *
- * \brief Blowfish block cipher
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_BLOWFISH_H
- #define MBEDTLS_BLOWFISH_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- #define MBEDTLS_BLOWFISH_ENCRYPT 1
- #define MBEDTLS_BLOWFISH_DECRYPT 0
- #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
- #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
- #define MBEDTLS_BLOWFISH_ROUNDS 16 /**< Rounds to use. When increasing this value, make sure to extend the initialisation vectors */
- #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 )
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /** Bad input data. */
- #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
- /** Invalid data input length. */
- #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
- /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
- */
- /** Blowfish hardware accelerator failed. */
- #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_BLOWFISH_ALT)
- // Regular implementation
- //
- /**
- * \brief Blowfish context structure
- */
- typedef struct mbedtls_blowfish_context
- {
- uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */
- uint32_t S[4][256]; /*!< key dependent S-boxes */
- }
- mbedtls_blowfish_context;
- #else /* MBEDTLS_BLOWFISH_ALT */
- #endif /* MBEDTLS_BLOWFISH_ALT */
- /**
- * \brief Initialize a Blowfish context.
- *
- * \param ctx The Blowfish context to be initialized.
- * This must not be \c NULL.
- */
- void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx );
- /**
- * \brief Clear a Blowfish context.
- *
- * \param ctx The Blowfish context to be cleared.
- * This may be \c NULL, in which case this function
- * returns immediately. If it is not \c NULL, it must
- * point to an initialized Blowfish context.
- */
- void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx );
- /**
- * \brief Perform a Blowfish key schedule operation.
- *
- * \param ctx The Blowfish context to perform the key schedule on.
- * \param key The encryption key. This must be a readable buffer of
- * length \p keybits Bits.
- * \param keybits The length of \p key in Bits. This must be between
- * \c 32 and \c 448 and a multiple of \c 8.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
- unsigned int keybits );
- /**
- * \brief Perform a Blowfish-ECB block encryption/decryption operation.
- *
- * \param ctx The Blowfish context to use. This must be initialized
- * and bound to a key.
- * \param mode The mode of operation. Possible values are
- * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or
- * #MBEDTLS_BLOWFISH_DECRYPT for decryption.
- * \param input The input block. This must be a readable buffer
- * of size \c 8 Bytes.
- * \param output The output block. This must be a writable buffer
- * of size \c 8 Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx,
- int mode,
- const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
- unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
- #if defined(MBEDTLS_CIPHER_MODE_CBC)
- /**
- * \brief Perform a Blowfish-CBC buffer encryption/decryption operation.
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the function same function again on the following
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If on the other hand you need to retain the contents of the
- * IV, you should either save it manually or use the cipher
- * module instead.
- *
- * \param ctx The Blowfish context to use. This must be initialized
- * and bound to a key.
- * \param mode The mode of operation. Possible values are
- * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or
- * #MBEDTLS_BLOWFISH_DECRYPT for decryption.
- * \param length The length of the input data in Bytes. This must be
- * multiple of \c 8.
- * \param iv The initialization vector. This must be a read/write buffer
- * of length \c 8 Bytes. It is updated by this function.
- * \param input The input data. This must be a readable buffer of length
- * \p length Bytes.
- * \param output The output data. This must be a writable buffer of length
- * \p length Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
- int mode,
- size_t length,
- unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CBC */
- #if defined(MBEDTLS_CIPHER_MODE_CFB)
- /**
- * \brief Perform a Blowfish CFB buffer encryption/decryption operation.
- *
- * \note Upon exit, the content of the IV is updated so that you can
- * call the function same function again on the following
- * block(s) of data and get the same result as if it was
- * encrypted in one call. This allows a "streaming" usage.
- * If on the other hand you need to retain the contents of the
- * IV, you should either save it manually or use the cipher
- * module instead.
- *
- * \param ctx The Blowfish context to use. This must be initialized
- * and bound to a key.
- * \param mode The mode of operation. Possible values are
- * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or
- * #MBEDTLS_BLOWFISH_DECRYPT for decryption.
- * \param length The length of the input data in Bytes.
- * \param iv_off The offset in the initialiation vector.
- * The value pointed to must be smaller than \c 8 Bytes.
- * It is updated by this function to support the aforementioned
- * streaming usage.
- * \param iv The initialization vector. This must be a read/write buffer
- * of size \c 8 Bytes. It is updated after use.
- * \param input The input data. This must be a readable buffer of length
- * \p length Bytes.
- * \param output The output data. This must be a writable buffer of length
- * \p length Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
- int mode,
- size_t length,
- size_t *iv_off,
- unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
- const unsigned char *input,
- unsigned char *output );
- #endif /*MBEDTLS_CIPHER_MODE_CFB */
- #if defined(MBEDTLS_CIPHER_MODE_CTR)
- /**
- * \brief Perform a Blowfish-CTR buffer encryption/decryption operation.
- *
- * \warning You must never reuse a nonce value with the same key. Doing so
- * would void the encryption for the two messages encrypted with
- * the same nonce and key.
- *
- * There are two common strategies for managing nonces with CTR:
- *
- * 1. You can handle everything as a single message processed over
- * successive calls to this function. In that case, you want to
- * set \p nonce_counter and \p nc_off to 0 for the first call, and
- * then preserve the values of \p nonce_counter, \p nc_off and \p
- * stream_block across calls to this function as they will be
- * updated by this function.
- *
- * With this strategy, you must not encrypt more than 2**64
- * blocks of data with the same key.
- *
- * 2. You can encrypt separate messages by dividing the \p
- * nonce_counter buffer in two areas: the first one used for a
- * per-message nonce, handled by yourself, and the second one
- * updated by this function internally.
- *
- * For example, you might reserve the first 4 bytes for the
- * per-message nonce, and the last 4 bytes for internal use. In that
- * case, before calling this function on a new message you need to
- * set the first 4 bytes of \p nonce_counter to your chosen nonce
- * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
- * stream_block to be ignored). That way, you can encrypt at most
- * 2**32 messages of up to 2**32 blocks each with the same key.
- *
- * The per-message nonce (or information sufficient to reconstruct
- * it) needs to be communicated with the ciphertext and must be unique.
- * The recommended way to ensure uniqueness is to use a message
- * counter.
- *
- * Note that for both stategies, sizes are measured in blocks and
- * that a Blowfish block is 8 bytes.
- *
- * \warning Upon return, \p stream_block contains sensitive data. Its
- * content must not be written to insecure storage and should be
- * securely discarded as soon as it's no longer needed.
- *
- * \param ctx The Blowfish context to use. This must be initialized
- * and bound to a key.
- * \param length The length of the input data in Bytes.
- * \param nc_off The offset in the current stream_block (for resuming
- * within current cipher stream). The offset pointer
- * should be \c 0 at the start of a stream and must be
- * smaller than \c 8. It is updated by this function.
- * \param nonce_counter The 64-bit nonce and counter. This must point to a
- * read/write buffer of length \c 8 Bytes.
- * \param stream_block The saved stream-block for resuming. This must point to
- * a read/write buffer of length \c 8 Bytes.
- * \param input The input data. This must be a readable buffer of
- * length \p length Bytes.
- * \param output The output data. This must be a writable buffer of
- * length \p length Bytes.
- *
- * \return \c 0 if successful.
- * \return A negative error code on failure.
- */
- int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
- size_t length,
- size_t *nc_off,
- unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
- unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
- const unsigned char *input,
- unsigned char *output );
- #endif /* MBEDTLS_CIPHER_MODE_CTR */
- #ifdef __cplusplus
- }
- #endif
- #endif /* blowfish.h */
- /********* Start of file include/mbedtls/ccm.h ************/
- /**
- * \file ccm.h
- *
- * \brief This file provides an API for the CCM authenticated encryption
- * mode for block ciphers.
- *
- * CCM combines Counter mode encryption with CBC-MAC authentication
- * for 128-bit block ciphers.
- *
- * Input to CCM includes the following elements:
- * <ul><li>Payload - data that is both authenticated and encrypted.</li>
- * <li>Associated data (Adata) - data that is authenticated but not
- * encrypted, For example, a header.</li>
- * <li>Nonce - A unique value that is assigned to the payload and the
- * associated data.</li></ul>
- *
- * Definition of CCM:
- * http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
- * RFC 3610 "Counter with CBC-MAC (CCM)"
- *
- * Related:
- * RFC 5116 "An Interface and Algorithms for Authenticated Encryption"
- *
- * Definition of CCM*:
- * IEEE 802.15.4 - IEEE Standard for Local and metropolitan area networks
- * Integer representation is fixed most-significant-octet-first order and
- * the representation of octets is most-significant-bit-first order. This is
- * consistent with RFC 3610.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_CCM_H
- #define MBEDTLS_CCM_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /** Bad input parameters to the function. */
- #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
- /** Authenticated decryption failed. */
- #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
- /* MBEDTLS_ERR_CCM_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** CCM hardware accelerator failed. */
- #define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_CCM_ALT)
- // Regular implementation
- //
- /**
- * \brief The CCM context-type definition. The CCM context is passed
- * to the APIs called.
- */
- typedef struct mbedtls_ccm_context
- {
- mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
- }
- mbedtls_ccm_context;
- #else /* MBEDTLS_CCM_ALT */
- #endif /* MBEDTLS_CCM_ALT */
- /**
- * \brief This function initializes the specified CCM context,
- * to make references valid, and prepare the context
- * for mbedtls_ccm_setkey() or mbedtls_ccm_free().
- *
- * \param ctx The CCM context to initialize. This must not be \c NULL.
- */
- void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
- /**
- * \brief This function initializes the CCM context set in the
- * \p ctx parameter and sets the encryption key.
- *
- * \param ctx The CCM context to initialize. This must be an initialized
- * context.
- * \param cipher The 128-bit block cipher to use.
- * \param key The encryption key. This must not be \c NULL.
- * \param keybits The key size in bits. This must be acceptable by the cipher.
- *
- * \return \c 0 on success.
- * \return A CCM or cipher-specific error code on failure.
- */
- int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
- mbedtls_cipher_id_t cipher,
- const unsigned char *key,
- unsigned int keybits );
- /**
- * \brief This function releases and clears the specified CCM context
- * and underlying cipher sub-context.
- *
- * \param ctx The CCM context to clear. If this is \c NULL, the function
- * has no effect. Otherwise, this must be initialized.
- */
- void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
- /**
- * \brief This function encrypts a buffer using CCM.
- *
- * \note The tag is written to a separate buffer. To concatenate
- * the \p tag with the \p output, as done in <em>RFC-3610:
- * Counter with CBC-MAC (CCM)</em>, use
- * \p tag = \p output + \p length, and make sure that the
- * output buffer is at least \p length + \p tag_len wide.
- *
- * \param ctx The CCM context to use for encryption. This must be
- * initialized and bound to a key.
- * \param length The length of the input data in Bytes.
- * \param iv The initialization vector (nonce). This must be a readable
- * buffer of at least \p iv_len Bytes.
- * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12,
- * or 13. The length L of the message length field is
- * 15 - \p iv_len.
- * \param add The additional data field. If \p add_len is greater than
- * zero, \p add must be a readable buffer of at least that
- * length.
- * \param add_len The length of additional data in Bytes.
- * This must be less than `2^16 - 2^8`.
- * \param input The buffer holding the input data. If \p length is greater
- * than zero, \p input must be a readable buffer of at least
- * that length.
- * \param output The buffer holding the output data. If \p length is greater
- * than zero, \p output must be a writable buffer of at least
- * that length.
- * \param tag The buffer holding the authentication field. This must be a
- * writable buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the authentication field to generate in Bytes:
- * 4, 6, 8, 10, 12, 14 or 16.
- *
- * \return \c 0 on success.
- * \return A CCM or cipher-specific error code on failure.
- */
- int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *add, size_t add_len,
- const unsigned char *input, unsigned char *output,
- unsigned char *tag, size_t tag_len );
- /**
- * \brief This function encrypts a buffer using CCM*.
- *
- * \note The tag is written to a separate buffer. To concatenate
- * the \p tag with the \p output, as done in <em>RFC-3610:
- * Counter with CBC-MAC (CCM)</em>, use
- * \p tag = \p output + \p length, and make sure that the
- * output buffer is at least \p length + \p tag_len wide.
- *
- * \note When using this function in a variable tag length context,
- * the tag length has to be encoded into the \p iv passed to
- * this function.
- *
- * \param ctx The CCM context to use for encryption. This must be
- * initialized and bound to a key.
- * \param length The length of the input data in Bytes.
- * \param iv The initialization vector (nonce). This must be a readable
- * buffer of at least \p iv_len Bytes.
- * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12,
- * or 13. The length L of the message length field is
- * 15 - \p iv_len.
- * \param add The additional data field. This must be a readable buffer of
- * at least \p add_len Bytes.
- * \param add_len The length of additional data in Bytes.
- * This must be less than 2^16 - 2^8.
- * \param input The buffer holding the input data. If \p length is greater
- * than zero, \p input must be a readable buffer of at least
- * that length.
- * \param output The buffer holding the output data. If \p length is greater
- * than zero, \p output must be a writable buffer of at least
- * that length.
- * \param tag The buffer holding the authentication field. This must be a
- * writable buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the authentication field to generate in Bytes:
- * 0, 4, 6, 8, 10, 12, 14 or 16.
- *
- * \warning Passing \c 0 as \p tag_len means that the message is no
- * longer authenticated.
- *
- * \return \c 0 on success.
- * \return A CCM or cipher-specific error code on failure.
- */
- int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *add, size_t add_len,
- const unsigned char *input, unsigned char *output,
- unsigned char *tag, size_t tag_len );
- /**
- * \brief This function performs a CCM authenticated decryption of a
- * buffer.
- *
- * \param ctx The CCM context to use for decryption. This must be
- * initialized and bound to a key.
- * \param length The length of the input data in Bytes.
- * \param iv The initialization vector (nonce). This must be a readable
- * buffer of at least \p iv_len Bytes.
- * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12,
- * or 13. The length L of the message length field is
- * 15 - \p iv_len.
- * \param add The additional data field. This must be a readable buffer
- * of at least that \p add_len Bytes..
- * \param add_len The length of additional data in Bytes.
- * This must be less than 2^16 - 2^8.
- * \param input The buffer holding the input data. If \p length is greater
- * than zero, \p input must be a readable buffer of at least
- * that length.
- * \param output The buffer holding the output data. If \p length is greater
- * than zero, \p output must be a writable buffer of at least
- * that length.
- * \param tag The buffer holding the authentication field. This must be a
- * readable buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the authentication field to generate in Bytes:
- * 4, 6, 8, 10, 12, 14 or 16.
- *
- * \return \c 0 on success. This indicates that the message is authentic.
- * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
- * \return A cipher-specific error code on calculation failure.
- */
- int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *add, size_t add_len,
- const unsigned char *input, unsigned char *output,
- const unsigned char *tag, size_t tag_len );
- /**
- * \brief This function performs a CCM* authenticated decryption of a
- * buffer.
- *
- * \note When using this function in a variable tag length context,
- * the tag length has to be decoded from \p iv and passed to
- * this function as \p tag_len. (\p tag needs to be adjusted
- * accordingly.)
- *
- * \param ctx The CCM context to use for decryption. This must be
- * initialized and bound to a key.
- * \param length The length of the input data in Bytes.
- * \param iv The initialization vector (nonce). This must be a readable
- * buffer of at least \p iv_len Bytes.
- * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12,
- * or 13. The length L of the message length field is
- * 15 - \p iv_len.
- * \param add The additional data field. This must be a readable buffer of
- * at least that \p add_len Bytes.
- * \param add_len The length of additional data in Bytes.
- * This must be less than 2^16 - 2^8.
- * \param input The buffer holding the input data. If \p length is greater
- * than zero, \p input must be a readable buffer of at least
- * that length.
- * \param output The buffer holding the output data. If \p length is greater
- * than zero, \p output must be a writable buffer of at least
- * that length.
- * \param tag The buffer holding the authentication field. This must be a
- * readable buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the authentication field in Bytes.
- * 0, 4, 6, 8, 10, 12, 14 or 16.
- *
- * \warning Passing \c 0 as \p tag_len means that the message is nos
- * longer authenticated.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
- * \return A cipher-specific error code on calculation failure.
- */
- int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
- const unsigned char *iv, size_t iv_len,
- const unsigned char *add, size_t add_len,
- const unsigned char *input, unsigned char *output,
- const unsigned char *tag, size_t tag_len );
- #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
- /**
- * \brief The CCM checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_ccm_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_CCM_H */
- /********* Start of file include/mbedtls/gcm.h ************/
- /**
- * \file gcm.h
- *
- * \brief This file contains GCM definitions and functions.
- *
- * The Galois/Counter Mode (GCM) for 128-bit block ciphers is defined
- * in <em>D. McGrew, J. Viega, The Galois/Counter Mode of Operation
- * (GCM), Natl. Inst. Stand. Technol.</em>
- *
- * For more information on GCM, see <em>NIST SP 800-38D: Recommendation for
- * Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC</em>.
- *
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_GCM_H
- #define MBEDTLS_GCM_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stdint.h>
- #define MBEDTLS_GCM_ENCRYPT 1
- #define MBEDTLS_GCM_DECRYPT 0
- /** Authenticated decryption failed. */
- #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
- /* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
- /** GCM hardware accelerator failed. */
- #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_GCM_ALT)
- /**
- * \brief The GCM context structure.
- */
- typedef struct mbedtls_gcm_context
- {
- mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
- uint64_t HL[16]; /*!< Precalculated HTable low. */
- uint64_t HH[16]; /*!< Precalculated HTable high. */
- uint64_t len; /*!< The total length of the encrypted data. */
- uint64_t add_len; /*!< The total length of the additional data. */
- unsigned char base_ectr[16]; /*!< The first ECTR for tag. */
- unsigned char y[16]; /*!< The Y working value. */
- unsigned char buf[16]; /*!< The buf working value. */
- int mode; /*!< The operation to perform:
- #MBEDTLS_GCM_ENCRYPT or
- #MBEDTLS_GCM_DECRYPT. */
- }
- mbedtls_gcm_context;
- #else /* !MBEDTLS_GCM_ALT */
- #endif /* !MBEDTLS_GCM_ALT */
- /**
- * \brief This function initializes the specified GCM context,
- * to make references valid, and prepares the context
- * for mbedtls_gcm_setkey() or mbedtls_gcm_free().
- *
- * The function does not bind the GCM context to a particular
- * cipher, nor set the key. For this purpose, use
- * mbedtls_gcm_setkey().
- *
- * \param ctx The GCM context to initialize. This must not be \c NULL.
- */
- void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
- /**
- * \brief This function associates a GCM context with a
- * cipher algorithm and a key.
- *
- * \param ctx The GCM context. This must be initialized.
- * \param cipher The 128-bit block cipher to use.
- * \param key The encryption key. This must be a readable buffer of at
- * least \p keybits bits.
- * \param keybits The key size in bits. Valid options are:
- * <ul><li>128 bits</li>
- * <li>192 bits</li>
- * <li>256 bits</li></ul>
- *
- * \return \c 0 on success.
- * \return A cipher-specific error code on failure.
- */
- int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
- mbedtls_cipher_id_t cipher,
- const unsigned char *key,
- unsigned int keybits );
- /**
- * \brief This function performs GCM encryption or decryption of a buffer.
- *
- * \note For encryption, the output buffer can be the same as the
- * input buffer. For decryption, the output buffer cannot be
- * the same as input buffer. If the buffers overlap, the output
- * buffer must trail at least 8 Bytes behind the input buffer.
- *
- * \warning When this function performs a decryption, it outputs the
- * authentication tag and does not verify that the data is
- * authentic. You should use this function to perform encryption
- * only. For decryption, use mbedtls_gcm_auth_decrypt() instead.
- *
- * \param ctx The GCM context to use for encryption or decryption. This
- * must be initialized.
- * \param mode The operation to perform:
- * - #MBEDTLS_GCM_ENCRYPT to perform authenticated encryption.
- * The ciphertext is written to \p output and the
- * authentication tag is written to \p tag.
- * - #MBEDTLS_GCM_DECRYPT to perform decryption.
- * The plaintext is written to \p output and the
- * authentication tag is written to \p tag.
- * Note that this mode is not recommended, because it does
- * not verify the authenticity of the data. For this reason,
- * you should use mbedtls_gcm_auth_decrypt() instead of
- * calling this function in decryption mode.
- * \param length The length of the input data, which is equal to the length
- * of the output data.
- * \param iv The initialization vector. This must be a readable buffer of
- * at least \p iv_len Bytes.
- * \param iv_len The length of the IV.
- * \param add The buffer holding the additional data. This must be of at
- * least that size in Bytes.
- * \param add_len The length of the additional data.
- * \param input The buffer holding the input data. If \p length is greater
- * than zero, this must be a readable buffer of at least that
- * size in Bytes.
- * \param output The buffer for holding the output data. If \p length is greater
- * than zero, this must be a writable buffer of at least that
- * size in Bytes.
- * \param tag_len The length of the tag to generate.
- * \param tag The buffer for holding the tag. This must be a writable
- * buffer of at least \p tag_len Bytes.
- *
- * \return \c 0 if the encryption or decryption was performed
- * successfully. Note that in #MBEDTLS_GCM_DECRYPT mode,
- * this does not indicate that the data is authentic.
- * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths or pointers are
- * not valid or a cipher-specific error code if the encryption
- * or decryption failed.
- */
- int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
- int mode,
- size_t length,
- const unsigned char *iv,
- size_t iv_len,
- const unsigned char *add,
- size_t add_len,
- const unsigned char *input,
- unsigned char *output,
- size_t tag_len,
- unsigned char *tag );
- /**
- * \brief This function performs a GCM authenticated decryption of a
- * buffer.
- *
- * \note For decryption, the output buffer cannot be the same as
- * input buffer. If the buffers overlap, the output buffer
- * must trail at least 8 Bytes behind the input buffer.
- *
- * \param ctx The GCM context. This must be initialized.
- * \param length The length of the ciphertext to decrypt, which is also
- * the length of the decrypted plaintext.
- * \param iv The initialization vector. This must be a readable buffer
- * of at least \p iv_len Bytes.
- * \param iv_len The length of the IV.
- * \param add The buffer holding the additional data. This must be of at
- * least that size in Bytes.
- * \param add_len The length of the additional data.
- * \param tag The buffer holding the tag to verify. This must be a
- * readable buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the tag to verify.
- * \param input The buffer holding the ciphertext. If \p length is greater
- * than zero, this must be a readable buffer of at least that
- * size.
- * \param output The buffer for holding the decrypted plaintext. If \p length
- * is greater than zero, this must be a writable buffer of at
- * least that size.
- *
- * \return \c 0 if successful and authenticated.
- * \return #MBEDTLS_ERR_GCM_AUTH_FAILED if the tag does not match.
- * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths or pointers are
- * not valid or a cipher-specific error code if the decryption
- * failed.
- */
- int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
- size_t length,
- const unsigned char *iv,
- size_t iv_len,
- const unsigned char *add,
- size_t add_len,
- const unsigned char *tag,
- size_t tag_len,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function starts a GCM encryption or decryption
- * operation.
- *
- * \param ctx The GCM context. This must be initialized.
- * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or
- * #MBEDTLS_GCM_DECRYPT.
- * \param iv The initialization vector. This must be a readable buffer of
- * at least \p iv_len Bytes.
- * \param iv_len The length of the IV.
- * \param add The buffer holding the additional data, or \c NULL
- * if \p add_len is \c 0.
- * \param add_len The length of the additional data. If \c 0,
- * \p add may be \c NULL.
- *
- * \return \c 0 on success.
- */
- int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
- int mode,
- const unsigned char *iv,
- size_t iv_len,
- const unsigned char *add,
- size_t add_len );
- /**
- * \brief This function feeds an input buffer into an ongoing GCM
- * encryption or decryption operation.
- *
- * ` The function expects input to be a multiple of 16
- * Bytes. Only the last call before calling
- * mbedtls_gcm_finish() can be less than 16 Bytes.
- *
- * \note For decryption, the output buffer cannot be the same as
- * input buffer. If the buffers overlap, the output buffer
- * must trail at least 8 Bytes behind the input buffer.
- *
- * \param ctx The GCM context. This must be initialized.
- * \param length The length of the input data. This must be a multiple of
- * 16 except in the last call before mbedtls_gcm_finish().
- * \param input The buffer holding the input data. If \p length is greater
- * than zero, this must be a readable buffer of at least that
- * size in Bytes.
- * \param output The buffer for holding the output data. If \p length is
- * greater than zero, this must be a writable buffer of at
- * least that size in Bytes.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
- */
- int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
- size_t length,
- const unsigned char *input,
- unsigned char *output );
- /**
- * \brief This function finishes the GCM operation and generates
- * the authentication tag.
- *
- * It wraps up the GCM stream, and generates the
- * tag. The tag can have a maximum length of 16 Bytes.
- *
- * \param ctx The GCM context. This must be initialized.
- * \param tag The buffer for holding the tag. This must be a writable
- * buffer of at least \p tag_len Bytes.
- * \param tag_len The length of the tag to generate. This must be at least
- * four.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
- */
- int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
- unsigned char *tag,
- size_t tag_len );
- /**
- * \brief This function clears a GCM context and the underlying
- * cipher sub-context.
- *
- * \param ctx The GCM context to clear. If this is \c NULL, the call has
- * no effect. Otherwise, this must be initialized.
- */
- void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The GCM checkup routine.
- *
- * \return \c 0 on success.
- * \return \c 1 on failure.
- */
- int mbedtls_gcm_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* gcm.h */
- /********* Start of file include/mbedtls/pem.h ************/
- /**
- * \file pem.h
- *
- * \brief Privacy Enhanced Mail (PEM) decoding
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PEM_H
- #define MBEDTLS_PEM_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- /**
- * \name PEM Error codes
- * These error codes are returned in case of errors reading the
- * PEM data.
- * \{
- */
- /** No PEM header or footer found. */
- #define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080
- /** PEM string is not as expected. */
- #define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100
- /** Failed to allocate memory. */
- #define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180
- /** RSA IV is not in hex-format. */
- #define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200
- /** Unsupported key encryption algorithm. */
- #define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280
- /** Private key password can't be empty. */
- #define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300
- /** Given private key password does not allow for correct decryption. */
- #define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380
- /** Unavailable feature, e.g. hashing/encryption combination. */
- #define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480
- /* \} name */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(MBEDTLS_PEM_PARSE_C)
- /**
- * \brief PEM context structure
- */
- typedef struct mbedtls_pem_context
- {
- unsigned char *buf; /*!< buffer for decoded data */
- size_t buflen; /*!< length of the buffer */
- unsigned char *info; /*!< buffer for extra header information */
- }
- mbedtls_pem_context;
- /**
- * \brief PEM context setup
- *
- * \param ctx context to be initialized
- */
- void mbedtls_pem_init( mbedtls_pem_context *ctx );
- /**
- * \brief Read a buffer for PEM information and store the resulting
- * data into the specified context buffers.
- *
- * \param ctx context to use
- * \param header header string to seek and expect
- * \param footer footer string to seek and expect
- * \param data source data to look in (must be nul-terminated)
- * \param pwd password for decryption (can be NULL)
- * \param pwdlen length of password
- * \param use_len destination for total length used (set after header is
- * correctly read, so unless you get
- * MBEDTLS_ERR_PEM_BAD_INPUT_DATA or
- * MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is
- * the length to skip)
- *
- * \note Attempts to check password correctness by verifying if
- * the decrypted text starts with an ASN.1 sequence of
- * appropriate length
- *
- * \return 0 on success, or a specific PEM error code
- */
- int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
- const unsigned char *data,
- const unsigned char *pwd,
- size_t pwdlen, size_t *use_len );
- /**
- * \brief PEM context memory freeing
- *
- * \param ctx context to be freed
- */
- void mbedtls_pem_free( mbedtls_pem_context *ctx );
- #endif /* MBEDTLS_PEM_PARSE_C */
- #if defined(MBEDTLS_PEM_WRITE_C)
- /**
- * \brief Write a buffer of PEM information from a DER encoded
- * buffer.
- *
- * \param header The header string to write.
- * \param footer The footer string to write.
- * \param der_data The DER data to encode.
- * \param der_len The length of the DER data \p der_data in Bytes.
- * \param buf The buffer to write to.
- * \param buf_len The length of the output buffer \p buf in Bytes.
- * \param olen The address at which to store the total length written
- * or required (if \p buf_len is not enough).
- *
- * \note You may pass \c NULL for \p buf and \c 0 for \p buf_len
- * to request the length of the resulting PEM buffer in
- * `*olen`.
- *
- * \note This function may be called with overlapping \p der_data
- * and \p buf buffers.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL if \p buf isn't large
- * enough to hold the PEM buffer. In this case, `*olen` holds
- * the required minimum size of \p buf.
- * \return Another PEM or BASE64 error code on other kinds of failure.
- */
- int mbedtls_pem_write_buffer( const char *header, const char *footer,
- const unsigned char *der_data, size_t der_len,
- unsigned char *buf, size_t buf_len, size_t *olen );
- #endif /* MBEDTLS_PEM_WRITE_C */
- #ifdef __cplusplus
- }
- #endif
- #endif /* pem.h */
- /********* Start of file include/mbedtls/asn1write.h ************/
- /**
- * \file asn1write.h
- *
- * \brief ASN.1 buffer writing functionality
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_ASN1_WRITE_H
- #define MBEDTLS_ASN1_WRITE_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #define MBEDTLS_ASN1_CHK_ADD(g, f) \
- do \
- { \
- if( ( ret = (f) ) < 0 ) \
- return( ret ); \
- else \
- (g) += ret; \
- } while( 0 )
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Write a length field in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param len The length value to write.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start,
- size_t len );
- /**
- * \brief Write an ASN.1 tag in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param tag The tag to write.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
- unsigned char tag );
- /**
- * \brief Write raw buffer data.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param buf The data buffer to write.
- * \param size The length of the data buffer.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
- const unsigned char *buf, size_t size );
- #if defined(MBEDTLS_BIGNUM_C)
- /**
- * \brief Write a arbitrary-precision number (#MBEDTLS_ASN1_INTEGER)
- * in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param X The MPI to write.
- * It must be non-negative.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start,
- const mbedtls_mpi *X );
- #endif /* MBEDTLS_BIGNUM_C */
- /**
- * \brief Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data
- * in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
- /**
- * \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data
- * in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param oid The OID to write.
- * \param oid_len The length of the OID.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
- const char *oid, size_t oid_len );
- /**
- * \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param oid The OID of the algorithm to write.
- * \param oid_len The length of the algorithm's OID.
- * \param par_len The length of the parameters, which must be already written.
- * If 0, NULL parameters are added
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
- unsigned char *start,
- const char *oid, size_t oid_len,
- size_t par_len );
- /**
- * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value
- * in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param boolean The boolean value to write, either \c 0 or \c 1.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start,
- int boolean );
- /**
- * \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value
- * in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param val The integer value to write.
- * It must be non-negative.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
- /**
- * \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
- * in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param val The integer value to write.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
- */
- int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val );
- /**
- * \brief Write a string in ASN.1 format using a specific
- * string encoding tag.
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param tag The string encoding tag to write, e.g.
- * #MBEDTLS_ASN1_UTF8_STRING.
- * \param text The string to write.
- * \param text_len The length of \p text in bytes (which might
- * be strictly larger than the number of characters).
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative error code on failure.
- */
- int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start,
- int tag, const char *text,
- size_t text_len );
- /**
- * \brief Write a string in ASN.1 format using the PrintableString
- * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING).
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param text The string to write.
- * \param text_len The length of \p text in bytes (which might
- * be strictly larger than the number of characters).
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative error code on failure.
- */
- int mbedtls_asn1_write_printable_string( unsigned char **p,
- unsigned char *start,
- const char *text, size_t text_len );
- /**
- * \brief Write a UTF8 string in ASN.1 format using the UTF8String
- * string encoding tag (#MBEDTLS_ASN1_UTF8_STRING).
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param text The string to write.
- * \param text_len The length of \p text in bytes (which might
- * be strictly larger than the number of characters).
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative error code on failure.
- */
- int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
- const char *text, size_t text_len );
- /**
- * \brief Write a string in ASN.1 format using the IA5String
- * string encoding tag (#MBEDTLS_ASN1_IA5_STRING).
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param text The string to write.
- * \param text_len The length of \p text in bytes (which might
- * be strictly larger than the number of characters).
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative error code on failure.
- */
- int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
- const char *text, size_t text_len );
- /**
- * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and
- * value in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param buf The bitstring to write.
- * \param bits The total number of bits in the bitstring.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative error code on failure.
- */
- int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
- const unsigned char *buf, size_t bits );
- /**
- * \brief This function writes a named bitstring tag
- * (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
- *
- * As stated in RFC 5280 Appendix B, trailing zeroes are
- * omitted when encoding named bitstrings in DER.
- *
- * \note This function works backwards within the data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer which is used for bounds-checking.
- * \param buf The bitstring to write.
- * \param bits The total number of bits in the bitstring.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative error code on failure.
- */
- int mbedtls_asn1_write_named_bitstring( unsigned char **p,
- unsigned char *start,
- const unsigned char *buf,
- size_t bits );
- /**
- * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING)
- * and value in ASN.1 format.
- *
- * \note This function works backwards in data buffer.
- *
- * \param p The reference to the current position pointer.
- * \param start The start of the buffer, for bounds-checking.
- * \param buf The buffer holding the data to write.
- * \param size The length of the data buffer \p buf.
- *
- * \return The number of bytes written to \p p on success.
- * \return A negative error code on failure.
- */
- int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
- const unsigned char *buf, size_t size );
- /**
- * \brief Create or find a specific named_data entry for writing in a
- * sequence or list based on the OID. If not already in there,
- * a new entry is added to the head of the list.
- * Warning: Destructive behaviour for the val data!
- *
- * \param list The pointer to the location of the head of the list to seek
- * through (will be updated in case of a new entry).
- * \param oid The OID to look for.
- * \param oid_len The size of the OID.
- * \param val The associated data to store. If this is \c NULL,
- * no data is copied to the new or existing buffer.
- * \param val_len The minimum length of the data buffer needed.
- * If this is 0, do not allocate a buffer for the associated
- * data.
- * If the OID was already present, enlarge, shrink or free
- * the existing buffer to fit \p val_len.
- *
- * \return A pointer to the new / existing entry on success.
- * \return \c NULL if if there was a memory allocation error.
- */
- mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list,
- const char *oid, size_t oid_len,
- const unsigned char *val,
- size_t val_len );
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_ASN1_WRITE_H */
- /********* Start of file include/mbedtls/hmac_drbg.h ************/
- /**
- * \file hmac_drbg.h
- *
- * \brief The HMAC_DRBG pseudorandom generator.
- *
- * This module implements the HMAC_DRBG pseudorandom generator described
- * in <em>NIST SP 800-90A: Recommendation for Random Number Generation Using
- * Deterministic Random Bit Generators</em>.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_HMAC_DRBG_H
- #define MBEDTLS_HMAC_DRBG_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_THREADING_C)
- #endif
- /*
- * Error codes
- */
- /** Too many random requested in single call. */
- #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
- /** Input too large (Entropy + additional). */
- #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
- /** Read/write error in file. */
- #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
- /** The entropy source failed. */
- #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
- /**
- * \name SECTION: Module settings
- *
- * The configuration options you can set for this module are in this section.
- * Either change them in config.h or define them on the compiler command line.
- * \{
- */
- #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
- #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
- #endif
- #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
- #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
- #endif
- #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
- #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
- #endif
- #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
- #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
- #endif
- /* \} name SECTION: Module settings */
- #define MBEDTLS_HMAC_DRBG_PR_OFF 0 /**< No prediction resistance */
- #define MBEDTLS_HMAC_DRBG_PR_ON 1 /**< Prediction resistance enabled */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * HMAC_DRBG context.
- */
- typedef struct mbedtls_hmac_drbg_context
- {
- /* Working state: the key K is not stored explicitly,
- * but is implied by the HMAC context */
- mbedtls_md_context_t md_ctx; /*!< HMAC context (inc. K) */
- unsigned char V[MBEDTLS_MD_MAX_SIZE]; /*!< V in the spec */
- int reseed_counter; /*!< reseed counter */
- /* Administrative state */
- size_t entropy_len; /*!< entropy bytes grabbed on each (re)seed */
- int prediction_resistance; /*!< enable prediction resistance (Automatic
- reseed before every random generation) */
- int reseed_interval; /*!< reseed interval */
- /* Callbacks */
- int (*f_entropy)(void *, unsigned char *, size_t); /*!< entropy function */
- void *p_entropy; /*!< context for the entropy function */
- #if defined(MBEDTLS_THREADING_C)
- /* Invariant: the mutex is initialized if and only if
- * md_ctx->md_info != NULL. This means that the mutex is initialized
- * during the initial seeding in mbedtls_hmac_drbg_seed() or
- * mbedtls_hmac_drbg_seed_buf() and freed in mbedtls_ctr_drbg_free().
- *
- * Note that this invariant may change without notice. Do not rely on it
- * and do not access the mutex directly in application code.
- */
- mbedtls_threading_mutex_t mutex;
- #endif
- } mbedtls_hmac_drbg_context;
- /**
- * \brief HMAC_DRBG context initialization.
- *
- * This function makes the context ready for mbedtls_hmac_drbg_seed(),
- * mbedtls_hmac_drbg_seed_buf() or mbedtls_hmac_drbg_free().
- *
- * \note The reseed interval is #MBEDTLS_HMAC_DRBG_RESEED_INTERVAL
- * by default. Override this value by calling
- * mbedtls_hmac_drbg_set_reseed_interval().
- *
- * \param ctx HMAC_DRBG context to be initialized.
- */
- void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
- /**
- * \brief HMAC_DRBG initial seeding.
- *
- * Set the initial seed and set up the entropy source for future reseeds.
- *
- * A typical choice for the \p f_entropy and \p p_entropy parameters is
- * to use the entropy module:
- * - \p f_entropy is mbedtls_entropy_func();
- * - \p p_entropy is an instance of ::mbedtls_entropy_context initialized
- * with mbedtls_entropy_init() (which registers the platform's default
- * entropy sources).
- *
- * You can provide a personalization string in addition to the
- * entropy source, to make this instantiation as unique as possible.
- *
- * \note By default, the security strength as defined by NIST is:
- * - 128 bits if \p md_info is SHA-1;
- * - 192 bits if \p md_info is SHA-224;
- * - 256 bits if \p md_info is SHA-256, SHA-384 or SHA-512.
- * Note that SHA-256 is just as efficient as SHA-224.
- * The security strength can be reduced if a smaller
- * entropy length is set with
- * mbedtls_hmac_drbg_set_entropy_len().
- *
- * \note The default entropy length is the security strength
- * (converted from bits to bytes). You can override
- * it by calling mbedtls_hmac_drbg_set_entropy_len().
- *
- * \note During the initial seeding, this function calls
- * the entropy source to obtain a nonce
- * whose length is half the entropy length.
- */
- #if defined(MBEDTLS_THREADING_C)
- /**
- * \note When Mbed TLS is built with threading support,
- * after this function returns successfully,
- * it is safe to call mbedtls_hmac_drbg_random()
- * from multiple threads. Other operations, including
- * reseeding, are not thread-safe.
- */
- #endif /* MBEDTLS_THREADING_C */
- /**
- * \param ctx HMAC_DRBG context to be seeded.
- * \param md_info MD algorithm to use for HMAC_DRBG.
- * \param f_entropy The entropy callback, taking as arguments the
- * \p p_entropy context, the buffer to fill, and the
- * length of the buffer.
- * \p f_entropy is always called with a length that is
- * less than or equal to the entropy length.
- * \param p_entropy The entropy context to pass to \p f_entropy.
- * \param custom The personalization string.
- * This can be \c NULL, in which case the personalization
- * string is empty regardless of the value of \p len.
- * \param len The length of the personalization string.
- * This must be at most #MBEDTLS_HMAC_DRBG_MAX_INPUT
- * and also at most
- * #MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT - \p entropy_len * 3 / 2
- * where \p entropy_len is the entropy length
- * described above.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info is
- * invalid.
- * \return #MBEDTLS_ERR_MD_ALLOC_FAILED if there was not enough
- * memory to allocate context data.
- * \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
- * if the call to \p f_entropy failed.
- */
- int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
- const mbedtls_md_info_t * md_info,
- int (*f_entropy)(void *, unsigned char *, size_t),
- void *p_entropy,
- const unsigned char *custom,
- size_t len );
- /**
- * \brief Initilisation of simpified HMAC_DRBG (never reseeds).
- *
- * This function is meant for use in algorithms that need a pseudorandom
- * input such as deterministic ECDSA.
- */
- #if defined(MBEDTLS_THREADING_C)
- /**
- * \note When Mbed TLS is built with threading support,
- * after this function returns successfully,
- * it is safe to call mbedtls_hmac_drbg_random()
- * from multiple threads. Other operations, including
- * reseeding, are not thread-safe.
- */
- #endif /* MBEDTLS_THREADING_C */
- /**
- * \param ctx HMAC_DRBG context to be initialised.
- * \param md_info MD algorithm to use for HMAC_DRBG.
- * \param data Concatenation of the initial entropy string and
- * the additional data.
- * \param data_len Length of \p data in bytes.
- *
- * \return \c 0 if successful. or
- * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info is
- * invalid.
- * \return #MBEDTLS_ERR_MD_ALLOC_FAILED if there was not enough
- * memory to allocate context data.
- */
- int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
- const mbedtls_md_info_t * md_info,
- const unsigned char *data, size_t data_len );
- /**
- * \brief This function turns prediction resistance on or off.
- * The default value is off.
- *
- * \note If enabled, entropy is gathered at the beginning of
- * every call to mbedtls_hmac_drbg_random_with_add()
- * or mbedtls_hmac_drbg_random().
- * Only use this if your entropy source has sufficient
- * throughput.
- *
- * \param ctx The HMAC_DRBG context.
- * \param resistance #MBEDTLS_HMAC_DRBG_PR_ON or #MBEDTLS_HMAC_DRBG_PR_OFF.
- */
- void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
- int resistance );
- /**
- * \brief This function sets the amount of entropy grabbed on each
- * seed or reseed.
- *
- * See the documentation of mbedtls_hmac_drbg_seed() for the default value.
- *
- * \param ctx The HMAC_DRBG context.
- * \param len The amount of entropy to grab, in bytes.
- */
- void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
- size_t len );
- /**
- * \brief Set the reseed interval.
- *
- * The reseed interval is the number of calls to mbedtls_hmac_drbg_random()
- * or mbedtls_hmac_drbg_random_with_add() after which the entropy function
- * is called again.
- *
- * The default value is #MBEDTLS_HMAC_DRBG_RESEED_INTERVAL.
- *
- * \param ctx The HMAC_DRBG context.
- * \param interval The reseed interval.
- */
- void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
- int interval );
- /**
- * \brief This function updates the state of the HMAC_DRBG context.
- *
- * \note This function is not thread-safe. It is not safe
- * to call this function if another thread might be
- * concurrently obtaining random numbers from the same
- * context or updating or reseeding the same context.
- *
- * \param ctx The HMAC_DRBG context.
- * \param additional The data to update the state with.
- * If this is \c NULL, there is no additional data.
- * \param add_len Length of \p additional in bytes.
- * Unused if \p additional is \c NULL.
- *
- * \return \c 0 on success, or an error from the underlying
- * hash calculation.
- */
- int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
- const unsigned char *additional, size_t add_len );
- /**
- * \brief This function reseeds the HMAC_DRBG context, that is
- * extracts data from the entropy source.
- *
- * \note This function is not thread-safe. It is not safe
- * to call this function if another thread might be
- * concurrently obtaining random numbers from the same
- * context or updating or reseeding the same context.
- *
- * \param ctx The HMAC_DRBG context.
- * \param additional Additional data to add to the state.
- * If this is \c NULL, there is no additional data
- * and \p len should be \c 0.
- * \param len The length of the additional data.
- * This must be at most #MBEDTLS_HMAC_DRBG_MAX_INPUT
- * and also at most
- * #MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT - \p entropy_len
- * where \p entropy_len is the entropy length
- * (see mbedtls_hmac_drbg_set_entropy_len()).
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
- * if a call to the entropy function failed.
- */
- int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
- const unsigned char *additional, size_t len );
- /**
- * \brief This function updates an HMAC_DRBG instance with additional
- * data and uses it to generate random data.
- *
- * This function automatically reseeds if the reseed counter is exceeded
- * or prediction resistance is enabled.
- *
- * \note This function is not thread-safe. It is not safe
- * to call this function if another thread might be
- * concurrently obtaining random numbers from the same
- * context or updating or reseeding the same context.
- *
- * \param p_rng The HMAC_DRBG context. This must be a pointer to a
- * #mbedtls_hmac_drbg_context structure.
- * \param output The buffer to fill.
- * \param output_len The length of the buffer in bytes.
- * This must be at most #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
- * \param additional Additional data to update with.
- * If this is \c NULL, there is no additional data
- * and \p add_len should be \c 0.
- * \param add_len The length of the additional data.
- * This must be at most #MBEDTLS_HMAC_DRBG_MAX_INPUT.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
- * if a call to the entropy source failed.
- * \return #MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG if
- * \p output_len > #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
- * \return #MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG if
- * \p add_len > #MBEDTLS_HMAC_DRBG_MAX_INPUT.
- */
- int mbedtls_hmac_drbg_random_with_add( void *p_rng,
- unsigned char *output, size_t output_len,
- const unsigned char *additional,
- size_t add_len );
- /**
- * \brief This function uses HMAC_DRBG to generate random data.
- *
- * This function automatically reseeds if the reseed counter is exceeded
- * or prediction resistance is enabled.
- */
- #if defined(MBEDTLS_THREADING_C)
- /**
- * \note When Mbed TLS is built with threading support,
- * it is safe to call mbedtls_ctr_drbg_random()
- * from multiple threads. Other operations, including
- * reseeding, are not thread-safe.
- */
- #endif /* MBEDTLS_THREADING_C */
- /**
- * \param p_rng The HMAC_DRBG context. This must be a pointer to a
- * #mbedtls_hmac_drbg_context structure.
- * \param output The buffer to fill.
- * \param out_len The length of the buffer in bytes.
- * This must be at most #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
- * if a call to the entropy source failed.
- * \return #MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG if
- * \p out_len > #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
- */
- int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
- /**
- * \brief This function resets HMAC_DRBG context to the state immediately
- * after initial call of mbedtls_hmac_drbg_init().
- *
- * \param ctx The HMAC_DRBG context to free.
- */
- void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
- #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief This function updates the state of the HMAC_DRBG context.
- *
- * \deprecated Superseded by mbedtls_hmac_drbg_update_ret()
- * in 2.16.0.
- *
- * \param ctx The HMAC_DRBG context.
- * \param additional The data to update the state with.
- * If this is \c NULL, there is no additional data.
- * \param add_len Length of \p additional in bytes.
- * Unused if \p additional is \c NULL.
- */
- MBEDTLS_DEPRECATED void mbedtls_hmac_drbg_update(
- mbedtls_hmac_drbg_context *ctx,
- const unsigned char *additional, size_t add_len );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_FS_IO)
- /**
- * \brief This function writes a seed file.
- *
- * \param ctx The HMAC_DRBG context.
- * \param path The name of the file.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR on file error.
- * \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED on reseed
- * failure.
- */
- int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
- /**
- * \brief This function reads and updates a seed file. The seed
- * is added to this instance.
- *
- * \param ctx The HMAC_DRBG context.
- * \param path The name of the file.
- *
- * \return \c 0 on success.
- * \return #MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR on file error.
- * \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED on
- * reseed failure.
- * \return #MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG if the existing
- * seed file is too large.
- */
- int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
- #endif /* MBEDTLS_FS_IO */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief The HMAC_DRBG Checkup routine.
- *
- * \return \c 0 if successful.
- * \return \c 1 if the test failed.
- */
- int mbedtls_hmac_drbg_self_test( int verbose );
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* hmac_drbg.h */
- /********* Start of file include/mbedtls/pkcs12.h ************/
- /**
- * \file pkcs12.h
- *
- * \brief PKCS#12 Personal Information Exchange Syntax
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PKCS12_H
- #define MBEDTLS_PKCS12_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80
- /** Feature not available, e.g. unsupported encryption scheme. */
- #define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00
- /** PBE ASN.1 data not as expected. */
- #define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80
- /** Given private key password does not allow for correct decryption. */
- #define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00
- #define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
- #define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */
- #define MBEDTLS_PKCS12_DERIVE_MAC_KEY 3 /**< integrity / MAC key */
- #define MBEDTLS_PKCS12_PBE_DECRYPT 0
- #define MBEDTLS_PKCS12_PBE_ENCRYPT 1
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(MBEDTLS_ASN1_PARSE_C)
- /**
- * \brief PKCS12 Password Based function (encryption / decryption)
- * for pbeWithSHAAnd128BitRC4
- *
- * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
- * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
- * \param pwd the password used (may be NULL if no password is used)
- * \param pwdlen length of the password (may be 0)
- * \param input the input data
- * \param len data length
- * \param output the output buffer
- *
- * \return 0 if successful, or a MBEDTLS_ERR_XXX code
- */
- int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
- const unsigned char *pwd, size_t pwdlen,
- const unsigned char *input, size_t len,
- unsigned char *output );
- /**
- * \brief PKCS12 Password Based function (encryption / decryption)
- * for cipher-based and mbedtls_md-based PBE's
- *
- * \param pbe_params an ASN1 buffer containing the pkcs-12 PbeParams structure
- * \param mode either #MBEDTLS_PKCS12_PBE_ENCRYPT or
- * #MBEDTLS_PKCS12_PBE_DECRYPT
- * \param cipher_type the cipher used
- * \param md_type the mbedtls_md used
- * \param pwd Latin1-encoded password used. This may only be \c NULL when
- * \p pwdlen is 0. No null terminator should be used.
- * \param pwdlen length of the password (may be 0)
- * \param input the input data
- * \param len data length
- * \param output the output buffer
- *
- * \return 0 if successful, or a MBEDTLS_ERR_XXX code
- */
- int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
- mbedtls_cipher_type_t cipher_type, mbedtls_md_type_t md_type,
- const unsigned char *pwd, size_t pwdlen,
- const unsigned char *input, size_t len,
- unsigned char *output );
- #endif /* MBEDTLS_ASN1_PARSE_C */
- /**
- * \brief The PKCS#12 derivation function uses a password and a salt
- * to produce pseudo-random bits for a particular "purpose".
- *
- * Depending on the given id, this function can produce an
- * encryption/decryption key, an initialization vector or an
- * integrity key.
- *
- * \param data buffer to store the derived data in
- * \param datalen length of buffer to fill
- * \param pwd The password to use. For compliance with PKCS#12 §B.1, this
- * should be a BMPString, i.e. a Unicode string where each
- * character is encoded as 2 bytes in big-endian order, with
- * no byte order mark and with a null terminator (i.e. the
- * last two bytes should be 0x00 0x00).
- * \param pwdlen length of the password (may be 0).
- * \param salt Salt buffer to use This may only be \c NULL when
- * \p saltlen is 0.
- * \param saltlen length of the salt (may be zero)
- * \param mbedtls_md mbedtls_md type to use during the derivation
- * \param id id that describes the purpose (can be
- * #MBEDTLS_PKCS12_DERIVE_KEY, #MBEDTLS_PKCS12_DERIVE_IV or
- * #MBEDTLS_PKCS12_DERIVE_MAC_KEY)
- * \param iterations number of iterations
- *
- * \return 0 if successful, or a MD, BIGNUM type error.
- */
- int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
- const unsigned char *pwd, size_t pwdlen,
- const unsigned char *salt, size_t saltlen,
- mbedtls_md_type_t mbedtls_md, int id, int iterations );
- #ifdef __cplusplus
- }
- #endif
- #endif /* pkcs12.h */
- /********* Start of file include/mbedtls/pkcs11.h ************/
- /**
- * \file pkcs11.h
- *
- * \brief Wrapper for PKCS#11 library libpkcs11-helper
- *
- * \author Adriaan de Jong <dejong@fox-it.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PKCS11_H
- #define MBEDTLS_PKCS11_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #if defined(MBEDTLS_PKCS11_C)
- #include <pkcs11-helper-1.0/pkcs11h-certificate.h>
- #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
- !defined(inline) && !defined(__cplusplus)
- #define inline __inline
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(MBEDTLS_DEPRECATED_REMOVED)
- /**
- * Context for PKCS #11 private keys.
- */
- typedef struct mbedtls_pkcs11_context
- {
- pkcs11h_certificate_t pkcs11h_cert;
- int len;
- } mbedtls_pkcs11_context;
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * Initialize a mbedtls_pkcs11_context.
- * (Just making memory references valid.)
- *
- * \deprecated This function is deprecated and will be removed in a
- * future version of the library.
- */
- MBEDTLS_DEPRECATED void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
- /**
- * Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate.
- *
- * \deprecated This function is deprecated and will be removed in a
- * future version of the library.
- *
- * \param cert X.509 certificate to fill
- * \param pkcs11h_cert PKCS #11 helper certificate
- *
- * \return 0 on success.
- */
- MBEDTLS_DEPRECATED int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert,
- pkcs11h_certificate_t pkcs11h_cert );
- /**
- * Set up a mbedtls_pkcs11_context storing the given certificate. Note that the
- * mbedtls_pkcs11_context will take over control of the certificate, freeing it when
- * done.
- *
- * \deprecated This function is deprecated and will be removed in a
- * future version of the library.
- *
- * \param priv_key Private key structure to fill.
- * \param pkcs11_cert PKCS #11 helper certificate
- *
- * \return 0 on success
- */
- MBEDTLS_DEPRECATED int mbedtls_pkcs11_priv_key_bind(
- mbedtls_pkcs11_context *priv_key,
- pkcs11h_certificate_t pkcs11_cert );
- /**
- * Free the contents of the given private key context. Note that the structure
- * itself is not freed.
- *
- * \deprecated This function is deprecated and will be removed in a
- * future version of the library.
- *
- * \param priv_key Private key structure to cleanup
- */
- MBEDTLS_DEPRECATED void mbedtls_pkcs11_priv_key_free(
- mbedtls_pkcs11_context *priv_key );
- /**
- * \brief Do an RSA private key decrypt, then remove the message
- * padding
- *
- * \deprecated This function is deprecated and will be removed in a future
- * version of the library.
- *
- * \param ctx PKCS #11 context
- * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
- * \param input buffer holding the encrypted data
- * \param output buffer that will hold the plaintext
- * \param olen will contain the plaintext length
- * \param output_max_len maximum length of the output buffer
- *
- * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
- *
- * \note The output buffer must be as large as the size
- * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
- * an error is thrown.
- */
- MBEDTLS_DEPRECATED int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
- int mode, size_t *olen,
- const unsigned char *input,
- unsigned char *output,
- size_t output_max_len );
- /**
- * \brief Do a private RSA to sign a message digest
- *
- * \deprecated This function is deprecated and will be removed in a future
- * version of the library.
- *
- * \param ctx PKCS #11 context
- * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
- * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
- * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
- * \param hash buffer holding the message digest
- * \param sig buffer that will hold the ciphertext
- *
- * \return 0 if the signing operation was successful,
- * or an MBEDTLS_ERR_RSA_XXX error code
- *
- * \note The "sig" buffer must be as large as the size
- * of ctx->N (eg. 128 bytes if RSA-1024 is used).
- */
- MBEDTLS_DEPRECATED int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
- int mode,
- mbedtls_md_type_t md_alg,
- unsigned int hashlen,
- const unsigned char *hash,
- unsigned char *sig );
- /**
- * SSL/TLS wrappers for PKCS#11 functions
- *
- * \deprecated This function is deprecated and will be removed in a future
- * version of the library.
- */
- MBEDTLS_DEPRECATED static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx,
- int mode, size_t *olen,
- const unsigned char *input, unsigned char *output,
- size_t output_max_len )
- {
- return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
- output_max_len );
- }
- /**
- * \brief This function signs a message digest using RSA.
- *
- * \deprecated This function is deprecated and will be removed in a future
- * version of the library.
- *
- * \param ctx The PKCS #11 context.
- * \param f_rng The RNG function. This parameter is unused.
- * \param p_rng The RNG context. This parameter is unused.
- * \param mode The operation to run. This must be set to
- * MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's
- * signature.
- * \param md_alg The message digest algorithm. One of the MBEDTLS_MD_XXX
- * must be passed to this function and MBEDTLS_MD_NONE can be
- * used for signing raw data.
- * \param hashlen The message digest length (for MBEDTLS_MD_NONE only).
- * \param hash The buffer holding the message digest.
- * \param sig The buffer that will hold the ciphertext.
- *
- * \return \c 0 if the signing operation was successful.
- * \return A non-zero error code on failure.
- *
- * \note The \p sig buffer must be as large as the size of
- * <code>ctx->N</code>. For example, 128 bytes if RSA-1024 is
- * used.
- */
- MBEDTLS_DEPRECATED static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
- int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
- const unsigned char *hash, unsigned char *sig )
- {
- ((void) f_rng);
- ((void) p_rng);
- return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
- hashlen, hash, sig );
- }
- /**
- * This function gets the length of the private key.
- *
- * \deprecated This function is deprecated and will be removed in a future
- * version of the library.
- *
- * \param ctx The PKCS #11 context.
- *
- * \return The length of the private key.
- */
- MBEDTLS_DEPRECATED static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
- {
- return ( (mbedtls_pkcs11_context *) ctx )->len;
- }
- #undef MBEDTLS_DEPRECATED
- #endif /* MBEDTLS_DEPRECATED_REMOVED */
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_PKCS11_C */
- #endif /* MBEDTLS_PKCS11_H */
- /********* Start of file include/mbedtls/pkcs5.h ************/
- /**
- * \file pkcs5.h
- *
- * \brief PKCS#5 functions
- *
- * \author Mathias Olsson <mathias@kompetensum.com>
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_PKCS5_H
- #define MBEDTLS_PKCS5_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80
- /** Unexpected ASN.1 data. */
- #define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00
- /** Requested encryption or digest alg not available. */
- #define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80
- /** Given private key password does not allow for correct decryption. */
- #define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00
- #define MBEDTLS_PKCS5_DECRYPT 0
- #define MBEDTLS_PKCS5_ENCRYPT 1
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(MBEDTLS_ASN1_PARSE_C)
- /**
- * \brief PKCS#5 PBES2 function
- *
- * \param pbe_params the ASN.1 algorithm parameters
- * \param mode either MBEDTLS_PKCS5_DECRYPT or MBEDTLS_PKCS5_ENCRYPT
- * \param pwd password to use when generating key
- * \param pwdlen length of password
- * \param data data to process
- * \param datalen length of data
- * \param output output buffer
- *
- * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
- */
- int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
- const unsigned char *pwd, size_t pwdlen,
- const unsigned char *data, size_t datalen,
- unsigned char *output );
- #endif /* MBEDTLS_ASN1_PARSE_C */
- /**
- * \brief PKCS#5 PBKDF2 using HMAC
- *
- * \param ctx Generic HMAC context
- * \param password Password to use when generating key
- * \param plen Length of password
- * \param salt Salt to use when generating key
- * \param slen Length of salt
- * \param iteration_count Iteration count
- * \param key_length Length of generated key in bytes
- * \param output Generated key. Must be at least as big as key_length
- *
- * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
- */
- int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *password,
- size_t plen, const unsigned char *salt, size_t slen,
- unsigned int iteration_count,
- uint32_t key_length, unsigned char *output );
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- int mbedtls_pkcs5_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* pkcs5.h */
- /********* Start of file include/mbedtls/oid.h ************/
- /**
- * \file oid.h
- *
- * \brief Object Identifier (OID) database
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_OID_H
- #define MBEDTLS_OID_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #if defined(MBEDTLS_CIPHER_C)
- #endif
- #if defined(MBEDTLS_MD_C)
- #endif
- /** OID is not found. */
- #define MBEDTLS_ERR_OID_NOT_FOUND -0x002E
- /** output buffer is too small */
- #define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B
- /* This is for the benefit of X.509, but defined here in order to avoid
- * having a "backwards" include of x.509.h here */
- /*
- * X.509 extension types (internal, arbitrary values for bitsets)
- */
- #define MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
- #define MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
- #define MBEDTLS_OID_X509_EXT_KEY_USAGE (1 << 2)
- #define MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES (1 << 3)
- #define MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS (1 << 4)
- #define MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME (1 << 5)
- #define MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME (1 << 6)
- #define MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
- #define MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS (1 << 8)
- #define MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS (1 << 9)
- #define MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS (1 << 10)
- #define MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE (1 << 11)
- #define MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
- #define MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13)
- #define MBEDTLS_OID_X509_EXT_FRESHEST_CRL (1 << 14)
- #define MBEDTLS_OID_X509_EXT_NS_CERT_TYPE (1 << 16)
- /*
- * Top level OID tuples
- */
- #define MBEDTLS_OID_ISO_MEMBER_BODIES "\x2a" /* {iso(1) member-body(2)} */
- #define MBEDTLS_OID_ISO_IDENTIFIED_ORG "\x2b" /* {iso(1) identified-organization(3)} */
- #define MBEDTLS_OID_ISO_CCITT_DS "\x55" /* {joint-iso-ccitt(2) ds(5)} */
- #define MBEDTLS_OID_ISO_ITU_COUNTRY "\x60" /* {joint-iso-itu-t(2) country(16)} */
- /*
- * ISO Member bodies OID parts
- */
- #define MBEDTLS_OID_COUNTRY_US "\x86\x48" /* {us(840)} */
- #define MBEDTLS_OID_ORG_RSA_DATA_SECURITY "\x86\xf7\x0d" /* {rsadsi(113549)} */
- #define MBEDTLS_OID_RSA_COMPANY MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \
- MBEDTLS_OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) rsadsi(113549)} */
- #define MBEDTLS_OID_ORG_ANSI_X9_62 "\xce\x3d" /* ansi-X9-62(10045) */
- #define MBEDTLS_OID_ANSI_X9_62 MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \
- MBEDTLS_OID_ORG_ANSI_X9_62
- /*
- * ISO Identified organization OID parts
- */
- #define MBEDTLS_OID_ORG_DOD "\x06" /* {dod(6)} */
- #define MBEDTLS_OID_ORG_OIW "\x0e"
- #define MBEDTLS_OID_OIW_SECSIG MBEDTLS_OID_ORG_OIW "\x03"
- #define MBEDTLS_OID_OIW_SECSIG_ALG MBEDTLS_OID_OIW_SECSIG "\x02"
- #define MBEDTLS_OID_OIW_SECSIG_SHA1 MBEDTLS_OID_OIW_SECSIG_ALG "\x1a"
- #define MBEDTLS_OID_ORG_CERTICOM "\x81\x04" /* certicom(132) */
- #define MBEDTLS_OID_CERTICOM MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_CERTICOM
- #define MBEDTLS_OID_ORG_TELETRUST "\x24" /* teletrust(36) */
- #define MBEDTLS_OID_TELETRUST MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_TELETRUST
- /*
- * ISO ITU OID parts
- */
- #define MBEDTLS_OID_ORGANIZATION "\x01" /* {organization(1)} */
- #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)} */
- #define MBEDTLS_OID_ORG_GOV "\x65" /* {gov(101)} */
- #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)} */
- #define MBEDTLS_OID_ORG_NETSCAPE "\x86\xF8\x42" /* {netscape(113730)} */
- #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)} */
- /* ISO arc for standard certificate and CRL extensions */
- #define MBEDTLS_OID_ID_CE MBEDTLS_OID_ISO_CCITT_DS "\x1D" /**< id-ce OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 29} */
- #define MBEDTLS_OID_NIST_ALG MBEDTLS_OID_GOV "\x03\x04" /** { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithm(4) */
- /**
- * Private Internet Extensions
- * { iso(1) identified-organization(3) dod(6) internet(1)
- * security(5) mechanisms(5) pkix(7) }
- */
- #define MBEDTLS_OID_INTERNET MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01"
- #define MBEDTLS_OID_PKIX MBEDTLS_OID_INTERNET "\x05\x05\x07"
- /*
- * Arc for standard naming attributes
- */
- #define MBEDTLS_OID_AT MBEDTLS_OID_ISO_CCITT_DS "\x04" /**< id-at OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 4} */
- #define MBEDTLS_OID_AT_CN MBEDTLS_OID_AT "\x03" /**< id-at-commonName AttributeType:= {id-at 3} */
- #define MBEDTLS_OID_AT_SUR_NAME MBEDTLS_OID_AT "\x04" /**< id-at-surName AttributeType:= {id-at 4} */
- #define MBEDTLS_OID_AT_SERIAL_NUMBER MBEDTLS_OID_AT "\x05" /**< id-at-serialNumber AttributeType:= {id-at 5} */
- #define MBEDTLS_OID_AT_COUNTRY MBEDTLS_OID_AT "\x06" /**< id-at-countryName AttributeType:= {id-at 6} */
- #define MBEDTLS_OID_AT_LOCALITY MBEDTLS_OID_AT "\x07" /**< id-at-locality AttributeType:= {id-at 7} */
- #define MBEDTLS_OID_AT_STATE MBEDTLS_OID_AT "\x08" /**< id-at-state AttributeType:= {id-at 8} */
- #define MBEDTLS_OID_AT_ORGANIZATION MBEDTLS_OID_AT "\x0A" /**< id-at-organizationName AttributeType:= {id-at 10} */
- #define MBEDTLS_OID_AT_ORG_UNIT MBEDTLS_OID_AT "\x0B" /**< id-at-organizationalUnitName AttributeType:= {id-at 11} */
- #define MBEDTLS_OID_AT_TITLE MBEDTLS_OID_AT "\x0C" /**< id-at-title AttributeType:= {id-at 12} */
- #define MBEDTLS_OID_AT_POSTAL_ADDRESS MBEDTLS_OID_AT "\x10" /**< id-at-postalAddress AttributeType:= {id-at 16} */
- #define MBEDTLS_OID_AT_POSTAL_CODE MBEDTLS_OID_AT "\x11" /**< id-at-postalCode AttributeType:= {id-at 17} */
- #define MBEDTLS_OID_AT_GIVEN_NAME MBEDTLS_OID_AT "\x2A" /**< id-at-givenName AttributeType:= {id-at 42} */
- #define MBEDTLS_OID_AT_INITIALS MBEDTLS_OID_AT "\x2B" /**< id-at-initials AttributeType:= {id-at 43} */
- #define MBEDTLS_OID_AT_GENERATION_QUALIFIER MBEDTLS_OID_AT "\x2C" /**< id-at-generationQualifier AttributeType:= {id-at 44} */
- #define MBEDTLS_OID_AT_UNIQUE_IDENTIFIER MBEDTLS_OID_AT "\x2D" /**< id-at-uniqueIdentifier AttributType:= {id-at 45} */
- #define MBEDTLS_OID_AT_DN_QUALIFIER MBEDTLS_OID_AT "\x2E" /**< id-at-dnQualifier AttributeType:= {id-at 46} */
- #define MBEDTLS_OID_AT_PSEUDONYM MBEDTLS_OID_AT "\x41" /**< id-at-pseudonym AttributeType:= {id-at 65} */
- #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)} */
- /*
- * OIDs for standard certificate extensions
- */
- #define MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_ID_CE "\x23" /**< id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } */
- #define MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER MBEDTLS_OID_ID_CE "\x0E" /**< id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } */
- #define MBEDTLS_OID_KEY_USAGE MBEDTLS_OID_ID_CE "\x0F" /**< id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } */
- #define MBEDTLS_OID_CERTIFICATE_POLICIES MBEDTLS_OID_ID_CE "\x20" /**< id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 } */
- #define MBEDTLS_OID_POLICY_MAPPINGS MBEDTLS_OID_ID_CE "\x21" /**< id-ce-policyMappings OBJECT IDENTIFIER ::= { id-ce 33 } */
- #define MBEDTLS_OID_SUBJECT_ALT_NAME MBEDTLS_OID_ID_CE "\x11" /**< id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } */
- #define MBEDTLS_OID_ISSUER_ALT_NAME MBEDTLS_OID_ID_CE "\x12" /**< id-ce-issuerAltName OBJECT IDENTIFIER ::= { id-ce 18 } */
- #define MBEDTLS_OID_SUBJECT_DIRECTORY_ATTRS MBEDTLS_OID_ID_CE "\x09" /**< id-ce-subjectDirectoryAttributes OBJECT IDENTIFIER ::= { id-ce 9 } */
- #define MBEDTLS_OID_BASIC_CONSTRAINTS MBEDTLS_OID_ID_CE "\x13" /**< id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } */
- #define MBEDTLS_OID_NAME_CONSTRAINTS MBEDTLS_OID_ID_CE "\x1E" /**< id-ce-nameConstraints OBJECT IDENTIFIER ::= { id-ce 30 } */
- #define MBEDTLS_OID_POLICY_CONSTRAINTS MBEDTLS_OID_ID_CE "\x24" /**< id-ce-policyConstraints OBJECT IDENTIFIER ::= { id-ce 36 } */
- #define MBEDTLS_OID_EXTENDED_KEY_USAGE MBEDTLS_OID_ID_CE "\x25" /**< id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 } */
- #define MBEDTLS_OID_CRL_DISTRIBUTION_POINTS MBEDTLS_OID_ID_CE "\x1F" /**< id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 } */
- #define MBEDTLS_OID_INIHIBIT_ANYPOLICY MBEDTLS_OID_ID_CE "\x36" /**< id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::= { id-ce 54 } */
- #define MBEDTLS_OID_FRESHEST_CRL MBEDTLS_OID_ID_CE "\x2E" /**< id-ce-freshestCRL OBJECT IDENTIFIER ::= { id-ce 46 } */
- /*
- * Certificate policies
- */
- #define MBEDTLS_OID_ANY_POLICY MBEDTLS_OID_CERTIFICATE_POLICIES "\x00" /**< anyPolicy OBJECT IDENTIFIER ::= { id-ce-certificatePolicies 0 } */
- /*
- * Netscape certificate extensions
- */
- #define MBEDTLS_OID_NS_CERT MBEDTLS_OID_NETSCAPE "\x01"
- #define MBEDTLS_OID_NS_CERT_TYPE MBEDTLS_OID_NS_CERT "\x01"
- #define MBEDTLS_OID_NS_BASE_URL MBEDTLS_OID_NS_CERT "\x02"
- #define MBEDTLS_OID_NS_REVOCATION_URL MBEDTLS_OID_NS_CERT "\x03"
- #define MBEDTLS_OID_NS_CA_REVOCATION_URL MBEDTLS_OID_NS_CERT "\x04"
- #define MBEDTLS_OID_NS_RENEWAL_URL MBEDTLS_OID_NS_CERT "\x07"
- #define MBEDTLS_OID_NS_CA_POLICY_URL MBEDTLS_OID_NS_CERT "\x08"
- #define MBEDTLS_OID_NS_SSL_SERVER_NAME MBEDTLS_OID_NS_CERT "\x0C"
- #define MBEDTLS_OID_NS_COMMENT MBEDTLS_OID_NS_CERT "\x0D"
- #define MBEDTLS_OID_NS_DATA_TYPE MBEDTLS_OID_NETSCAPE "\x02"
- #define MBEDTLS_OID_NS_CERT_SEQUENCE MBEDTLS_OID_NS_DATA_TYPE "\x05"
- /*
- * OIDs for CRL extensions
- */
- #define MBEDTLS_OID_PRIVATE_KEY_USAGE_PERIOD MBEDTLS_OID_ID_CE "\x10"
- #define MBEDTLS_OID_CRL_NUMBER MBEDTLS_OID_ID_CE "\x14" /**< id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } */
- /*
- * X.509 v3 Extended key usage OIDs
- */
- #define MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE MBEDTLS_OID_EXTENDED_KEY_USAGE "\x00" /**< anyExtendedKeyUsage OBJECT IDENTIFIER ::= { id-ce-extKeyUsage 0 } */
- #define MBEDTLS_OID_KP MBEDTLS_OID_PKIX "\x03" /**< id-kp OBJECT IDENTIFIER ::= { id-pkix 3 } */
- #define MBEDTLS_OID_SERVER_AUTH MBEDTLS_OID_KP "\x01" /**< id-kp-serverAuth OBJECT IDENTIFIER ::= { id-kp 1 } */
- #define MBEDTLS_OID_CLIENT_AUTH MBEDTLS_OID_KP "\x02" /**< id-kp-clientAuth OBJECT IDENTIFIER ::= { id-kp 2 } */
- #define MBEDTLS_OID_CODE_SIGNING MBEDTLS_OID_KP "\x03" /**< id-kp-codeSigning OBJECT IDENTIFIER ::= { id-kp 3 } */
- #define MBEDTLS_OID_EMAIL_PROTECTION MBEDTLS_OID_KP "\x04" /**< id-kp-emailProtection OBJECT IDENTIFIER ::= { id-kp 4 } */
- #define MBEDTLS_OID_TIME_STAMPING MBEDTLS_OID_KP "\x08" /**< id-kp-timeStamping OBJECT IDENTIFIER ::= { id-kp 8 } */
- #define MBEDTLS_OID_OCSP_SIGNING MBEDTLS_OID_KP "\x09" /**< id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 } */
- /**
- * Wi-SUN Alliance Field Area Network
- * { iso(1) identified-organization(3) dod(6) internet(1)
- * private(4) enterprise(1) WiSUN(45605) FieldAreaNetwork(1) }
- */
- #define MBEDTLS_OID_WISUN_FAN MBEDTLS_OID_INTERNET "\x04\x01\x82\xe4\x25\x01"
- #define MBEDTLS_OID_ON MBEDTLS_OID_PKIX "\x08" /**< id-on OBJECT IDENTIFIER ::= { id-pkix 8 } */
- #define MBEDTLS_OID_ON_HW_MODULE_NAME MBEDTLS_OID_ON "\x04" /**< id-on-hardwareModuleName OBJECT IDENTIFIER ::= { id-on 4 } */
- /*
- * PKCS definition OIDs
- */
- #define MBEDTLS_OID_PKCS MBEDTLS_OID_RSA_COMPANY "\x01" /**< pkcs OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) 1 } */
- #define MBEDTLS_OID_PKCS1 MBEDTLS_OID_PKCS "\x01" /**< pkcs-1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1 } */
- #define MBEDTLS_OID_PKCS5 MBEDTLS_OID_PKCS "\x05" /**< pkcs-5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 5 } */
- #define MBEDTLS_OID_PKCS9 MBEDTLS_OID_PKCS "\x09" /**< pkcs-9 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 9 } */
- #define MBEDTLS_OID_PKCS12 MBEDTLS_OID_PKCS "\x0c" /**< pkcs-12 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 12 } */
- /*
- * PKCS#1 OIDs
- */
- #define MBEDTLS_OID_PKCS1_RSA MBEDTLS_OID_PKCS1 "\x01" /**< rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 } */
- #define MBEDTLS_OID_PKCS1_MD2 MBEDTLS_OID_PKCS1 "\x02" /**< md2WithRSAEncryption ::= { pkcs-1 2 } */
- #define MBEDTLS_OID_PKCS1_MD4 MBEDTLS_OID_PKCS1 "\x03" /**< md4WithRSAEncryption ::= { pkcs-1 3 } */
- #define MBEDTLS_OID_PKCS1_MD5 MBEDTLS_OID_PKCS1 "\x04" /**< md5WithRSAEncryption ::= { pkcs-1 4 } */
- #define MBEDTLS_OID_PKCS1_SHA1 MBEDTLS_OID_PKCS1 "\x05" /**< sha1WithRSAEncryption ::= { pkcs-1 5 } */
- #define MBEDTLS_OID_PKCS1_SHA224 MBEDTLS_OID_PKCS1 "\x0e" /**< sha224WithRSAEncryption ::= { pkcs-1 14 } */
- #define MBEDTLS_OID_PKCS1_SHA256 MBEDTLS_OID_PKCS1 "\x0b" /**< sha256WithRSAEncryption ::= { pkcs-1 11 } */
- #define MBEDTLS_OID_PKCS1_SHA384 MBEDTLS_OID_PKCS1 "\x0c" /**< sha384WithRSAEncryption ::= { pkcs-1 12 } */
- #define MBEDTLS_OID_PKCS1_SHA512 MBEDTLS_OID_PKCS1 "\x0d" /**< sha512WithRSAEncryption ::= { pkcs-1 13 } */
- #define MBEDTLS_OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D"
- #define MBEDTLS_OID_PKCS9_EMAIL MBEDTLS_OID_PKCS9 "\x01" /**< emailAddress AttributeType ::= { pkcs-9 1 } */
- /* RFC 4055 */
- #define MBEDTLS_OID_RSASSA_PSS MBEDTLS_OID_PKCS1 "\x0a" /**< id-RSASSA-PSS ::= { pkcs-1 10 } */
- #define MBEDTLS_OID_MGF1 MBEDTLS_OID_PKCS1 "\x08" /**< id-mgf1 ::= { pkcs-1 8 } */
- /*
- * Digest algorithms
- */
- #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 } */
- #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 } */
- #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 } */
- #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 } */
- #define MBEDTLS_OID_DIGEST_ALG_SHA224 MBEDTLS_OID_NIST_ALG "\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 } */
- #define MBEDTLS_OID_DIGEST_ALG_SHA256 MBEDTLS_OID_NIST_ALG "\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 } */
- #define MBEDTLS_OID_DIGEST_ALG_SHA384 MBEDTLS_OID_NIST_ALG "\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 } */
- #define MBEDTLS_OID_DIGEST_ALG_SHA512 MBEDTLS_OID_NIST_ALG "\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 } */
- #define MBEDTLS_OID_DIGEST_ALG_RIPEMD160 MBEDTLS_OID_TELETRUST "\x03\x02\x01" /**< id-ripemd160 OBJECT IDENTIFIER :: { iso(1) identified-organization(3) teletrust(36) algorithm(3) hashAlgorithm(2) ripemd160(1) } */
- #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 } */
- #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 } */
- #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 } */
- #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 } */
- #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 } */
- /*
- * Encryption algorithms
- */
- #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 } */
- #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 } */
- #define MBEDTLS_OID_AES MBEDTLS_OID_NIST_ALG "\x01" /** aes OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithm(4) 1 } */
- /*
- * Key Wrapping algorithms
- */
- /*
- * RFC 5649
- */
- #define MBEDTLS_OID_AES128_KW MBEDTLS_OID_AES "\x05" /** id-aes128-wrap OBJECT IDENTIFIER ::= { aes 5 } */
- #define MBEDTLS_OID_AES128_KWP MBEDTLS_OID_AES "\x08" /** id-aes128-wrap-pad OBJECT IDENTIFIER ::= { aes 8 } */
- #define MBEDTLS_OID_AES192_KW MBEDTLS_OID_AES "\x19" /** id-aes192-wrap OBJECT IDENTIFIER ::= { aes 25 } */
- #define MBEDTLS_OID_AES192_KWP MBEDTLS_OID_AES "\x1c" /** id-aes192-wrap-pad OBJECT IDENTIFIER ::= { aes 28 } */
- #define MBEDTLS_OID_AES256_KW MBEDTLS_OID_AES "\x2d" /** id-aes256-wrap OBJECT IDENTIFIER ::= { aes 45 } */
- #define MBEDTLS_OID_AES256_KWP MBEDTLS_OID_AES "\x30" /** id-aes256-wrap-pad OBJECT IDENTIFIER ::= { aes 48 } */
- /*
- * PKCS#5 OIDs
- */
- #define MBEDTLS_OID_PKCS5_PBKDF2 MBEDTLS_OID_PKCS5 "\x0c" /**< id-PBKDF2 OBJECT IDENTIFIER ::= {pkcs-5 12} */
- #define MBEDTLS_OID_PKCS5_PBES2 MBEDTLS_OID_PKCS5 "\x0d" /**< id-PBES2 OBJECT IDENTIFIER ::= {pkcs-5 13} */
- #define MBEDTLS_OID_PKCS5_PBMAC1 MBEDTLS_OID_PKCS5 "\x0e" /**< id-PBMAC1 OBJECT IDENTIFIER ::= {pkcs-5 14} */
- /*
- * PKCS#5 PBES1 algorithms
- */
- #define MBEDTLS_OID_PKCS5_PBE_MD2_DES_CBC MBEDTLS_OID_PKCS5 "\x01" /**< pbeWithMD2AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 1} */
- #define MBEDTLS_OID_PKCS5_PBE_MD2_RC2_CBC MBEDTLS_OID_PKCS5 "\x04" /**< pbeWithMD2AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 4} */
- #define MBEDTLS_OID_PKCS5_PBE_MD5_DES_CBC MBEDTLS_OID_PKCS5 "\x03" /**< pbeWithMD5AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 3} */
- #define MBEDTLS_OID_PKCS5_PBE_MD5_RC2_CBC MBEDTLS_OID_PKCS5 "\x06" /**< pbeWithMD5AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 6} */
- #define MBEDTLS_OID_PKCS5_PBE_SHA1_DES_CBC MBEDTLS_OID_PKCS5 "\x0a" /**< pbeWithSHA1AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 10} */
- #define MBEDTLS_OID_PKCS5_PBE_SHA1_RC2_CBC MBEDTLS_OID_PKCS5 "\x0b" /**< pbeWithSHA1AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 11} */
- /*
- * PKCS#8 OIDs
- */
- #define MBEDTLS_OID_PKCS9_CSR_EXT_REQ MBEDTLS_OID_PKCS9 "\x0e" /**< extensionRequest OBJECT IDENTIFIER ::= {pkcs-9 14} */
- /*
- * PKCS#12 PBE OIDs
- */
- #define MBEDTLS_OID_PKCS12_PBE MBEDTLS_OID_PKCS12 "\x01" /**< pkcs-12PbeIds OBJECT IDENTIFIER ::= {pkcs-12 1} */
- #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_128 MBEDTLS_OID_PKCS12_PBE "\x01" /**< pbeWithSHAAnd128BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 1} */
- #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_40 MBEDTLS_OID_PKCS12_PBE "\x02" /**< pbeWithSHAAnd40BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 2} */
- #define MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x03" /**< pbeWithSHAAnd3-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 3} */
- #define MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x04" /**< pbeWithSHAAnd2-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 4} */
- #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_128_CBC MBEDTLS_OID_PKCS12_PBE "\x05" /**< pbeWithSHAAnd128BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 5} */
- #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_40_CBC MBEDTLS_OID_PKCS12_PBE "\x06" /**< pbeWithSHAAnd40BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 6} */
- /*
- * EC key algorithms from RFC 5480
- */
- /* id-ecPublicKey OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 } */
- #define MBEDTLS_OID_EC_ALG_UNRESTRICTED MBEDTLS_OID_ANSI_X9_62 "\x02\01"
- /* id-ecDH OBJECT IDENTIFIER ::= {
- * iso(1) identified-organization(3) certicom(132)
- * schemes(1) ecdh(12) } */
- #define MBEDTLS_OID_EC_ALG_ECDH MBEDTLS_OID_CERTICOM "\x01\x0c"
- /*
- * ECParameters namedCurve identifiers, from RFC 5480, RFC 5639, and SEC2
- */
- /* secp192r1 OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 1 } */
- #define MBEDTLS_OID_EC_GRP_SECP192R1 MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x01"
- /* secp224r1 OBJECT IDENTIFIER ::= {
- * iso(1) identified-organization(3) certicom(132) curve(0) 33 } */
- #define MBEDTLS_OID_EC_GRP_SECP224R1 MBEDTLS_OID_CERTICOM "\x00\x21"
- /* secp256r1 OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 7 } */
- #define MBEDTLS_OID_EC_GRP_SECP256R1 MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x07"
- /* secp384r1 OBJECT IDENTIFIER ::= {
- * iso(1) identified-organization(3) certicom(132) curve(0) 34 } */
- #define MBEDTLS_OID_EC_GRP_SECP384R1 MBEDTLS_OID_CERTICOM "\x00\x22"
- /* secp521r1 OBJECT IDENTIFIER ::= {
- * iso(1) identified-organization(3) certicom(132) curve(0) 35 } */
- #define MBEDTLS_OID_EC_GRP_SECP521R1 MBEDTLS_OID_CERTICOM "\x00\x23"
- /* secp192k1 OBJECT IDENTIFIER ::= {
- * iso(1) identified-organization(3) certicom(132) curve(0) 31 } */
- #define MBEDTLS_OID_EC_GRP_SECP192K1 MBEDTLS_OID_CERTICOM "\x00\x1f"
- /* secp224k1 OBJECT IDENTIFIER ::= {
- * iso(1) identified-organization(3) certicom(132) curve(0) 32 } */
- #define MBEDTLS_OID_EC_GRP_SECP224K1 MBEDTLS_OID_CERTICOM "\x00\x20"
- /* secp256k1 OBJECT IDENTIFIER ::= {
- * iso(1) identified-organization(3) certicom(132) curve(0) 10 } */
- #define MBEDTLS_OID_EC_GRP_SECP256K1 MBEDTLS_OID_CERTICOM "\x00\x0a"
- /* RFC 5639 4.1
- * ecStdCurvesAndGeneration OBJECT IDENTIFIER::= {iso(1)
- * identified-organization(3) teletrust(36) algorithm(3) signature-
- * algorithm(3) ecSign(2) 8}
- * ellipticCurve OBJECT IDENTIFIER ::= {ecStdCurvesAndGeneration 1}
- * versionOne OBJECT IDENTIFIER ::= {ellipticCurve 1} */
- #define MBEDTLS_OID_EC_BRAINPOOL_V1 MBEDTLS_OID_TELETRUST "\x03\x03\x02\x08\x01\x01"
- /* brainpoolP256r1 OBJECT IDENTIFIER ::= {versionOne 7} */
- #define MBEDTLS_OID_EC_GRP_BP256R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x07"
- /* brainpoolP384r1 OBJECT IDENTIFIER ::= {versionOne 11} */
- #define MBEDTLS_OID_EC_GRP_BP384R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0B"
- /* brainpoolP512r1 OBJECT IDENTIFIER ::= {versionOne 13} */
- #define MBEDTLS_OID_EC_GRP_BP512R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0D"
- /*
- * SEC1 C.1
- *
- * prime-field OBJECT IDENTIFIER ::= { id-fieldType 1 }
- * id-fieldType OBJECT IDENTIFIER ::= { ansi-X9-62 fieldType(1)}
- */
- #define MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE MBEDTLS_OID_ANSI_X9_62 "\x01"
- #define MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE "\x01"
- /*
- * ECDSA signature identifiers, from RFC 5480
- */
- #define MBEDTLS_OID_ANSI_X9_62_SIG MBEDTLS_OID_ANSI_X9_62 "\x04" /* signatures(4) */
- #define MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 MBEDTLS_OID_ANSI_X9_62_SIG "\x03" /* ecdsa-with-SHA2(3) */
- /* ecdsa-with-SHA1 OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) 1 } */
- #define MBEDTLS_OID_ECDSA_SHA1 MBEDTLS_OID_ANSI_X9_62_SIG "\x01"
- /* ecdsa-with-SHA224 OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
- * ecdsa-with-SHA2(3) 1 } */
- #define MBEDTLS_OID_ECDSA_SHA224 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x01"
- /* ecdsa-with-SHA256 OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
- * ecdsa-with-SHA2(3) 2 } */
- #define MBEDTLS_OID_ECDSA_SHA256 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x02"
- /* ecdsa-with-SHA384 OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
- * ecdsa-with-SHA2(3) 3 } */
- #define MBEDTLS_OID_ECDSA_SHA384 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x03"
- /* ecdsa-with-SHA512 OBJECT IDENTIFIER ::= {
- * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
- * ecdsa-with-SHA2(3) 4 } */
- #define MBEDTLS_OID_ECDSA_SHA512 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04"
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief Base OID descriptor structure
- */
- typedef struct mbedtls_oid_descriptor_t
- {
- const char *asn1; /*!< OID ASN.1 representation */
- size_t asn1_len; /*!< length of asn1 */
- const char *name; /*!< official name (e.g. from RFC) */
- const char *description; /*!< human friendly description */
- } mbedtls_oid_descriptor_t;
- /**
- * \brief Translate an ASN.1 OID into its numeric representation
- * (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549")
- *
- * \param buf buffer to put representation in
- * \param size size of the buffer
- * \param oid OID to translate
- *
- * \return Length of the string written (excluding final NULL) or
- * MBEDTLS_ERR_OID_BUF_TOO_SMALL in case of error
- */
- int mbedtls_oid_get_numeric_string( char *buf, size_t size, const mbedtls_asn1_buf *oid );
- /**
- * \brief Translate an X.509 extension OID into local values
- *
- * \param oid OID to use
- * \param ext_type place to store the extension type
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_x509_ext_type( const mbedtls_asn1_buf *oid, int *ext_type );
- /**
- * \brief Translate an X.509 attribute type OID into the short name
- * (e.g. the OID for an X520 Common Name into "CN")
- *
- * \param oid OID to use
- * \param short_name place to store the string pointer
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_attr_short_name( const mbedtls_asn1_buf *oid, const char **short_name );
- /**
- * \brief Translate PublicKeyAlgorithm OID into pk_type
- *
- * \param oid OID to use
- * \param pk_alg place to store public key algorithm
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_pk_alg( const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_alg );
- /**
- * \brief Translate pk_type into PublicKeyAlgorithm OID
- *
- * \param pk_alg Public key type to look for
- * \param oid place to store ASN.1 OID string pointer
- * \param olen length of the OID
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_oid_by_pk_alg( mbedtls_pk_type_t pk_alg,
- const char **oid, size_t *olen );
- #if defined(MBEDTLS_ECP_C)
- /**
- * \brief Translate NamedCurve OID into an EC group identifier
- *
- * \param oid OID to use
- * \param grp_id place to store group id
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_ec_grp( const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id );
- /**
- * \brief Translate EC group identifier into NamedCurve OID
- *
- * \param grp_id EC group identifier
- * \param oid place to store ASN.1 OID string pointer
- * \param olen length of the OID
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_oid_by_ec_grp( mbedtls_ecp_group_id grp_id,
- const char **oid, size_t *olen );
- #endif /* MBEDTLS_ECP_C */
- #if defined(MBEDTLS_MD_C)
- /**
- * \brief Translate SignatureAlgorithm OID into md_type and pk_type
- *
- * \param oid OID to use
- * \param md_alg place to store message digest algorithm
- * \param pk_alg place to store public key algorithm
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_sig_alg( const mbedtls_asn1_buf *oid,
- mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg );
- /**
- * \brief Translate SignatureAlgorithm OID into description
- *
- * \param oid OID to use
- * \param desc place to store string pointer
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_sig_alg_desc( const mbedtls_asn1_buf *oid, const char **desc );
- /**
- * \brief Translate md_type and pk_type into SignatureAlgorithm OID
- *
- * \param md_alg message digest algorithm
- * \param pk_alg public key algorithm
- * \param oid place to store ASN.1 OID string pointer
- * \param olen length of the OID
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_oid_by_sig_alg( mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
- const char **oid, size_t *olen );
- /**
- * \brief Translate hash algorithm OID into md_type
- *
- * \param oid OID to use
- * \param md_alg place to store message digest algorithm
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_md_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg );
- /**
- * \brief Translate hmac algorithm OID into md_type
- *
- * \param oid OID to use
- * \param md_hmac place to store message hmac algorithm
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac );
- #endif /* MBEDTLS_MD_C */
- /**
- * \brief Translate Extended Key Usage OID into description
- *
- * \param oid OID to use
- * \param desc place to store string pointer
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_extended_key_usage( const mbedtls_asn1_buf *oid, const char **desc );
- /**
- * \brief Translate certificate policies OID into description
- *
- * \param oid OID to use
- * \param desc place to store string pointer
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_certificate_policies( const mbedtls_asn1_buf *oid, const char **desc );
- /**
- * \brief Translate md_type into hash algorithm OID
- *
- * \param md_alg message digest algorithm
- * \param oid place to store ASN.1 OID string pointer
- * \param olen length of the OID
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_oid_by_md( mbedtls_md_type_t md_alg, const char **oid, size_t *olen );
- #if defined(MBEDTLS_CIPHER_C)
- /**
- * \brief Translate encryption algorithm OID into cipher_type
- *
- * \param oid OID to use
- * \param cipher_alg place to store cipher algorithm
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_cipher_alg( const mbedtls_asn1_buf *oid, mbedtls_cipher_type_t *cipher_alg );
- #endif /* MBEDTLS_CIPHER_C */
- #if defined(MBEDTLS_PKCS12_C)
- /**
- * \brief Translate PKCS#12 PBE algorithm OID into md_type and
- * cipher_type
- *
- * \param oid OID to use
- * \param md_alg place to store message digest algorithm
- * \param cipher_alg place to store cipher algorithm
- *
- * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
- */
- int mbedtls_oid_get_pkcs12_pbe_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg,
- mbedtls_cipher_type_t *cipher_alg );
- #endif /* MBEDTLS_PKCS12_C */
- #ifdef __cplusplus
- }
- #endif
- #endif /* oid.h */
- /********* Start of file include/mbedtls/ripemd160.h ************/
- /**
- * \file ripemd160.h
- *
- * \brief RIPE MD-160 message digest
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_RIPEMD160_H
- #define MBEDTLS_RIPEMD160_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used.
- */
- /** RIPEMD160 hardware accelerator failed */
- #define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined(MBEDTLS_RIPEMD160_ALT)
- // Regular implementation
- //
- /**
- * \brief RIPEMD-160 context structure
- */
- typedef struct mbedtls_ripemd160_context
- {
- uint32_t total[2]; /*!< number of bytes processed */
- uint32_t state[5]; /*!< intermediate digest state */
- unsigned char buffer[64]; /*!< data block being processed */
- }
- mbedtls_ripemd160_context;
- #else /* MBEDTLS_RIPEMD160_ALT */
- #endif /* MBEDTLS_RIPEMD160_ALT */
- /**
- * \brief Initialize RIPEMD-160 context
- *
- * \param ctx RIPEMD-160 context to be initialized
- */
- void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
- /**
- * \brief Clear RIPEMD-160 context
- *
- * \param ctx RIPEMD-160 context to be cleared
- */
- void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
- /**
- * \brief Clone (the state of) an RIPEMD-160 context
- *
- * \param dst The destination context
- * \param src The context to be cloned
- */
- void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
- const mbedtls_ripemd160_context *src );
- /**
- * \brief RIPEMD-160 context setup
- *
- * \param ctx context to be initialized
- *
- * \return 0 if successful
- */
- int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
- /**
- * \brief RIPEMD-160 process buffer
- *
- * \param ctx RIPEMD-160 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- *
- * \return 0 if successful
- */
- int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief RIPEMD-160 final digest
- *
- * \param ctx RIPEMD-160 context
- * \param output RIPEMD-160 checksum result
- *
- * \return 0 if successful
- */
- int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
- unsigned char output[20] );
- /**
- * \brief RIPEMD-160 process data block (internal use only)
- *
- * \param ctx RIPEMD-160 context
- * \param data buffer holding one block of data
- *
- * \return 0 if successful
- */
- int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
- const unsigned char data[64] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief RIPEMD-160 context setup
- *
- * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
- *
- * \param ctx context to be initialized
- */
- MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
- mbedtls_ripemd160_context *ctx );
- /**
- * \brief RIPEMD-160 process buffer
- *
- * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
- *
- * \param ctx RIPEMD-160 context
- * \param input buffer holding the data
- * \param ilen length of the input data
- */
- MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
- mbedtls_ripemd160_context *ctx,
- const unsigned char *input,
- size_t ilen );
- /**
- * \brief RIPEMD-160 final digest
- *
- * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
- *
- * \param ctx RIPEMD-160 context
- * \param output RIPEMD-160 checksum result
- */
- MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
- mbedtls_ripemd160_context *ctx,
- unsigned char output[20] );
- /**
- * \brief RIPEMD-160 process data block (internal use only)
- *
- * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
- *
- * \param ctx RIPEMD-160 context
- * \param data buffer holding one block of data
- */
- MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
- mbedtls_ripemd160_context *ctx,
- const unsigned char data[64] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- /**
- * \brief Output = RIPEMD-160( input buffer )
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output RIPEMD-160 checksum result
- *
- * \return 0 if successful
- */
- int mbedtls_ripemd160_ret( const unsigned char *input,
- size_t ilen,
- unsigned char output[20] );
- #if !defined(MBEDTLS_DEPRECATED_REMOVED)
- #if defined(MBEDTLS_DEPRECATED_WARNING)
- #define MBEDTLS_DEPRECATED __attribute__((deprecated))
- #else
- #define MBEDTLS_DEPRECATED
- #endif
- /**
- * \brief Output = RIPEMD-160( input buffer )
- *
- * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
- *
- * \param input buffer holding the data
- * \param ilen length of the input data
- * \param output RIPEMD-160 checksum result
- */
- MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
- size_t ilen,
- unsigned char output[20] );
- #undef MBEDTLS_DEPRECATED
- #endif /* !MBEDTLS_DEPRECATED_REMOVED */
- #if defined(MBEDTLS_SELF_TEST)
- /**
- * \brief Checkup routine
- *
- * \return 0 if successful, or 1 if the test failed
- */
- int mbedtls_ripemd160_self_test( int verbose );
- #endif /* MBEDTLS_SELF_TEST */
- #ifdef __cplusplus
- }
- #endif
- #endif /* mbedtls_ripemd160.h */
- /********* Start of file include/mbedtls/hkdf.h ************/
- /**
- * \file hkdf.h
- *
- * \brief This file contains the HKDF interface.
- *
- * The HMAC-based Extract-and-Expand Key Derivation Function (HKDF) is
- * specified by RFC 5869.
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef MBEDTLS_HKDF_H
- #define MBEDTLS_HKDF_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /**
- * \name HKDF Error codes
- * \{
- */
- /** Bad input parameters to function. */
- #define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA -0x5F80
- /* \} name */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * \brief This is the HMAC-based Extract-and-Expand Key Derivation Function
- * (HKDF).
- *
- * \param md A hash function; md.size denotes the length of the hash
- * function output in bytes.
- * \param salt An optional salt value (a non-secret random value);
- * if the salt is not provided, a string of all zeros of
- * md.size length is used as the salt.
- * \param salt_len The length in bytes of the optional \p salt.
- * \param ikm The input keying material.
- * \param ikm_len The length in bytes of \p ikm.
- * \param info An optional context and application specific information
- * string. This can be a zero-length string.
- * \param info_len The length of \p info in bytes.
- * \param okm The output keying material of \p okm_len bytes.
- * \param okm_len The length of the output keying material in bytes. This
- * must be less than or equal to 255 * md.size bytes.
- *
- * \return 0 on success.
- * \return #MBEDTLS_ERR_HKDF_BAD_INPUT_DATA when the parameters are invalid.
- * \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying
- * MD layer.
- */
- int mbedtls_hkdf( const mbedtls_md_info_t *md, const unsigned char *salt,
- size_t salt_len, const unsigned char *ikm, size_t ikm_len,
- const unsigned char *info, size_t info_len,
- unsigned char *okm, size_t okm_len );
- /**
- * \brief Take the input keying material \p ikm and extract from it a
- * fixed-length pseudorandom key \p prk.
- *
- * \warning This function should only be used if the security of it has been
- * studied and established in that particular context (eg. TLS 1.3
- * key schedule). For standard HKDF security guarantees use
- * \c mbedtls_hkdf instead.
- *
- * \param md A hash function; md.size denotes the length of the
- * hash function output in bytes.
- * \param salt An optional salt value (a non-secret random value);
- * if the salt is not provided, a string of all zeros
- * of md.size length is used as the salt.
- * \param salt_len The length in bytes of the optional \p salt.
- * \param ikm The input keying material.
- * \param ikm_len The length in bytes of \p ikm.
- * \param[out] prk A pseudorandom key of at least md.size bytes.
- *
- * \return 0 on success.
- * \return #MBEDTLS_ERR_HKDF_BAD_INPUT_DATA when the parameters are invalid.
- * \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying
- * MD layer.
- */
- int mbedtls_hkdf_extract( const mbedtls_md_info_t *md,
- const unsigned char *salt, size_t salt_len,
- const unsigned char *ikm, size_t ikm_len,
- unsigned char *prk );
- /**
- * \brief Expand the supplied \p prk into several additional pseudorandom
- * keys, which is the output of the HKDF.
- *
- * \warning This function should only be used if the security of it has been
- * studied and established in that particular context (eg. TLS 1.3
- * key schedule). For standard HKDF security guarantees use
- * \c mbedtls_hkdf instead.
- *
- * \param md A hash function; md.size denotes the length of the hash
- * function output in bytes.
- * \param prk A pseudorandom key of at least md.size bytes. \p prk is
- * usually the output from the HKDF extract step.
- * \param prk_len The length in bytes of \p prk.
- * \param info An optional context and application specific information
- * string. This can be a zero-length string.
- * \param info_len The length of \p info in bytes.
- * \param okm The output keying material of \p okm_len bytes.
- * \param okm_len The length of the output keying material in bytes. This
- * must be less than or equal to 255 * md.size bytes.
- *
- * \return 0 on success.
- * \return #MBEDTLS_ERR_HKDF_BAD_INPUT_DATA when the parameters are invalid.
- * \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying
- * MD layer.
- */
- int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk,
- size_t prk_len, const unsigned char *info,
- size_t info_len, unsigned char *okm, size_t okm_len );
- #ifdef __cplusplus
- }
- #endif
- #endif /* hkdf.h */
- /********* Start of file include/mbedtls/version.h ************/
- /**
- * \file version.h
- *
- * \brief Run-time version information
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /*
- * This set of compile-time defines and run-time variables can be used to
- * determine the version number of the mbed TLS library used.
- */
- #ifndef MBEDTLS_VERSION_H
- #define MBEDTLS_VERSION_H
- #if !defined(MBEDTLS_CONFIG_FILE)
- #else
- #endif
- /**
- * The version number x.y.z is split into three parts.
- * Major, Minor, Patchlevel
- */
- #define MBEDTLS_VERSION_MAJOR 2
- #define MBEDTLS_VERSION_MINOR 28
- #define MBEDTLS_VERSION_PATCH 0
- /**
- * The single version number has the following structure:
- * MMNNPP00
- * Major version | Minor version | Patch version
- */
- #define MBEDTLS_VERSION_NUMBER 0x021C0000
- #define MBEDTLS_VERSION_STRING "2.28.0"
- #define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.28.0"
- #if defined(MBEDTLS_VERSION_C)
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Get the version number.
- *
- * \return The constructed version number in the format
- * MMNNPP00 (Major, Minor, Patch).
- */
- unsigned int mbedtls_version_get_number( void );
- /**
- * Get the version string ("x.y.z").
- *
- * \param string The string that will receive the value.
- * (Should be at least 9 bytes in size)
- */
- void mbedtls_version_get_string( char *string );
- /**
- * Get the full version string ("mbed TLS x.y.z").
- *
- * \param string The string that will receive the value. The mbed TLS version
- * string will use 18 bytes AT MOST including a terminating
- * null byte.
- * (So the buffer should be at least 18 bytes to receive this
- * version string).
- */
- void mbedtls_version_get_string_full( char *string );
- /**
- * \brief Check if support for a feature was compiled into this
- * mbed TLS binary. This allows you to see at runtime if the
- * library was for instance compiled with or without
- * Multi-threading support.
- *
- * \note only checks against defines in the sections "System
- * support", "mbed TLS modules" and "mbed TLS feature
- * support" in config.h
- *
- * \param feature The string for the define to check (e.g. "MBEDTLS_AES_C")
- *
- * \return 0 if the feature is present,
- * -1 if the feature is not present and
- * -2 if support for feature checking as a whole was not
- * compiled in.
- */
- int mbedtls_version_check_feature( const char *feature );
- #ifdef __cplusplus
- }
- #endif
- #endif /* MBEDTLS_VERSION_C */
- #endif /* version.h */
- #endif /* ME_COM_MBEDTLS */
|