Crypto.c 229 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991
  1. /** @file
  2. Implements the EDK II Crypto Protocol/PPI services using the library services
  3. from BaseCryptLib and TlsLib.
  4. Copyright (C) Microsoft Corporation. All rights reserved.
  5. Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <Base.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/BaseCryptLib.h>
  11. #include <Library/TlsLib.h>
  12. #include <Protocol/Crypto.h>
  13. #include <Pcd/PcdCryptoServiceFamilyEnable.h>
  14. /**
  15. A macro used to retrieve the FixedAtBuild PcdCryptoServiceFamilyEnable with a
  16. typecast to its associcted structure type PCD_CRYPTO_SERVICE_FAMILY_ENABLE.
  17. **/
  18. #define EDKII_CRYPTO_PCD ((const PCD_CRYPTO_SERVICE_FAMILY_ENABLE *)\
  19. (FixedPcdGetPtr (PcdCryptoServiceFamilyEnable)))
  20. /**
  21. A macro used to call a non-void BaseCryptLib function if it is enabled.
  22. If a BaseCryptLib function is not enabled, there will be no references to it
  23. from this module and will be optimized away reducing the size of this module.
  24. @param Enable The name of the enable field in PCD
  25. PcdCryptoServiceFamilyEnable for the BaseCryptLib
  26. function being called. If the value of this field
  27. is non-zero, then the BaseCryptLib function is
  28. enabled.
  29. @param Function The name of the BaseCryptLib function.
  30. @param Args The argument list to pass to Function.
  31. @param ErrorReturnValue The value to return if the BaseCryptLib function is
  32. not enabled.
  33. **/
  34. #define CALL_BASECRYPTLIB(Enable, Function, Args, ErrorReturnValue) \
  35. EDKII_CRYPTO_PCD->Enable \
  36. ? Function Args \
  37. : (BaseCryptLibServiceNotEnabled (#Function), ErrorReturnValue)
  38. /**
  39. A macro used to call a void BaseCryptLib function if it is enabled.
  40. If a BaseCryptLib function is not enabled, there will be no references to it
  41. from this module and will be optimized away reducing the size of this module.
  42. @param Enable The name of the enable field in PCD
  43. PcdCryptoServiceFamilyEnable for the BaseCryptLib
  44. function being called. If the value of this field
  45. is non-zero, then the BaseCryptLib function is
  46. enabled.
  47. @param Function The name of the BaseCryptLib function.
  48. @param Args The argument list to pass to Function.
  49. **/
  50. #define CALL_VOID_BASECRYPTLIB(Enable, Function, Args) \
  51. EDKII_CRYPTO_PCD->Enable \
  52. ? Function Args \
  53. : BaseCryptLibServiceNotEnabled (#Function)
  54. /**
  55. Internal worker function that prints a debug message and asserts if a call is
  56. made to a BaseCryptLib function that is not enabled in the EDK II Crypto
  57. Protocol/PPI.
  58. If this debug message and assert are observed, then a module is using
  59. BaseCryptLib function that is not enabled in a Crypto driver. The
  60. PcdCryptoServiceFamilyEnable should be updated to enable the missing service.
  61. @param[in] FunctionName Null-terminated ASCII string that is the name of an
  62. EDK II Crypto service.
  63. **/
  64. static
  65. VOID
  66. BaseCryptLibServiceNotEnabled (
  67. IN CONST CHAR8 *FunctionName
  68. )
  69. {
  70. DEBUG ((DEBUG_ERROR, "[%a] Function %a() is not enabled\n", gEfiCallerBaseName, FunctionName));
  71. ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
  72. }
  73. /**
  74. Internal worker function that prints a debug message and asserts if a call is
  75. made to a BaseCryptLib function that is deprecated and unsupported any longer.
  76. @param[in] FunctionName Null-terminated ASCII string that is the name of an
  77. EDK II Crypto service.
  78. **/
  79. static
  80. VOID
  81. BaseCryptLibServiceDeprecated (
  82. IN CONST CHAR8 *FunctionName
  83. )
  84. {
  85. DEBUG ((DEBUG_ERROR, "[%a] Function %a() is deprecated and unsupported any longer\n", gEfiCallerBaseName, FunctionName));
  86. ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
  87. }
  88. /**
  89. Returns the version of the EDK II Crypto Protocol.
  90. @return The version of the EDK II Crypto Protocol.
  91. **/
  92. UINTN
  93. EFIAPI
  94. CryptoServiceGetCryptoVersion (
  95. VOID
  96. )
  97. {
  98. return EDKII_CRYPTO_VERSION;
  99. }
  100. // =====================================================================================
  101. // One-Way Cryptographic Hash Primitives
  102. // =====================================================================================
  103. /**
  104. MD4 is deprecated and unsupported any longer.
  105. Keep the function field for binary compability.
  106. @retval 0 This interface is not supported.
  107. **/
  108. UINTN
  109. EFIAPI
  110. DeprecatedCryptoServiceMd4GetContextSize (
  111. VOID
  112. )
  113. {
  114. return BaseCryptLibServiceDeprecated ("Md4GetContextSize"), 0;
  115. }
  116. /**
  117. MD4 is deprecated and unsupported any longer.
  118. Keep the function field for binary compability.
  119. @param[out] Md4Context Pointer to MD4 context being initialized.
  120. @retval FALSE This interface is not supported.
  121. **/
  122. BOOLEAN
  123. EFIAPI
  124. DeprecatedCryptoServiceMd4Init (
  125. OUT VOID *Md4Context
  126. )
  127. {
  128. return BaseCryptLibServiceDeprecated ("Md4Init"), FALSE;
  129. }
  130. /**
  131. MD4 is deprecated and unsupported any longer.
  132. Keep the function field for binary compability.
  133. @param[in] Md4Context Pointer to MD4 context being copied.
  134. @param[out] NewMd4Context Pointer to new MD4 context.
  135. @retval FALSE This interface is not supported.
  136. **/
  137. BOOLEAN
  138. EFIAPI
  139. DeprecatedCryptoServiceMd4Duplicate (
  140. IN CONST VOID *Md4Context,
  141. OUT VOID *NewMd4Context
  142. )
  143. {
  144. return BaseCryptLibServiceDeprecated ("Md4Duplicate"), FALSE;
  145. }
  146. /**
  147. MD4 is deprecated and unsupported any longer.
  148. Keep the function field for binary compability.
  149. @param[in, out] Md4Context Pointer to the MD4 context.
  150. @param[in] Data Pointer to the buffer containing the data to be hashed.
  151. @param[in] DataSize Size of Data buffer in bytes.
  152. @retval FALSE This interface is not supported.
  153. **/
  154. BOOLEAN
  155. EFIAPI
  156. DeprecatedCryptoServiceMd4Update (
  157. IN OUT VOID *Md4Context,
  158. IN CONST VOID *Data,
  159. IN UINTN DataSize
  160. )
  161. {
  162. return BaseCryptLibServiceDeprecated ("Md4Update"), FALSE;
  163. }
  164. /**
  165. MD4 is deprecated and unsupported any longer.
  166. Keep the function field for binary compability.
  167. @param[in, out] Md4Context Pointer to the MD4 context.
  168. @param[out] HashValue Pointer to a buffer that receives the MD4 digest
  169. value (16 bytes).
  170. @retval FALSE This interface is not supported.
  171. **/
  172. BOOLEAN
  173. EFIAPI
  174. DeprecatedCryptoServiceMd4Final (
  175. IN OUT VOID *Md4Context,
  176. OUT UINT8 *HashValue
  177. )
  178. {
  179. return BaseCryptLibServiceDeprecated ("Md4Final"), FALSE;
  180. }
  181. /**
  182. MD4 is deprecated and unsupported any longer.
  183. Keep the function field for binary compability.
  184. @param[in] Data Pointer to the buffer containing the data to be hashed.
  185. @param[in] DataSize Size of Data buffer in bytes.
  186. @param[out] HashValue Pointer to a buffer that receives the MD4 digest
  187. value (16 bytes).
  188. @retval FALSE This interface is not supported.
  189. **/
  190. BOOLEAN
  191. EFIAPI
  192. DeprecatedCryptoServiceMd4HashAll (
  193. IN CONST VOID *Data,
  194. IN UINTN DataSize,
  195. OUT UINT8 *HashValue
  196. )
  197. {
  198. return BaseCryptLibServiceDeprecated ("Md4HashAll"), FALSE;
  199. }
  200. #ifndef ENABLE_MD5_DEPRECATED_INTERFACES
  201. /**
  202. Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
  203. If this interface is not supported, then return zero.
  204. @retval 0 This interface is not supported.
  205. **/
  206. UINTN
  207. EFIAPI
  208. DeprecatedCryptoServiceMd5GetContextSize (
  209. VOID
  210. )
  211. {
  212. return BaseCryptLibServiceDeprecated ("Md5GetContextSize"), 0;
  213. }
  214. /**
  215. Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
  216. subsequent use.
  217. If Md5Context is NULL, then return FALSE.
  218. If this interface is not supported, then return FALSE.
  219. @param[out] Md5Context Pointer to MD5 context being initialized.
  220. @retval FALSE This interface is not supported.
  221. **/
  222. BOOLEAN
  223. EFIAPI
  224. DeprecatedCryptoServiceMd5Init (
  225. OUT VOID *Md5Context
  226. )
  227. {
  228. return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;
  229. }
  230. /**
  231. Makes a copy of an existing MD5 context.
  232. If Md5Context is NULL, then return FALSE.
  233. If NewMd5Context is NULL, then return FALSE.
  234. If this interface is not supported, then return FALSE.
  235. @param[in] Md5Context Pointer to MD5 context being copied.
  236. @param[out] NewMd5Context Pointer to new MD5 context.
  237. @retval FALSE This interface is not supported.
  238. **/
  239. BOOLEAN
  240. EFIAPI
  241. DeprecatedCryptoServiceMd5Duplicate (
  242. IN CONST VOID *Md5Context,
  243. OUT VOID *NewMd5Context
  244. )
  245. {
  246. return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;
  247. }
  248. /**
  249. Digests the input data and updates MD5 context.
  250. This function performs MD5 digest on a data buffer of the specified size.
  251. It can be called multiple times to compute the digest of long or discontinuous data streams.
  252. MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
  253. by Md5Final(). Behavior with invalid context is undefined.
  254. If Md5Context is NULL, then return FALSE.
  255. If this interface is not supported, then return FALSE.
  256. @param[in, out] Md5Context Pointer to the MD5 context.
  257. @param[in] Data Pointer to the buffer containing the data to be hashed.
  258. @param[in] DataSize Size of Data buffer in bytes.
  259. @retval FALSE This interface is not supported.
  260. **/
  261. BOOLEAN
  262. EFIAPI
  263. DeprecatedCryptoServiceMd5Update (
  264. IN OUT VOID *Md5Context,
  265. IN CONST VOID *Data,
  266. IN UINTN DataSize
  267. )
  268. {
  269. return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;
  270. }
  271. /**
  272. Completes computation of the MD5 digest value.
  273. This function completes MD5 hash computation and retrieves the digest value into
  274. the specified memory. After this function has been called, the MD5 context cannot
  275. be used again.
  276. MD5 context should be already correctly initialized by Md5Init(), and should not be
  277. finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
  278. If Md5Context is NULL, then return FALSE.
  279. If HashValue is NULL, then return FALSE.
  280. If this interface is not supported, then return FALSE.
  281. @param[in, out] Md5Context Pointer to the MD5 context.
  282. @param[out] HashValue Pointer to a buffer that receives the MD5 digest
  283. value (16 bytes).
  284. @retval FALSE This interface is not supported.
  285. **/
  286. BOOLEAN
  287. EFIAPI
  288. DeprecatedCryptoServiceMd5Final (
  289. IN OUT VOID *Md5Context,
  290. OUT UINT8 *HashValue
  291. )
  292. {
  293. return BaseCryptLibServiceDeprecated ("Md5Final"), FALSE;
  294. }
  295. /**
  296. Computes the MD5 message digest of a input data buffer.
  297. This function performs the MD5 message digest of a given data buffer, and places
  298. the digest value into the specified memory.
  299. If this interface is not supported, then return FALSE.
  300. @param[in] Data Pointer to the buffer containing the data to be hashed.
  301. @param[in] DataSize Size of Data buffer in bytes.
  302. @param[out] HashValue Pointer to a buffer that receives the MD5 digest
  303. value (16 bytes).
  304. @retval FALSE This interface is not supported.
  305. **/
  306. BOOLEAN
  307. EFIAPI
  308. DeprecatedCryptoServiceMd5HashAll (
  309. IN CONST VOID *Data,
  310. IN UINTN DataSize,
  311. OUT UINT8 *HashValue
  312. )
  313. {
  314. return BaseCryptLibServiceDeprecated ("Md5HashAll"), FALSE;
  315. }
  316. #else
  317. /**
  318. Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
  319. If this interface is not supported, then return zero.
  320. @return The size, in bytes, of the context buffer required for MD5 hash operations.
  321. @retval 0 This interface is not supported.
  322. **/
  323. UINTN
  324. EFIAPI
  325. CryptoServiceMd5GetContextSize (
  326. VOID
  327. )
  328. {
  329. return CALL_BASECRYPTLIB (Md5.Services.GetContextSize, Md5GetContextSize, (), 0);
  330. }
  331. /**
  332. Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
  333. subsequent use.
  334. If Md5Context is NULL, then return FALSE.
  335. If this interface is not supported, then return FALSE.
  336. @param[out] Md5Context Pointer to MD5 context being initialized.
  337. @retval TRUE MD5 context initialization succeeded.
  338. @retval FALSE MD5 context initialization failed.
  339. @retval FALSE This interface is not supported.
  340. **/
  341. BOOLEAN
  342. EFIAPI
  343. CryptoServiceMd5Init (
  344. OUT VOID *Md5Context
  345. )
  346. {
  347. return CALL_BASECRYPTLIB (Md5.Services.Init, Md5Init, (Md5Context), FALSE);
  348. }
  349. /**
  350. Makes a copy of an existing MD5 context.
  351. If Md5Context is NULL, then return FALSE.
  352. If NewMd5Context is NULL, then return FALSE.
  353. If this interface is not supported, then return FALSE.
  354. @param[in] Md5Context Pointer to MD5 context being copied.
  355. @param[out] NewMd5Context Pointer to new MD5 context.
  356. @retval TRUE MD5 context copy succeeded.
  357. @retval FALSE MD5 context copy failed.
  358. @retval FALSE This interface is not supported.
  359. **/
  360. BOOLEAN
  361. EFIAPI
  362. CryptoServiceMd5Duplicate (
  363. IN CONST VOID *Md5Context,
  364. OUT VOID *NewMd5Context
  365. )
  366. {
  367. return CALL_BASECRYPTLIB (Md5.Services.Duplicate, Md5Duplicate, (Md5Context, NewMd5Context), FALSE);
  368. }
  369. /**
  370. Digests the input data and updates MD5 context.
  371. This function performs MD5 digest on a data buffer of the specified size.
  372. It can be called multiple times to compute the digest of long or discontinuous data streams.
  373. MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
  374. by Md5Final(). Behavior with invalid context is undefined.
  375. If Md5Context is NULL, then return FALSE.
  376. If this interface is not supported, then return FALSE.
  377. @param[in, out] Md5Context Pointer to the MD5 context.
  378. @param[in] Data Pointer to the buffer containing the data to be hashed.
  379. @param[in] DataSize Size of Data buffer in bytes.
  380. @retval TRUE MD5 data digest succeeded.
  381. @retval FALSE MD5 data digest failed.
  382. @retval FALSE This interface is not supported.
  383. **/
  384. BOOLEAN
  385. EFIAPI
  386. CryptoServiceMd5Update (
  387. IN OUT VOID *Md5Context,
  388. IN CONST VOID *Data,
  389. IN UINTN DataSize
  390. )
  391. {
  392. return CALL_BASECRYPTLIB (Md5.Services.Update, Md5Update, (Md5Context, Data, DataSize), FALSE);
  393. }
  394. /**
  395. Completes computation of the MD5 digest value.
  396. This function completes MD5 hash computation and retrieves the digest value into
  397. the specified memory. After this function has been called, the MD5 context cannot
  398. be used again.
  399. MD5 context should be already correctly initialized by Md5Init(), and should not be
  400. finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
  401. If Md5Context is NULL, then return FALSE.
  402. If HashValue is NULL, then return FALSE.
  403. If this interface is not supported, then return FALSE.
  404. @param[in, out] Md5Context Pointer to the MD5 context.
  405. @param[out] HashValue Pointer to a buffer that receives the MD5 digest
  406. value (16 bytes).
  407. @retval TRUE MD5 digest computation succeeded.
  408. @retval FALSE MD5 digest computation failed.
  409. @retval FALSE This interface is not supported.
  410. **/
  411. BOOLEAN
  412. EFIAPI
  413. CryptoServiceMd5Final (
  414. IN OUT VOID *Md5Context,
  415. OUT UINT8 *HashValue
  416. )
  417. {
  418. return CALL_BASECRYPTLIB (Md5.Services.Final, Md5Final, (Md5Context, HashValue), FALSE);
  419. }
  420. /**
  421. Computes the MD5 message digest of a input data buffer.
  422. This function performs the MD5 message digest of a given data buffer, and places
  423. the digest value into the specified memory.
  424. If this interface is not supported, then return FALSE.
  425. @param[in] Data Pointer to the buffer containing the data to be hashed.
  426. @param[in] DataSize Size of Data buffer in bytes.
  427. @param[out] HashValue Pointer to a buffer that receives the MD5 digest
  428. value (16 bytes).
  429. @retval TRUE MD5 digest computation succeeded.
  430. @retval FALSE MD5 digest computation failed.
  431. @retval FALSE This interface is not supported.
  432. **/
  433. BOOLEAN
  434. EFIAPI
  435. CryptoServiceMd5HashAll (
  436. IN CONST VOID *Data,
  437. IN UINTN DataSize,
  438. OUT UINT8 *HashValue
  439. )
  440. {
  441. return CALL_BASECRYPTLIB (Md5.Services.HashAll, Md5HashAll, (Data, DataSize, HashValue), FALSE);
  442. }
  443. #endif
  444. #ifdef DISABLE_SHA1_DEPRECATED_INTERFACES
  445. /**
  446. Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
  447. If this interface is not supported, then return zero.
  448. @retval 0 This interface is not supported.
  449. **/
  450. UINTN
  451. EFIAPI
  452. DeprecatedCryptoServiceSha1GetContextSize (
  453. VOID
  454. )
  455. {
  456. return BaseCryptLibServiceDeprecated ("Sha1GetContextSize"), 0;
  457. }
  458. /**
  459. Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
  460. subsequent use.
  461. If Sha1Context is NULL, then return FALSE.
  462. If this interface is not supported, then return FALSE.
  463. @param[out] Sha1Context Pointer to SHA-1 context being initialized.
  464. @retval TRUE SHA-1 context initialization succeeded.
  465. @retval FALSE SHA-1 context initialization failed.
  466. @retval FALSE This interface is not supported.
  467. **/
  468. BOOLEAN
  469. EFIAPI
  470. DeprecatedCryptoServiceSha1Init (
  471. OUT VOID *Sha1Context
  472. )
  473. {
  474. return BaseCryptLibServiceDeprecated ("Sha1Init"), FALSE;
  475. }
  476. /**
  477. Makes a copy of an existing SHA-1 context.
  478. If Sha1Context is NULL, then return FALSE.
  479. If NewSha1Context is NULL, then return FALSE.
  480. If this interface is not supported, then return FALSE.
  481. @param[in] Sha1Context Pointer to SHA-1 context being copied.
  482. @param[out] NewSha1Context Pointer to new SHA-1 context.
  483. @retval FALSE This interface is not supported.
  484. **/
  485. BOOLEAN
  486. EFIAPI
  487. DeprecatedCryptoServiceSha1Duplicate (
  488. IN CONST VOID *Sha1Context,
  489. OUT VOID *NewSha1Context
  490. )
  491. {
  492. return BaseCryptLibServiceDeprecated ("Sha1Duplicate"), FALSE;
  493. }
  494. /**
  495. Digests the input data and updates SHA-1 context.
  496. This function performs SHA-1 digest on a data buffer of the specified size.
  497. It can be called multiple times to compute the digest of long or discontinuous data streams.
  498. SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
  499. by Sha1Final(). Behavior with invalid context is undefined.
  500. If Sha1Context is NULL, then return FALSE.
  501. If this interface is not supported, then return FALSE.
  502. @param[in, out] Sha1Context Pointer to the SHA-1 context.
  503. @param[in] Data Pointer to the buffer containing the data to be hashed.
  504. @param[in] DataSize Size of Data buffer in bytes.
  505. @retval FALSE This interface is not supported.
  506. **/
  507. BOOLEAN
  508. EFIAPI
  509. DeprecatedCryptoServiceSha1Update (
  510. IN OUT VOID *Sha1Context,
  511. IN CONST VOID *Data,
  512. IN UINTN DataSize
  513. )
  514. {
  515. return BaseCryptLibServiceDeprecated ("Sha1Update"), FALSE;
  516. }
  517. /**
  518. Completes computation of the SHA-1 digest value.
  519. This function completes SHA-1 hash computation and retrieves the digest value into
  520. the specified memory. After this function has been called, the SHA-1 context cannot
  521. be used again.
  522. SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
  523. finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
  524. If Sha1Context is NULL, then return FALSE.
  525. If HashValue is NULL, then return FALSE.
  526. If this interface is not supported, then return FALSE.
  527. @param[in, out] Sha1Context Pointer to the SHA-1 context.
  528. @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
  529. value (20 bytes).
  530. @retval FALSE This interface is not supported.
  531. **/
  532. BOOLEAN
  533. EFIAPI
  534. DeprecatedCryptoServiceSha1Final (
  535. IN OUT VOID *Sha1Context,
  536. OUT UINT8 *HashValue
  537. )
  538. {
  539. return BaseCryptLibServiceDeprecated ("Sha1Final"), FALSE;
  540. }
  541. /**
  542. Computes the SHA-1 message digest of a input data buffer.
  543. This function performs the SHA-1 message digest of a given data buffer, and places
  544. the digest value into the specified memory.
  545. If this interface is not supported, then return FALSE.
  546. @param[in] Data Pointer to the buffer containing the data to be hashed.
  547. @param[in] DataSize Size of Data buffer in bytes.
  548. @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
  549. value (20 bytes).
  550. @retval FALSE This interface is not supported.
  551. **/
  552. BOOLEAN
  553. EFIAPI
  554. DeprecatedCryptoServiceSha1HashAll (
  555. IN CONST VOID *Data,
  556. IN UINTN DataSize,
  557. OUT UINT8 *HashValue
  558. )
  559. {
  560. return BaseCryptLibServiceDeprecated ("Sha1HashAll"), FALSE;
  561. }
  562. #else
  563. /**
  564. Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
  565. If this interface is not supported, then return zero.
  566. @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
  567. @retval 0 This interface is not supported.
  568. **/
  569. UINTN
  570. EFIAPI
  571. CryptoServiceSha1GetContextSize (
  572. VOID
  573. )
  574. {
  575. return CALL_BASECRYPTLIB (Sha1.Services.GetContextSize, Sha1GetContextSize, (), 0);
  576. }
  577. /**
  578. Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
  579. subsequent use.
  580. If Sha1Context is NULL, then return FALSE.
  581. If this interface is not supported, then return FALSE.
  582. @param[out] Sha1Context Pointer to SHA-1 context being initialized.
  583. @retval TRUE SHA-1 context initialization succeeded.
  584. @retval FALSE SHA-1 context initialization failed.
  585. @retval FALSE This interface is not supported.
  586. **/
  587. BOOLEAN
  588. EFIAPI
  589. CryptoServiceSha1Init (
  590. OUT VOID *Sha1Context
  591. )
  592. {
  593. return CALL_BASECRYPTLIB (Sha1.Services.Init, Sha1Init, (Sha1Context), FALSE);
  594. }
  595. /**
  596. Makes a copy of an existing SHA-1 context.
  597. If Sha1Context is NULL, then return FALSE.
  598. If NewSha1Context is NULL, then return FALSE.
  599. If this interface is not supported, then return FALSE.
  600. @param[in] Sha1Context Pointer to SHA-1 context being copied.
  601. @param[out] NewSha1Context Pointer to new SHA-1 context.
  602. @retval TRUE SHA-1 context copy succeeded.
  603. @retval FALSE SHA-1 context copy failed.
  604. @retval FALSE This interface is not supported.
  605. **/
  606. BOOLEAN
  607. EFIAPI
  608. CryptoServiceSha1Duplicate (
  609. IN CONST VOID *Sha1Context,
  610. OUT VOID *NewSha1Context
  611. )
  612. {
  613. return CALL_BASECRYPTLIB (Sha1.Services.Duplicate, Sha1Duplicate, (Sha1Context, NewSha1Context), FALSE);
  614. }
  615. /**
  616. Digests the input data and updates SHA-1 context.
  617. This function performs SHA-1 digest on a data buffer of the specified size.
  618. It can be called multiple times to compute the digest of long or discontinuous data streams.
  619. SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
  620. by Sha1Final(). Behavior with invalid context is undefined.
  621. If Sha1Context is NULL, then return FALSE.
  622. If this interface is not supported, then return FALSE.
  623. @param[in, out] Sha1Context Pointer to the SHA-1 context.
  624. @param[in] Data Pointer to the buffer containing the data to be hashed.
  625. @param[in] DataSize Size of Data buffer in bytes.
  626. @retval TRUE SHA-1 data digest succeeded.
  627. @retval FALSE SHA-1 data digest failed.
  628. @retval FALSE This interface is not supported.
  629. **/
  630. BOOLEAN
  631. EFIAPI
  632. CryptoServiceSha1Update (
  633. IN OUT VOID *Sha1Context,
  634. IN CONST VOID *Data,
  635. IN UINTN DataSize
  636. )
  637. {
  638. return CALL_BASECRYPTLIB (Sha1.Services.Update, Sha1Update, (Sha1Context, Data, DataSize), FALSE);
  639. }
  640. /**
  641. Completes computation of the SHA-1 digest value.
  642. This function completes SHA-1 hash computation and retrieves the digest value into
  643. the specified memory. After this function has been called, the SHA-1 context cannot
  644. be used again.
  645. SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
  646. finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
  647. If Sha1Context is NULL, then return FALSE.
  648. If HashValue is NULL, then return FALSE.
  649. If this interface is not supported, then return FALSE.
  650. @param[in, out] Sha1Context Pointer to the SHA-1 context.
  651. @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
  652. value (20 bytes).
  653. @retval TRUE SHA-1 digest computation succeeded.
  654. @retval FALSE SHA-1 digest computation failed.
  655. @retval FALSE This interface is not supported.
  656. **/
  657. BOOLEAN
  658. EFIAPI
  659. CryptoServiceSha1Final (
  660. IN OUT VOID *Sha1Context,
  661. OUT UINT8 *HashValue
  662. )
  663. {
  664. return CALL_BASECRYPTLIB (Sha1.Services.Final, Sha1Final, (Sha1Context, HashValue), FALSE);
  665. }
  666. /**
  667. Computes the SHA-1 message digest of a input data buffer.
  668. This function performs the SHA-1 message digest of a given data buffer, and places
  669. the digest value into the specified memory.
  670. If this interface is not supported, then return FALSE.
  671. @param[in] Data Pointer to the buffer containing the data to be hashed.
  672. @param[in] DataSize Size of Data buffer in bytes.
  673. @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
  674. value (20 bytes).
  675. @retval TRUE SHA-1 digest computation succeeded.
  676. @retval FALSE SHA-1 digest computation failed.
  677. @retval FALSE This interface is not supported.
  678. **/
  679. BOOLEAN
  680. EFIAPI
  681. CryptoServiceSha1HashAll (
  682. IN CONST VOID *Data,
  683. IN UINTN DataSize,
  684. OUT UINT8 *HashValue
  685. )
  686. {
  687. return CALL_BASECRYPTLIB (Sha1.Services.HashAll, Sha1HashAll, (Data, DataSize, HashValue), FALSE);
  688. }
  689. #endif
  690. /**
  691. Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.
  692. @return The size, in bytes, of the context buffer required for SHA-256 hash operations.
  693. **/
  694. UINTN
  695. EFIAPI
  696. CryptoServiceSha256GetContextSize (
  697. VOID
  698. )
  699. {
  700. return CALL_BASECRYPTLIB (Sha256.Services.GetContextSize, Sha256GetContextSize, (), 0);
  701. }
  702. /**
  703. Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for
  704. subsequent use.
  705. If Sha256Context is NULL, then return FALSE.
  706. @param[out] Sha256Context Pointer to SHA-256 context being initialized.
  707. @retval TRUE SHA-256 context initialization succeeded.
  708. @retval FALSE SHA-256 context initialization failed.
  709. **/
  710. BOOLEAN
  711. EFIAPI
  712. CryptoServiceSha256Init (
  713. OUT VOID *Sha256Context
  714. )
  715. {
  716. return CALL_BASECRYPTLIB (Sha256.Services.Init, Sha256Init, (Sha256Context), FALSE);
  717. }
  718. /**
  719. Makes a copy of an existing SHA-256 context.
  720. If Sha256Context is NULL, then return FALSE.
  721. If NewSha256Context is NULL, then return FALSE.
  722. If this interface is not supported, then return FALSE.
  723. @param[in] Sha256Context Pointer to SHA-256 context being copied.
  724. @param[out] NewSha256Context Pointer to new SHA-256 context.
  725. @retval TRUE SHA-256 context copy succeeded.
  726. @retval FALSE SHA-256 context copy failed.
  727. @retval FALSE This interface is not supported.
  728. **/
  729. BOOLEAN
  730. EFIAPI
  731. CryptoServiceSha256Duplicate (
  732. IN CONST VOID *Sha256Context,
  733. OUT VOID *NewSha256Context
  734. )
  735. {
  736. return CALL_BASECRYPTLIB (Sha256.Services.Duplicate, Sha256Duplicate, (Sha256Context, NewSha256Context), FALSE);
  737. }
  738. /**
  739. Digests the input data and updates SHA-256 context.
  740. This function performs SHA-256 digest on a data buffer of the specified size.
  741. It can be called multiple times to compute the digest of long or discontinuous data streams.
  742. SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized
  743. by Sha256Final(). Behavior with invalid context is undefined.
  744. If Sha256Context is NULL, then return FALSE.
  745. @param[in, out] Sha256Context Pointer to the SHA-256 context.
  746. @param[in] Data Pointer to the buffer containing the data to be hashed.
  747. @param[in] DataSize Size of Data buffer in bytes.
  748. @retval TRUE SHA-256 data digest succeeded.
  749. @retval FALSE SHA-256 data digest failed.
  750. **/
  751. BOOLEAN
  752. EFIAPI
  753. CryptoServiceSha256Update (
  754. IN OUT VOID *Sha256Context,
  755. IN CONST VOID *Data,
  756. IN UINTN DataSize
  757. )
  758. {
  759. return CALL_BASECRYPTLIB (Sha256.Services.Update, Sha256Update, (Sha256Context, Data, DataSize), FALSE);
  760. }
  761. /**
  762. Completes computation of the SHA-256 digest value.
  763. This function completes SHA-256 hash computation and retrieves the digest value into
  764. the specified memory. After this function has been called, the SHA-256 context cannot
  765. be used again.
  766. SHA-256 context should be already correctly initialized by Sha256Init(), and should not be
  767. finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.
  768. If Sha256Context is NULL, then return FALSE.
  769. If HashValue is NULL, then return FALSE.
  770. @param[in, out] Sha256Context Pointer to the SHA-256 context.
  771. @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
  772. value (32 bytes).
  773. @retval TRUE SHA-256 digest computation succeeded.
  774. @retval FALSE SHA-256 digest computation failed.
  775. **/
  776. BOOLEAN
  777. EFIAPI
  778. CryptoServiceSha256Final (
  779. IN OUT VOID *Sha256Context,
  780. OUT UINT8 *HashValue
  781. )
  782. {
  783. return CALL_BASECRYPTLIB (Sha256.Services.Final, Sha256Final, (Sha256Context, HashValue), FALSE);
  784. }
  785. /**
  786. Computes the SHA-256 message digest of a input data buffer.
  787. This function performs the SHA-256 message digest of a given data buffer, and places
  788. the digest value into the specified memory.
  789. If this interface is not supported, then return FALSE.
  790. @param[in] Data Pointer to the buffer containing the data to be hashed.
  791. @param[in] DataSize Size of Data buffer in bytes.
  792. @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest
  793. value (32 bytes).
  794. @retval TRUE SHA-256 digest computation succeeded.
  795. @retval FALSE SHA-256 digest computation failed.
  796. @retval FALSE This interface is not supported.
  797. **/
  798. BOOLEAN
  799. EFIAPI
  800. CryptoServiceSha256HashAll (
  801. IN CONST VOID *Data,
  802. IN UINTN DataSize,
  803. OUT UINT8 *HashValue
  804. )
  805. {
  806. return CALL_BASECRYPTLIB (Sha256.Services.HashAll, Sha256HashAll, (Data, DataSize, HashValue), FALSE);
  807. }
  808. /**
  809. Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
  810. @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
  811. **/
  812. UINTN
  813. EFIAPI
  814. CryptoServiceSha384GetContextSize (
  815. VOID
  816. )
  817. {
  818. return CALL_BASECRYPTLIB (Sha384.Services.GetContextSize, Sha384GetContextSize, (), 0);
  819. }
  820. /**
  821. Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
  822. subsequent use.
  823. If Sha384Context is NULL, then return FALSE.
  824. @param[out] Sha384Context Pointer to SHA-384 context being initialized.
  825. @retval TRUE SHA-384 context initialization succeeded.
  826. @retval FALSE SHA-384 context initialization failed.
  827. **/
  828. BOOLEAN
  829. EFIAPI
  830. CryptoServiceSha384Init (
  831. OUT VOID *Sha384Context
  832. )
  833. {
  834. return CALL_BASECRYPTLIB (Sha384.Services.Init, Sha384Init, (Sha384Context), FALSE);
  835. }
  836. /**
  837. Makes a copy of an existing SHA-384 context.
  838. If Sha384Context is NULL, then return FALSE.
  839. If NewSha384Context is NULL, then return FALSE.
  840. If this interface is not supported, then return FALSE.
  841. @param[in] Sha384Context Pointer to SHA-384 context being copied.
  842. @param[out] NewSha384Context Pointer to new SHA-384 context.
  843. @retval TRUE SHA-384 context copy succeeded.
  844. @retval FALSE SHA-384 context copy failed.
  845. @retval FALSE This interface is not supported.
  846. **/
  847. BOOLEAN
  848. EFIAPI
  849. CryptoServiceSha384Duplicate (
  850. IN CONST VOID *Sha384Context,
  851. OUT VOID *NewSha384Context
  852. )
  853. {
  854. return CALL_BASECRYPTLIB (Sha384.Services.Duplicate, Sha384Duplicate, (Sha384Context, NewSha384Context), FALSE);
  855. }
  856. /**
  857. Digests the input data and updates SHA-384 context.
  858. This function performs SHA-384 digest on a data buffer of the specified size.
  859. It can be called multiple times to compute the digest of long or discontinuous data streams.
  860. SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
  861. by Sha384Final(). Behavior with invalid context is undefined.
  862. If Sha384Context is NULL, then return FALSE.
  863. @param[in, out] Sha384Context Pointer to the SHA-384 context.
  864. @param[in] Data Pointer to the buffer containing the data to be hashed.
  865. @param[in] DataSize Size of Data buffer in bytes.
  866. @retval TRUE SHA-384 data digest succeeded.
  867. @retval FALSE SHA-384 data digest failed.
  868. **/
  869. BOOLEAN
  870. EFIAPI
  871. CryptoServiceSha384Update (
  872. IN OUT VOID *Sha384Context,
  873. IN CONST VOID *Data,
  874. IN UINTN DataSize
  875. )
  876. {
  877. return CALL_BASECRYPTLIB (Sha384.Services.Update, Sha384Update, (Sha384Context, Data, DataSize), FALSE);
  878. }
  879. /**
  880. Completes computation of the SHA-384 digest value.
  881. This function completes SHA-384 hash computation and retrieves the digest value into
  882. the specified memory. After this function has been called, the SHA-384 context cannot
  883. be used again.
  884. SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
  885. finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
  886. If Sha384Context is NULL, then return FALSE.
  887. If HashValue is NULL, then return FALSE.
  888. @param[in, out] Sha384Context Pointer to the SHA-384 context.
  889. @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
  890. value (48 bytes).
  891. @retval TRUE SHA-384 digest computation succeeded.
  892. @retval FALSE SHA-384 digest computation failed.
  893. **/
  894. BOOLEAN
  895. EFIAPI
  896. CryptoServiceSha384Final (
  897. IN OUT VOID *Sha384Context,
  898. OUT UINT8 *HashValue
  899. )
  900. {
  901. return CALL_BASECRYPTLIB (Sha384.Services.Final, Sha384Final, (Sha384Context, HashValue), FALSE);
  902. }
  903. /**
  904. Computes the SHA-384 message digest of a input data buffer.
  905. This function performs the SHA-384 message digest of a given data buffer, and places
  906. the digest value into the specified memory.
  907. If this interface is not supported, then return FALSE.
  908. @param[in] Data Pointer to the buffer containing the data to be hashed.
  909. @param[in] DataSize Size of Data buffer in bytes.
  910. @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
  911. value (48 bytes).
  912. @retval TRUE SHA-384 digest computation succeeded.
  913. @retval FALSE SHA-384 digest computation failed.
  914. @retval FALSE This interface is not supported.
  915. **/
  916. BOOLEAN
  917. EFIAPI
  918. CryptoServiceSha384HashAll (
  919. IN CONST VOID *Data,
  920. IN UINTN DataSize,
  921. OUT UINT8 *HashValue
  922. )
  923. {
  924. return CALL_BASECRYPTLIB (Sha384.Services.HashAll, Sha384HashAll, (Data, DataSize, HashValue), FALSE);
  925. }
  926. /**
  927. Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
  928. @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
  929. **/
  930. UINTN
  931. EFIAPI
  932. CryptoServiceSha512GetContextSize (
  933. VOID
  934. )
  935. {
  936. return CALL_BASECRYPTLIB (Sha512.Services.GetContextSize, Sha512GetContextSize, (), 0);
  937. }
  938. /**
  939. Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
  940. subsequent use.
  941. If Sha512Context is NULL, then return FALSE.
  942. @param[out] Sha512Context Pointer to SHA-512 context being initialized.
  943. @retval TRUE SHA-512 context initialization succeeded.
  944. @retval FALSE SHA-512 context initialization failed.
  945. **/
  946. BOOLEAN
  947. EFIAPI
  948. CryptoServiceSha512Init (
  949. OUT VOID *Sha512Context
  950. )
  951. {
  952. return CALL_BASECRYPTLIB (Sha512.Services.Init, Sha512Init, (Sha512Context), FALSE);
  953. }
  954. /**
  955. Makes a copy of an existing SHA-512 context.
  956. If Sha512Context is NULL, then return FALSE.
  957. If NewSha512Context is NULL, then return FALSE.
  958. If this interface is not supported, then return FALSE.
  959. @param[in] Sha512Context Pointer to SHA-512 context being copied.
  960. @param[out] NewSha512Context Pointer to new SHA-512 context.
  961. @retval TRUE SHA-512 context copy succeeded.
  962. @retval FALSE SHA-512 context copy failed.
  963. @retval FALSE This interface is not supported.
  964. **/
  965. BOOLEAN
  966. EFIAPI
  967. CryptoServiceSha512Duplicate (
  968. IN CONST VOID *Sha512Context,
  969. OUT VOID *NewSha512Context
  970. )
  971. {
  972. return CALL_BASECRYPTLIB (Sha512.Services.Duplicate, Sha512Duplicate, (Sha512Context, NewSha512Context), FALSE);
  973. }
  974. /**
  975. Digests the input data and updates SHA-512 context.
  976. This function performs SHA-512 digest on a data buffer of the specified size.
  977. It can be called multiple times to compute the digest of long or discontinuous data streams.
  978. SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
  979. by Sha512Final(). Behavior with invalid context is undefined.
  980. If Sha512Context is NULL, then return FALSE.
  981. @param[in, out] Sha512Context Pointer to the SHA-512 context.
  982. @param[in] Data Pointer to the buffer containing the data to be hashed.
  983. @param[in] DataSize Size of Data buffer in bytes.
  984. @retval TRUE SHA-512 data digest succeeded.
  985. @retval FALSE SHA-512 data digest failed.
  986. **/
  987. BOOLEAN
  988. EFIAPI
  989. CryptoServiceSha512Update (
  990. IN OUT VOID *Sha512Context,
  991. IN CONST VOID *Data,
  992. IN UINTN DataSize
  993. )
  994. {
  995. return CALL_BASECRYPTLIB (Sha512.Services.Update, Sha512Update, (Sha512Context, Data, DataSize), FALSE);
  996. }
  997. /**
  998. Completes computation of the SHA-512 digest value.
  999. This function completes SHA-512 hash computation and retrieves the digest value into
  1000. the specified memory. After this function has been called, the SHA-512 context cannot
  1001. be used again.
  1002. SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
  1003. finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
  1004. If Sha512Context is NULL, then return FALSE.
  1005. If HashValue is NULL, then return FALSE.
  1006. @param[in, out] Sha512Context Pointer to the SHA-512 context.
  1007. @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
  1008. value (64 bytes).
  1009. @retval TRUE SHA-512 digest computation succeeded.
  1010. @retval FALSE SHA-512 digest computation failed.
  1011. **/
  1012. BOOLEAN
  1013. EFIAPI
  1014. CryptoServiceSha512Final (
  1015. IN OUT VOID *Sha512Context,
  1016. OUT UINT8 *HashValue
  1017. )
  1018. {
  1019. return CALL_BASECRYPTLIB (Sha512.Services.Final, Sha512Final, (Sha512Context, HashValue), FALSE);
  1020. }
  1021. /**
  1022. Computes the SHA-512 message digest of a input data buffer.
  1023. This function performs the SHA-512 message digest of a given data buffer, and places
  1024. the digest value into the specified memory.
  1025. If this interface is not supported, then return FALSE.
  1026. @param[in] Data Pointer to the buffer containing the data to be hashed.
  1027. @param[in] DataSize Size of Data buffer in bytes.
  1028. @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
  1029. value (64 bytes).
  1030. @retval TRUE SHA-512 digest computation succeeded.
  1031. @retval FALSE SHA-512 digest computation failed.
  1032. @retval FALSE This interface is not supported.
  1033. **/
  1034. BOOLEAN
  1035. EFIAPI
  1036. CryptoServiceSha512HashAll (
  1037. IN CONST VOID *Data,
  1038. IN UINTN DataSize,
  1039. OUT UINT8 *HashValue
  1040. )
  1041. {
  1042. return CALL_BASECRYPTLIB (Sha512.Services.HashAll, Sha512HashAll, (Data, DataSize, HashValue), FALSE);
  1043. }
  1044. /**
  1045. Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.
  1046. @return The size, in bytes, of the context buffer required for SM3 hash operations.
  1047. **/
  1048. UINTN
  1049. EFIAPI
  1050. CryptoServiceSm3GetContextSize (
  1051. VOID
  1052. )
  1053. {
  1054. return CALL_BASECRYPTLIB (Sm3.Services.GetContextSize, Sm3GetContextSize, (), 0);
  1055. }
  1056. /**
  1057. Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for
  1058. subsequent use.
  1059. If Sm3Context is NULL, then return FALSE.
  1060. @param[out] Sm3Context Pointer to SM3 context being initialized.
  1061. @retval TRUE SM3 context initialization succeeded.
  1062. @retval FALSE SM3 context initialization failed.
  1063. **/
  1064. BOOLEAN
  1065. EFIAPI
  1066. CryptoServiceSm3Init (
  1067. OUT VOID *Sm3Context
  1068. )
  1069. {
  1070. return CALL_BASECRYPTLIB (Sm3.Services.Init, Sm3Init, (Sm3Context), FALSE);
  1071. }
  1072. /**
  1073. Makes a copy of an existing SM3 context.
  1074. If Sm3Context is NULL, then return FALSE.
  1075. If NewSm3Context is NULL, then return FALSE.
  1076. If this interface is not supported, then return FALSE.
  1077. @param[in] Sm3Context Pointer to SM3 context being copied.
  1078. @param[out] NewSm3Context Pointer to new SM3 context.
  1079. @retval TRUE SM3 context copy succeeded.
  1080. @retval FALSE SM3 context copy failed.
  1081. @retval FALSE This interface is not supported.
  1082. **/
  1083. BOOLEAN
  1084. EFIAPI
  1085. CryptoServiceSm3Duplicate (
  1086. IN CONST VOID *Sm3Context,
  1087. OUT VOID *NewSm3Context
  1088. )
  1089. {
  1090. return CALL_BASECRYPTLIB (Sm3.Services.Duplicate, Sm3Duplicate, (Sm3Context, NewSm3Context), FALSE);
  1091. }
  1092. /**
  1093. Digests the input data and updates SM3 context.
  1094. This function performs SM3 digest on a data buffer of the specified size.
  1095. It can be called multiple times to compute the digest of long or discontinuous data streams.
  1096. SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized
  1097. by Sm3Final(). Behavior with invalid context is undefined.
  1098. If Sm3Context is NULL, then return FALSE.
  1099. @param[in, out] Sm3Context Pointer to the SM3 context.
  1100. @param[in] Data Pointer to the buffer containing the data to be hashed.
  1101. @param[in] DataSize Size of Data buffer in bytes.
  1102. @retval TRUE SM3 data digest succeeded.
  1103. @retval FALSE SM3 data digest failed.
  1104. **/
  1105. BOOLEAN
  1106. EFIAPI
  1107. CryptoServiceSm3Update (
  1108. IN OUT VOID *Sm3Context,
  1109. IN CONST VOID *Data,
  1110. IN UINTN DataSize
  1111. )
  1112. {
  1113. return CALL_BASECRYPTLIB (Sm3.Services.Update, Sm3Update, (Sm3Context, Data, DataSize), FALSE);
  1114. }
  1115. /**
  1116. Completes computation of the SM3 digest value.
  1117. This function completes SM3 hash computation and retrieves the digest value into
  1118. the specified memory. After this function has been called, the SM3 context cannot
  1119. be used again.
  1120. SM3 context should be already correctly initialized by Sm3Init(), and should not be
  1121. finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.
  1122. If Sm3Context is NULL, then return FALSE.
  1123. If HashValue is NULL, then return FALSE.
  1124. @param[in, out] Sm3Context Pointer to the SM3 context.
  1125. @param[out] HashValue Pointer to a buffer that receives the SM3 digest
  1126. value (32 bytes).
  1127. @retval TRUE SM3 digest computation succeeded.
  1128. @retval FALSE SM3 digest computation failed.
  1129. **/
  1130. BOOLEAN
  1131. EFIAPI
  1132. CryptoServiceSm3Final (
  1133. IN OUT VOID *Sm3Context,
  1134. OUT UINT8 *HashValue
  1135. )
  1136. {
  1137. return CALL_BASECRYPTLIB (Sm3.Services.Final, Sm3Final, (Sm3Context, HashValue), FALSE);
  1138. }
  1139. /**
  1140. Computes the SM3 message digest of a input data buffer.
  1141. This function performs the SM3 message digest of a given data buffer, and places
  1142. the digest value into the specified memory.
  1143. If this interface is not supported, then return FALSE.
  1144. @param[in] Data Pointer to the buffer containing the data to be hashed.
  1145. @param[in] DataSize Size of Data buffer in bytes.
  1146. @param[out] HashValue Pointer to a buffer that receives the SM3 digest
  1147. value (32 bytes).
  1148. @retval TRUE SM3 digest computation succeeded.
  1149. @retval FALSE SM3 digest computation failed.
  1150. @retval FALSE This interface is not supported.
  1151. **/
  1152. BOOLEAN
  1153. EFIAPI
  1154. CryptoServiceSm3HashAll (
  1155. IN CONST VOID *Data,
  1156. IN UINTN DataSize,
  1157. OUT UINT8 *HashValue
  1158. )
  1159. {
  1160. return CALL_BASECRYPTLIB (Sm3.Services.HashAll, Sm3HashAll, (Data, DataSize, HashValue), FALSE);
  1161. }
  1162. // =====================================================================================
  1163. // MAC (Message Authentication Code) Primitive
  1164. // =====================================================================================
  1165. /**
  1166. HMAC MD5 is deprecated and unsupported any longer.
  1167. Keep the function field for binary compability.
  1168. @retval NULL This interface is not supported.
  1169. **/
  1170. VOID *
  1171. EFIAPI
  1172. DeprecatedCryptoServiceHmacMd5New (
  1173. VOID
  1174. )
  1175. {
  1176. return BaseCryptLibServiceDeprecated ("HmacMd5New"), NULL;
  1177. }
  1178. /**
  1179. HMAC MD5 is deprecated and unsupported any longer.
  1180. Keep the function field for binary compability.
  1181. @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.
  1182. **/
  1183. VOID
  1184. EFIAPI
  1185. DeprecatedCryptoServiceHmacMd5Free (
  1186. IN VOID *HmacMd5Ctx
  1187. )
  1188. {
  1189. BaseCryptLibServiceDeprecated ("HmacMd5Free");
  1190. }
  1191. /**
  1192. HMAC MD5 is deprecated and unsupported any longer.
  1193. Keep the function field for binary compability.
  1194. @param[out] HmacMd5Context Pointer to HMAC-MD5 context.
  1195. @param[in] Key Pointer to the user-supplied key.
  1196. @param[in] KeySize Key size in bytes.
  1197. @retval FALSE This interface is not supported.
  1198. **/
  1199. BOOLEAN
  1200. EFIAPI
  1201. DeprecatedCryptoServiceHmacMd5SetKey (
  1202. OUT VOID *HmacMd5Context,
  1203. IN CONST UINT8 *Key,
  1204. IN UINTN KeySize
  1205. )
  1206. {
  1207. return BaseCryptLibServiceDeprecated ("HmacMd5SetKey"), FALSE;
  1208. }
  1209. /**
  1210. HMAC MD5 is deprecated and unsupported any longer.
  1211. Keep the function field for binary compability.
  1212. @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
  1213. @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
  1214. @retval FALSE This interface is not supported.
  1215. **/
  1216. BOOLEAN
  1217. EFIAPI
  1218. DeprecatedCryptoServiceHmacMd5Duplicate (
  1219. IN CONST VOID *HmacMd5Context,
  1220. OUT VOID *NewHmacMd5Context
  1221. )
  1222. {
  1223. return BaseCryptLibServiceDeprecated ("HmacMd5Duplicate"), FALSE;
  1224. }
  1225. /**
  1226. HMAC MD5 is deprecated and unsupported any longer.
  1227. Keep the function field for binary compability.
  1228. @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
  1229. @param[in] Data Pointer to the buffer containing the data to be digested.
  1230. @param[in] DataSize Size of Data buffer in bytes.
  1231. @retval FALSE This interface is not supported.
  1232. **/
  1233. BOOLEAN
  1234. EFIAPI
  1235. DeprecatedCryptoServiceHmacMd5Update (
  1236. IN OUT VOID *HmacMd5Context,
  1237. IN CONST VOID *Data,
  1238. IN UINTN DataSize
  1239. )
  1240. {
  1241. return BaseCryptLibServiceDeprecated ("HmacMd5Update"), FALSE;
  1242. }
  1243. /**
  1244. HMAC MD5 is deprecated and unsupported any longer.
  1245. Keep the function field for binary compability.
  1246. @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
  1247. @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
  1248. value (16 bytes).
  1249. @retval FALSE This interface is not supported.
  1250. **/
  1251. BOOLEAN
  1252. EFIAPI
  1253. DeprecatedCryptoServiceHmacMd5Final (
  1254. IN OUT VOID *HmacMd5Context,
  1255. OUT UINT8 *HmacValue
  1256. )
  1257. {
  1258. return BaseCryptLibServiceDeprecated ("HmacMd5Final"), FALSE;
  1259. }
  1260. /**
  1261. HMAC SHA1 is deprecated and unsupported any longer.
  1262. Keep the function field for binary compability.
  1263. @return NULL This interface is not supported.
  1264. **/
  1265. VOID *
  1266. EFIAPI
  1267. DeprecatedCryptoServiceHmacSha1New (
  1268. VOID
  1269. )
  1270. {
  1271. return BaseCryptLibServiceDeprecated ("HmacSha1New"), NULL;
  1272. }
  1273. /**
  1274. HMAC SHA1 is deprecated and unsupported any longer.
  1275. Keep the function field for binary compability.
  1276. @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
  1277. **/
  1278. VOID
  1279. EFIAPI
  1280. DeprecatedCryptoServiceHmacSha1Free (
  1281. IN VOID *HmacSha1Ctx
  1282. )
  1283. {
  1284. BaseCryptLibServiceDeprecated ("HmacSha1Free");
  1285. }
  1286. /**
  1287. HMAC SHA1 is deprecated and unsupported any longer.
  1288. Keep the function field for binary compability.
  1289. @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.
  1290. @param[in] Key Pointer to the user-supplied key.
  1291. @param[in] KeySize Key size in bytes.
  1292. @retval FALSE This interface is not supported.
  1293. **/
  1294. BOOLEAN
  1295. EFIAPI
  1296. DeprecatedCryptoServiceHmacSha1SetKey (
  1297. OUT VOID *HmacSha1Context,
  1298. IN CONST UINT8 *Key,
  1299. IN UINTN KeySize
  1300. )
  1301. {
  1302. return BaseCryptLibServiceDeprecated ("HmacSha1SetKey"), FALSE;
  1303. }
  1304. /**
  1305. HMAC SHA1 is deprecated and unsupported any longer.
  1306. Keep the function field for binary compability.
  1307. @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
  1308. @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
  1309. @retval FALSE This interface is not supported.
  1310. **/
  1311. BOOLEAN
  1312. EFIAPI
  1313. DeprecatedCryptoServiceHmacSha1Duplicate (
  1314. IN CONST VOID *HmacSha1Context,
  1315. OUT VOID *NewHmacSha1Context
  1316. )
  1317. {
  1318. return BaseCryptLibServiceDeprecated ("HmacSha1Duplicate"), FALSE;
  1319. }
  1320. /**
  1321. HMAC SHA1 is deprecated and unsupported any longer.
  1322. Keep the function field for binary compability.
  1323. @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
  1324. @param[in] Data Pointer to the buffer containing the data to be digested.
  1325. @param[in] DataSize Size of Data buffer in bytes.
  1326. @retval FALSE This interface is not supported.
  1327. **/
  1328. BOOLEAN
  1329. EFIAPI
  1330. DeprecatedCryptoServiceHmacSha1Update (
  1331. IN OUT VOID *HmacSha1Context,
  1332. IN CONST VOID *Data,
  1333. IN UINTN DataSize
  1334. )
  1335. {
  1336. return BaseCryptLibServiceDeprecated ("HmacSha1Update"), FALSE;
  1337. }
  1338. /**
  1339. HMAC SHA1 is deprecated and unsupported any longer.
  1340. Keep the function field for binary compability.
  1341. @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
  1342. @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
  1343. value (20 bytes).
  1344. @retval FALSE This interface is not supported.
  1345. **/
  1346. BOOLEAN
  1347. EFIAPI
  1348. DeprecatedCryptoServiceHmacSha1Final (
  1349. IN OUT VOID *HmacSha1Context,
  1350. OUT UINT8 *HmacValue
  1351. )
  1352. {
  1353. return BaseCryptLibServiceDeprecated ("HmacSha1Final"), FALSE;
  1354. }
  1355. /**
  1356. Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
  1357. @return Pointer to the HMAC_CTX context that has been initialized.
  1358. If the allocations fails, HmacSha256New() returns NULL.
  1359. **/
  1360. VOID *
  1361. EFIAPI
  1362. CryptoServiceHmacSha256New (
  1363. VOID
  1364. )
  1365. {
  1366. return CALL_BASECRYPTLIB (HmacSha256.Services.New, HmacSha256New, (), NULL);
  1367. }
  1368. /**
  1369. Release the specified HMAC_CTX context.
  1370. @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
  1371. **/
  1372. VOID
  1373. EFIAPI
  1374. CryptoServiceHmacSha256Free (
  1375. IN VOID *HmacSha256Ctx
  1376. )
  1377. {
  1378. CALL_VOID_BASECRYPTLIB (HmacSha256.Services.Free, HmacSha256Free, (HmacSha256Ctx));
  1379. }
  1380. /**
  1381. Set user-supplied key for subsequent use. It must be done before any
  1382. calling to HmacSha256Update().
  1383. If HmacSha256Context is NULL, then return FALSE.
  1384. If this interface is not supported, then return FALSE.
  1385. @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
  1386. @param[in] Key Pointer to the user-supplied key.
  1387. @param[in] KeySize Key size in bytes.
  1388. @retval TRUE The Key is set successfully.
  1389. @retval FALSE The Key is set unsuccessfully.
  1390. @retval FALSE This interface is not supported.
  1391. **/
  1392. BOOLEAN
  1393. EFIAPI
  1394. CryptoServiceHmacSha256SetKey (
  1395. OUT VOID *HmacSha256Context,
  1396. IN CONST UINT8 *Key,
  1397. IN UINTN KeySize
  1398. )
  1399. {
  1400. return CALL_BASECRYPTLIB (HmacSha256.Services.SetKey, HmacSha256SetKey, (HmacSha256Context, Key, KeySize), FALSE);
  1401. }
  1402. /**
  1403. Makes a copy of an existing HMAC-SHA256 context.
  1404. If HmacSha256Context is NULL, then return FALSE.
  1405. If NewHmacSha256Context is NULL, then return FALSE.
  1406. If this interface is not supported, then return FALSE.
  1407. @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
  1408. @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
  1409. @retval TRUE HMAC-SHA256 context copy succeeded.
  1410. @retval FALSE HMAC-SHA256 context copy failed.
  1411. @retval FALSE This interface is not supported.
  1412. **/
  1413. BOOLEAN
  1414. EFIAPI
  1415. CryptoServiceHmacSha256Duplicate (
  1416. IN CONST VOID *HmacSha256Context,
  1417. OUT VOID *NewHmacSha256Context
  1418. )
  1419. {
  1420. return CALL_BASECRYPTLIB (HmacSha256.Services.Duplicate, HmacSha256Duplicate, (HmacSha256Context, NewHmacSha256Context), FALSE);
  1421. }
  1422. /**
  1423. Digests the input data and updates HMAC-SHA256 context.
  1424. This function performs HMAC-SHA256 digest on a data buffer of the specified size.
  1425. It can be called multiple times to compute the digest of long or discontinuous data streams.
  1426. HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
  1427. by HmacSha256Final(). Behavior with invalid context is undefined.
  1428. If HmacSha256Context is NULL, then return FALSE.
  1429. If this interface is not supported, then return FALSE.
  1430. @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
  1431. @param[in] Data Pointer to the buffer containing the data to be digested.
  1432. @param[in] DataSize Size of Data buffer in bytes.
  1433. @retval TRUE HMAC-SHA256 data digest succeeded.
  1434. @retval FALSE HMAC-SHA256 data digest failed.
  1435. @retval FALSE This interface is not supported.
  1436. **/
  1437. BOOLEAN
  1438. EFIAPI
  1439. CryptoServiceHmacSha256Update (
  1440. IN OUT VOID *HmacSha256Context,
  1441. IN CONST VOID *Data,
  1442. IN UINTN DataSize
  1443. )
  1444. {
  1445. return CALL_BASECRYPTLIB (HmacSha256.Services.Update, HmacSha256Update, (HmacSha256Context, Data, DataSize), FALSE);
  1446. }
  1447. /**
  1448. Completes computation of the HMAC-SHA256 digest value.
  1449. This function completes HMAC-SHA256 hash computation and retrieves the digest value into
  1450. the specified memory. After this function has been called, the HMAC-SHA256 context cannot
  1451. be used again.
  1452. HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
  1453. by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
  1454. If HmacSha256Context is NULL, then return FALSE.
  1455. If HmacValue is NULL, then return FALSE.
  1456. If this interface is not supported, then return FALSE.
  1457. @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
  1458. @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
  1459. value (32 bytes).
  1460. @retval TRUE HMAC-SHA256 digest computation succeeded.
  1461. @retval FALSE HMAC-SHA256 digest computation failed.
  1462. @retval FALSE This interface is not supported.
  1463. **/
  1464. BOOLEAN
  1465. EFIAPI
  1466. CryptoServiceHmacSha256Final (
  1467. IN OUT VOID *HmacSha256Context,
  1468. OUT UINT8 *HmacValue
  1469. )
  1470. {
  1471. return CALL_BASECRYPTLIB (HmacSha256.Services.Final, HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);
  1472. }
  1473. /**
  1474. Computes the HMAC-SHA256 digest of a input data buffer.
  1475. This function performs the HMAC-SHA256 digest of a given data buffer, and places
  1476. the digest value into the specified memory.
  1477. If this interface is not supported, then return FALSE.
  1478. @param[in] Data Pointer to the buffer containing the data to be digested.
  1479. @param[in] DataSize Size of Data buffer in bytes.
  1480. @param[in] Key Pointer to the user-supplied key.
  1481. @param[in] KeySize Key size in bytes.
  1482. @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
  1483. value (32 bytes).
  1484. @retval TRUE HMAC-SHA256 digest computation succeeded.
  1485. @retval FALSE HMAC-SHA256 digest computation failed.
  1486. @retval FALSE This interface is not supported.
  1487. **/
  1488. BOOLEAN
  1489. EFIAPI
  1490. CryptoServiceHmacSha256All (
  1491. IN CONST VOID *Data,
  1492. IN UINTN DataSize,
  1493. IN CONST UINT8 *Key,
  1494. IN UINTN KeySize,
  1495. OUT UINT8 *HmacValue
  1496. )
  1497. {
  1498. return CALL_BASECRYPTLIB (HmacSha256.Services.All, HmacSha256All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);
  1499. }
  1500. /**
  1501. Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.
  1502. @return Pointer to the HMAC_CTX context that has been initialized.
  1503. If the allocations fails, HmacSha384New() returns NULL.
  1504. **/
  1505. VOID *
  1506. EFIAPI
  1507. CryptoServiceHmacSha384New (
  1508. VOID
  1509. )
  1510. {
  1511. return CALL_BASECRYPTLIB (HmacSha384.Services.New, HmacSha384New, (), NULL);
  1512. }
  1513. /**
  1514. Release the specified HMAC_CTX context.
  1515. @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.
  1516. **/
  1517. VOID
  1518. EFIAPI
  1519. CryptoServiceHmacSha384Free (
  1520. IN VOID *HmacSha384Ctx
  1521. )
  1522. {
  1523. CALL_VOID_BASECRYPTLIB (HmacSha384.Services.Free, HmacSha384Free, (HmacSha384Ctx));
  1524. }
  1525. /**
  1526. Set user-supplied key for subsequent use. It must be done before any
  1527. calling to HmacSha384Update().
  1528. If HmacSha384Context is NULL, then return FALSE.
  1529. If this interface is not supported, then return FALSE.
  1530. @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.
  1531. @param[in] Key Pointer to the user-supplied key.
  1532. @param[in] KeySize Key size in bytes.
  1533. @retval TRUE The Key is set successfully.
  1534. @retval FALSE The Key is set unsuccessfully.
  1535. @retval FALSE This interface is not supported.
  1536. **/
  1537. BOOLEAN
  1538. EFIAPI
  1539. CryptoServiceHmacSha384SetKey (
  1540. OUT VOID *HmacSha384Context,
  1541. IN CONST UINT8 *Key,
  1542. IN UINTN KeySize
  1543. )
  1544. {
  1545. return CALL_BASECRYPTLIB (HmacSha384.Services.SetKey, HmacSha384SetKey, (HmacSha384Context, Key, KeySize), FALSE);
  1546. }
  1547. /**
  1548. Makes a copy of an existing HMAC-SHA384 context.
  1549. If HmacSha384Context is NULL, then return FALSE.
  1550. If NewHmacSha384Context is NULL, then return FALSE.
  1551. If this interface is not supported, then return FALSE.
  1552. @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.
  1553. @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.
  1554. @retval TRUE HMAC-SHA384 context copy succeeded.
  1555. @retval FALSE HMAC-SHA384 context copy failed.
  1556. @retval FALSE This interface is not supported.
  1557. **/
  1558. BOOLEAN
  1559. EFIAPI
  1560. CryptoServiceHmacSha384Duplicate (
  1561. IN CONST VOID *HmacSha384Context,
  1562. OUT VOID *NewHmacSha384Context
  1563. )
  1564. {
  1565. return CALL_BASECRYPTLIB (HmacSha384.Services.Duplicate, HmacSha256Duplicate, (HmacSha384Context, NewHmacSha384Context), FALSE);
  1566. }
  1567. /**
  1568. Digests the input data and updates HMAC-SHA384 context.
  1569. This function performs HMAC-SHA384 digest on a data buffer of the specified size.
  1570. It can be called multiple times to compute the digest of long or discontinuous data streams.
  1571. HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
  1572. by HmacSha384Final(). Behavior with invalid context is undefined.
  1573. If HmacSha384Context is NULL, then return FALSE.
  1574. If this interface is not supported, then return FALSE.
  1575. @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
  1576. @param[in] Data Pointer to the buffer containing the data to be digested.
  1577. @param[in] DataSize Size of Data buffer in bytes.
  1578. @retval TRUE HMAC-SHA384 data digest succeeded.
  1579. @retval FALSE HMAC-SHA384 data digest failed.
  1580. @retval FALSE This interface is not supported.
  1581. **/
  1582. BOOLEAN
  1583. EFIAPI
  1584. CryptoServiceHmacSha384Update (
  1585. IN OUT VOID *HmacSha384Context,
  1586. IN CONST VOID *Data,
  1587. IN UINTN DataSize
  1588. )
  1589. {
  1590. return CALL_BASECRYPTLIB (HmacSha384.Services.Update, HmacSha384Update, (HmacSha384Context, Data, DataSize), FALSE);
  1591. }
  1592. /**
  1593. Completes computation of the HMAC-SHA384 digest value.
  1594. This function completes HMAC-SHA384 hash computation and retrieves the digest value into
  1595. the specified memory. After this function has been called, the HMAC-SHA384 context cannot
  1596. be used again.
  1597. HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized
  1598. by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.
  1599. If HmacSha384Context is NULL, then return FALSE.
  1600. If HmacValue is NULL, then return FALSE.
  1601. If this interface is not supported, then return FALSE.
  1602. @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.
  1603. @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest
  1604. value (48 bytes).
  1605. @retval TRUE HMAC-SHA384 digest computation succeeded.
  1606. @retval FALSE HMAC-SHA384 digest computation failed.
  1607. @retval FALSE This interface is not supported.
  1608. **/
  1609. BOOLEAN
  1610. EFIAPI
  1611. CryptoServiceHmacSha384Final (
  1612. IN OUT VOID *HmacSha384Context,
  1613. OUT UINT8 *HmacValue
  1614. )
  1615. {
  1616. return CALL_BASECRYPTLIB (HmacSha384.Services.Final, HmacSha384Final, (HmacSha384Context, HmacValue), FALSE);
  1617. }
  1618. /**
  1619. Computes the HMAC-SHA384 digest of a input data buffer.
  1620. This function performs the HMAC-SHA384 digest of a given data buffer, and places
  1621. the digest value into the specified memory.
  1622. If this interface is not supported, then return FALSE.
  1623. @param[in] Data Pointer to the buffer containing the data to be digested.
  1624. @param[in] DataSize Size of Data buffer in bytes.
  1625. @param[in] Key Pointer to the user-supplied key.
  1626. @param[in] KeySize Key size in bytes.
  1627. @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest
  1628. value (48 bytes).
  1629. @retval TRUE HMAC-SHA384 digest computation succeeded.
  1630. @retval FALSE HMAC-SHA384 digest computation failed.
  1631. @retval FALSE This interface is not supported.
  1632. **/
  1633. BOOLEAN
  1634. EFIAPI
  1635. CryptoServiceHmacSha384All (
  1636. IN CONST VOID *Data,
  1637. IN UINTN DataSize,
  1638. IN CONST UINT8 *Key,
  1639. IN UINTN KeySize,
  1640. OUT UINT8 *HmacValue
  1641. )
  1642. {
  1643. return CALL_BASECRYPTLIB (HmacSha384.Services.All, HmacSha384All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);
  1644. }
  1645. // =====================================================================================
  1646. // Symmetric Cryptography Primitive
  1647. // =====================================================================================
  1648. /**
  1649. TDES is deprecated and unsupported any longer.
  1650. Keep the function field for binary compability.
  1651. @retval 0 This interface is not supported.
  1652. **/
  1653. UINTN
  1654. EFIAPI
  1655. DeprecatedCryptoServiceTdesGetContextSize (
  1656. VOID
  1657. )
  1658. {
  1659. return BaseCryptLibServiceDeprecated ("TdesGetContextSize"), 0;
  1660. }
  1661. /**
  1662. TDES is deprecated and unsupported any longer.
  1663. Keep the function field for binary compability.
  1664. @param[out] TdesContext Pointer to TDES context being initialized.
  1665. @param[in] Key Pointer to the user-supplied TDES key.
  1666. @param[in] KeyLength Length of TDES key in bits.
  1667. @retval FALSE This interface is not supported.
  1668. **/
  1669. BOOLEAN
  1670. EFIAPI
  1671. DeprecatedCryptoServiceTdesInit (
  1672. OUT VOID *TdesContext,
  1673. IN CONST UINT8 *Key,
  1674. IN UINTN KeyLength
  1675. )
  1676. {
  1677. return BaseCryptLibServiceDeprecated ("TdesInit"), FALSE;
  1678. }
  1679. /**
  1680. TDES is deprecated and unsupported any longer.
  1681. Keep the function field for binary compability.
  1682. @param[in] TdesContext Pointer to the TDES context.
  1683. @param[in] Input Pointer to the buffer containing the data to be encrypted.
  1684. @param[in] InputSize Size of the Input buffer in bytes.
  1685. @param[out] Output Pointer to a buffer that receives the TDES encryption output.
  1686. @retval FALSE This interface is not supported.
  1687. **/
  1688. BOOLEAN
  1689. EFIAPI
  1690. DeprecatedCryptoServiceTdesEcbEncrypt (
  1691. IN VOID *TdesContext,
  1692. IN CONST UINT8 *Input,
  1693. IN UINTN InputSize,
  1694. OUT UINT8 *Output
  1695. )
  1696. {
  1697. return BaseCryptLibServiceDeprecated ("TdesEcbEncrypt"), FALSE;
  1698. }
  1699. /**
  1700. TDES is deprecated and unsupported any longer.
  1701. Keep the function field for binary compability.
  1702. @param[in] TdesContext Pointer to the TDES context.
  1703. @param[in] Input Pointer to the buffer containing the data to be decrypted.
  1704. @param[in] InputSize Size of the Input buffer in bytes.
  1705. @param[out] Output Pointer to a buffer that receives the TDES decryption output.
  1706. @retval FALSE This interface is not supported.
  1707. **/
  1708. BOOLEAN
  1709. EFIAPI
  1710. DeprecatedCryptoServiceTdesEcbDecrypt (
  1711. IN VOID *TdesContext,
  1712. IN CONST UINT8 *Input,
  1713. IN UINTN InputSize,
  1714. OUT UINT8 *Output
  1715. )
  1716. {
  1717. return BaseCryptLibServiceDeprecated ("TdesEcbDecrypt"), FALSE;
  1718. }
  1719. /**
  1720. TDES is deprecated and unsupported any longer.
  1721. Keep the function field for binary compability.
  1722. @param[in] TdesContext Pointer to the TDES context.
  1723. @param[in] Input Pointer to the buffer containing the data to be encrypted.
  1724. @param[in] InputSize Size of the Input buffer in bytes.
  1725. @param[in] Ivec Pointer to initialization vector.
  1726. @param[out] Output Pointer to a buffer that receives the TDES encryption output.
  1727. @retval FALSE This interface is not supported.
  1728. **/
  1729. BOOLEAN
  1730. EFIAPI
  1731. DeprecatedCryptoServiceTdesCbcEncrypt (
  1732. IN VOID *TdesContext,
  1733. IN CONST UINT8 *Input,
  1734. IN UINTN InputSize,
  1735. IN CONST UINT8 *Ivec,
  1736. OUT UINT8 *Output
  1737. )
  1738. {
  1739. return BaseCryptLibServiceDeprecated ("TdesCbcEncrypt"), FALSE;
  1740. }
  1741. /**
  1742. TDES is deprecated and unsupported any longer.
  1743. Keep the function field for binary compability.
  1744. @param[in] TdesContext Pointer to the TDES context.
  1745. @param[in] Input Pointer to the buffer containing the data to be encrypted.
  1746. @param[in] InputSize Size of the Input buffer in bytes.
  1747. @param[in] Ivec Pointer to initialization vector.
  1748. @param[out] Output Pointer to a buffer that receives the TDES encryption output.
  1749. @retval FALSE This interface is not supported.
  1750. **/
  1751. BOOLEAN
  1752. EFIAPI
  1753. DeprecatedCryptoServiceTdesCbcDecrypt (
  1754. IN VOID *TdesContext,
  1755. IN CONST UINT8 *Input,
  1756. IN UINTN InputSize,
  1757. IN CONST UINT8 *Ivec,
  1758. OUT UINT8 *Output
  1759. )
  1760. {
  1761. return BaseCryptLibServiceDeprecated ("TdesCbcDecrypt"), FALSE;
  1762. }
  1763. /**
  1764. Retrieves the size, in bytes, of the context buffer required for AES operations.
  1765. If this interface is not supported, then return zero.
  1766. @return The size, in bytes, of the context buffer required for AES operations.
  1767. @retval 0 This interface is not supported.
  1768. **/
  1769. UINTN
  1770. EFIAPI
  1771. CryptoServiceAesGetContextSize (
  1772. VOID
  1773. )
  1774. {
  1775. return CALL_BASECRYPTLIB (Aes.Services.GetContextSize, AesGetContextSize, (), 0);
  1776. }
  1777. /**
  1778. Initializes user-supplied memory as AES context for subsequent use.
  1779. This function initializes user-supplied memory pointed by AesContext as AES context.
  1780. In addition, it sets up all AES key materials for subsequent encryption and decryption
  1781. operations.
  1782. There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
  1783. If AesContext is NULL, then return FALSE.
  1784. If Key is NULL, then return FALSE.
  1785. If KeyLength is not valid, then return FALSE.
  1786. If this interface is not supported, then return FALSE.
  1787. @param[out] AesContext Pointer to AES context being initialized.
  1788. @param[in] Key Pointer to the user-supplied AES key.
  1789. @param[in] KeyLength Length of AES key in bits.
  1790. @retval TRUE AES context initialization succeeded.
  1791. @retval FALSE AES context initialization failed.
  1792. @retval FALSE This interface is not supported.
  1793. **/
  1794. BOOLEAN
  1795. EFIAPI
  1796. CryptoServiceAesInit (
  1797. OUT VOID *AesContext,
  1798. IN CONST UINT8 *Key,
  1799. IN UINTN KeyLength
  1800. )
  1801. {
  1802. return CALL_BASECRYPTLIB (Aes.Services.Init, AesInit, (AesContext, Key, KeyLength), FALSE);
  1803. }
  1804. /**
  1805. AES ECB Mode is deprecated and unsupported any longer.
  1806. Keep the function field for binary compability.
  1807. @param[in] AesContext Pointer to the AES context.
  1808. @param[in] Input Pointer to the buffer containing the data to be encrypted.
  1809. @param[in] InputSize Size of the Input buffer in bytes.
  1810. @param[out] Output Pointer to a buffer that receives the AES encryption output.
  1811. @retval FALSE This interface is not supported.
  1812. **/
  1813. BOOLEAN
  1814. EFIAPI
  1815. DeprecatedCryptoServiceAesEcbEncrypt (
  1816. IN VOID *AesContext,
  1817. IN CONST UINT8 *Input,
  1818. IN UINTN InputSize,
  1819. OUT UINT8 *Output
  1820. )
  1821. {
  1822. return BaseCryptLibServiceDeprecated ("AesEcbEncrypt"), FALSE;
  1823. }
  1824. /**
  1825. AES ECB Mode is deprecated and unsupported any longer.
  1826. Keep the function field for binary compability.
  1827. @param[in] AesContext Pointer to the AES context.
  1828. @param[in] Input Pointer to the buffer containing the data to be decrypted.
  1829. @param[in] InputSize Size of the Input buffer in bytes.
  1830. @param[out] Output Pointer to a buffer that receives the AES decryption output.
  1831. @retval FALSE This interface is not supported.
  1832. **/
  1833. BOOLEAN
  1834. EFIAPI
  1835. DeprecatedCryptoServiceAesEcbDecrypt (
  1836. IN VOID *AesContext,
  1837. IN CONST UINT8 *Input,
  1838. IN UINTN InputSize,
  1839. OUT UINT8 *Output
  1840. )
  1841. {
  1842. return BaseCryptLibServiceDeprecated ("AesEcbDecrypt"), FALSE;
  1843. }
  1844. /**
  1845. Performs AES encryption on a data buffer of the specified size in CBC mode.
  1846. This function performs AES encryption on data buffer pointed by Input, of specified
  1847. size of InputSize, in CBC mode.
  1848. InputSize must be multiple of block size (16 bytes). This function does not perform
  1849. padding. Caller must perform padding, if necessary, to ensure valid input data size.
  1850. Initialization vector should be one block size (16 bytes).
  1851. AesContext should be already correctly initialized by AesInit(). Behavior with
  1852. invalid AES context is undefined.
  1853. If AesContext is NULL, then return FALSE.
  1854. If Input is NULL, then return FALSE.
  1855. If InputSize is not multiple of block size (16 bytes), then return FALSE.
  1856. If Ivec is NULL, then return FALSE.
  1857. If Output is NULL, then return FALSE.
  1858. If this interface is not supported, then return FALSE.
  1859. @param[in] AesContext Pointer to the AES context.
  1860. @param[in] Input Pointer to the buffer containing the data to be encrypted.
  1861. @param[in] InputSize Size of the Input buffer in bytes.
  1862. @param[in] Ivec Pointer to initialization vector.
  1863. @param[out] Output Pointer to a buffer that receives the AES encryption output.
  1864. @retval TRUE AES encryption succeeded.
  1865. @retval FALSE AES encryption failed.
  1866. @retval FALSE This interface is not supported.
  1867. **/
  1868. BOOLEAN
  1869. EFIAPI
  1870. CryptoServiceAesCbcEncrypt (
  1871. IN VOID *AesContext,
  1872. IN CONST UINT8 *Input,
  1873. IN UINTN InputSize,
  1874. IN CONST UINT8 *Ivec,
  1875. OUT UINT8 *Output
  1876. )
  1877. {
  1878. return CALL_BASECRYPTLIB (Aes.Services.CbcEncrypt, AesCbcEncrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);
  1879. }
  1880. /**
  1881. Performs AES decryption on a data buffer of the specified size in CBC mode.
  1882. This function performs AES decryption on data buffer pointed by Input, of specified
  1883. size of InputSize, in CBC mode.
  1884. InputSize must be multiple of block size (16 bytes). This function does not perform
  1885. padding. Caller must perform padding, if necessary, to ensure valid input data size.
  1886. Initialization vector should be one block size (16 bytes).
  1887. AesContext should be already correctly initialized by AesInit(). Behavior with
  1888. invalid AES context is undefined.
  1889. If AesContext is NULL, then return FALSE.
  1890. If Input is NULL, then return FALSE.
  1891. If InputSize is not multiple of block size (16 bytes), then return FALSE.
  1892. If Ivec is NULL, then return FALSE.
  1893. If Output is NULL, then return FALSE.
  1894. If this interface is not supported, then return FALSE.
  1895. @param[in] AesContext Pointer to the AES context.
  1896. @param[in] Input Pointer to the buffer containing the data to be encrypted.
  1897. @param[in] InputSize Size of the Input buffer in bytes.
  1898. @param[in] Ivec Pointer to initialization vector.
  1899. @param[out] Output Pointer to a buffer that receives the AES encryption output.
  1900. @retval TRUE AES decryption succeeded.
  1901. @retval FALSE AES decryption failed.
  1902. @retval FALSE This interface is not supported.
  1903. **/
  1904. BOOLEAN
  1905. EFIAPI
  1906. CryptoServiceAesCbcDecrypt (
  1907. IN VOID *AesContext,
  1908. IN CONST UINT8 *Input,
  1909. IN UINTN InputSize,
  1910. IN CONST UINT8 *Ivec,
  1911. OUT UINT8 *Output
  1912. )
  1913. {
  1914. return CALL_BASECRYPTLIB (Aes.Services.CbcDecrypt, AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);
  1915. }
  1916. /**
  1917. ARC4 is deprecated and unsupported any longer.
  1918. Keep the function field for binary compability.
  1919. @retval 0 This interface is not supported.
  1920. **/
  1921. UINTN
  1922. EFIAPI
  1923. DeprecatedCryptoServiceArc4GetContextSize (
  1924. VOID
  1925. )
  1926. {
  1927. return BaseCryptLibServiceDeprecated ("Arc4GetContextSize"), 0;
  1928. }
  1929. /**
  1930. ARC4 is deprecated and unsupported any longer.
  1931. Keep the function field for binary compability.
  1932. @param[out] Arc4Context Pointer to ARC4 context being initialized.
  1933. @param[in] Key Pointer to the user-supplied ARC4 key.
  1934. @param[in] KeySize Size of ARC4 key in bytes.
  1935. @retval FALSE This interface is not supported.
  1936. **/
  1937. BOOLEAN
  1938. EFIAPI
  1939. DeprecatedCryptoServiceArc4Init (
  1940. OUT VOID *Arc4Context,
  1941. IN CONST UINT8 *Key,
  1942. IN UINTN KeySize
  1943. )
  1944. {
  1945. return BaseCryptLibServiceDeprecated ("Arc4Init"), FALSE;
  1946. }
  1947. /**
  1948. ARC4 is deprecated and unsupported any longer.
  1949. Keep the function field for binary compability.
  1950. @param[in, out] Arc4Context Pointer to the ARC4 context.
  1951. @param[in] Input Pointer to the buffer containing the data to be encrypted.
  1952. @param[in] InputSize Size of the Input buffer in bytes.
  1953. @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
  1954. @retval FALSE This interface is not supported.
  1955. **/
  1956. BOOLEAN
  1957. EFIAPI
  1958. DeprecatedCryptoServiceArc4Encrypt (
  1959. IN OUT VOID *Arc4Context,
  1960. IN CONST UINT8 *Input,
  1961. IN UINTN InputSize,
  1962. OUT UINT8 *Output
  1963. )
  1964. {
  1965. return BaseCryptLibServiceDeprecated ("Arc4Encrypt"), FALSE;
  1966. }
  1967. /**
  1968. ARC4 is deprecated and unsupported any longer.
  1969. Keep the function field for binary compability.
  1970. @param[in, out] Arc4Context Pointer to the ARC4 context.
  1971. @param[in] Input Pointer to the buffer containing the data to be decrypted.
  1972. @param[in] InputSize Size of the Input buffer in bytes.
  1973. @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
  1974. @retval FALSE This interface is not supported.
  1975. **/
  1976. BOOLEAN
  1977. EFIAPI
  1978. DeprecatedCryptoServiceArc4Decrypt (
  1979. IN OUT VOID *Arc4Context,
  1980. IN UINT8 *Input,
  1981. IN UINTN InputSize,
  1982. OUT UINT8 *Output
  1983. )
  1984. {
  1985. return BaseCryptLibServiceDeprecated ("Arc4Decrypt"), FALSE;
  1986. }
  1987. /**
  1988. ARC4 is deprecated and unsupported any longer.
  1989. Keep the function field for binary compability.
  1990. @param[in, out] Arc4Context Pointer to the ARC4 context.
  1991. @retval FALSE This interface is not supported.
  1992. **/
  1993. BOOLEAN
  1994. EFIAPI
  1995. DeprecatedCryptoServiceArc4Reset (
  1996. IN OUT VOID *Arc4Context
  1997. )
  1998. {
  1999. return BaseCryptLibServiceDeprecated ("Arc4Reset"), FALSE;
  2000. }
  2001. // =====================================================================================
  2002. // Asymmetric Cryptography Primitive
  2003. // =====================================================================================
  2004. /**
  2005. Allocates and initializes one RSA context for subsequent use.
  2006. @return Pointer to the RSA context that has been initialized.
  2007. If the allocations fails, RsaNew() returns NULL.
  2008. **/
  2009. VOID *
  2010. EFIAPI
  2011. CryptoServiceRsaNew (
  2012. VOID
  2013. )
  2014. {
  2015. return CALL_BASECRYPTLIB (Rsa.Services.New, RsaNew, (), NULL);
  2016. }
  2017. /**
  2018. Release the specified RSA context.
  2019. If RsaContext is NULL, then return FALSE.
  2020. @param[in] RsaContext Pointer to the RSA context to be released.
  2021. **/
  2022. VOID
  2023. EFIAPI
  2024. CryptoServiceRsaFree (
  2025. IN VOID *RsaContext
  2026. )
  2027. {
  2028. CALL_VOID_BASECRYPTLIB (Rsa.Services.Free, RsaFree, (RsaContext));
  2029. }
  2030. /**
  2031. Sets the tag-designated key component into the established RSA context.
  2032. This function sets the tag-designated RSA key component into the established
  2033. RSA context from the user-specified non-negative integer (octet string format
  2034. represented in RSA PKCS#1).
  2035. If BigNumber is NULL, then the specified key component in RSA context is cleared.
  2036. If RsaContext is NULL, then return FALSE.
  2037. @param[in, out] RsaContext Pointer to RSA context being set.
  2038. @param[in] KeyTag Tag of RSA key component being set.
  2039. @param[in] BigNumber Pointer to octet integer buffer.
  2040. If NULL, then the specified key component in RSA
  2041. context is cleared.
  2042. @param[in] BnSize Size of big number buffer in bytes.
  2043. If BigNumber is NULL, then it is ignored.
  2044. @retval TRUE RSA key component was set successfully.
  2045. @retval FALSE Invalid RSA key component tag.
  2046. **/
  2047. BOOLEAN
  2048. EFIAPI
  2049. CryptoServiceRsaSetKey (
  2050. IN OUT VOID *RsaContext,
  2051. IN RSA_KEY_TAG KeyTag,
  2052. IN CONST UINT8 *BigNumber,
  2053. IN UINTN BnSize
  2054. )
  2055. {
  2056. return CALL_BASECRYPTLIB (Rsa.Services.SetKey, RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
  2057. }
  2058. /**
  2059. Gets the tag-designated RSA key component from the established RSA context.
  2060. This function retrieves the tag-designated RSA key component from the
  2061. established RSA context as a non-negative integer (octet string format
  2062. represented in RSA PKCS#1).
  2063. If specified key component has not been set or has been cleared, then returned
  2064. BnSize is set to 0.
  2065. If the BigNumber buffer is too small to hold the contents of the key, FALSE
  2066. is returned and BnSize is set to the required buffer size to obtain the key.
  2067. If RsaContext is NULL, then return FALSE.
  2068. If BnSize is NULL, then return FALSE.
  2069. If BnSize is large enough but BigNumber is NULL, then return FALSE.
  2070. If this interface is not supported, then return FALSE.
  2071. @param[in, out] RsaContext Pointer to RSA context being set.
  2072. @param[in] KeyTag Tag of RSA key component being set.
  2073. @param[out] BigNumber Pointer to octet integer buffer.
  2074. @param[in, out] BnSize On input, the size of big number buffer in bytes.
  2075. On output, the size of data returned in big number buffer in bytes.
  2076. @retval TRUE RSA key component was retrieved successfully.
  2077. @retval FALSE Invalid RSA key component tag.
  2078. @retval FALSE BnSize is too small.
  2079. @retval FALSE This interface is not supported.
  2080. **/
  2081. BOOLEAN
  2082. EFIAPI
  2083. CryptoServiceRsaGetKey (
  2084. IN OUT VOID *RsaContext,
  2085. IN RSA_KEY_TAG KeyTag,
  2086. OUT UINT8 *BigNumber,
  2087. IN OUT UINTN *BnSize
  2088. )
  2089. {
  2090. return CALL_BASECRYPTLIB (Rsa.Services.GetKey, RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
  2091. }
  2092. /**
  2093. Generates RSA key components.
  2094. This function generates RSA key components. It takes RSA public exponent E and
  2095. length in bits of RSA modulus N as input, and generates all key components.
  2096. If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
  2097. Before this function can be invoked, pseudorandom number generator must be correctly
  2098. initialized by RandomSeed().
  2099. If RsaContext is NULL, then return FALSE.
  2100. If this interface is not supported, then return FALSE.
  2101. @param[in, out] RsaContext Pointer to RSA context being set.
  2102. @param[in] ModulusLength Length of RSA modulus N in bits.
  2103. @param[in] PublicExponent Pointer to RSA public exponent.
  2104. @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
  2105. @retval TRUE RSA key component was generated successfully.
  2106. @retval FALSE Invalid RSA key component tag.
  2107. @retval FALSE This interface is not supported.
  2108. **/
  2109. BOOLEAN
  2110. EFIAPI
  2111. CryptoServiceRsaGenerateKey (
  2112. IN OUT VOID *RsaContext,
  2113. IN UINTN ModulusLength,
  2114. IN CONST UINT8 *PublicExponent,
  2115. IN UINTN PublicExponentSize
  2116. )
  2117. {
  2118. return CALL_BASECRYPTLIB (Rsa.Services.GenerateKey, RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);
  2119. }
  2120. /**
  2121. Validates key components of RSA context.
  2122. NOTE: This function performs integrity checks on all the RSA key material, so
  2123. the RSA key structure must contain all the private key data.
  2124. This function validates key components of RSA context in following aspects:
  2125. - Whether p is a prime
  2126. - Whether q is a prime
  2127. - Whether n = p * q
  2128. - Whether d*e = 1 mod lcm(p-1,q-1)
  2129. If RsaContext is NULL, then return FALSE.
  2130. If this interface is not supported, then return FALSE.
  2131. @param[in] RsaContext Pointer to RSA context to check.
  2132. @retval TRUE RSA key components are valid.
  2133. @retval FALSE RSA key components are not valid.
  2134. @retval FALSE This interface is not supported.
  2135. **/
  2136. BOOLEAN
  2137. EFIAPI
  2138. CryptoServiceRsaCheckKey (
  2139. IN VOID *RsaContext
  2140. )
  2141. {
  2142. return CALL_BASECRYPTLIB (Rsa.Services.CheckKey, RsaCheckKey, (RsaContext), FALSE);
  2143. }
  2144. /**
  2145. Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
  2146. This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
  2147. RSA PKCS#1.
  2148. If the Signature buffer is too small to hold the contents of signature, FALSE
  2149. is returned and SigSize is set to the required buffer size to obtain the signature.
  2150. If RsaContext is NULL, then return FALSE.
  2151. If MessageHash is NULL, then return FALSE.
  2152. If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
  2153. If SigSize is large enough but Signature is NULL, then return FALSE.
  2154. If this interface is not supported, then return FALSE.
  2155. @param[in] RsaContext Pointer to RSA context for signature generation.
  2156. @param[in] MessageHash Pointer to octet message hash to be signed.
  2157. @param[in] HashSize Size of the message hash in bytes.
  2158. @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
  2159. @param[in, out] SigSize On input, the size of Signature buffer in bytes.
  2160. On output, the size of data returned in Signature buffer in bytes.
  2161. @retval TRUE Signature successfully generated in PKCS1-v1_5.
  2162. @retval FALSE Signature generation failed.
  2163. @retval FALSE SigSize is too small.
  2164. @retval FALSE This interface is not supported.
  2165. **/
  2166. BOOLEAN
  2167. EFIAPI
  2168. CryptoServiceRsaPkcs1Sign (
  2169. IN VOID *RsaContext,
  2170. IN CONST UINT8 *MessageHash,
  2171. IN UINTN HashSize,
  2172. OUT UINT8 *Signature,
  2173. IN OUT UINTN *SigSize
  2174. )
  2175. {
  2176. return CALL_BASECRYPTLIB (Rsa.Services.Pkcs1Sign, RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
  2177. }
  2178. /**
  2179. Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
  2180. RSA PKCS#1.
  2181. If RsaContext is NULL, then return FALSE.
  2182. If MessageHash is NULL, then return FALSE.
  2183. If Signature is NULL, then return FALSE.
  2184. If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
  2185. @param[in] RsaContext Pointer to RSA context for signature verification.
  2186. @param[in] MessageHash Pointer to octet message hash to be checked.
  2187. @param[in] HashSize Size of the message hash in bytes.
  2188. @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
  2189. @param[in] SigSize Size of signature in bytes.
  2190. @retval TRUE Valid signature encoded in PKCS1-v1_5.
  2191. @retval FALSE Invalid signature or invalid RSA context.
  2192. **/
  2193. BOOLEAN
  2194. EFIAPI
  2195. CryptoServiceRsaPkcs1Verify (
  2196. IN VOID *RsaContext,
  2197. IN CONST UINT8 *MessageHash,
  2198. IN UINTN HashSize,
  2199. IN CONST UINT8 *Signature,
  2200. IN UINTN SigSize
  2201. )
  2202. {
  2203. return CALL_BASECRYPTLIB (Rsa.Services.Pkcs1Verify, RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
  2204. }
  2205. /**
  2206. Retrieve the RSA Private Key from the password-protected PEM key data.
  2207. If PemData is NULL, then return FALSE.
  2208. If RsaContext is NULL, then return FALSE.
  2209. If this interface is not supported, then return FALSE.
  2210. @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
  2211. @param[in] PemSize Size of the PEM key data in bytes.
  2212. @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
  2213. @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
  2214. RSA private key component. Use RsaFree() function to free the
  2215. resource.
  2216. @retval TRUE RSA Private Key was retrieved successfully.
  2217. @retval FALSE Invalid PEM key data or incorrect password.
  2218. @retval FALSE This interface is not supported.
  2219. **/
  2220. BOOLEAN
  2221. EFIAPI
  2222. CryptoServiceRsaGetPrivateKeyFromPem (
  2223. IN CONST UINT8 *PemData,
  2224. IN UINTN PemSize,
  2225. IN CONST CHAR8 *Password,
  2226. OUT VOID **RsaContext
  2227. )
  2228. {
  2229. return CALL_BASECRYPTLIB (Rsa.Services.GetPrivateKeyFromPem, RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);
  2230. }
  2231. /**
  2232. Retrieve the RSA Public Key from one DER-encoded X509 certificate.
  2233. If Cert is NULL, then return FALSE.
  2234. If RsaContext is NULL, then return FALSE.
  2235. If this interface is not supported, then return FALSE.
  2236. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2237. @param[in] CertSize Size of the X509 certificate in bytes.
  2238. @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
  2239. RSA public key component. Use RsaFree() function to free the
  2240. resource.
  2241. @retval TRUE RSA Public Key was retrieved successfully.
  2242. @retval FALSE Fail to retrieve RSA public key from X509 certificate.
  2243. @retval FALSE This interface is not supported.
  2244. **/
  2245. BOOLEAN
  2246. EFIAPI
  2247. CryptoServiceRsaGetPublicKeyFromX509 (
  2248. IN CONST UINT8 *Cert,
  2249. IN UINTN CertSize,
  2250. OUT VOID **RsaContext
  2251. )
  2252. {
  2253. return CALL_BASECRYPTLIB (Rsa.Services.GetPublicKeyFromX509, RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);
  2254. }
  2255. /**
  2256. Retrieve the subject bytes from one X.509 certificate.
  2257. If Cert is NULL, then return FALSE.
  2258. If SubjectSize is NULL, then return FALSE.
  2259. If this interface is not supported, then return FALSE.
  2260. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2261. @param[in] CertSize Size of the X509 certificate in bytes.
  2262. @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
  2263. @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
  2264. and the size of buffer returned CertSubject on output.
  2265. @retval TRUE The certificate subject retrieved successfully.
  2266. @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
  2267. The SubjectSize will be updated with the required size.
  2268. @retval FALSE This interface is not supported.
  2269. **/
  2270. BOOLEAN
  2271. EFIAPI
  2272. CryptoServiceX509GetSubjectName (
  2273. IN CONST UINT8 *Cert,
  2274. IN UINTN CertSize,
  2275. OUT UINT8 *CertSubject,
  2276. IN OUT UINTN *SubjectSize
  2277. )
  2278. {
  2279. return CALL_BASECRYPTLIB (X509.Services.GetSubjectName, X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);
  2280. }
  2281. /**
  2282. Retrieve the common name (CN) string from one X.509 certificate.
  2283. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2284. @param[in] CertSize Size of the X509 certificate in bytes.
  2285. @param[out] CommonName Buffer to contain the retrieved certificate common
  2286. name string (UTF8). At most CommonNameSize bytes will be
  2287. written and the string will be null terminated. May be
  2288. NULL in order to determine the size buffer needed.
  2289. @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
  2290. and the size of buffer returned CommonName on output.
  2291. If CommonName is NULL then the amount of space needed
  2292. in buffer (including the final null) is returned.
  2293. @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
  2294. @retval RETURN_INVALID_PARAMETER If Cert is NULL.
  2295. If CommonNameSize is NULL.
  2296. If CommonName is not NULL and *CommonNameSize is 0.
  2297. If Certificate is invalid.
  2298. @retval RETURN_NOT_FOUND If no CommonName entry exists.
  2299. @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
  2300. (including the final null) is returned in the
  2301. CommonNameSize parameter.
  2302. @retval RETURN_UNSUPPORTED The operation is not supported.
  2303. **/
  2304. RETURN_STATUS
  2305. EFIAPI
  2306. CryptoServiceX509GetCommonName (
  2307. IN CONST UINT8 *Cert,
  2308. IN UINTN CertSize,
  2309. OUT CHAR8 *CommonName OPTIONAL,
  2310. IN OUT UINTN *CommonNameSize
  2311. )
  2312. {
  2313. return CALL_BASECRYPTLIB (X509.Services.GetCommonName, X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);
  2314. }
  2315. /**
  2316. Retrieve the organization name (O) string from one X.509 certificate.
  2317. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2318. @param[in] CertSize Size of the X509 certificate in bytes.
  2319. @param[out] NameBuffer Buffer to contain the retrieved certificate organization
  2320. name string. At most NameBufferSize bytes will be
  2321. written and the string will be null terminated. May be
  2322. NULL in order to determine the size buffer needed.
  2323. @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
  2324. and the size of buffer returned Name on output.
  2325. If NameBuffer is NULL then the amount of space needed
  2326. in buffer (including the final null) is returned.
  2327. @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
  2328. @retval RETURN_INVALID_PARAMETER If Cert is NULL.
  2329. If NameBufferSize is NULL.
  2330. If NameBuffer is not NULL and *CommonNameSize is 0.
  2331. If Certificate is invalid.
  2332. @retval RETURN_NOT_FOUND If no Organization Name entry exists.
  2333. @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
  2334. (including the final null) is returned in the
  2335. CommonNameSize parameter.
  2336. @retval RETURN_UNSUPPORTED The operation is not supported.
  2337. **/
  2338. RETURN_STATUS
  2339. EFIAPI
  2340. CryptoServiceX509GetOrganizationName (
  2341. IN CONST UINT8 *Cert,
  2342. IN UINTN CertSize,
  2343. OUT CHAR8 *NameBuffer OPTIONAL,
  2344. IN OUT UINTN *NameBufferSize
  2345. )
  2346. {
  2347. return CALL_BASECRYPTLIB (X509.Services.GetOrganizationName, X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);
  2348. }
  2349. /**
  2350. Verify one X509 certificate was issued by the trusted CA.
  2351. If Cert is NULL, then return FALSE.
  2352. If CACert is NULL, then return FALSE.
  2353. If this interface is not supported, then return FALSE.
  2354. @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
  2355. @param[in] CertSize Size of the X509 certificate in bytes.
  2356. @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
  2357. @param[in] CACertSize Size of the CA Certificate in bytes.
  2358. @retval TRUE The certificate was issued by the trusted CA.
  2359. @retval FALSE Invalid certificate or the certificate was not issued by the given
  2360. trusted CA.
  2361. @retval FALSE This interface is not supported.
  2362. **/
  2363. BOOLEAN
  2364. EFIAPI
  2365. CryptoServiceX509VerifyCert (
  2366. IN CONST UINT8 *Cert,
  2367. IN UINTN CertSize,
  2368. IN CONST UINT8 *CACert,
  2369. IN UINTN CACertSize
  2370. )
  2371. {
  2372. return CALL_BASECRYPTLIB (X509.Services.VerifyCert, X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);
  2373. }
  2374. /**
  2375. Construct a X509 object from DER-encoded certificate data.
  2376. If Cert is NULL, then return FALSE.
  2377. If SingleX509Cert is NULL, then return FALSE.
  2378. If this interface is not supported, then return FALSE.
  2379. @param[in] Cert Pointer to the DER-encoded certificate data.
  2380. @param[in] CertSize The size of certificate data in bytes.
  2381. @param[out] SingleX509Cert The generated X509 object.
  2382. @retval TRUE The X509 object generation succeeded.
  2383. @retval FALSE The operation failed.
  2384. @retval FALSE This interface is not supported.
  2385. **/
  2386. BOOLEAN
  2387. EFIAPI
  2388. CryptoServiceX509ConstructCertificate (
  2389. IN CONST UINT8 *Cert,
  2390. IN UINTN CertSize,
  2391. OUT UINT8 **SingleX509Cert
  2392. )
  2393. {
  2394. return CALL_BASECRYPTLIB (X509.Services.ConstructCertificate, X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);
  2395. }
  2396. /**
  2397. Construct a X509 stack object from a list of DER-encoded certificate data.
  2398. If X509Stack is NULL, then return FALSE.
  2399. If this interface is not supported, then return FALSE.
  2400. @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
  2401. On output, pointer to the X509 stack object with new
  2402. inserted X509 certificate.
  2403. @param[in] Args VA_LIST marker for the variable argument list.
  2404. A list of DER-encoded single certificate data followed
  2405. by certificate size. A NULL terminates the list. The
  2406. pairs are the arguments to X509ConstructCertificate().
  2407. @retval TRUE The X509 stack construction succeeded.
  2408. @retval FALSE The construction operation failed.
  2409. @retval FALSE This interface is not supported.
  2410. **/
  2411. BOOLEAN
  2412. EFIAPI
  2413. CryptoServiceX509ConstructCertificateStackV (
  2414. IN OUT UINT8 **X509Stack,
  2415. IN VA_LIST Args
  2416. )
  2417. {
  2418. return CALL_BASECRYPTLIB (X509.Services.ConstructCertificateStackV, X509ConstructCertificateStackV, (X509Stack, Args), FALSE);
  2419. }
  2420. /**
  2421. Construct a X509 stack object from a list of DER-encoded certificate data.
  2422. If X509Stack is NULL, then return FALSE.
  2423. If this interface is not supported, then return FALSE.
  2424. @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
  2425. On output, pointer to the X509 stack object with new
  2426. inserted X509 certificate.
  2427. @param ... A list of DER-encoded single certificate data followed
  2428. by certificate size. A NULL terminates the list. The
  2429. pairs are the arguments to X509ConstructCertificate().
  2430. @retval TRUE The X509 stack construction succeeded.
  2431. @retval FALSE The construction operation failed.
  2432. @retval FALSE This interface is not supported.
  2433. **/
  2434. BOOLEAN
  2435. EFIAPI
  2436. CryptoServiceX509ConstructCertificateStack (
  2437. IN OUT UINT8 **X509Stack,
  2438. ...
  2439. )
  2440. {
  2441. VA_LIST Args;
  2442. BOOLEAN Result;
  2443. VA_START (Args, X509Stack);
  2444. Result = CryptoServiceX509ConstructCertificateStackV (X509Stack, Args);
  2445. VA_END (Args);
  2446. return Result;
  2447. }
  2448. /**
  2449. Release the specified X509 object.
  2450. If the interface is not supported, then ASSERT().
  2451. @param[in] X509Cert Pointer to the X509 object to be released.
  2452. **/
  2453. VOID
  2454. EFIAPI
  2455. CryptoServiceX509Free (
  2456. IN VOID *X509Cert
  2457. )
  2458. {
  2459. CALL_VOID_BASECRYPTLIB (X509.Services.Free, X509Free, (X509Cert));
  2460. }
  2461. /**
  2462. Release the specified X509 stack object.
  2463. If the interface is not supported, then ASSERT().
  2464. @param[in] X509Stack Pointer to the X509 stack object to be released.
  2465. **/
  2466. VOID
  2467. EFIAPI
  2468. CryptoServiceX509StackFree (
  2469. IN VOID *X509Stack
  2470. )
  2471. {
  2472. CALL_VOID_BASECRYPTLIB (X509.Services.StackFree, X509StackFree, (X509Stack));
  2473. }
  2474. /**
  2475. Retrieve the TBSCertificate from one given X.509 certificate.
  2476. @param[in] Cert Pointer to the given DER-encoded X509 certificate.
  2477. @param[in] CertSize Size of the X509 certificate in bytes.
  2478. @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
  2479. @param[out] TBSCertSize Size of the TBS certificate in bytes.
  2480. If Cert is NULL, then return FALSE.
  2481. If TBSCert is NULL, then return FALSE.
  2482. If TBSCertSize is NULL, then return FALSE.
  2483. If this interface is not supported, then return FALSE.
  2484. @retval TRUE The TBSCertificate was retrieved successfully.
  2485. @retval FALSE Invalid X.509 certificate.
  2486. **/
  2487. BOOLEAN
  2488. EFIAPI
  2489. CryptoServiceX509GetTBSCert (
  2490. IN CONST UINT8 *Cert,
  2491. IN UINTN CertSize,
  2492. OUT UINT8 **TBSCert,
  2493. OUT UINTN *TBSCertSize
  2494. )
  2495. {
  2496. return CALL_BASECRYPTLIB (X509.Services.GetTBSCert, X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);
  2497. }
  2498. /**
  2499. Retrieve the version from one X.509 certificate.
  2500. If Cert is NULL, then return FALSE.
  2501. If CertSize is 0, then return FALSE.
  2502. If this interface is not supported, then return FALSE.
  2503. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2504. @param[in] CertSize Size of the X509 certificate in bytes.
  2505. @param[out] Version Pointer to the retrieved version integer.
  2506. @retval TRUE The certificate version retrieved successfully.
  2507. @retval FALSE If Cert is NULL or CertSize is Zero.
  2508. @retval FALSE The operation is not supported.
  2509. **/
  2510. BOOLEAN
  2511. EFIAPI
  2512. CryptoServiceX509GetVersion (
  2513. IN CONST UINT8 *Cert,
  2514. IN UINTN CertSize,
  2515. OUT UINTN *Version
  2516. )
  2517. {
  2518. return CALL_BASECRYPTLIB (X509.Services.GetVersion, X509GetVersion, (Cert, CertSize, Version), FALSE);
  2519. }
  2520. /**
  2521. Retrieve the serialNumber from one X.509 certificate.
  2522. If Cert is NULL, then return FALSE.
  2523. If CertSize is 0, then return FALSE.
  2524. If this interface is not supported, then return FALSE.
  2525. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2526. @param[in] CertSize Size of the X509 certificate in bytes.
  2527. @param[out] SerialNumber Pointer to the retrieved certificate SerialNumber bytes.
  2528. @param[in, out] SerialNumberSize The size in bytes of the SerialNumber buffer on input,
  2529. and the size of buffer returned SerialNumber on output.
  2530. @retval TRUE The certificate serialNumber retrieved successfully.
  2531. @retval FALSE If Cert is NULL or CertSize is Zero.
  2532. If SerialNumberSize is NULL.
  2533. If Certificate is invalid.
  2534. @retval FALSE If no SerialNumber exists.
  2535. @retval FALSE If the SerialNumber is NULL. The required buffer size
  2536. (including the final null) is returned in the
  2537. SerialNumberSize parameter.
  2538. @retval FALSE The operation is not supported.
  2539. **/
  2540. BOOLEAN
  2541. EFIAPI
  2542. CryptoServiceX509GetSerialNumber (
  2543. IN CONST UINT8 *Cert,
  2544. IN UINTN CertSize,
  2545. OUT UINT8 *SerialNumber, OPTIONAL
  2546. IN OUT UINTN *SerialNumberSize
  2547. )
  2548. {
  2549. return CALL_BASECRYPTLIB (X509.Services.GetSerialNumber, X509GetSerialNumber, (Cert, CertSize, SerialNumber, SerialNumberSize), FALSE);
  2550. }
  2551. /**
  2552. Retrieve the issuer bytes from one X.509 certificate.
  2553. If Cert is NULL, then return FALSE.
  2554. If CertIssuerSize is NULL, then return FALSE.
  2555. If this interface is not supported, then return FALSE.
  2556. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2557. @param[in] CertSize Size of the X509 certificate in bytes.
  2558. @param[out] CertIssuer Pointer to the retrieved certificate subject bytes.
  2559. @param[in, out] CertIssuerSize The size in bytes of the CertIssuer buffer on input,
  2560. and the size of buffer returned CertSubject on output.
  2561. @retval TRUE The certificate issuer retrieved successfully.
  2562. @retval FALSE Invalid certificate, or the CertIssuerSize is too small for the result.
  2563. The CertIssuerSize will be updated with the required size.
  2564. @retval FALSE This interface is not supported.
  2565. **/
  2566. BOOLEAN
  2567. EFIAPI
  2568. CryptoServiceX509GetIssuerName (
  2569. IN CONST UINT8 *Cert,
  2570. IN UINTN CertSize,
  2571. OUT UINT8 *CertIssuer,
  2572. IN OUT UINTN *CertIssuerSize
  2573. )
  2574. {
  2575. return CALL_BASECRYPTLIB (X509.Services.GetIssuerName, X509GetIssuerName, (Cert, CertSize, CertIssuer, CertIssuerSize), FALSE);
  2576. }
  2577. /**
  2578. Retrieve the Signature Algorithm from one X.509 certificate.
  2579. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2580. @param[in] CertSize Size of the X509 certificate in bytes.
  2581. @param[out] Oid Signature Algorithm Object identifier buffer.
  2582. @param[in,out] OidSize Signature Algorithm Object identifier buffer size
  2583. @retval TRUE The certificate Extension data retrieved successfully.
  2584. @retval FALSE If Cert is NULL.
  2585. If OidSize is NULL.
  2586. If Oid is not NULL and *OidSize is 0.
  2587. If Certificate is invalid.
  2588. @retval FALSE If no SignatureType.
  2589. @retval FALSE If the Oid is NULL. The required buffer size
  2590. is returned in the OidSize.
  2591. @retval FALSE The operation is not supported.
  2592. **/
  2593. BOOLEAN
  2594. EFIAPI
  2595. CryptoServiceX509GetSignatureAlgorithm (
  2596. IN CONST UINT8 *Cert,
  2597. IN UINTN CertSize,
  2598. OUT UINT8 *Oid, OPTIONAL
  2599. IN OUT UINTN *OidSize
  2600. )
  2601. {
  2602. return CALL_BASECRYPTLIB (X509.Services.GetSignatureAlgorithm, X509GetSignatureAlgorithm, (Cert, CertSize, Oid, OidSize), FALSE);
  2603. }
  2604. /**
  2605. Retrieve Extension data from one X.509 certificate.
  2606. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2607. @param[in] CertSize Size of the X509 certificate in bytes.
  2608. @param[in] Oid Object identifier buffer
  2609. @param[in] OidSize Object identifier buffer size
  2610. @param[out] ExtensionData Extension bytes.
  2611. @param[in, out] ExtensionDataSize Extension bytes size.
  2612. @retval TRUE The certificate Extension data retrieved successfully.
  2613. @retval FALSE If Cert is NULL.
  2614. If ExtensionDataSize is NULL.
  2615. If ExtensionData is not NULL and *ExtensionDataSize is 0.
  2616. If Certificate is invalid.
  2617. @retval FALSE If no Extension entry match Oid.
  2618. @retval FALSE If the ExtensionData is NULL. The required buffer size
  2619. is returned in the ExtensionDataSize parameter.
  2620. @retval FALSE The operation is not supported.
  2621. **/
  2622. BOOLEAN
  2623. EFIAPI
  2624. CryptoServiceX509GetExtensionData (
  2625. IN CONST UINT8 *Cert,
  2626. IN UINTN CertSize,
  2627. IN CONST UINT8 *Oid,
  2628. IN UINTN OidSize,
  2629. OUT UINT8 *ExtensionData,
  2630. IN OUT UINTN *ExtensionDataSize
  2631. )
  2632. {
  2633. return CALL_BASECRYPTLIB (X509.Services.GetExtensionData, X509GetExtensionData, (Cert, CertSize, Oid, OidSize, ExtensionData, ExtensionDataSize), FALSE);
  2634. }
  2635. /**
  2636. Retrieve the Extended Key Usage from one X.509 certificate.
  2637. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2638. @param[in] CertSize Size of the X509 certificate in bytes.
  2639. @param[out] Usage Key Usage bytes.
  2640. @param[in, out] UsageSize Key Usage buffer sizs in bytes.
  2641. @retval TRUE The Usage bytes retrieve successfully.
  2642. @retval FALSE If Cert is NULL.
  2643. If CertSize is NULL.
  2644. If Usage is not NULL and *UsageSize is 0.
  2645. If Cert is invalid.
  2646. @retval FALSE If the Usage is NULL. The required buffer size
  2647. is returned in the UsageSize parameter.
  2648. @retval FALSE The operation is not supported.
  2649. **/
  2650. BOOLEAN
  2651. EFIAPI
  2652. CryptoServiceX509GetExtendedKeyUsage (
  2653. IN CONST UINT8 *Cert,
  2654. IN UINTN CertSize,
  2655. OUT UINT8 *Usage,
  2656. IN OUT UINTN *UsageSize
  2657. )
  2658. {
  2659. return CALL_BASECRYPTLIB (X509.Services.GetExtendedKeyUsage, X509GetExtendedKeyUsage, (Cert, CertSize, Usage, UsageSize), FALSE);
  2660. }
  2661. /**
  2662. Retrieve the Validity from one X.509 certificate
  2663. If Cert is NULL, then return FALSE.
  2664. If CertIssuerSize is NULL, then return FALSE.
  2665. If this interface is not supported, then return FALSE.
  2666. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2667. @param[in] CertSize Size of the X509 certificate in bytes.
  2668. @param[in] From notBefore Pointer to DateTime object.
  2669. @param[in,out] FromSize notBefore DateTime object size.
  2670. @param[in] To notAfter Pointer to DateTime object.
  2671. @param[in,out] ToSize notAfter DateTime object size.
  2672. Note: X509CompareDateTime to compare DateTime oject
  2673. x509SetDateTime to get a DateTime object from a DateTimeStr
  2674. @retval TRUE The certificate Validity retrieved successfully.
  2675. @retval FALSE Invalid certificate, or Validity retrieve failed.
  2676. @retval FALSE This interface is not supported.
  2677. **/
  2678. BOOLEAN
  2679. EFIAPI
  2680. CryptoServiceX509GetValidity (
  2681. IN CONST UINT8 *Cert,
  2682. IN UINTN CertSize,
  2683. IN UINT8 *From,
  2684. IN OUT UINTN *FromSize,
  2685. IN UINT8 *To,
  2686. IN OUT UINTN *ToSize
  2687. )
  2688. {
  2689. return CALL_BASECRYPTLIB (X509.Services.GetValidity, X509GetValidity, (Cert, CertSize, From, FromSize, To, ToSize), FALSE);
  2690. }
  2691. /**
  2692. Format a DateTimeStr to DataTime object in DataTime Buffer
  2693. If DateTimeStr is NULL, then return FALSE.
  2694. If DateTimeSize is NULL, then return FALSE.
  2695. If this interface is not supported, then return FALSE.
  2696. @param[in] DateTimeStr DateTime string like YYYYMMDDhhmmssZ
  2697. Ref: https://www.w3.org/TR/NOTE-datetime
  2698. Z stand for UTC time
  2699. @param[out] DateTime Pointer to a DateTime object.
  2700. @param[in,out] DateTimeSize DateTime object buffer size.
  2701. @retval TRUE The DateTime object create successfully.
  2702. @retval FALSE If DateTimeStr is NULL.
  2703. If DateTimeSize is NULL.
  2704. If DateTime is not NULL and *DateTimeSize is 0.
  2705. If Year Month Day Hour Minute Second combination is invalid datetime.
  2706. @retval FALSE If the DateTime is NULL. The required buffer size
  2707. (including the final null) is returned in the
  2708. DateTimeSize parameter.
  2709. @retval FALSE The operation is not supported.
  2710. **/
  2711. BOOLEAN
  2712. EFIAPI
  2713. CryptoServiceX509FormatDateTime (
  2714. IN CONST CHAR8 *DateTimeStr,
  2715. OUT VOID *DateTime,
  2716. IN OUT UINTN *DateTimeSize
  2717. )
  2718. {
  2719. return CALL_BASECRYPTLIB (X509.Services.FormatDateTime, X509FormatDateTime, (DateTimeStr, DateTime, DateTimeSize), FALSE);
  2720. }
  2721. /**
  2722. Compare DateTime1 object and DateTime2 object.
  2723. If DateTime1 is NULL, then return -2.
  2724. If DateTime2 is NULL, then return -2.
  2725. If DateTime1 == DateTime2, then return 0
  2726. If DateTime1 > DateTime2, then return 1
  2727. If DateTime1 < DateTime2, then return -1
  2728. @param[in] DateTime1 Pointer to a DateTime Ojbect
  2729. @param[in] DateTime2 Pointer to a DateTime Object
  2730. @retval 0 If DateTime1 == DateTime2
  2731. @retval 1 If DateTime1 > DateTime2
  2732. @retval -1 If DateTime1 < DateTime2
  2733. **/
  2734. INT32
  2735. EFIAPI
  2736. CryptoServiceX509CompareDateTime (
  2737. IN CONST VOID *DateTime1,
  2738. IN CONST VOID *DateTime2
  2739. )
  2740. {
  2741. return CALL_BASECRYPTLIB (X509.Services.CompareDateTime, X509CompareDateTime, (DateTime1, DateTime2), FALSE);
  2742. }
  2743. /**
  2744. Retrieve the Key Usage from one X.509 certificate.
  2745. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2746. @param[in] CertSize Size of the X509 certificate in bytes.
  2747. @param[out] Usage Key Usage (CRYPTO_X509_KU_*)
  2748. @retval TRUE The certificate Key Usage retrieved successfully.
  2749. @retval FALSE Invalid certificate, or Usage is NULL
  2750. @retval FALSE This interface is not supported.
  2751. **/
  2752. BOOLEAN
  2753. EFIAPI
  2754. CryptoServiceX509GetKeyUsage (
  2755. IN CONST UINT8 *Cert,
  2756. IN UINTN CertSize,
  2757. OUT UINTN *Usage
  2758. )
  2759. {
  2760. return CALL_BASECRYPTLIB (X509.Services.GetKeyUsage, X509GetKeyUsage, (Cert, CertSize, Usage), FALSE);
  2761. }
  2762. /**
  2763. Verify one X509 certificate was issued by the trusted CA.
  2764. @param[in] RootCert Trusted Root Certificate buffer
  2765. @param[in] RootCertLength Trusted Root Certificate buffer length
  2766. @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates
  2767. where the first certificate is signed by the Root
  2768. Certificate or is the Root Cerificate itself. and
  2769. subsequent cerificate is signed by the preceding
  2770. cerificate.
  2771. @param[in] CertChainLength Total length of the certificate chain, in bytes.
  2772. @retval TRUE All cerificates was issued by the first certificate in X509Certchain.
  2773. @retval FALSE Invalid certificate or the certificate was not issued by the given
  2774. trusted CA.
  2775. **/
  2776. BOOLEAN
  2777. EFIAPI
  2778. CryptoServiceX509VerifyCertChain (
  2779. IN CONST UINT8 *RootCert,
  2780. IN UINTN RootCertLength,
  2781. IN CONST UINT8 *CertChain,
  2782. IN UINTN CertChainLength
  2783. )
  2784. {
  2785. return CALL_BASECRYPTLIB (X509.Services.VerifyCertChain, X509VerifyCertChain, (RootCert, RootCertLength, CertChain, CertChainLength), FALSE);
  2786. }
  2787. /**
  2788. Get one X509 certificate from CertChain.
  2789. @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates
  2790. where the first certificate is signed by the Root
  2791. Certificate or is the Root Cerificate itself. and
  2792. subsequent cerificate is signed by the preceding
  2793. cerificate.
  2794. @param[in] CertChainLength Total length of the certificate chain, in bytes.
  2795. @param[in] CertIndex Index of certificate.
  2796. @param[out] Cert The certificate at the index of CertChain.
  2797. @param[out] CertLength The length certificate at the index of CertChain.
  2798. @retval TRUE Success.
  2799. @retval FALSE Failed to get certificate from certificate chain.
  2800. **/
  2801. BOOLEAN
  2802. EFIAPI
  2803. CryptoServiceX509GetCertFromCertChain (
  2804. IN CONST UINT8 *CertChain,
  2805. IN UINTN CertChainLength,
  2806. IN CONST INT32 CertIndex,
  2807. OUT CONST UINT8 **Cert,
  2808. OUT UINTN *CertLength
  2809. )
  2810. {
  2811. return CALL_BASECRYPTLIB (X509.Services.GetCertFromCertChain, X509GetCertFromCertChain, (CertChain, CertChainLength, CertIndex, Cert, CertLength), FALSE);
  2812. }
  2813. /**
  2814. Retrieve the tag and length of the tag.
  2815. @param Ptr The position in the ASN.1 data
  2816. @param End End of data
  2817. @param Length The variable that will receive the length
  2818. @param Tag The expected tag
  2819. @retval TRUE Get tag successful
  2820. @retval FALSe Failed to get tag or tag not match
  2821. **/
  2822. BOOLEAN
  2823. EFIAPI
  2824. CryptoServiceAsn1GetTag (
  2825. IN OUT UINT8 **Ptr,
  2826. IN CONST UINT8 *End,
  2827. OUT UINTN *Length,
  2828. IN UINT32 Tag
  2829. )
  2830. {
  2831. return CALL_BASECRYPTLIB (X509.Services.Asn1GetTag, Asn1GetTag, (Ptr, End, Length, Tag), FALSE);
  2832. }
  2833. /**
  2834. Retrieve the basic constraints from one X.509 certificate.
  2835. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  2836. @param[in] CertSize size of the X509 certificate in bytes.
  2837. @param[out] BasicConstraints basic constraints bytes.
  2838. @param[in, out] BasicConstraintsSize basic constraints buffer sizs in bytes.
  2839. @retval TRUE The basic constraints retrieve successfully.
  2840. @retval FALSE If cert is NULL.
  2841. If cert_size is NULL.
  2842. If basic_constraints is not NULL and *basic_constraints_size is 0.
  2843. If cert is invalid.
  2844. @retval FALSE The required buffer size is small.
  2845. The return buffer size is basic_constraints_size parameter.
  2846. @retval FALSE If no Extension entry match oid.
  2847. @retval FALSE The operation is not supported.
  2848. **/
  2849. BOOLEAN
  2850. EFIAPI
  2851. CryptoServiceX509GetExtendedBasicConstraints (
  2852. CONST UINT8 *Cert,
  2853. UINTN CertSize,
  2854. UINT8 *BasicConstraints,
  2855. UINTN *BasicConstraintsSize
  2856. )
  2857. {
  2858. return CALL_BASECRYPTLIB (X509.Services.GetExtendedBasicConstraints, X509GetExtendedBasicConstraints, (Cert, CertSize, BasicConstraints, BasicConstraintsSize), FALSE);
  2859. }
  2860. /**
  2861. Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
  2862. password based encryption key derivation function PBKDF2, as specified in RFC 2898.
  2863. If Password or Salt or OutKey is NULL, then return FALSE.
  2864. If the hash algorithm could not be determined, then return FALSE.
  2865. If this interface is not supported, then return FALSE.
  2866. @param[in] PasswordLength Length of input password in bytes.
  2867. @param[in] Password Pointer to the array for the password.
  2868. @param[in] SaltLength Size of the Salt in bytes.
  2869. @param[in] Salt Pointer to the Salt.
  2870. @param[in] IterationCount Number of iterations to perform. Its value should be
  2871. greater than or equal to 1.
  2872. @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
  2873. NOTE: DigestSize will be used to determine the hash algorithm.
  2874. Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
  2875. @param[in] KeyLength Size of the derived key buffer in bytes.
  2876. @param[out] OutKey Pointer to the output derived key buffer.
  2877. @retval TRUE A key was derived successfully.
  2878. @retval FALSE One of the pointers was NULL or one of the sizes was too large.
  2879. @retval FALSE The hash algorithm could not be determined from the digest size.
  2880. @retval FALSE The key derivation operation failed.
  2881. @retval FALSE This interface is not supported.
  2882. **/
  2883. BOOLEAN
  2884. EFIAPI
  2885. CryptoServicePkcs5HashPassword (
  2886. IN UINTN PasswordLength,
  2887. IN CONST CHAR8 *Password,
  2888. IN UINTN SaltLength,
  2889. IN CONST UINT8 *Salt,
  2890. IN UINTN IterationCount,
  2891. IN UINTN DigestSize,
  2892. IN UINTN KeyLength,
  2893. OUT UINT8 *OutKey
  2894. )
  2895. {
  2896. return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs5HashPassword, Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);
  2897. }
  2898. /**
  2899. Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
  2900. encrypted message in a newly allocated buffer.
  2901. Things that can cause a failure include:
  2902. - X509 key size does not match any known key size.
  2903. - Fail to parse X509 certificate.
  2904. - Fail to allocate an intermediate buffer.
  2905. - Null pointer provided for a non-optional parameter.
  2906. - Data size is too large for the provided key size (max size is a function of key size
  2907. and hash digest size).
  2908. @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
  2909. will be used to encrypt the data.
  2910. @param[in] PublicKeySize Size of the X509 cert buffer.
  2911. @param[in] InData Data to be encrypted.
  2912. @param[in] InDataSize Size of the data buffer.
  2913. @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
  2914. to be used when initializing the PRNG. NULL otherwise.
  2915. @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
  2916. 0 otherwise.
  2917. @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
  2918. message.
  2919. @param[out] EncryptedDataSize Size of the encrypted message buffer.
  2920. @retval TRUE Encryption was successful.
  2921. @retval FALSE Encryption failed.
  2922. **/
  2923. BOOLEAN
  2924. EFIAPI
  2925. CryptoServicePkcs1v2Encrypt (
  2926. IN CONST UINT8 *PublicKey,
  2927. IN UINTN PublicKeySize,
  2928. IN UINT8 *InData,
  2929. IN UINTN InDataSize,
  2930. IN CONST UINT8 *PrngSeed OPTIONAL,
  2931. IN UINTN PrngSeedSize OPTIONAL,
  2932. OUT UINT8 **EncryptedData,
  2933. OUT UINTN *EncryptedDataSize
  2934. )
  2935. {
  2936. return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs1v2Encrypt, Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);
  2937. }
  2938. /**
  2939. Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
  2940. Cryptographic Message Syntax Standard". The input signed data could be wrapped
  2941. in a ContentInfo structure.
  2942. If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
  2943. return FALSE. If P7Length overflow, then return FALSE.
  2944. If this interface is not supported, then return FALSE.
  2945. @param[in] P7Data Pointer to the PKCS#7 message to verify.
  2946. @param[in] P7Length Length of the PKCS#7 message in bytes.
  2947. @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
  2948. It's caller's responsibility to free the buffer with
  2949. Pkcs7FreeSigners().
  2950. This data structure is EFI_CERT_STACK type.
  2951. @param[out] StackLength Length of signer's certificates in bytes.
  2952. @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
  2953. It's caller's responsibility to free the buffer with
  2954. Pkcs7FreeSigners().
  2955. @param[out] CertLength Length of the trusted certificate in bytes.
  2956. @retval TRUE The operation is finished successfully.
  2957. @retval FALSE Error occurs during the operation.
  2958. @retval FALSE This interface is not supported.
  2959. **/
  2960. BOOLEAN
  2961. EFIAPI
  2962. CryptoServicePkcs7GetSigners (
  2963. IN CONST UINT8 *P7Data,
  2964. IN UINTN P7Length,
  2965. OUT UINT8 **CertStack,
  2966. OUT UINTN *StackLength,
  2967. OUT UINT8 **TrustedCert,
  2968. OUT UINTN *CertLength
  2969. )
  2970. {
  2971. return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetSigners, Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);
  2972. }
  2973. /**
  2974. Wrap function to use free() to free allocated memory for certificates.
  2975. If this interface is not supported, then ASSERT().
  2976. @param[in] Certs Pointer to the certificates to be freed.
  2977. **/
  2978. VOID
  2979. EFIAPI
  2980. CryptoServicePkcs7FreeSigners (
  2981. IN UINT8 *Certs
  2982. )
  2983. {
  2984. CALL_VOID_BASECRYPTLIB (Pkcs.Services.Pkcs7FreeSigners, Pkcs7FreeSigners, (Certs));
  2985. }
  2986. /**
  2987. Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
  2988. Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
  2989. unchained to the signer's certificates.
  2990. The input signed data could be wrapped in a ContentInfo structure.
  2991. @param[in] P7Data Pointer to the PKCS#7 message.
  2992. @param[in] P7Length Length of the PKCS#7 message in bytes.
  2993. @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
  2994. certificate. It's caller's responsibility to free the buffer
  2995. with Pkcs7FreeSigners().
  2996. This data structure is EFI_CERT_STACK type.
  2997. @param[out] ChainLength Length of the chained certificates list buffer in bytes.
  2998. @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
  2999. responsibility to free the buffer with Pkcs7FreeSigners().
  3000. This data structure is EFI_CERT_STACK type.
  3001. @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
  3002. @retval TRUE The operation is finished successfully.
  3003. @retval FALSE Error occurs during the operation.
  3004. **/
  3005. BOOLEAN
  3006. EFIAPI
  3007. CryptoServicePkcs7GetCertificatesList (
  3008. IN CONST UINT8 *P7Data,
  3009. IN UINTN P7Length,
  3010. OUT UINT8 **SignerChainCerts,
  3011. OUT UINTN *ChainLength,
  3012. OUT UINT8 **UnchainCerts,
  3013. OUT UINTN *UnchainLength
  3014. )
  3015. {
  3016. return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetCertificatesList, Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);
  3017. }
  3018. /**
  3019. Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
  3020. Syntax Standard, version 1.5". This interface is only intended to be used for
  3021. application to perform PKCS#7 functionality validation.
  3022. If this interface is not supported, then return FALSE.
  3023. @param[in] PrivateKey Pointer to the PEM-formatted private key data for
  3024. data signing.
  3025. @param[in] PrivateKeySize Size of the PEM private key data in bytes.
  3026. @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
  3027. key data.
  3028. @param[in] InData Pointer to the content to be signed.
  3029. @param[in] InDataSize Size of InData in bytes.
  3030. @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
  3031. @param[in] OtherCerts Pointer to an optional additional set of certificates to
  3032. include in the PKCS#7 signedData (e.g. any intermediate
  3033. CAs in the chain).
  3034. @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
  3035. responsibility to free the buffer with FreePool().
  3036. @param[out] SignedDataSize Size of SignedData in bytes.
  3037. @retval TRUE PKCS#7 data signing succeeded.
  3038. @retval FALSE PKCS#7 data signing failed.
  3039. @retval FALSE This interface is not supported.
  3040. **/
  3041. BOOLEAN
  3042. EFIAPI
  3043. CryptoServicePkcs7Sign (
  3044. IN CONST UINT8 *PrivateKey,
  3045. IN UINTN PrivateKeySize,
  3046. IN CONST UINT8 *KeyPassword,
  3047. IN UINT8 *InData,
  3048. IN UINTN InDataSize,
  3049. IN UINT8 *SignCert,
  3050. IN UINT8 *OtherCerts OPTIONAL,
  3051. OUT UINT8 **SignedData,
  3052. OUT UINTN *SignedDataSize
  3053. )
  3054. {
  3055. return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7Sign, Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);
  3056. }
  3057. /**
  3058. Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
  3059. Cryptographic Message Syntax Standard". The input signed data could be wrapped
  3060. in a ContentInfo structure.
  3061. If P7Data, TrustedCert or InData is NULL, then return FALSE.
  3062. If P7Length, CertLength or DataLength overflow, then return FALSE.
  3063. If this interface is not supported, then return FALSE.
  3064. @param[in] P7Data Pointer to the PKCS#7 message to verify.
  3065. @param[in] P7Length Length of the PKCS#7 message in bytes.
  3066. @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
  3067. is used for certificate chain verification.
  3068. @param[in] CertLength Length of the trusted certificate in bytes.
  3069. @param[in] InData Pointer to the content to be verified.
  3070. @param[in] DataLength Length of InData in bytes.
  3071. @retval TRUE The specified PKCS#7 signed data is valid.
  3072. @retval FALSE Invalid PKCS#7 signed data.
  3073. @retval FALSE This interface is not supported.
  3074. **/
  3075. BOOLEAN
  3076. EFIAPI
  3077. CryptoServicePkcs7Verify (
  3078. IN CONST UINT8 *P7Data,
  3079. IN UINTN P7Length,
  3080. IN CONST UINT8 *TrustedCert,
  3081. IN UINTN CertLength,
  3082. IN CONST UINT8 *InData,
  3083. IN UINTN DataLength
  3084. )
  3085. {
  3086. return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7Verify, Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);
  3087. }
  3088. /**
  3089. This function receives a PKCS7 formatted signature, and then verifies that
  3090. the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
  3091. leaf signing certificate.
  3092. Note that this function does not validate the certificate chain.
  3093. Applications for custom EKU's are quite flexible. For example, a policy EKU
  3094. may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
  3095. certificate issued might also contain this EKU, thus constraining the
  3096. sub-ordinate certificate. Other applications might allow a certificate
  3097. embedded in a device to specify that other Object Identifiers (OIDs) are
  3098. present which contains binary data specifying custom capabilities that
  3099. the device is able to do.
  3100. @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
  3101. containing the content block with both the signature,
  3102. the signer's certificate, and any necessary intermediate
  3103. certificates.
  3104. @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
  3105. @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
  3106. required EKUs that must be present in the signature.
  3107. @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
  3108. @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
  3109. must be present in the leaf signer. If it is
  3110. FALSE, then we will succeed if we find any
  3111. of the specified EKU's.
  3112. @retval EFI_SUCCESS The required EKUs were found in the signature.
  3113. @retval EFI_INVALID_PARAMETER A parameter was invalid.
  3114. @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
  3115. **/
  3116. RETURN_STATUS
  3117. EFIAPI
  3118. CryptoServiceVerifyEKUsInPkcs7Signature (
  3119. IN CONST UINT8 *Pkcs7Signature,
  3120. IN CONST UINT32 SignatureSize,
  3121. IN CONST CHAR8 *RequiredEKUs[],
  3122. IN CONST UINT32 RequiredEKUsSize,
  3123. IN BOOLEAN RequireAllPresent
  3124. )
  3125. {
  3126. return CALL_BASECRYPTLIB (Pkcs.Services.VerifyEKUsInPkcs7Signature, VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);
  3127. }
  3128. /**
  3129. Extracts the attached content from a PKCS#7 signed data if existed. The input signed
  3130. data could be wrapped in a ContentInfo structure.
  3131. If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
  3132. then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
  3133. Caution: This function may receive untrusted input. So this function will do
  3134. basic check for PKCS#7 data structure.
  3135. @param[in] P7Data Pointer to the PKCS#7 signed data to process.
  3136. @param[in] P7Length Length of the PKCS#7 signed data in bytes.
  3137. @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
  3138. It's caller's responsibility to free the buffer with FreePool().
  3139. @param[out] ContentSize The size of the extracted content in bytes.
  3140. @retval TRUE The P7Data was correctly formatted for processing.
  3141. @retval FALSE The P7Data was not correctly formatted for processing.
  3142. **/
  3143. BOOLEAN
  3144. EFIAPI
  3145. CryptoServicePkcs7GetAttachedContent (
  3146. IN CONST UINT8 *P7Data,
  3147. IN UINTN P7Length,
  3148. OUT VOID **Content,
  3149. OUT UINTN *ContentSize
  3150. )
  3151. {
  3152. return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetAttachedContent, Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);
  3153. }
  3154. /**
  3155. Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
  3156. Authenticode Portable Executable Signature Format".
  3157. If AuthData is NULL, then return FALSE.
  3158. If ImageHash is NULL, then return FALSE.
  3159. If this interface is not supported, then return FALSE.
  3160. @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
  3161. PE/COFF image to be verified.
  3162. @param[in] DataSize Size of the Authenticode Signature in bytes.
  3163. @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
  3164. is used for certificate chain verification.
  3165. @param[in] CertSize Size of the trusted certificate in bytes.
  3166. @param[in] ImageHash Pointer to the original image file hash value. The procedure
  3167. for calculating the image hash value is described in Authenticode
  3168. specification.
  3169. @param[in] HashSize Size of Image hash value in bytes.
  3170. @retval TRUE The specified Authenticode Signature is valid.
  3171. @retval FALSE Invalid Authenticode Signature.
  3172. @retval FALSE This interface is not supported.
  3173. **/
  3174. BOOLEAN
  3175. EFIAPI
  3176. CryptoServiceAuthenticodeVerify (
  3177. IN CONST UINT8 *AuthData,
  3178. IN UINTN DataSize,
  3179. IN CONST UINT8 *TrustedCert,
  3180. IN UINTN CertSize,
  3181. IN CONST UINT8 *ImageHash,
  3182. IN UINTN HashSize
  3183. )
  3184. {
  3185. return CALL_BASECRYPTLIB (Pkcs.Services.AuthenticodeVerify, AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);
  3186. }
  3187. /**
  3188. Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
  3189. signature.
  3190. If AuthData is NULL, then return FALSE.
  3191. If this interface is not supported, then return FALSE.
  3192. @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
  3193. PE/COFF image to be verified.
  3194. @param[in] DataSize Size of the Authenticode Signature in bytes.
  3195. @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
  3196. is used for TSA certificate chain verification.
  3197. @param[in] CertSize Size of the trusted certificate in bytes.
  3198. @param[out] SigningTime Return the time of timestamp generation time if the timestamp
  3199. signature is valid.
  3200. @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
  3201. @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
  3202. **/
  3203. BOOLEAN
  3204. EFIAPI
  3205. CryptoServiceImageTimestampVerify (
  3206. IN CONST UINT8 *AuthData,
  3207. IN UINTN DataSize,
  3208. IN CONST UINT8 *TsaCert,
  3209. IN UINTN CertSize,
  3210. OUT EFI_TIME *SigningTime
  3211. )
  3212. {
  3213. return CALL_BASECRYPTLIB (Pkcs.Services.ImageTimestampVerify, ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);
  3214. }
  3215. // =====================================================================================
  3216. // DH Key Exchange Primitive
  3217. // =====================================================================================
  3218. /**
  3219. Allocates and Initializes one Diffie-Hellman Context for subsequent use.
  3220. @return Pointer to the Diffie-Hellman Context that has been initialized.
  3221. If the allocations fails, DhNew() returns NULL.
  3222. If the interface is not supported, DhNew() returns NULL.
  3223. **/
  3224. VOID *
  3225. EFIAPI
  3226. CryptoServiceDhNew (
  3227. VOID
  3228. )
  3229. {
  3230. return CALL_BASECRYPTLIB (Dh.Services.New, DhNew, (), NULL);
  3231. }
  3232. /**
  3233. Release the specified DH context.
  3234. If the interface is not supported, then ASSERT().
  3235. @param[in] DhContext Pointer to the DH context to be released.
  3236. **/
  3237. VOID
  3238. EFIAPI
  3239. CryptoServiceDhFree (
  3240. IN VOID *DhContext
  3241. )
  3242. {
  3243. CALL_VOID_BASECRYPTLIB (Dh.Services.Free, DhFree, (DhContext));
  3244. }
  3245. /**
  3246. Generates DH parameter.
  3247. Given generator g, and length of prime number p in bits, this function generates p,
  3248. and sets DH context according to value of g and p.
  3249. Before this function can be invoked, pseudorandom number generator must be correctly
  3250. initialized by RandomSeed().
  3251. If DhContext is NULL, then return FALSE.
  3252. If Prime is NULL, then return FALSE.
  3253. If this interface is not supported, then return FALSE.
  3254. @param[in, out] DhContext Pointer to the DH context.
  3255. @param[in] Generator Value of generator.
  3256. @param[in] PrimeLength Length in bits of prime to be generated.
  3257. @param[out] Prime Pointer to the buffer to receive the generated prime number.
  3258. @retval TRUE DH parameter generation succeeded.
  3259. @retval FALSE Value of Generator is not supported.
  3260. @retval FALSE PRNG fails to generate random prime number with PrimeLength.
  3261. @retval FALSE This interface is not supported.
  3262. **/
  3263. BOOLEAN
  3264. EFIAPI
  3265. CryptoServiceDhGenerateParameter (
  3266. IN OUT VOID *DhContext,
  3267. IN UINTN Generator,
  3268. IN UINTN PrimeLength,
  3269. OUT UINT8 *Prime
  3270. )
  3271. {
  3272. return CALL_BASECRYPTLIB (Dh.Services.GenerateParameter, DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
  3273. }
  3274. /**
  3275. Sets generator and prime parameters for DH.
  3276. Given generator g, and prime number p, this function and sets DH
  3277. context accordingly.
  3278. If DhContext is NULL, then return FALSE.
  3279. If Prime is NULL, then return FALSE.
  3280. If this interface is not supported, then return FALSE.
  3281. @param[in, out] DhContext Pointer to the DH context.
  3282. @param[in] Generator Value of generator.
  3283. @param[in] PrimeLength Length in bits of prime to be generated.
  3284. @param[in] Prime Pointer to the prime number.
  3285. @retval TRUE DH parameter setting succeeded.
  3286. @retval FALSE Value of Generator is not supported.
  3287. @retval FALSE Value of Generator is not suitable for the Prime.
  3288. @retval FALSE Value of Prime is not a prime number.
  3289. @retval FALSE Value of Prime is not a safe prime number.
  3290. @retval FALSE This interface is not supported.
  3291. **/
  3292. BOOLEAN
  3293. EFIAPI
  3294. CryptoServiceDhSetParameter (
  3295. IN OUT VOID *DhContext,
  3296. IN UINTN Generator,
  3297. IN UINTN PrimeLength,
  3298. IN CONST UINT8 *Prime
  3299. )
  3300. {
  3301. return CALL_BASECRYPTLIB (Dh.Services.SetParameter, DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
  3302. }
  3303. /**
  3304. Generates DH public key.
  3305. This function generates random secret exponent, and computes the public key, which is
  3306. returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
  3307. If the PublicKey buffer is too small to hold the public key, FALSE is returned and
  3308. PublicKeySize is set to the required buffer size to obtain the public key.
  3309. If DhContext is NULL, then return FALSE.
  3310. If PublicKeySize is NULL, then return FALSE.
  3311. If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
  3312. If this interface is not supported, then return FALSE.
  3313. @param[in, out] DhContext Pointer to the DH context.
  3314. @param[out] PublicKey Pointer to the buffer to receive generated public key.
  3315. @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
  3316. On output, the size of data returned in PublicKey buffer in bytes.
  3317. @retval TRUE DH public key generation succeeded.
  3318. @retval FALSE DH public key generation failed.
  3319. @retval FALSE PublicKeySize is not large enough.
  3320. @retval FALSE This interface is not supported.
  3321. **/
  3322. BOOLEAN
  3323. EFIAPI
  3324. CryptoServiceDhGenerateKey (
  3325. IN OUT VOID *DhContext,
  3326. OUT UINT8 *PublicKey,
  3327. IN OUT UINTN *PublicKeySize
  3328. )
  3329. {
  3330. return CALL_BASECRYPTLIB (Dh.Services.GenerateKey, DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);
  3331. }
  3332. /**
  3333. Computes exchanged common key.
  3334. Given peer's public key, this function computes the exchanged common key, based on its own
  3335. context including value of prime modulus and random secret exponent.
  3336. If DhContext is NULL, then return FALSE.
  3337. If PeerPublicKey is NULL, then return FALSE.
  3338. If KeySize is NULL, then return FALSE.
  3339. If Key is NULL, then return FALSE.
  3340. If KeySize is not large enough, then return FALSE.
  3341. If this interface is not supported, then return FALSE.
  3342. @param[in, out] DhContext Pointer to the DH context.
  3343. @param[in] PeerPublicKey Pointer to the peer's public key.
  3344. @param[in] PeerPublicKeySize Size of peer's public key in bytes.
  3345. @param[out] Key Pointer to the buffer to receive generated key.
  3346. @param[in, out] KeySize On input, the size of Key buffer in bytes.
  3347. On output, the size of data returned in Key buffer in bytes.
  3348. @retval TRUE DH exchanged key generation succeeded.
  3349. @retval FALSE DH exchanged key generation failed.
  3350. @retval FALSE KeySize is not large enough.
  3351. @retval FALSE This interface is not supported.
  3352. **/
  3353. BOOLEAN
  3354. EFIAPI
  3355. CryptoServiceDhComputeKey (
  3356. IN OUT VOID *DhContext,
  3357. IN CONST UINT8 *PeerPublicKey,
  3358. IN UINTN PeerPublicKeySize,
  3359. OUT UINT8 *Key,
  3360. IN OUT UINTN *KeySize
  3361. )
  3362. {
  3363. return CALL_BASECRYPTLIB (Dh.Services.ComputeKey, DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);
  3364. }
  3365. // =====================================================================================
  3366. // Pseudo-Random Generation Primitive
  3367. // =====================================================================================
  3368. /**
  3369. Sets up the seed value for the pseudorandom number generator.
  3370. This function sets up the seed value for the pseudorandom number generator.
  3371. If Seed is not NULL, then the seed passed in is used.
  3372. If Seed is NULL, then default seed is used.
  3373. If this interface is not supported, then return FALSE.
  3374. @param[in] Seed Pointer to seed value.
  3375. If NULL, default seed is used.
  3376. @param[in] SeedSize Size of seed value.
  3377. If Seed is NULL, this parameter is ignored.
  3378. @retval TRUE Pseudorandom number generator has enough entropy for random generation.
  3379. @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
  3380. @retval FALSE This interface is not supported.
  3381. **/
  3382. BOOLEAN
  3383. EFIAPI
  3384. CryptoServiceRandomSeed (
  3385. IN CONST UINT8 *Seed OPTIONAL,
  3386. IN UINTN SeedSize
  3387. )
  3388. {
  3389. return CALL_BASECRYPTLIB (Random.Services.Seed, RandomSeed, (Seed, SeedSize), FALSE);
  3390. }
  3391. /**
  3392. Generates a pseudorandom byte stream of the specified size.
  3393. If Output is NULL, then return FALSE.
  3394. If this interface is not supported, then return FALSE.
  3395. @param[out] Output Pointer to buffer to receive random value.
  3396. @param[in] Size Size of random bytes to generate.
  3397. @retval TRUE Pseudorandom byte stream generated successfully.
  3398. @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
  3399. @retval FALSE This interface is not supported.
  3400. **/
  3401. BOOLEAN
  3402. EFIAPI
  3403. CryptoServiceRandomBytes (
  3404. OUT UINT8 *Output,
  3405. IN UINTN Size
  3406. )
  3407. {
  3408. return CALL_BASECRYPTLIB (Random.Services.Bytes, RandomBytes, (Output, Size), FALSE);
  3409. }
  3410. // =====================================================================================
  3411. // Key Derivation Function Primitive
  3412. // =====================================================================================
  3413. /**
  3414. Derive key data using HMAC-SHA256 based KDF.
  3415. @param[in] Key Pointer to the user-supplied key.
  3416. @param[in] KeySize Key size in bytes.
  3417. @param[in] Salt Pointer to the salt(non-secret) value.
  3418. @param[in] SaltSize Salt size in bytes.
  3419. @param[in] Info Pointer to the application specific info.
  3420. @param[in] InfoSize Info size in bytes.
  3421. @param[out] Out Pointer to buffer to receive hkdf value.
  3422. @param[in] OutSize Size of hkdf bytes to generate.
  3423. @retval TRUE Hkdf generated successfully.
  3424. @retval FALSE Hkdf generation failed.
  3425. **/
  3426. BOOLEAN
  3427. EFIAPI
  3428. CryptoServiceHkdfSha256ExtractAndExpand (
  3429. IN CONST UINT8 *Key,
  3430. IN UINTN KeySize,
  3431. IN CONST UINT8 *Salt,
  3432. IN UINTN SaltSize,
  3433. IN CONST UINT8 *Info,
  3434. IN UINTN InfoSize,
  3435. OUT UINT8 *Out,
  3436. IN UINTN OutSize
  3437. )
  3438. {
  3439. return CALL_BASECRYPTLIB (Hkdf.Services.Sha256ExtractAndExpand, HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);
  3440. }
  3441. /**
  3442. Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).
  3443. @param[in] Key Pointer to the user-supplied key.
  3444. @param[in] KeySize key size in bytes.
  3445. @param[in] Salt Pointer to the salt(non-secret) value.
  3446. @param[in] SaltSize salt size in bytes.
  3447. @param[out] PrkOut Pointer to buffer to receive hkdf value.
  3448. @param[in] PrkOutSize size of hkdf bytes to generate.
  3449. @retval true Hkdf generated successfully.
  3450. @retval false Hkdf generation failed.
  3451. **/
  3452. BOOLEAN
  3453. EFIAPI
  3454. CryptoServiceHkdfSha256Extract (
  3455. IN CONST UINT8 *Key,
  3456. IN UINTN KeySize,
  3457. IN CONST UINT8 *Salt,
  3458. IN UINTN SaltSize,
  3459. OUT UINT8 *PrkOut,
  3460. UINTN PrkOutSize
  3461. )
  3462. {
  3463. return CALL_BASECRYPTLIB (Hkdf.Services.Sha256Extract, HkdfSha256Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);
  3464. }
  3465. /**
  3466. Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).
  3467. @param[in] Prk Pointer to the user-supplied key.
  3468. @param[in] PrkSize Key size in bytes.
  3469. @param[in] Info Pointer to the application specific info.
  3470. @param[in] InfoSize Info size in bytes.
  3471. @param[out] Out Pointer to buffer to receive hkdf value.
  3472. @param[in] OutSize Size of hkdf bytes to generate.
  3473. @retval TRUE Hkdf generated successfully.
  3474. @retval FALSE Hkdf generation failed.
  3475. **/
  3476. BOOLEAN
  3477. EFIAPI
  3478. CryptoServiceHkdfSha256Expand (
  3479. IN CONST UINT8 *Prk,
  3480. IN UINTN PrkSize,
  3481. IN CONST UINT8 *Info,
  3482. IN UINTN InfoSize,
  3483. OUT UINT8 *Out,
  3484. IN UINTN OutSize
  3485. )
  3486. {
  3487. return CALL_BASECRYPTLIB (Hkdf.Services.Sha256Expand, HkdfSha256Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);
  3488. }
  3489. /**
  3490. Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
  3491. @param[in] Key Pointer to the user-supplied key.
  3492. @param[in] KeySize Key size in bytes.
  3493. @param[in] Salt Pointer to the salt(non-secret) value.
  3494. @param[in] SaltSize Salt size in bytes.
  3495. @param[in] Info Pointer to the application specific info.
  3496. @param[in] InfoSize Info size in bytes.
  3497. @param[out] Out Pointer to buffer to receive hkdf value.
  3498. @param[in] OutSize Size of hkdf bytes to generate.
  3499. @retval TRUE Hkdf generated successfully.
  3500. @retval FALSE Hkdf generation failed.
  3501. **/
  3502. BOOLEAN
  3503. EFIAPI
  3504. CryptoServiceHkdfSha384ExtractAndExpand (
  3505. IN CONST UINT8 *Key,
  3506. IN UINTN KeySize,
  3507. IN CONST UINT8 *Salt,
  3508. IN UINTN SaltSize,
  3509. IN CONST UINT8 *Info,
  3510. IN UINTN InfoSize,
  3511. OUT UINT8 *Out,
  3512. IN UINTN OutSize
  3513. )
  3514. {
  3515. return CALL_BASECRYPTLIB (Hkdf.Services.Sha384ExtractAndExpand, HkdfSha384ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);
  3516. }
  3517. /**
  3518. Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).
  3519. @param[in] Key Pointer to the user-supplied key.
  3520. @param[in] KeySize key size in bytes.
  3521. @param[in] Salt Pointer to the salt(non-secret) value.
  3522. @param[in] SaltSize salt size in bytes.
  3523. @param[out] PrkOut Pointer to buffer to receive hkdf value.
  3524. @param[in] PrkOutSize size of hkdf bytes to generate.
  3525. @retval true Hkdf generated successfully.
  3526. @retval false Hkdf generation failed.
  3527. **/
  3528. BOOLEAN
  3529. EFIAPI
  3530. CryptoServiceHkdfSha384Extract (
  3531. IN CONST UINT8 *Key,
  3532. IN UINTN KeySize,
  3533. IN CONST UINT8 *Salt,
  3534. IN UINTN SaltSize,
  3535. OUT UINT8 *PrkOut,
  3536. UINTN PrkOutSize
  3537. )
  3538. {
  3539. return CALL_BASECRYPTLIB (Hkdf.Services.Sha384Extract, HkdfSha384Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);
  3540. }
  3541. /**
  3542. Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).
  3543. @param[in] Prk Pointer to the user-supplied key.
  3544. @param[in] PrkSize Key size in bytes.
  3545. @param[in] Info Pointer to the application specific info.
  3546. @param[in] InfoSize Info size in bytes.
  3547. @param[out] Out Pointer to buffer to receive hkdf value.
  3548. @param[in] OutSize Size of hkdf bytes to generate.
  3549. @retval TRUE Hkdf generated successfully.
  3550. @retval FALSE Hkdf generation failed.
  3551. **/
  3552. BOOLEAN
  3553. EFIAPI
  3554. CryptoServiceHkdfSha384Expand (
  3555. IN CONST UINT8 *Prk,
  3556. IN UINTN PrkSize,
  3557. IN CONST UINT8 *Info,
  3558. IN UINTN InfoSize,
  3559. OUT UINT8 *Out,
  3560. IN UINTN OutSize
  3561. )
  3562. {
  3563. return CALL_BASECRYPTLIB (Hkdf.Services.Sha384Expand, HkdfSha384Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);
  3564. }
  3565. /**
  3566. Initializes the OpenSSL library.
  3567. This function registers ciphers and digests used directly and indirectly
  3568. by SSL/TLS, and initializes the readable error messages.
  3569. This function must be called before any other action takes places.
  3570. @retval TRUE The OpenSSL library has been initialized.
  3571. @retval FALSE Failed to initialize the OpenSSL library.
  3572. **/
  3573. BOOLEAN
  3574. EFIAPI
  3575. CryptoServiceTlsInitialize (
  3576. VOID
  3577. )
  3578. {
  3579. return CALL_BASECRYPTLIB (Tls.Services.Initialize, TlsInitialize, (), FALSE);
  3580. }
  3581. /**
  3582. Free an allocated SSL_CTX object.
  3583. @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
  3584. **/
  3585. VOID
  3586. EFIAPI
  3587. CryptoServiceTlsCtxFree (
  3588. IN VOID *TlsCtx
  3589. )
  3590. {
  3591. CALL_VOID_BASECRYPTLIB (Tls.Services.CtxFree, TlsCtxFree, (TlsCtx));
  3592. }
  3593. /**
  3594. Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
  3595. connections.
  3596. @param[in] MajorVer Major Version of TLS/SSL Protocol.
  3597. @param[in] MinorVer Minor Version of TLS/SSL Protocol.
  3598. @return Pointer to an allocated SSL_CTX object.
  3599. If the creation failed, TlsCtxNew() returns NULL.
  3600. **/
  3601. VOID *
  3602. EFIAPI
  3603. CryptoServiceTlsCtxNew (
  3604. IN UINT8 MajorVer,
  3605. IN UINT8 MinorVer
  3606. )
  3607. {
  3608. return CALL_BASECRYPTLIB (Tls.Services.CtxNew, TlsCtxNew, (MajorVer, MinorVer), NULL);
  3609. }
  3610. /**
  3611. Free an allocated TLS object.
  3612. This function removes the TLS object pointed to by Tls and frees up the
  3613. allocated memory. If Tls is NULL, nothing is done.
  3614. @param[in] Tls Pointer to the TLS object to be freed.
  3615. **/
  3616. VOID
  3617. EFIAPI
  3618. CryptoServiceTlsFree (
  3619. IN VOID *Tls
  3620. )
  3621. {
  3622. CALL_VOID_BASECRYPTLIB (Tls.Services.Free, TlsFree, (Tls));
  3623. }
  3624. /**
  3625. Create a new TLS object for a connection.
  3626. This function creates a new TLS object for a connection. The new object
  3627. inherits the setting of the underlying context TlsCtx: connection method,
  3628. options, verification setting.
  3629. @param[in] TlsCtx Pointer to the SSL_CTX object.
  3630. @return Pointer to an allocated SSL object.
  3631. If the creation failed, TlsNew() returns NULL.
  3632. **/
  3633. VOID *
  3634. EFIAPI
  3635. CryptoServiceTlsNew (
  3636. IN VOID *TlsCtx
  3637. )
  3638. {
  3639. return CALL_BASECRYPTLIB (Tls.Services.New, TlsNew, (TlsCtx), NULL);
  3640. }
  3641. /**
  3642. Checks if the TLS handshake was done.
  3643. This function will check if the specified TLS handshake was done.
  3644. @param[in] Tls Pointer to the TLS object for handshake state checking.
  3645. @retval TRUE The TLS handshake was done.
  3646. @retval FALSE The TLS handshake was not done.
  3647. **/
  3648. BOOLEAN
  3649. EFIAPI
  3650. CryptoServiceTlsInHandshake (
  3651. IN VOID *Tls
  3652. )
  3653. {
  3654. return CALL_BASECRYPTLIB (Tls.Services.InHandshake, TlsInHandshake, (Tls), FALSE);
  3655. }
  3656. /**
  3657. Perform a TLS/SSL handshake.
  3658. This function will perform a TLS/SSL handshake.
  3659. @param[in] Tls Pointer to the TLS object for handshake operation.
  3660. @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
  3661. @param[in] BufferInSize Packet size in bytes for the most recently received TLS
  3662. Handshake packet.
  3663. @param[out] BufferOut Pointer to the buffer to hold the built packet.
  3664. @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
  3665. the buffer size provided by the caller. On output, it
  3666. is the buffer size in fact needed to contain the
  3667. packet.
  3668. @retval EFI_SUCCESS The required TLS packet is built successfully.
  3669. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  3670. Tls is NULL.
  3671. BufferIn is NULL but BufferInSize is NOT 0.
  3672. BufferInSize is 0 but BufferIn is NOT NULL.
  3673. BufferOutSize is NULL.
  3674. BufferOut is NULL if *BufferOutSize is not zero.
  3675. @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
  3676. @retval EFI_ABORTED Something wrong during handshake.
  3677. **/
  3678. EFI_STATUS
  3679. EFIAPI
  3680. CryptoServiceTlsDoHandshake (
  3681. IN VOID *Tls,
  3682. IN UINT8 *BufferIn OPTIONAL,
  3683. IN UINTN BufferInSize OPTIONAL,
  3684. OUT UINT8 *BufferOut OPTIONAL,
  3685. IN OUT UINTN *BufferOutSize
  3686. )
  3687. {
  3688. return CALL_BASECRYPTLIB (Tls.Services.DoHandshake, TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
  3689. }
  3690. /**
  3691. Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
  3692. TLS session has errors and the response packet needs to be Alert message based on error type.
  3693. @param[in] Tls Pointer to the TLS object for state checking.
  3694. @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
  3695. @param[in] BufferInSize Packet size in bytes for the most recently received TLS
  3696. Alert packet.
  3697. @param[out] BufferOut Pointer to the buffer to hold the built packet.
  3698. @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
  3699. the buffer size provided by the caller. On output, it
  3700. is the buffer size in fact needed to contain the
  3701. packet.
  3702. @retval EFI_SUCCESS The required TLS packet is built successfully.
  3703. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  3704. Tls is NULL.
  3705. BufferIn is NULL but BufferInSize is NOT 0.
  3706. BufferInSize is 0 but BufferIn is NOT NULL.
  3707. BufferOutSize is NULL.
  3708. BufferOut is NULL if *BufferOutSize is not zero.
  3709. @retval EFI_ABORTED An error occurred.
  3710. @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
  3711. **/
  3712. EFI_STATUS
  3713. EFIAPI
  3714. CryptoServiceTlsHandleAlert (
  3715. IN VOID *Tls,
  3716. IN UINT8 *BufferIn OPTIONAL,
  3717. IN UINTN BufferInSize OPTIONAL,
  3718. OUT UINT8 *BufferOut OPTIONAL,
  3719. IN OUT UINTN *BufferOutSize
  3720. )
  3721. {
  3722. return CALL_BASECRYPTLIB (Tls.Services.HandleAlert, TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
  3723. }
  3724. /**
  3725. Build the CloseNotify packet.
  3726. @param[in] Tls Pointer to the TLS object for state checking.
  3727. @param[in, out] Buffer Pointer to the buffer to hold the built packet.
  3728. @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
  3729. the buffer size provided by the caller. On output, it
  3730. is the buffer size in fact needed to contain the
  3731. packet.
  3732. @retval EFI_SUCCESS The required TLS packet is built successfully.
  3733. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  3734. Tls is NULL.
  3735. BufferSize is NULL.
  3736. Buffer is NULL if *BufferSize is not zero.
  3737. @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
  3738. **/
  3739. EFI_STATUS
  3740. EFIAPI
  3741. CryptoServiceTlsCloseNotify (
  3742. IN VOID *Tls,
  3743. IN OUT UINT8 *Buffer,
  3744. IN OUT UINTN *BufferSize
  3745. )
  3746. {
  3747. return CALL_BASECRYPTLIB (Tls.Services.CloseNotify, TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);
  3748. }
  3749. /**
  3750. Attempts to read bytes from one TLS object and places the data in Buffer.
  3751. This function will attempt to read BufferSize bytes from the TLS object
  3752. and places the data in Buffer.
  3753. @param[in] Tls Pointer to the TLS object.
  3754. @param[in,out] Buffer Pointer to the buffer to store the data.
  3755. @param[in] BufferSize The size of Buffer in bytes.
  3756. @retval >0 The amount of data successfully read from the TLS object.
  3757. @retval <=0 No data was successfully read.
  3758. **/
  3759. INTN
  3760. EFIAPI
  3761. CryptoServiceTlsCtrlTrafficOut (
  3762. IN VOID *Tls,
  3763. IN OUT VOID *Buffer,
  3764. IN UINTN BufferSize
  3765. )
  3766. {
  3767. return CALL_BASECRYPTLIB (Tls.Services.CtrlTrafficOut, TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);
  3768. }
  3769. /**
  3770. Attempts to write data from the buffer to TLS object.
  3771. This function will attempt to write BufferSize bytes data from the Buffer
  3772. to the TLS object.
  3773. @param[in] Tls Pointer to the TLS object.
  3774. @param[in] Buffer Pointer to the data buffer.
  3775. @param[in] BufferSize The size of Buffer in bytes.
  3776. @retval >0 The amount of data successfully written to the TLS object.
  3777. @retval <=0 No data was successfully written.
  3778. **/
  3779. INTN
  3780. EFIAPI
  3781. CryptoServiceTlsCtrlTrafficIn (
  3782. IN VOID *Tls,
  3783. IN VOID *Buffer,
  3784. IN UINTN BufferSize
  3785. )
  3786. {
  3787. return CALL_BASECRYPTLIB (Tls.Services.CtrlTrafficIn, TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);
  3788. }
  3789. /**
  3790. Attempts to read bytes from the specified TLS connection into the buffer.
  3791. This function tries to read BufferSize bytes data from the specified TLS
  3792. connection into the Buffer.
  3793. @param[in] Tls Pointer to the TLS connection for data reading.
  3794. @param[in,out] Buffer Pointer to the data buffer.
  3795. @param[in] BufferSize The size of Buffer in bytes.
  3796. @retval >0 The read operation was successful, and return value is the
  3797. number of bytes actually read from the TLS connection.
  3798. @retval <=0 The read operation was not successful.
  3799. **/
  3800. INTN
  3801. EFIAPI
  3802. CryptoServiceTlsRead (
  3803. IN VOID *Tls,
  3804. IN OUT VOID *Buffer,
  3805. IN UINTN BufferSize
  3806. )
  3807. {
  3808. return CALL_BASECRYPTLIB (Tls.Services.Read, TlsRead, (Tls, Buffer, BufferSize), 0);
  3809. }
  3810. /**
  3811. Attempts to write data to a TLS connection.
  3812. This function tries to write BufferSize bytes data from the Buffer into the
  3813. specified TLS connection.
  3814. @param[in] Tls Pointer to the TLS connection for data writing.
  3815. @param[in] Buffer Pointer to the data buffer.
  3816. @param[in] BufferSize The size of Buffer in bytes.
  3817. @retval >0 The write operation was successful, and return value is the
  3818. number of bytes actually written to the TLS connection.
  3819. @retval <=0 The write operation was not successful.
  3820. **/
  3821. INTN
  3822. EFIAPI
  3823. CryptoServiceTlsWrite (
  3824. IN VOID *Tls,
  3825. IN VOID *Buffer,
  3826. IN UINTN BufferSize
  3827. )
  3828. {
  3829. return CALL_BASECRYPTLIB (Tls.Services.Write, TlsWrite, (Tls, Buffer, BufferSize), 0);
  3830. }
  3831. /**
  3832. Shutdown a TLS connection.
  3833. Shutdown the TLS connection without releasing the resources, meaning a new
  3834. connection can be started without calling TlsNew() and without setting
  3835. certificates etc.
  3836. @param[in] Tls Pointer to the TLS object to shutdown.
  3837. @retval EFI_SUCCESS The TLS is shutdown successfully.
  3838. @retval EFI_INVALID_PARAMETER Tls is NULL.
  3839. @retval EFI_PROTOCOL_ERROR Some other error occurred.
  3840. **/
  3841. EFI_STATUS
  3842. EFIAPI
  3843. CryptoServiceTlsShutdown (
  3844. IN VOID *Tls
  3845. )
  3846. {
  3847. return CALL_BASECRYPTLIB (Tls.Services.Shutdown, TlsShutdown, (Tls), EFI_UNSUPPORTED);
  3848. }
  3849. /**
  3850. Set a new TLS/SSL method for a particular TLS object.
  3851. This function sets a new TLS/SSL method for a particular TLS object.
  3852. @param[in] Tls Pointer to a TLS object.
  3853. @param[in] MajorVer Major Version of TLS/SSL Protocol.
  3854. @param[in] MinorVer Minor Version of TLS/SSL Protocol.
  3855. @retval EFI_SUCCESS The TLS/SSL method was set successfully.
  3856. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  3857. @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
  3858. **/
  3859. EFI_STATUS
  3860. EFIAPI
  3861. CryptoServiceTlsSetVersion (
  3862. IN VOID *Tls,
  3863. IN UINT8 MajorVer,
  3864. IN UINT8 MinorVer
  3865. )
  3866. {
  3867. return CALL_BASECRYPTLIB (TlsSet.Services.Version, TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);
  3868. }
  3869. /**
  3870. Set TLS object to work in client or server mode.
  3871. This function prepares a TLS object to work in client or server mode.
  3872. @param[in] Tls Pointer to a TLS object.
  3873. @param[in] IsServer Work in server mode.
  3874. @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
  3875. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  3876. @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
  3877. **/
  3878. EFI_STATUS
  3879. EFIAPI
  3880. CryptoServiceTlsSetConnectionEnd (
  3881. IN VOID *Tls,
  3882. IN BOOLEAN IsServer
  3883. )
  3884. {
  3885. return CALL_BASECRYPTLIB (TlsSet.Services.ConnectionEnd, TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);
  3886. }
  3887. /**
  3888. Set the ciphers list to be used by the TLS object.
  3889. This function sets the ciphers for use by a specified TLS object.
  3890. @param[in] Tls Pointer to a TLS object.
  3891. @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
  3892. cipher identifier comes from the TLS Cipher Suite
  3893. Registry of the IANA, interpreting Byte1 and Byte2
  3894. in network (big endian) byte order.
  3895. @param[in] CipherNum The number of cipher in the list.
  3896. @retval EFI_SUCCESS The ciphers list was set successfully.
  3897. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  3898. @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
  3899. @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
  3900. **/
  3901. EFI_STATUS
  3902. EFIAPI
  3903. CryptoServiceTlsSetCipherList (
  3904. IN VOID *Tls,
  3905. IN UINT16 *CipherId,
  3906. IN UINTN CipherNum
  3907. )
  3908. {
  3909. return CALL_BASECRYPTLIB (TlsSet.Services.CipherList, TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);
  3910. }
  3911. /**
  3912. Set the compression method for TLS/SSL operations.
  3913. This function handles TLS/SSL integrated compression methods.
  3914. @param[in] CompMethod The compression method ID.
  3915. @retval EFI_SUCCESS The compression method for the communication was
  3916. set successfully.
  3917. @retval EFI_UNSUPPORTED Unsupported compression method.
  3918. **/
  3919. EFI_STATUS
  3920. EFIAPI
  3921. CryptoServiceTlsSetCompressionMethod (
  3922. IN UINT8 CompMethod
  3923. )
  3924. {
  3925. return CALL_BASECRYPTLIB (TlsSet.Services.CompressionMethod, TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);
  3926. }
  3927. /**
  3928. Set peer certificate verification mode for the TLS connection.
  3929. This function sets the verification mode flags for the TLS connection.
  3930. @param[in] Tls Pointer to the TLS object.
  3931. @param[in] VerifyMode A set of logically or'ed verification mode flags.
  3932. **/
  3933. VOID
  3934. EFIAPI
  3935. CryptoServiceTlsSetVerify (
  3936. IN VOID *Tls,
  3937. IN UINT32 VerifyMode
  3938. )
  3939. {
  3940. CALL_VOID_BASECRYPTLIB (TlsSet.Services.Verify, TlsSetVerify, (Tls, VerifyMode));
  3941. }
  3942. /**
  3943. Set the specified host name to be verified.
  3944. @param[in] Tls Pointer to the TLS object.
  3945. @param[in] Flags The setting flags during the validation.
  3946. @param[in] HostName The specified host name to be verified.
  3947. @retval EFI_SUCCESS The HostName setting was set successfully.
  3948. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  3949. @retval EFI_ABORTED Invalid HostName setting.
  3950. **/
  3951. EFI_STATUS
  3952. EFIAPI
  3953. CryptoServiceTlsSetVerifyHost (
  3954. IN VOID *Tls,
  3955. IN UINT32 Flags,
  3956. IN CHAR8 *HostName
  3957. )
  3958. {
  3959. return CALL_BASECRYPTLIB (TlsSet.Services.VerifyHost, TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);
  3960. }
  3961. /**
  3962. Sets a TLS/SSL session ID to be used during TLS/SSL connect.
  3963. This function sets a session ID to be used when the TLS/SSL connection is
  3964. to be established.
  3965. @param[in] Tls Pointer to the TLS object.
  3966. @param[in] SessionId Session ID data used for session resumption.
  3967. @param[in] SessionIdLen Length of Session ID in bytes.
  3968. @retval EFI_SUCCESS Session ID was set successfully.
  3969. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  3970. @retval EFI_UNSUPPORTED No available session for ID setting.
  3971. **/
  3972. EFI_STATUS
  3973. EFIAPI
  3974. CryptoServiceTlsSetSessionId (
  3975. IN VOID *Tls,
  3976. IN UINT8 *SessionId,
  3977. IN UINT16 SessionIdLen
  3978. )
  3979. {
  3980. return CALL_BASECRYPTLIB (TlsSet.Services.SessionId, TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
  3981. }
  3982. /**
  3983. Adds the CA to the cert store when requesting Server or Client authentication.
  3984. This function adds the CA certificate to the list of CAs when requesting
  3985. Server or Client authentication for the chosen TLS connection.
  3986. @param[in] Tls Pointer to the TLS object.
  3987. @param[in] Data Pointer to the data buffer of a DER-encoded binary
  3988. X.509 certificate or PEM-encoded X.509 certificate.
  3989. @param[in] DataSize The size of data buffer in bytes.
  3990. @retval EFI_SUCCESS The operation succeeded.
  3991. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  3992. @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
  3993. @retval EFI_ABORTED Invalid X.509 certificate.
  3994. **/
  3995. EFI_STATUS
  3996. EFIAPI
  3997. CryptoServiceTlsSetCaCertificate (
  3998. IN VOID *Tls,
  3999. IN VOID *Data,
  4000. IN UINTN DataSize
  4001. )
  4002. {
  4003. return CALL_BASECRYPTLIB (TlsSet.Services.CaCertificate, TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4004. }
  4005. /**
  4006. Loads the local public certificate into the specified TLS object.
  4007. This function loads the X.509 certificate into the specified TLS object
  4008. for TLS negotiation.
  4009. @param[in] Tls Pointer to the TLS object.
  4010. @param[in] Data Pointer to the data buffer of a DER-encoded binary
  4011. X.509 certificate or PEM-encoded X.509 certificate.
  4012. @param[in] DataSize The size of data buffer in bytes.
  4013. @retval EFI_SUCCESS The operation succeeded.
  4014. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  4015. @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
  4016. @retval EFI_ABORTED Invalid X.509 certificate.
  4017. **/
  4018. EFI_STATUS
  4019. EFIAPI
  4020. CryptoServiceTlsSetHostPublicCert (
  4021. IN VOID *Tls,
  4022. IN VOID *Data,
  4023. IN UINTN DataSize
  4024. )
  4025. {
  4026. return CALL_BASECRYPTLIB (TlsSet.Services.HostPublicCert, TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4027. }
  4028. /**
  4029. Adds the local private key to the specified TLS object.
  4030. This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private
  4031. key) into the specified TLS object for TLS negotiation.
  4032. @param[in] Tls Pointer to the TLS object.
  4033. @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded
  4034. or PKCS#8 private key.
  4035. @param[in] DataSize The size of data buffer in bytes.
  4036. @param[in] Password Pointer to NULL-terminated private key password, set it to NULL
  4037. if private key not encrypted.
  4038. @retval EFI_SUCCESS The operation succeeded.
  4039. @retval EFI_UNSUPPORTED This function is not supported.
  4040. @retval EFI_ABORTED Invalid private key data.
  4041. **/
  4042. EFI_STATUS
  4043. EFIAPI
  4044. CryptoServiceTlsSetHostPrivateKeyEx (
  4045. IN VOID *Tls,
  4046. IN VOID *Data,
  4047. IN UINTN DataSize,
  4048. IN VOID *Password OPTIONAL
  4049. )
  4050. {
  4051. return CALL_BASECRYPTLIB (TlsSet.Services.HostPrivateKeyEx, TlsSetHostPrivateKeyEx, (Tls, Data, DataSize, Password), EFI_UNSUPPORTED);
  4052. }
  4053. /**
  4054. Adds the local private key to the specified TLS object.
  4055. This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private
  4056. key) into the specified TLS object for TLS negotiation.
  4057. @param[in] Tls Pointer to the TLS object.
  4058. @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded
  4059. or PKCS#8 private key.
  4060. @param[in] DataSize The size of data buffer in bytes.
  4061. @retval EFI_SUCCESS The operation succeeded.
  4062. @retval EFI_UNSUPPORTED This function is not supported.
  4063. @retval EFI_ABORTED Invalid private key data.
  4064. **/
  4065. EFI_STATUS
  4066. EFIAPI
  4067. CryptoServiceTlsSetHostPrivateKey (
  4068. IN VOID *Tls,
  4069. IN VOID *Data,
  4070. IN UINTN DataSize
  4071. )
  4072. {
  4073. return CALL_BASECRYPTLIB (TlsSet.Services.HostPrivateKey, TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4074. }
  4075. /**
  4076. Adds the CA-supplied certificate revocation list for certificate validation.
  4077. This function adds the CA-supplied certificate revocation list data for
  4078. certificate validity checking.
  4079. @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
  4080. @param[in] DataSize The size of data buffer in bytes.
  4081. @retval EFI_SUCCESS The operation succeeded.
  4082. @retval EFI_UNSUPPORTED This function is not supported.
  4083. @retval EFI_ABORTED Invalid CRL data.
  4084. **/
  4085. EFI_STATUS
  4086. EFIAPI
  4087. CryptoServiceTlsSetCertRevocationList (
  4088. IN VOID *Data,
  4089. IN UINTN DataSize
  4090. )
  4091. {
  4092. return CALL_BASECRYPTLIB (TlsSet.Services.CertRevocationList, TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
  4093. }
  4094. /**
  4095. Set the signature algorithm list to used by the TLS object.
  4096. This function sets the signature algorithms for use by a specified TLS object.
  4097. @param[in] Tls Pointer to a TLS object.
  4098. @param[in] Data Array of UINT8 of signature algorithms. The array consists of
  4099. pairs of the hash algorithm and the signature algorithm as defined
  4100. in RFC 5246
  4101. @param[in] DataSize The length the SignatureAlgoList. Must be divisible by 2.
  4102. @retval EFI_SUCCESS The signature algorithm list was set successfully.
  4103. @retval EFI_INVALID_PARAMETER The parameters are invalid.
  4104. @retval EFI_UNSUPPORTED No supported TLS signature algorithm was found in SignatureAlgoList
  4105. @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
  4106. **/
  4107. EFI_STATUS
  4108. EFIAPI
  4109. CryptoServiceTlsSetSignatureAlgoList (
  4110. IN VOID *Tls,
  4111. IN UINT8 *Data,
  4112. IN UINTN DataSize
  4113. )
  4114. {
  4115. return CALL_BASECRYPTLIB (TlsSet.Services.SignatureAlgoList, TlsSetSignatureAlgoList, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4116. }
  4117. /**
  4118. Set the EC curve to be used for TLS flows
  4119. This function sets the EC curve to be used for TLS flows.
  4120. @param[in] Tls Pointer to a TLS object.
  4121. @param[in] Data An EC named curve as defined in section 5.1.1 of RFC 4492.
  4122. @param[in] DataSize Size of Data, it should be sizeof (UINT32)
  4123. @retval EFI_SUCCESS The EC curve was set successfully.
  4124. @retval EFI_INVALID_PARAMETER The parameters are invalid.
  4125. @retval EFI_UNSUPPORTED The requested TLS EC curve is not supported
  4126. **/
  4127. EFI_STATUS
  4128. EFIAPI
  4129. CryptoServiceTlsSetEcCurve (
  4130. IN VOID *Tls,
  4131. IN UINT8 *Data,
  4132. IN UINTN DataSize
  4133. )
  4134. {
  4135. return CALL_BASECRYPTLIB (TlsSet.Services.EcCurve, TlsSetEcCurve, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4136. }
  4137. /**
  4138. Gets the protocol version used by the specified TLS connection.
  4139. This function returns the protocol version used by the specified TLS
  4140. connection.
  4141. If Tls is NULL, then ASSERT().
  4142. @param[in] Tls Pointer to the TLS object.
  4143. @return The protocol version of the specified TLS connection.
  4144. **/
  4145. UINT16
  4146. EFIAPI
  4147. CryptoServiceTlsGetVersion (
  4148. IN VOID *Tls
  4149. )
  4150. {
  4151. return CALL_BASECRYPTLIB (TlsGet.Services.Version, TlsGetVersion, (Tls), 0);
  4152. }
  4153. /**
  4154. Gets the connection end of the specified TLS connection.
  4155. This function returns the connection end (as client or as server) used by
  4156. the specified TLS connection.
  4157. If Tls is NULL, then ASSERT().
  4158. @param[in] Tls Pointer to the TLS object.
  4159. @return The connection end used by the specified TLS connection.
  4160. **/
  4161. UINT8
  4162. EFIAPI
  4163. CryptoServiceTlsGetConnectionEnd (
  4164. IN VOID *Tls
  4165. )
  4166. {
  4167. return CALL_BASECRYPTLIB (TlsGet.Services.ConnectionEnd, TlsGetConnectionEnd, (Tls), 0);
  4168. }
  4169. /**
  4170. Gets the cipher suite used by the specified TLS connection.
  4171. This function returns current cipher suite used by the specified
  4172. TLS connection.
  4173. @param[in] Tls Pointer to the TLS object.
  4174. @param[in,out] CipherId The cipher suite used by the TLS object.
  4175. @retval EFI_SUCCESS The cipher suite was returned successfully.
  4176. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  4177. @retval EFI_UNSUPPORTED Unsupported cipher suite.
  4178. **/
  4179. EFI_STATUS
  4180. EFIAPI
  4181. CryptoServiceTlsGetCurrentCipher (
  4182. IN VOID *Tls,
  4183. IN OUT UINT16 *CipherId
  4184. )
  4185. {
  4186. return CALL_BASECRYPTLIB (TlsGet.Services.CurrentCipher, TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);
  4187. }
  4188. /**
  4189. Gets the compression methods used by the specified TLS connection.
  4190. This function returns current integrated compression methods used by
  4191. the specified TLS connection.
  4192. @param[in] Tls Pointer to the TLS object.
  4193. @param[in,out] CompressionId The current compression method used by
  4194. the TLS object.
  4195. @retval EFI_SUCCESS The compression method was returned successfully.
  4196. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  4197. @retval EFI_ABORTED Invalid Compression method.
  4198. @retval EFI_UNSUPPORTED This function is not supported.
  4199. **/
  4200. EFI_STATUS
  4201. EFIAPI
  4202. CryptoServiceTlsGetCurrentCompressionId (
  4203. IN VOID *Tls,
  4204. IN OUT UINT8 *CompressionId
  4205. )
  4206. {
  4207. return CALL_BASECRYPTLIB (TlsGet.Services.CurrentCompressionId, TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);
  4208. }
  4209. /**
  4210. Gets the verification mode currently set in the TLS connection.
  4211. This function returns the peer verification mode currently set in the
  4212. specified TLS connection.
  4213. If Tls is NULL, then ASSERT().
  4214. @param[in] Tls Pointer to the TLS object.
  4215. @return The verification mode set in the specified TLS connection.
  4216. **/
  4217. UINT32
  4218. EFIAPI
  4219. CryptoServiceTlsGetVerify (
  4220. IN VOID *Tls
  4221. )
  4222. {
  4223. return CALL_BASECRYPTLIB (TlsGet.Services.Verify, TlsGetVerify, (Tls), 0);
  4224. }
  4225. /**
  4226. Gets the session ID used by the specified TLS connection.
  4227. This function returns the TLS/SSL session ID currently used by the
  4228. specified TLS connection.
  4229. @param[in] Tls Pointer to the TLS object.
  4230. @param[in,out] SessionId Buffer to contain the returned session ID.
  4231. @param[in,out] SessionIdLen The length of Session ID in bytes.
  4232. @retval EFI_SUCCESS The Session ID was returned successfully.
  4233. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  4234. @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
  4235. **/
  4236. EFI_STATUS
  4237. EFIAPI
  4238. CryptoServiceTlsGetSessionId (
  4239. IN VOID *Tls,
  4240. IN OUT UINT8 *SessionId,
  4241. IN OUT UINT16 *SessionIdLen
  4242. )
  4243. {
  4244. return CALL_BASECRYPTLIB (TlsGet.Services.SessionId, TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
  4245. }
  4246. /**
  4247. Gets the client random data used in the specified TLS connection.
  4248. This function returns the TLS/SSL client random data currently used in
  4249. the specified TLS connection.
  4250. @param[in] Tls Pointer to the TLS object.
  4251. @param[in,out] ClientRandom Buffer to contain the returned client
  4252. random data (32 bytes).
  4253. **/
  4254. VOID
  4255. EFIAPI
  4256. CryptoServiceTlsGetClientRandom (
  4257. IN VOID *Tls,
  4258. IN OUT UINT8 *ClientRandom
  4259. )
  4260. {
  4261. CALL_VOID_BASECRYPTLIB (TlsGet.Services.ClientRandom, TlsGetClientRandom, (Tls, ClientRandom));
  4262. }
  4263. /**
  4264. Gets the server random data used in the specified TLS connection.
  4265. This function returns the TLS/SSL server random data currently used in
  4266. the specified TLS connection.
  4267. @param[in] Tls Pointer to the TLS object.
  4268. @param[in,out] ServerRandom Buffer to contain the returned server
  4269. random data (32 bytes).
  4270. **/
  4271. VOID
  4272. EFIAPI
  4273. CryptoServiceTlsGetServerRandom (
  4274. IN VOID *Tls,
  4275. IN OUT UINT8 *ServerRandom
  4276. )
  4277. {
  4278. CALL_VOID_BASECRYPTLIB (TlsGet.Services.ServerRandom, TlsGetServerRandom, (Tls, ServerRandom));
  4279. }
  4280. /**
  4281. Gets the master key data used in the specified TLS connection.
  4282. This function returns the TLS/SSL master key material currently used in
  4283. the specified TLS connection.
  4284. @param[in] Tls Pointer to the TLS object.
  4285. @param[in,out] KeyMaterial Buffer to contain the returned key material.
  4286. @retval EFI_SUCCESS Key material was returned successfully.
  4287. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  4288. @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
  4289. **/
  4290. EFI_STATUS
  4291. EFIAPI
  4292. CryptoServiceTlsGetKeyMaterial (
  4293. IN VOID *Tls,
  4294. IN OUT UINT8 *KeyMaterial
  4295. )
  4296. {
  4297. return CALL_BASECRYPTLIB (TlsGet.Services.KeyMaterial, TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);
  4298. }
  4299. /**
  4300. Gets the CA Certificate from the cert store.
  4301. This function returns the CA certificate for the chosen
  4302. TLS connection.
  4303. @param[in] Tls Pointer to the TLS object.
  4304. @param[out] Data Pointer to the data buffer to receive the CA
  4305. certificate data sent to the client.
  4306. @param[in,out] DataSize The size of data buffer in bytes.
  4307. @retval EFI_SUCCESS The operation succeeded.
  4308. @retval EFI_UNSUPPORTED This function is not supported.
  4309. @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
  4310. **/
  4311. EFI_STATUS
  4312. EFIAPI
  4313. CryptoServiceTlsGetCaCertificate (
  4314. IN VOID *Tls,
  4315. OUT VOID *Data,
  4316. IN OUT UINTN *DataSize
  4317. )
  4318. {
  4319. return CALL_BASECRYPTLIB (TlsGet.Services.CaCertificate, TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4320. }
  4321. /**
  4322. Gets the local public Certificate set in the specified TLS object.
  4323. This function returns the local public certificate which was currently set
  4324. in the specified TLS object.
  4325. @param[in] Tls Pointer to the TLS object.
  4326. @param[out] Data Pointer to the data buffer to receive the local
  4327. public certificate.
  4328. @param[in,out] DataSize The size of data buffer in bytes.
  4329. @retval EFI_SUCCESS The operation succeeded.
  4330. @retval EFI_INVALID_PARAMETER The parameter is invalid.
  4331. @retval EFI_NOT_FOUND The certificate is not found.
  4332. @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
  4333. **/
  4334. EFI_STATUS
  4335. EFIAPI
  4336. CryptoServiceTlsGetHostPublicCert (
  4337. IN VOID *Tls,
  4338. OUT VOID *Data,
  4339. IN OUT UINTN *DataSize
  4340. )
  4341. {
  4342. return CALL_BASECRYPTLIB (TlsGet.Services.HostPublicCert, TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4343. }
  4344. /**
  4345. Gets the local private key set in the specified TLS object.
  4346. This function returns the local private key data which was currently set
  4347. in the specified TLS object.
  4348. @param[in] Tls Pointer to the TLS object.
  4349. @param[out] Data Pointer to the data buffer to receive the local
  4350. private key data.
  4351. @param[in,out] DataSize The size of data buffer in bytes.
  4352. @retval EFI_SUCCESS The operation succeeded.
  4353. @retval EFI_UNSUPPORTED This function is not supported.
  4354. @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
  4355. **/
  4356. EFI_STATUS
  4357. EFIAPI
  4358. CryptoServiceTlsGetHostPrivateKey (
  4359. IN VOID *Tls,
  4360. OUT VOID *Data,
  4361. IN OUT UINTN *DataSize
  4362. )
  4363. {
  4364. return CALL_BASECRYPTLIB (TlsGet.Services.HostPrivateKey, TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
  4365. }
  4366. /**
  4367. Gets the CA-supplied certificate revocation list data set in the specified
  4368. TLS object.
  4369. This function returns the CA-supplied certificate revocation list data which
  4370. was currently set in the specified TLS object.
  4371. @param[out] Data Pointer to the data buffer to receive the CRL data.
  4372. @param[in,out] DataSize The size of data buffer in bytes.
  4373. @retval EFI_SUCCESS The operation succeeded.
  4374. @retval EFI_UNSUPPORTED This function is not supported.
  4375. @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
  4376. **/
  4377. EFI_STATUS
  4378. EFIAPI
  4379. CryptoServiceTlsGetCertRevocationList (
  4380. OUT VOID *Data,
  4381. IN OUT UINTN *DataSize
  4382. )
  4383. {
  4384. return CALL_BASECRYPTLIB (TlsGet.Services.CertRevocationList, TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
  4385. }
  4386. /**
  4387. Derive keying material from a TLS connection.
  4388. This function exports keying material using the mechanism described in RFC
  4389. 5705.
  4390. @param[in] Tls Pointer to the TLS object
  4391. @param[in] Label Description of the key for the PRF function
  4392. @param[in] Context Optional context
  4393. @param[in] ContextLen The length of the context value in bytes
  4394. @param[out] KeyBuffer Buffer to hold the output of the TLS-PRF
  4395. @param[in] KeyBufferLen The length of the KeyBuffer
  4396. @retval EFI_SUCCESS The operation succeeded.
  4397. @retval EFI_INVALID_PARAMETER The TLS object is invalid.
  4398. @retval EFI_PROTOCOL_ERROR Some other error occurred.
  4399. **/
  4400. EFI_STATUS
  4401. EFIAPI
  4402. CryptoServiceTlsGetExportKey (
  4403. IN VOID *Tls,
  4404. IN CONST VOID *Label,
  4405. IN CONST VOID *Context,
  4406. IN UINTN ContextLen,
  4407. OUT VOID *KeyBuffer,
  4408. IN UINTN KeyBufferLen
  4409. )
  4410. {
  4411. return CALL_BASECRYPTLIB (
  4412. TlsGet.Services.ExportKey,
  4413. TlsGetExportKey,
  4414. (Tls, Label, Context, ContextLen,
  4415. KeyBuffer, KeyBufferLen),
  4416. EFI_UNSUPPORTED
  4417. );
  4418. }
  4419. /**
  4420. Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.
  4421. This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in
  4422. RFC 8017.
  4423. Mask generation function is the same as the message digest algorithm.
  4424. If the Signature buffer is too small to hold the contents of signature, FALSE
  4425. is returned and SigSize is set to the required buffer size to obtain the signature.
  4426. If RsaContext is NULL, then return FALSE.
  4427. If Message is NULL, then return FALSE.
  4428. If MsgSize is zero or > INT_MAX, then return FALSE.
  4429. If DigestLen is NOT 32, 48 or 64, return FALSE.
  4430. If SaltLen is not equal to DigestLen, then return FALSE.
  4431. If SigSize is large enough but Signature is NULL, then return FALSE.
  4432. If this interface is not supported, then return FALSE.
  4433. @param[in] RsaContext Pointer to RSA context for signature generation.
  4434. @param[in] Message Pointer to octet message to be signed.
  4435. @param[in] MsgSize Size of the message in bytes.
  4436. @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.
  4437. @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.
  4438. @param[out] Signature Pointer to buffer to receive RSA PSS signature.
  4439. @param[in, out] SigSize On input, the size of Signature buffer in bytes.
  4440. On output, the size of data returned in Signature buffer in bytes.
  4441. @retval TRUE Signature successfully generated in RSASSA-PSS.
  4442. @retval FALSE Signature generation failed.
  4443. @retval FALSE SigSize is too small.
  4444. @retval FALSE This interface is not supported.
  4445. **/
  4446. BOOLEAN
  4447. EFIAPI
  4448. CryptoServiceRsaPssSign (
  4449. IN VOID *RsaContext,
  4450. IN CONST UINT8 *Message,
  4451. IN UINTN MsgSize,
  4452. IN UINT16 DigestLen,
  4453. IN UINT16 SaltLen,
  4454. OUT UINT8 *Signature,
  4455. IN OUT UINTN *SigSize
  4456. )
  4457. {
  4458. return CALL_BASECRYPTLIB (RsaPss.Services.Sign, RsaPssSign, (RsaContext, Message, MsgSize, DigestLen, SaltLen, Signature, SigSize), FALSE);
  4459. }
  4460. /**
  4461. Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.
  4462. Implementation determines salt length automatically from the signature encoding.
  4463. Mask generation function is the same as the message digest algorithm.
  4464. Salt length should be equal to digest length.
  4465. @param[in] RsaContext Pointer to RSA context for signature verification.
  4466. @param[in] Message Pointer to octet message to be verified.
  4467. @param[in] MsgSize Size of the message in bytes.
  4468. @param[in] Signature Pointer to RSASSA-PSS signature to be verified.
  4469. @param[in] SigSize Size of signature in bytes.
  4470. @param[in] DigestLen Length of digest for RSA operation.
  4471. @param[in] SaltLen Salt length for PSS encoding.
  4472. @retval TRUE Valid signature encoded in RSASSA-PSS.
  4473. @retval FALSE Invalid signature or invalid RSA context.
  4474. **/
  4475. BOOLEAN
  4476. EFIAPI
  4477. CryptoServiceRsaPssVerify (
  4478. IN VOID *RsaContext,
  4479. IN CONST UINT8 *Message,
  4480. IN UINTN MsgSize,
  4481. IN CONST UINT8 *Signature,
  4482. IN UINTN SigSize,
  4483. IN UINT16 DigestLen,
  4484. IN UINT16 SaltLen
  4485. )
  4486. {
  4487. return CALL_BASECRYPTLIB (RsaPss.Services.Verify, RsaPssVerify, (RsaContext, Message, MsgSize, Signature, SigSize, DigestLen, SaltLen), FALSE);
  4488. }
  4489. /**
  4490. Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,
  4491. published December 2016.
  4492. @param[in] Input Pointer to the input message (X).
  4493. @param[in] InputByteLen The number(>0) of input bytes provided for the input data.
  4494. @param[in] BlockSize The size of each block (B).
  4495. @param[out] Output Pointer to the output buffer.
  4496. @param[in] OutputByteLen The desired number of output bytes (L).
  4497. @param[in] Customization Pointer to the customization string (S).
  4498. @param[in] CustomByteLen The length of the customization string in bytes.
  4499. @retval TRUE ParallelHash256 digest computation succeeded.
  4500. @retval FALSE ParallelHash256 digest computation failed.
  4501. @retval FALSE This interface is not supported.
  4502. **/
  4503. BOOLEAN
  4504. EFIAPI
  4505. CryptoServiceParallelHash256HashAll (
  4506. IN CONST VOID *Input,
  4507. IN UINTN InputByteLen,
  4508. IN UINTN BlockSize,
  4509. OUT VOID *Output,
  4510. IN UINTN OutputByteLen,
  4511. IN CONST VOID *Customization,
  4512. IN UINTN CustomByteLen
  4513. )
  4514. {
  4515. return CALL_BASECRYPTLIB (ParallelHash.Services.HashAll, ParallelHash256HashAll, (Input, InputByteLen, BlockSize, Output, OutputByteLen, Customization, CustomByteLen), FALSE);
  4516. }
  4517. /**
  4518. Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).
  4519. IvSize must be 12, otherwise FALSE is returned.
  4520. KeySize must be 16, 24 or 32, otherwise FALSE is returned.
  4521. TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
  4522. @param[in] Key Pointer to the encryption key.
  4523. @param[in] KeySize Size of the encryption key in bytes.
  4524. @param[in] Iv Pointer to the IV value.
  4525. @param[in] IvSize Size of the IV value in bytes.
  4526. @param[in] AData Pointer to the additional authenticated data (AAD).
  4527. @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
  4528. @param[in] DataIn Pointer to the input data buffer to be encrypted.
  4529. @param[in] DataInSize Size of the input data buffer in bytes.
  4530. @param[out] TagOut Pointer to a buffer that receives the authentication tag output.
  4531. @param[in] TagSize Size of the authentication tag in bytes.
  4532. @param[out] DataOut Pointer to a buffer that receives the encryption output.
  4533. @param[out] DataOutSize Size of the output data buffer in bytes.
  4534. @retval TRUE AEAD AES-GCM authenticated encryption succeeded.
  4535. @retval FALSE AEAD AES-GCM authenticated encryption failed.
  4536. **/
  4537. BOOLEAN
  4538. EFIAPI
  4539. CryptoServiceAeadAesGcmEncrypt (
  4540. IN CONST UINT8 *Key,
  4541. IN UINTN KeySize,
  4542. IN CONST UINT8 *Iv,
  4543. IN UINTN IvSize,
  4544. IN CONST UINT8 *AData,
  4545. IN UINTN ADataSize,
  4546. IN CONST UINT8 *DataIn,
  4547. IN UINTN DataInSize,
  4548. OUT UINT8 *TagOut,
  4549. IN UINTN TagSize,
  4550. OUT UINT8 *DataOut,
  4551. OUT UINTN *DataOutSize
  4552. )
  4553. {
  4554. return CALL_BASECRYPTLIB (AeadAesGcm.Services.Encrypt, AeadAesGcmEncrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, TagOut, TagSize, DataOut, DataOutSize), FALSE);
  4555. }
  4556. /**
  4557. Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).
  4558. IvSize must be 12, otherwise FALSE is returned.
  4559. KeySize must be 16, 24 or 32, otherwise FALSE is returned.
  4560. TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.
  4561. If additional authenticated data verification fails, FALSE is returned.
  4562. @param[in] Key Pointer to the encryption key.
  4563. @param[in] KeySize Size of the encryption key in bytes.
  4564. @param[in] Iv Pointer to the IV value.
  4565. @param[in] IvSize Size of the IV value in bytes.
  4566. @param[in] AData Pointer to the additional authenticated data (AAD).
  4567. @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.
  4568. @param[in] DataIn Pointer to the input data buffer to be decrypted.
  4569. @param[in] DataInSize Size of the input data buffer in bytes.
  4570. @param[in] Tag Pointer to a buffer that contains the authentication tag.
  4571. @param[in] TagSize Size of the authentication tag in bytes.
  4572. @param[out] DataOut Pointer to a buffer that receives the decryption output.
  4573. @param[out] DataOutSize Size of the output data buffer in bytes.
  4574. @retval TRUE AEAD AES-GCM authenticated decryption succeeded.
  4575. @retval FALSE AEAD AES-GCM authenticated decryption failed.
  4576. **/
  4577. BOOLEAN
  4578. EFIAPI
  4579. CryptoServiceAeadAesGcmDecrypt (
  4580. IN CONST UINT8 *Key,
  4581. IN UINTN KeySize,
  4582. IN CONST UINT8 *Iv,
  4583. IN UINTN IvSize,
  4584. IN CONST UINT8 *AData,
  4585. IN UINTN ADataSize,
  4586. IN CONST UINT8 *DataIn,
  4587. IN UINTN DataInSize,
  4588. IN CONST UINT8 *Tag,
  4589. IN UINTN TagSize,
  4590. OUT UINT8 *DataOut,
  4591. OUT UINTN *DataOutSize
  4592. )
  4593. {
  4594. return CALL_BASECRYPTLIB (AeadAesGcm.Services.Decrypt, AeadAesGcmDecrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, Tag, TagSize, DataOut, DataOutSize), FALSE);
  4595. }
  4596. // =====================================================================================
  4597. // Big number primitives
  4598. // =====================================================================================
  4599. /**
  4600. Allocate new Big Number.
  4601. @retval New BigNum opaque structure or NULL on failure.
  4602. **/
  4603. VOID *
  4604. EFIAPI
  4605. CryptoServiceBigNumInit (
  4606. VOID
  4607. )
  4608. {
  4609. return CALL_BASECRYPTLIB (Bn.Services.Init, BigNumInit, (), NULL);
  4610. }
  4611. /**
  4612. Allocate new Big Number and assign the provided value to it.
  4613. @param[in] Buf Big endian encoded buffer.
  4614. @param[in] Len Buffer length.
  4615. @retval New BigNum opaque structure or NULL on failure.
  4616. **/
  4617. VOID *
  4618. EFIAPI
  4619. CryptoServiceBigNumFromBin (
  4620. IN CONST UINT8 *Buf,
  4621. IN UINTN Len
  4622. )
  4623. {
  4624. return CALL_BASECRYPTLIB (Bn.Services.FromBin, BigNumFromBin, (Buf, Len), NULL);
  4625. }
  4626. /**
  4627. Convert the absolute value of Bn into big-endian form and store it at Buf.
  4628. The Buf array should have at least BigNumBytes() in it.
  4629. @param[in] Bn Big number to convert.
  4630. @param[out] Buf Output buffer.
  4631. @retval The length of the big-endian number placed at Buf or -1 on error.
  4632. **/
  4633. INTN
  4634. EFIAPI
  4635. CryptoServiceBigNumToBin (
  4636. IN CONST VOID *Bn,
  4637. OUT UINT8 *Buf
  4638. )
  4639. {
  4640. return CALL_BASECRYPTLIB (Bn.Services.ToBin, BigNumToBin, (Bn, Buf), -1);
  4641. }
  4642. /**
  4643. Free the Big Number.
  4644. @param[in] Bn Big number to free.
  4645. @param[in] Clear TRUE if the buffer should be cleared.
  4646. **/
  4647. VOID
  4648. EFIAPI
  4649. CryptoServiceBigNumFree (
  4650. IN VOID *Bn,
  4651. IN BOOLEAN Clear
  4652. )
  4653. {
  4654. CALL_VOID_BASECRYPTLIB (Bn.Services.Free, BigNumFree, (Bn, Clear));
  4655. }
  4656. /**
  4657. Calculate the sum of two Big Numbers.
  4658. Please note, all "out" Big number arguments should be properly initialized
  4659. by calling to BigNumInit() or BigNumFromBin() functions.
  4660. @param[in] BnA Big number.
  4661. @param[in] BnB Big number.
  4662. @param[out] BnRes The result of BnA + BnB.
  4663. @retval TRUE On success.
  4664. @retval FALSE Otherwise.
  4665. **/
  4666. BOOLEAN
  4667. EFIAPI
  4668. CryptoServiceBigNumAdd (
  4669. IN CONST VOID *BnA,
  4670. IN CONST VOID *BnB,
  4671. OUT VOID *BnRes
  4672. )
  4673. {
  4674. return CALL_BASECRYPTLIB (Bn.Services.Add, BigNumAdd, (BnA, BnB, BnRes), FALSE);
  4675. }
  4676. /**
  4677. Subtract two Big Numbers.
  4678. Please note, all "out" Big number arguments should be properly initialized
  4679. by calling to BigNumInit() or BigNumFromBin() functions.
  4680. @param[in] BnA Big number.
  4681. @param[in] BnB Big number.
  4682. @param[out] BnRes The result of BnA - BnB.
  4683. @retval TRUE On success.
  4684. @retval FALSE Otherwise.
  4685. **/
  4686. BOOLEAN
  4687. EFIAPI
  4688. CryptoServiceBigNumSub (
  4689. IN CONST VOID *BnA,
  4690. IN CONST VOID *BnB,
  4691. OUT VOID *BnRes
  4692. )
  4693. {
  4694. return CALL_BASECRYPTLIB (Bn.Services.Sub, BigNumSub, (BnA, BnB, BnRes), FALSE);
  4695. }
  4696. /**
  4697. Calculate remainder: BnRes = BnA % BnB.
  4698. Please note, all "out" Big number arguments should be properly initialized
  4699. by calling to BigNumInit() or BigNumFromBin() functions.
  4700. @param[in] BnA Big number.
  4701. @param[in] BnB Big number.
  4702. @param[out] BnRes The result of BnA % BnB.
  4703. @retval TRUE On success.
  4704. @retval FALSE Otherwise.
  4705. **/
  4706. BOOLEAN
  4707. EFIAPI
  4708. CryptoServiceBigNumMod (
  4709. IN CONST VOID *BnA,
  4710. IN CONST VOID *BnB,
  4711. OUT VOID *BnRes
  4712. )
  4713. {
  4714. return CALL_BASECRYPTLIB (Bn.Services.Mod, BigNumMod, (BnA, BnB, BnRes), FALSE);
  4715. }
  4716. /**
  4717. Compute BnA to the BnP-th power modulo BnM.
  4718. Please note, all "out" Big number arguments should be properly initialized.
  4719. by calling to BigNumInit() or BigNumFromBin() functions.
  4720. @param[in] BnA Big number.
  4721. @param[in] BnP Big number (power).
  4722. @param[in] BnM Big number (modulo).
  4723. @param[out] BnRes The result of (BnA ^ BnP) % BnM.
  4724. @retval TRUE On success.
  4725. @retval FALSE Otherwise.
  4726. **/
  4727. BOOLEAN
  4728. EFIAPI
  4729. CryptoServiceBigNumExpMod (
  4730. IN CONST VOID *BnA,
  4731. IN CONST VOID *BnP,
  4732. IN CONST VOID *BnM,
  4733. OUT VOID *BnRes
  4734. )
  4735. {
  4736. return CALL_BASECRYPTLIB (Bn.Services.ExpMod, BigNumExpMod, (BnA, BnP, BnM, BnRes), FALSE);
  4737. }
  4738. /**
  4739. Compute BnA inverse modulo BnM.
  4740. Please note, all "out" Big number arguments should be properly initialized
  4741. by calling to BigNumInit() or BigNumFromBin() functions.
  4742. @param[in] BnA Big number.
  4743. @param[in] BnM Big number (modulo).
  4744. @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.
  4745. @retval TRUE On success.
  4746. @retval FALSE Otherwise.
  4747. **/
  4748. BOOLEAN
  4749. EFIAPI
  4750. CryptoServiceBigNumInverseMod (
  4751. IN CONST VOID *BnA,
  4752. IN CONST VOID *BnM,
  4753. OUT VOID *BnRes
  4754. )
  4755. {
  4756. return CALL_BASECRYPTLIB (Bn.Services.InverseMod, BigNumInverseMod, (BnA, BnM, BnRes), FALSE);
  4757. }
  4758. /**
  4759. Divide two Big Numbers.
  4760. Please note, all "out" Big number arguments should be properly initialized
  4761. by calling to BigNumInit() or BigNumFromBin() functions.
  4762. @param[in] BnA Big number.
  4763. @param[in] BnB Big number.
  4764. @param[out] BnRes The result, such that BnA / BnB.
  4765. @retval TRUE On success.
  4766. @retval FALSE Otherwise.
  4767. **/
  4768. BOOLEAN
  4769. EFIAPI
  4770. CryptoServiceBigNumDiv (
  4771. IN CONST VOID *BnA,
  4772. IN CONST VOID *BnB,
  4773. OUT VOID *BnRes
  4774. )
  4775. {
  4776. return CALL_BASECRYPTLIB (Bn.Services.Div, BigNumDiv, (BnA, BnB, BnRes), FALSE);
  4777. }
  4778. /**
  4779. Multiply two Big Numbers modulo BnM.
  4780. Please note, all "out" Big number arguments should be properly initialized
  4781. by calling to BigNumInit() or BigNumFromBin() functions.
  4782. @param[in] BnA Big number.
  4783. @param[in] BnB Big number.
  4784. @param[in] BnM Big number (modulo).
  4785. @param[out] BnRes The result, such that (BnA * BnB) % BnM.
  4786. @retval TRUE On success.
  4787. @retval FALSE Otherwise.
  4788. **/
  4789. BOOLEAN
  4790. EFIAPI
  4791. CryptoServiceBigNumMulMod (
  4792. IN CONST VOID *BnA,
  4793. IN CONST VOID *BnB,
  4794. IN CONST VOID *BnM,
  4795. OUT VOID *BnRes
  4796. )
  4797. {
  4798. return CALL_BASECRYPTLIB (Bn.Services.MulMod, BigNumMulMod, (BnA, BnB, BnM, BnRes), FALSE);
  4799. }
  4800. /**
  4801. Compare two Big Numbers.
  4802. @param[in] BnA Big number.
  4803. @param[in] BnB Big number.
  4804. @retval 0 BnA == BnB.
  4805. @retval 1 BnA > BnB.
  4806. @retval -1 BnA < BnB.
  4807. **/
  4808. INTN
  4809. EFIAPI
  4810. CryptoServiceBigNumCmp (
  4811. IN CONST VOID *BnA,
  4812. IN CONST VOID *BnB
  4813. )
  4814. {
  4815. return CALL_BASECRYPTLIB (Bn.Services.Cmp, BigNumCmp, (BnA, BnB), 0);
  4816. }
  4817. /**
  4818. Get number of bits in Bn.
  4819. @param[in] Bn Big number.
  4820. @retval Number of bits.
  4821. **/
  4822. UINTN
  4823. EFIAPI
  4824. CryptoServiceBigNumBits (
  4825. IN CONST VOID *Bn
  4826. )
  4827. {
  4828. return CALL_BASECRYPTLIB (Bn.Services.Bits, BigNumBits, (Bn), 0);
  4829. }
  4830. /**
  4831. Get number of bytes in Bn.
  4832. @param[in] Bn Big number.
  4833. @retval Number of bytes.
  4834. **/
  4835. UINTN
  4836. EFIAPI
  4837. CryptoServiceBigNumBytes (
  4838. IN CONST VOID *Bn
  4839. )
  4840. {
  4841. return CALL_BASECRYPTLIB (Bn.Services.Bytes, BigNumBytes, (Bn), 0);
  4842. }
  4843. /**
  4844. Checks if Big Number equals to the given Num.
  4845. @param[in] Bn Big number.
  4846. @param[in] Num Number.
  4847. @retval TRUE iff Bn == Num.
  4848. @retval FALSE otherwise.
  4849. **/
  4850. BOOLEAN
  4851. EFIAPI
  4852. CryptoServiceBigNumIsWord (
  4853. IN CONST VOID *Bn,
  4854. IN UINTN Num
  4855. )
  4856. {
  4857. return CALL_BASECRYPTLIB (Bn.Services.IsWord, BigNumIsWord, (Bn, Num), FALSE);
  4858. }
  4859. /**
  4860. Checks if Big Number is odd.
  4861. @param[in] Bn Big number.
  4862. @retval TRUE Bn is odd (Bn % 2 == 1).
  4863. @retval FALSE otherwise.
  4864. **/
  4865. BOOLEAN
  4866. EFIAPI
  4867. CryptoServiceBigNumIsOdd (
  4868. IN CONST VOID *Bn
  4869. )
  4870. {
  4871. return CALL_BASECRYPTLIB (Bn.Services.IsOdd, BigNumIsOdd, (Bn), FALSE);
  4872. }
  4873. /**
  4874. Copy Big number.
  4875. @param[out] BnDst Destination.
  4876. @param[in] BnSrc Source.
  4877. @retval BnDst on success.
  4878. @retval NULL otherwise.
  4879. **/
  4880. VOID *
  4881. EFIAPI
  4882. CryptoServiceBigNumCopy (
  4883. OUT VOID *BnDst,
  4884. IN CONST VOID *BnSrc
  4885. )
  4886. {
  4887. return CALL_BASECRYPTLIB (Bn.Services.Copy, BigNumCopy, (BnDst, BnSrc), NULL);
  4888. }
  4889. /**
  4890. Get constant Big number with value of "1".
  4891. This may be used to save expensive allocations.
  4892. @retval Big Number with value of 1.
  4893. **/
  4894. CONST VOID *
  4895. EFIAPI
  4896. CryptoServiceBigNumValueOne (
  4897. VOID
  4898. )
  4899. {
  4900. return CALL_BASECRYPTLIB (Bn.Services.ValueOne, BigNumValueOne, (), NULL);
  4901. }
  4902. /**
  4903. Shift right Big Number.
  4904. Please note, all "out" Big number arguments should be properly initialized
  4905. by calling to BigNumInit() or BigNumFromBin() functions.
  4906. @param[in] Bn Big number.
  4907. @param[in] N Number of bits to shift.
  4908. @param[out] BnRes The result.
  4909. @retval TRUE On success.
  4910. @retval FALSE Otherwise.
  4911. **/
  4912. BOOLEAN
  4913. EFIAPI
  4914. CryptoServiceBigNumRShift (
  4915. IN CONST VOID *Bn,
  4916. IN UINTN N,
  4917. OUT VOID *BnRes
  4918. )
  4919. {
  4920. return CALL_BASECRYPTLIB (Bn.Services.RShift, BigNumRShift, (Bn, N, BnRes), FALSE);
  4921. }
  4922. /**
  4923. Mark Big Number for constant time computations.
  4924. This function should be called before any constant time computations are
  4925. performed on the given Big number.
  4926. @param[in] Bn Big number.
  4927. **/
  4928. VOID
  4929. EFIAPI
  4930. CryptoServiceBigNumConstTime (
  4931. IN VOID *Bn
  4932. )
  4933. {
  4934. CALL_VOID_BASECRYPTLIB (Bn.Services.ConstTime, BigNumConstTime, (Bn));
  4935. }
  4936. /**
  4937. Calculate square modulo.
  4938. Please note, all "out" Big number arguments should be properly initialized
  4939. by calling to BigNumInit() or BigNumFromBin() functions.
  4940. @param[in] BnA Big number.
  4941. @param[in] BnM Big number (modulo).
  4942. @param[out] BnRes The result, such that (BnA ^ 2) % BnM.
  4943. @retval TRUE On success.
  4944. @retval FALSE Otherwise.
  4945. **/
  4946. BOOLEAN
  4947. EFIAPI
  4948. CryptoServiceBigNumSqrMod (
  4949. IN CONST VOID *BnA,
  4950. IN CONST VOID *BnM,
  4951. OUT VOID *BnRes
  4952. )
  4953. {
  4954. return CALL_BASECRYPTLIB (Bn.Services.SqrMod, BigNumSqrMod, (BnA, BnM, BnRes), FALSE);
  4955. }
  4956. /**
  4957. Create new Big Number computation context. This is an opaque structure
  4958. which should be passed to any function that requires it. The BN context is
  4959. needed to optimize calculations and expensive allocations.
  4960. @retval Big Number context struct or NULL on failure.
  4961. **/
  4962. VOID *
  4963. EFIAPI
  4964. CryptoServiceBigNumNewContext (
  4965. VOID
  4966. )
  4967. {
  4968. return CALL_BASECRYPTLIB (Bn.Services.NewContext, BigNumNewContext, (), NULL);
  4969. }
  4970. /**
  4971. Free Big Number context that was allocated with BigNumNewContext().
  4972. @param[in] BnCtx Big number context to free.
  4973. **/
  4974. VOID
  4975. EFIAPI
  4976. CryptoServiceBigNumContextFree (
  4977. IN VOID *BnCtx
  4978. )
  4979. {
  4980. CALL_VOID_BASECRYPTLIB (Bn.Services.ContextFree, BigNumContextFree, (BnCtx));
  4981. }
  4982. /**
  4983. Set Big Number to a given value.
  4984. @param[in] Bn Big number to set.
  4985. @param[in] Val Value to set.
  4986. @retval TRUE On success.
  4987. @retval FALSE Otherwise.
  4988. **/
  4989. BOOLEAN
  4990. EFIAPI
  4991. CryptoServiceBigNumSetUint (
  4992. IN VOID *Bn,
  4993. IN UINTN Val
  4994. )
  4995. {
  4996. return CALL_BASECRYPTLIB (Bn.Services.SetUint, BigNumSetUint, (Bn, Val), FALSE);
  4997. }
  4998. /**
  4999. Add two Big Numbers modulo BnM.
  5000. @param[in] BnA Big number.
  5001. @param[in] BnB Big number.
  5002. @param[in] BnM Big number (modulo).
  5003. @param[out] BnRes The result, such that (BnA + BnB) % BnM.
  5004. @retval TRUE On success.
  5005. @retval FALSE Otherwise.
  5006. **/
  5007. BOOLEAN
  5008. EFIAPI
  5009. CryptoServiceBigNumAddMod (
  5010. IN CONST VOID *BnA,
  5011. IN CONST VOID *BnB,
  5012. IN CONST VOID *BnM,
  5013. OUT VOID *BnRes
  5014. )
  5015. {
  5016. return CALL_BASECRYPTLIB (Bn.Services.AddMod, BigNumAddMod, (BnA, BnB, BnM, BnRes), FALSE);
  5017. }
  5018. // =====================================================================================
  5019. // Basic Elliptic Curve Primitives
  5020. // =====================================================================================
  5021. /**
  5022. Initialize new opaque EcGroup object. This object represents an EC curve and
  5023. and is used for calculation within this group. This object should be freed
  5024. using EcGroupFree() function.
  5025. @param[in] CryptoNid Identifying number for the ECC curve (Defined in
  5026. BaseCryptLib.h).
  5027. @retval EcGroup object On success.
  5028. @retval NULL On failure.
  5029. **/
  5030. VOID *
  5031. EFIAPI
  5032. CryptoServiceEcGroupInit (
  5033. IN UINTN CryptoNid
  5034. )
  5035. {
  5036. return CALL_BASECRYPTLIB (Ec.Services.GroupInit, EcGroupInit, (CryptoNid), NULL);
  5037. }
  5038. /**
  5039. Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.
  5040. This function will set the provided Big Number objects to the corresponding
  5041. values. The caller needs to make sure all the "out" BigNumber parameters
  5042. are properly initialized.
  5043. @param[in] EcGroup EC group object.
  5044. @param[out] BnPrime Group prime number.
  5045. @param[out] BnA A coefficient.
  5046. @param[out] BnB B coefficient.
  5047. @param[in] BnCtx BN context.
  5048. @retval TRUE On success.
  5049. @retval FALSE Otherwise.
  5050. **/
  5051. BOOLEAN
  5052. EFIAPI
  5053. CryptoServiceEcGroupGetCurve (
  5054. IN CONST VOID *EcGroup,
  5055. OUT VOID *BnPrime,
  5056. OUT VOID *BnA,
  5057. OUT VOID *BnB,
  5058. IN VOID *BnCtx
  5059. )
  5060. {
  5061. return CALL_BASECRYPTLIB (Ec.Services.GroupGetCurve, EcGroupGetCurve, (EcGroup, BnPrime, BnA, BnB, BnCtx), FALSE);
  5062. }
  5063. /**
  5064. Get EC group order.
  5065. This function will set the provided Big Number object to the corresponding
  5066. value. The caller needs to make sure that the "out" BigNumber parameter
  5067. is properly initialized.
  5068. @param[in] EcGroup EC group object.
  5069. @param[out] BnOrder Group prime number.
  5070. @retval TRUE On success.
  5071. @retval FALSE Otherwise.
  5072. **/
  5073. BOOLEAN
  5074. EFIAPI
  5075. CryptoServiceEcGroupGetOrder (
  5076. IN VOID *EcGroup,
  5077. OUT VOID *BnOrder
  5078. )
  5079. {
  5080. return CALL_BASECRYPTLIB (Ec.Services.GroupGetOrder, EcGroupGetOrder, (EcGroup, BnOrder), FALSE);
  5081. }
  5082. /**
  5083. Free previously allocated EC group object using EcGroupInit().
  5084. @param[in] EcGroup EC group object to free.
  5085. **/
  5086. VOID
  5087. EFIAPI
  5088. CryptoServiceEcGroupFree (
  5089. IN VOID *EcGroup
  5090. )
  5091. {
  5092. CALL_VOID_BASECRYPTLIB (Ec.Services.GroupFree, EcGroupFree, (EcGroup));
  5093. }
  5094. /**
  5095. Initialize new opaque EC Point object. This object represents an EC point
  5096. within the given EC group (curve).
  5097. @param[in] EC Group, properly initialized using EcGroupInit().
  5098. @retval EC Point object On success.
  5099. @retval NULL On failure.
  5100. **/
  5101. VOID *
  5102. EFIAPI
  5103. CryptoServiceEcPointInit (
  5104. IN CONST VOID *EcGroup
  5105. )
  5106. {
  5107. return CALL_BASECRYPTLIB (Ec.Services.PointInit, EcPointInit, (EcGroup), NULL);
  5108. }
  5109. /**
  5110. Free previously allocated EC Point object using EcPointInit().
  5111. @param[in] EcPoint EC Point to free.
  5112. @param[in] Clear TRUE iff the memory should be cleared.
  5113. **/
  5114. VOID
  5115. EFIAPI
  5116. CryptoServiceEcPointDeInit (
  5117. IN VOID *EcPoint,
  5118. IN BOOLEAN Clear
  5119. )
  5120. {
  5121. CALL_VOID_BASECRYPTLIB (Ec.Services.PointDeInit, EcPointDeInit, (EcPoint, Clear));
  5122. }
  5123. /**
  5124. Get EC point affine (x,y) coordinates.
  5125. This function will set the provided Big Number objects to the corresponding
  5126. values. The caller needs to make sure all the "out" BigNumber parameters
  5127. are properly initialized.
  5128. @param[in] EcGroup EC group object.
  5129. @param[in] EcPoint EC point object.
  5130. @param[out] BnX X coordinate.
  5131. @param[out] BnY Y coordinate.
  5132. @param[in] BnCtx BN context, created with BigNumNewContext().
  5133. @retval TRUE On success.
  5134. @retval FALSE Otherwise.
  5135. **/
  5136. BOOLEAN
  5137. EFIAPI
  5138. CryptoServiceEcPointGetAffineCoordinates (
  5139. IN CONST VOID *EcGroup,
  5140. IN CONST VOID *EcPoint,
  5141. OUT VOID *BnX,
  5142. OUT VOID *BnY,
  5143. IN VOID *BnCtx
  5144. )
  5145. {
  5146. return CALL_BASECRYPTLIB (Ec.Services.PointGetAffineCoordinates, EcPointGetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);
  5147. }
  5148. /**
  5149. Set EC point affine (x,y) coordinates.
  5150. @param[in] EcGroup EC group object.
  5151. @param[in] EcPoint EC point object.
  5152. @param[in] BnX X coordinate.
  5153. @param[in] BnY Y coordinate.
  5154. @param[in] BnCtx BN context, created with BigNumNewContext().
  5155. @retval TRUE On success.
  5156. @retval FALSE Otherwise.
  5157. **/
  5158. BOOLEAN
  5159. EFIAPI
  5160. CryptoServiceEcPointSetAffineCoordinates (
  5161. IN CONST VOID *EcGroup,
  5162. IN VOID *EcPoint,
  5163. IN CONST VOID *BnX,
  5164. IN CONST VOID *BnY,
  5165. IN VOID *BnCtx
  5166. )
  5167. {
  5168. return CALL_BASECRYPTLIB (Ec.Services.PointSetAffineCoordinates, EcPointSetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);
  5169. }
  5170. /**
  5171. EC Point addition. EcPointResult = EcPointA + EcPointB.
  5172. @param[in] EcGroup EC group object.
  5173. @param[out] EcPointResult EC point to hold the result. The point should
  5174. be properly initialized.
  5175. @param[in] EcPointA EC Point.
  5176. @param[in] EcPointB EC Point.
  5177. @param[in] BnCtx BN context, created with BigNumNewContext().
  5178. @retval TRUE On success.
  5179. @retval FALSE Otherwise.
  5180. **/
  5181. BOOLEAN
  5182. EFIAPI
  5183. CryptoServiceEcPointAdd (
  5184. IN CONST VOID *EcGroup,
  5185. OUT VOID *EcPointResult,
  5186. IN CONST VOID *EcPointA,
  5187. IN CONST VOID *EcPointB,
  5188. IN VOID *BnCtx
  5189. )
  5190. {
  5191. return CALL_BASECRYPTLIB (Ec.Services.PointAdd, EcPointAdd, (EcGroup, EcPointResult, EcPointA, EcPointB, BnCtx), FALSE);
  5192. }
  5193. /**
  5194. Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.
  5195. @param[in] EcGroup EC group object.
  5196. @param[out] EcPointResult EC point to hold the result. The point should
  5197. be properly initialized.
  5198. @param[in] EcPoint EC Point.
  5199. @param[in] BnPScalar P Scalar.
  5200. @param[in] BnCtx BN context, created with BigNumNewContext().
  5201. @retval TRUE On success.
  5202. @retval FALSE Otherwise.
  5203. **/
  5204. BOOLEAN
  5205. EFIAPI
  5206. CryptoServiceEcPointMul (
  5207. IN CONST VOID *EcGroup,
  5208. OUT VOID *EcPointResult,
  5209. IN CONST VOID *EcPoint,
  5210. IN CONST VOID *BnPScalar,
  5211. IN VOID *BnCtx
  5212. )
  5213. {
  5214. return CALL_BASECRYPTLIB (Ec.Services.PointMul, EcPointMul, (EcGroup, EcPointResult, EcPoint, BnPScalar, BnCtx), FALSE);
  5215. }
  5216. /**
  5217. Calculate the inverse of the supplied EC point.
  5218. @param[in] EcGroup EC group object.
  5219. @param[in,out] EcPoint EC point to invert.
  5220. @param[in] BnCtx BN context, created with BigNumNewContext().
  5221. @retval TRUE On success.
  5222. @retval FALSE Otherwise.
  5223. **/
  5224. BOOLEAN
  5225. EFIAPI
  5226. CryptoServiceEcPointInvert (
  5227. IN CONST VOID *EcGroup,
  5228. IN OUT VOID *EcPoint,
  5229. IN VOID *BnCtx
  5230. )
  5231. {
  5232. return CALL_BASECRYPTLIB (Ec.Services.PointInvert, EcPointInvert, (EcGroup, EcPoint, BnCtx), FALSE);
  5233. }
  5234. /**
  5235. Check if the supplied point is on EC curve.
  5236. @param[in] EcGroup EC group object.
  5237. @param[in] EcPoint EC point to check.
  5238. @param[in] BnCtx BN context, created with BigNumNewContext().
  5239. @retval TRUE On curve.
  5240. @retval FALSE Otherwise.
  5241. **/
  5242. BOOLEAN
  5243. EFIAPI
  5244. CryptoServiceEcPointIsOnCurve (
  5245. IN CONST VOID *EcGroup,
  5246. IN CONST VOID *EcPoint,
  5247. IN VOID *BnCtx
  5248. )
  5249. {
  5250. return CALL_BASECRYPTLIB (Ec.Services.PointIsOnCurve, EcPointIsOnCurve, (EcGroup, EcPoint, BnCtx), FALSE);
  5251. }
  5252. /**
  5253. Check if the supplied point is at infinity.
  5254. @param[in] EcGroup EC group object.
  5255. @param[in] EcPoint EC point to check.
  5256. @retval TRUE At infinity.
  5257. @retval FALSE Otherwise.
  5258. **/
  5259. BOOLEAN
  5260. EFIAPI
  5261. CryptoServiceEcPointIsAtInfinity (
  5262. IN CONST VOID *EcGroup,
  5263. IN CONST VOID *EcPoint
  5264. )
  5265. {
  5266. return CALL_BASECRYPTLIB (Ec.Services.PointIsAtInfinity, EcPointIsAtInfinity, (EcGroup, EcPoint), FALSE);
  5267. }
  5268. /**
  5269. Check if EC points are equal.
  5270. @param[in] EcGroup EC group object.
  5271. @param[in] EcPointA EC point A.
  5272. @param[in] EcPointB EC point B.
  5273. @param[in] BnCtx BN context, created with BigNumNewContext().
  5274. @retval TRUE A == B.
  5275. @retval FALSE Otherwise.
  5276. **/
  5277. BOOLEAN
  5278. EFIAPI
  5279. CryptoServiceEcPointEqual (
  5280. IN CONST VOID *EcGroup,
  5281. IN CONST VOID *EcPointA,
  5282. IN CONST VOID *EcPointB,
  5283. IN VOID *BnCtx
  5284. )
  5285. {
  5286. return CALL_BASECRYPTLIB (Ec.Services.PointEqual, EcPointEqual, (EcGroup, EcPointA, EcPointB, BnCtx), FALSE);
  5287. }
  5288. /**
  5289. Set EC point compressed coordinates. Points can be described in terms of
  5290. their compressed coordinates. For a point (x, y), for any given value for x
  5291. such that the point is on the curve there will only ever be two possible
  5292. values for y. Therefore, a point can be set using this function where BnX is
  5293. the x coordinate and YBit is a value 0 or 1 to identify which of the two
  5294. possible values for y should be used.
  5295. @param[in] EcGroup EC group object.
  5296. @param[in] EcPoint EC Point.
  5297. @param[in] BnX X coordinate.
  5298. @param[in] YBit 0 or 1 to identify which Y value is used.
  5299. @param[in] BnCtx BN context, created with BigNumNewContext().
  5300. @retval TRUE On success.
  5301. @retval FALSE Otherwise.
  5302. **/
  5303. BOOLEAN
  5304. EFIAPI
  5305. CryptoServiceEcPointSetCompressedCoordinates (
  5306. IN CONST VOID *EcGroup,
  5307. IN VOID *EcPoint,
  5308. IN CONST VOID *BnX,
  5309. IN UINT8 YBit,
  5310. IN VOID *BnCtx
  5311. )
  5312. {
  5313. return CALL_BASECRYPTLIB (Ec.Services.PointSetCompressedCoordinates, EcPointSetCompressedCoordinates, (EcGroup, EcPoint, BnX, YBit, BnCtx), FALSE);
  5314. }
  5315. // =====================================================================================
  5316. // Elliptic Curve Diffie Hellman Primitives
  5317. // =====================================================================================
  5318. /**
  5319. Allocates and Initializes one Elliptic Curve Context for subsequent use
  5320. with the NID.
  5321. @param[in] Nid cipher NID
  5322. @return Pointer to the Elliptic Curve Context that has been initialized.
  5323. If the allocations fails, EcNewByNid() returns NULL.
  5324. **/
  5325. VOID *
  5326. EFIAPI
  5327. CryptoServiceEcNewByNid (
  5328. IN UINTN Nid
  5329. )
  5330. {
  5331. return CALL_BASECRYPTLIB (Ec.Services.NewByNid, EcNewByNid, (Nid), NULL);
  5332. }
  5333. /**
  5334. Release the specified EC context.
  5335. @param[in] EcContext Pointer to the EC context to be released.
  5336. **/
  5337. VOID
  5338. EFIAPI
  5339. CryptoServiceEcFree (
  5340. IN VOID *EcContext
  5341. )
  5342. {
  5343. CALL_VOID_BASECRYPTLIB (Ec.Services.Free, EcFree, (EcContext));
  5344. }
  5345. /**
  5346. Generates EC key and returns EC public key (X, Y), Please note, this function uses
  5347. pseudo random number generator. The caller must make sure RandomSeed()
  5348. function was properly called before.
  5349. The Ec context should be correctly initialized by EcNewByNid.
  5350. This function generates random secret, and computes the public key (X, Y), which is
  5351. returned via parameter Public, PublicSize.
  5352. X is the first half of Public with size being PublicSize / 2,
  5353. Y is the second half of Public with size being PublicSize / 2.
  5354. EC context is updated accordingly.
  5355. If the Public buffer is too small to hold the public X, Y, FALSE is returned and
  5356. PublicSize is set to the required buffer size to obtain the public X, Y.
  5357. For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
  5358. For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
  5359. For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
  5360. If EcContext is NULL, then return FALSE.
  5361. If PublicSize is NULL, then return FALSE.
  5362. If PublicSize is large enough but Public is NULL, then return FALSE.
  5363. @param[in, out] EcContext Pointer to the EC context.
  5364. @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
  5365. @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
  5366. On output, the size of data returned in Public buffer in bytes.
  5367. @retval TRUE EC public X,Y generation succeeded.
  5368. @retval FALSE EC public X,Y generation failed.
  5369. @retval FALSE PublicKeySize is not large enough.
  5370. **/
  5371. BOOLEAN
  5372. EFIAPI
  5373. CryptoServiceEcGenerateKey (
  5374. IN OUT VOID *EcContext,
  5375. OUT UINT8 *PublicKey,
  5376. IN OUT UINTN *PublicKeySize
  5377. )
  5378. {
  5379. return CALL_BASECRYPTLIB (Ec.Services.GenerateKey, EcGenerateKey, (EcContext, PublicKey, PublicKeySize), FALSE);
  5380. }
  5381. /**
  5382. Gets the public key component from the established EC context.
  5383. The Ec context should be correctly initialized by EcNewByNid, and successfully
  5384. generate key pair from EcGenerateKey().
  5385. For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.
  5386. For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.
  5387. For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.
  5388. @param[in, out] EcContext Pointer to EC context being set.
  5389. @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.
  5390. @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.
  5391. On output, the size of data returned in Public buffer in bytes.
  5392. @retval TRUE EC key component was retrieved successfully.
  5393. @retval FALSE Invalid EC key component.
  5394. **/
  5395. BOOLEAN
  5396. EFIAPI
  5397. CryptoServiceEcGetPubKey (
  5398. IN OUT VOID *EcContext,
  5399. OUT UINT8 *PublicKey,
  5400. IN OUT UINTN *PublicKeySize
  5401. )
  5402. {
  5403. return CALL_BASECRYPTLIB (Ec.Services.GetPubKey, EcGetPubKey, (EcContext, PublicKey, PublicKeySize), FALSE);
  5404. }
  5405. /**
  5406. Computes exchanged common key.
  5407. Given peer's public key (X, Y), this function computes the exchanged common key,
  5408. based on its own context including value of curve parameter and random secret.
  5409. X is the first half of PeerPublic with size being PeerPublicSize / 2,
  5410. Y is the second half of PeerPublic with size being PeerPublicSize / 2.
  5411. If EcContext is NULL, then return FALSE.
  5412. If PeerPublic is NULL, then return FALSE.
  5413. If PeerPublicSize is 0, then return FALSE.
  5414. If Key is NULL, then return FALSE.
  5415. If KeySize is not large enough, then return FALSE.
  5416. For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.
  5417. For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.
  5418. For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.
  5419. @param[in, out] EcContext Pointer to the EC context.
  5420. @param[in] PeerPublic Pointer to the peer's public X,Y.
  5421. @param[in] PeerPublicSize Size of peer's public X,Y in bytes.
  5422. @param[in] CompressFlag Flag of PeerPublic is compressed or not.
  5423. @param[out] Key Pointer to the buffer to receive generated key.
  5424. @param[in, out] KeySize On input, the size of Key buffer in bytes.
  5425. On output, the size of data returned in Key buffer in bytes.
  5426. @retval TRUE EC exchanged key generation succeeded.
  5427. @retval FALSE EC exchanged key generation failed.
  5428. @retval FALSE KeySize is not large enough.
  5429. **/
  5430. BOOLEAN
  5431. EFIAPI
  5432. CryptoServiceEcDhComputeKey (
  5433. IN OUT VOID *EcContext,
  5434. IN CONST UINT8 *PeerPublic,
  5435. IN UINTN PeerPublicSize,
  5436. IN CONST INT32 *CompressFlag,
  5437. OUT UINT8 *Key,
  5438. IN OUT UINTN *KeySize
  5439. )
  5440. {
  5441. return CALL_BASECRYPTLIB (Ec.Services.DhComputeKey, EcDhComputeKey, (EcContext, PeerPublic, PeerPublicSize, CompressFlag, Key, KeySize), FALSE);
  5442. }
  5443. /**
  5444. Retrieve the EC Public Key from one DER-encoded X509 certificate.
  5445. @param[in] Cert Pointer to the DER-encoded X509 certificate.
  5446. @param[in] CertSize Size of the X509 certificate in bytes.
  5447. @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
  5448. EC public key component. Use EcFree() function to free the
  5449. resource.
  5450. If Cert is NULL, then return FALSE.
  5451. If EcContext is NULL, then return FALSE.
  5452. @retval TRUE EC Public Key was retrieved successfully.
  5453. @retval FALSE Fail to retrieve EC public key from X509 certificate.
  5454. **/
  5455. BOOLEAN
  5456. EFIAPI
  5457. CryptoServiceEcGetPublicKeyFromX509 (
  5458. IN CONST UINT8 *Cert,
  5459. IN UINTN CertSize,
  5460. OUT VOID **EcContext
  5461. )
  5462. {
  5463. return CALL_BASECRYPTLIB (Ec.Services.GetPublicKeyFromX509, EcGetPublicKeyFromX509, (Cert, CertSize, EcContext), FALSE);
  5464. }
  5465. /**
  5466. Retrieve the EC Private Key from the password-protected PEM key data.
  5467. @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
  5468. @param[in] PemSize Size of the PEM key data in bytes.
  5469. @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
  5470. @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved
  5471. EC private key component. Use EcFree() function to free the
  5472. resource.
  5473. If PemData is NULL, then return FALSE.
  5474. If EcContext is NULL, then return FALSE.
  5475. @retval TRUE EC Private Key was retrieved successfully.
  5476. @retval FALSE Invalid PEM key data or incorrect password.
  5477. **/
  5478. BOOLEAN
  5479. EFIAPI
  5480. CryptoServiceEcGetPrivateKeyFromPem (
  5481. IN CONST UINT8 *PemData,
  5482. IN UINTN PemSize,
  5483. IN CONST CHAR8 *Password,
  5484. OUT VOID **EcContext
  5485. )
  5486. {
  5487. return CALL_BASECRYPTLIB (Ec.Services.GetPrivateKeyFromPem, EcGetPrivateKeyFromPem, (PemData, PemSize, Password, EcContext), FALSE);
  5488. }
  5489. /**
  5490. Carries out the EC-DSA signature.
  5491. This function carries out the EC-DSA signature.
  5492. If the Signature buffer is too small to hold the contents of signature, FALSE
  5493. is returned and SigSize is set to the required buffer size to obtain the signature.
  5494. If EcContext is NULL, then return FALSE.
  5495. If MessageHash is NULL, then return FALSE.
  5496. If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
  5497. If SigSize is large enough but Signature is NULL, then return FALSE.
  5498. For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
  5499. For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
  5500. For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
  5501. @param[in] EcContext Pointer to EC context for signature generation.
  5502. @param[in] HashNid hash NID
  5503. @param[in] MessageHash Pointer to octet message hash to be signed.
  5504. @param[in] HashSize Size of the message hash in bytes.
  5505. @param[out] Signature Pointer to buffer to receive EC-DSA signature.
  5506. @param[in, out] SigSize On input, the size of Signature buffer in bytes.
  5507. On output, the size of data returned in Signature buffer in bytes.
  5508. @retval TRUE Signature successfully generated in EC-DSA.
  5509. @retval FALSE Signature generation failed.
  5510. @retval FALSE SigSize is too small.
  5511. **/
  5512. BOOLEAN
  5513. EFIAPI
  5514. CryptoServiceEcDsaSign (
  5515. IN VOID *EcContext,
  5516. IN UINTN HashNid,
  5517. IN CONST UINT8 *MessageHash,
  5518. IN UINTN HashSize,
  5519. OUT UINT8 *Signature,
  5520. IN OUT UINTN *SigSize
  5521. )
  5522. {
  5523. return CALL_BASECRYPTLIB (Ec.Services.DsaSign, EcDsaSign, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);
  5524. }
  5525. /**
  5526. Verifies the EC-DSA signature.
  5527. If EcContext is NULL, then return FALSE.
  5528. If MessageHash is NULL, then return FALSE.
  5529. If Signature is NULL, then return FALSE.
  5530. If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.
  5531. For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.
  5532. For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.
  5533. For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.
  5534. @param[in] EcContext Pointer to EC context for signature verification.
  5535. @param[in] HashNid hash NID
  5536. @param[in] MessageHash Pointer to octet message hash to be checked.
  5537. @param[in] HashSize Size of the message hash in bytes.
  5538. @param[in] Signature Pointer to EC-DSA signature to be verified.
  5539. @param[in] SigSize Size of signature in bytes.
  5540. @retval TRUE Valid signature encoded in EC-DSA.
  5541. @retval FALSE Invalid signature or invalid EC context.
  5542. **/
  5543. BOOLEAN
  5544. EFIAPI
  5545. CryptoServiceEcDsaVerify (
  5546. IN VOID *EcContext,
  5547. IN UINTN HashNid,
  5548. IN CONST UINT8 *MessageHash,
  5549. IN UINTN HashSize,
  5550. IN CONST UINT8 *Signature,
  5551. IN UINTN SigSize
  5552. )
  5553. {
  5554. return CALL_BASECRYPTLIB (Ec.Services.DsaVerify, EcDsaVerify, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);
  5555. }
  5556. const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = {
  5557. /// Version
  5558. CryptoServiceGetCryptoVersion,
  5559. /// HMAC MD5 - deprecated and unsupported
  5560. DeprecatedCryptoServiceHmacMd5New,
  5561. DeprecatedCryptoServiceHmacMd5Free,
  5562. DeprecatedCryptoServiceHmacMd5SetKey,
  5563. DeprecatedCryptoServiceHmacMd5Duplicate,
  5564. DeprecatedCryptoServiceHmacMd5Update,
  5565. DeprecatedCryptoServiceHmacMd5Final,
  5566. /// HMAC SHA1 - deprecated and unsupported
  5567. DeprecatedCryptoServiceHmacSha1New,
  5568. DeprecatedCryptoServiceHmacSha1Free,
  5569. DeprecatedCryptoServiceHmacSha1SetKey,
  5570. DeprecatedCryptoServiceHmacSha1Duplicate,
  5571. DeprecatedCryptoServiceHmacSha1Update,
  5572. DeprecatedCryptoServiceHmacSha1Final,
  5573. /// HMAC SHA256
  5574. CryptoServiceHmacSha256New,
  5575. CryptoServiceHmacSha256Free,
  5576. CryptoServiceHmacSha256SetKey,
  5577. CryptoServiceHmacSha256Duplicate,
  5578. CryptoServiceHmacSha256Update,
  5579. CryptoServiceHmacSha256Final,
  5580. /// Md4 - deprecated and unsupported
  5581. DeprecatedCryptoServiceMd4GetContextSize,
  5582. DeprecatedCryptoServiceMd4Init,
  5583. DeprecatedCryptoServiceMd4Duplicate,
  5584. DeprecatedCryptoServiceMd4Update,
  5585. DeprecatedCryptoServiceMd4Final,
  5586. DeprecatedCryptoServiceMd4HashAll,
  5587. #ifndef ENABLE_MD5_DEPRECATED_INTERFACES
  5588. /// Md5 - deprecated and unsupported
  5589. DeprecatedCryptoServiceMd5GetContextSize,
  5590. DeprecatedCryptoServiceMd5Init,
  5591. DeprecatedCryptoServiceMd5Duplicate,
  5592. DeprecatedCryptoServiceMd5Update,
  5593. DeprecatedCryptoServiceMd5Final,
  5594. DeprecatedCryptoServiceMd5HashAll,
  5595. #else
  5596. /// Md5
  5597. CryptoServiceMd5GetContextSize,
  5598. CryptoServiceMd5Init,
  5599. CryptoServiceMd5Duplicate,
  5600. CryptoServiceMd5Update,
  5601. CryptoServiceMd5Final,
  5602. CryptoServiceMd5HashAll,
  5603. #endif
  5604. /// Pkcs
  5605. CryptoServicePkcs1v2Encrypt,
  5606. CryptoServicePkcs5HashPassword,
  5607. CryptoServicePkcs7Verify,
  5608. CryptoServiceVerifyEKUsInPkcs7Signature,
  5609. CryptoServicePkcs7GetSigners,
  5610. CryptoServicePkcs7FreeSigners,
  5611. CryptoServicePkcs7Sign,
  5612. CryptoServicePkcs7GetAttachedContent,
  5613. CryptoServicePkcs7GetCertificatesList,
  5614. CryptoServiceAuthenticodeVerify,
  5615. CryptoServiceImageTimestampVerify,
  5616. /// DH
  5617. CryptoServiceDhNew,
  5618. CryptoServiceDhFree,
  5619. CryptoServiceDhGenerateParameter,
  5620. CryptoServiceDhSetParameter,
  5621. CryptoServiceDhGenerateKey,
  5622. CryptoServiceDhComputeKey,
  5623. /// Random
  5624. CryptoServiceRandomSeed,
  5625. CryptoServiceRandomBytes,
  5626. /// RSA
  5627. CryptoServiceRsaPkcs1Verify,
  5628. CryptoServiceRsaNew,
  5629. CryptoServiceRsaFree,
  5630. CryptoServiceRsaSetKey,
  5631. CryptoServiceRsaGetKey,
  5632. CryptoServiceRsaGenerateKey,
  5633. CryptoServiceRsaCheckKey,
  5634. CryptoServiceRsaPkcs1Sign,
  5635. CryptoServiceRsaPkcs1Verify,
  5636. CryptoServiceRsaGetPrivateKeyFromPem,
  5637. CryptoServiceRsaGetPublicKeyFromX509,
  5638. #ifdef DISABLE_SHA1_DEPRECATED_INTERFACES
  5639. /// Sha1 - deprecated and unsupported
  5640. DeprecatedCryptoServiceSha1GetContextSize,
  5641. DeprecatedCryptoServiceSha1Init,
  5642. DeprecatedCryptoServiceSha1Duplicate,
  5643. DeprecatedCryptoServiceSha1Update,
  5644. DeprecatedCryptoServiceSha1Final,
  5645. DeprecatedCryptoServiceSha1HashAll,
  5646. #else
  5647. /// Sha1
  5648. CryptoServiceSha1GetContextSize,
  5649. CryptoServiceSha1Init,
  5650. CryptoServiceSha1Duplicate,
  5651. CryptoServiceSha1Update,
  5652. CryptoServiceSha1Final,
  5653. CryptoServiceSha1HashAll,
  5654. #endif
  5655. /// Sha256
  5656. CryptoServiceSha256GetContextSize,
  5657. CryptoServiceSha256Init,
  5658. CryptoServiceSha256Duplicate,
  5659. CryptoServiceSha256Update,
  5660. CryptoServiceSha256Final,
  5661. CryptoServiceSha256HashAll,
  5662. /// Sha384
  5663. CryptoServiceSha384GetContextSize,
  5664. CryptoServiceSha384Init,
  5665. CryptoServiceSha384Duplicate,
  5666. CryptoServiceSha384Update,
  5667. CryptoServiceSha384Final,
  5668. CryptoServiceSha384HashAll,
  5669. /// Sha512
  5670. CryptoServiceSha512GetContextSize,
  5671. CryptoServiceSha512Init,
  5672. CryptoServiceSha512Duplicate,
  5673. CryptoServiceSha512Update,
  5674. CryptoServiceSha512Final,
  5675. CryptoServiceSha512HashAll,
  5676. /// X509
  5677. CryptoServiceX509GetSubjectName,
  5678. CryptoServiceX509GetCommonName,
  5679. CryptoServiceX509GetOrganizationName,
  5680. CryptoServiceX509VerifyCert,
  5681. CryptoServiceX509ConstructCertificate,
  5682. CryptoServiceX509ConstructCertificateStack,
  5683. CryptoServiceX509Free,
  5684. CryptoServiceX509StackFree,
  5685. CryptoServiceX509GetTBSCert,
  5686. /// TDES - deprecated and unsupported
  5687. DeprecatedCryptoServiceTdesGetContextSize,
  5688. DeprecatedCryptoServiceTdesInit,
  5689. DeprecatedCryptoServiceTdesEcbEncrypt,
  5690. DeprecatedCryptoServiceTdesEcbDecrypt,
  5691. DeprecatedCryptoServiceTdesCbcEncrypt,
  5692. DeprecatedCryptoServiceTdesCbcDecrypt,
  5693. /// AES - ECB mode is deprecated and unsupported
  5694. CryptoServiceAesGetContextSize,
  5695. CryptoServiceAesInit,
  5696. DeprecatedCryptoServiceAesEcbEncrypt,
  5697. DeprecatedCryptoServiceAesEcbDecrypt,
  5698. CryptoServiceAesCbcEncrypt,
  5699. CryptoServiceAesCbcDecrypt,
  5700. /// Arc4 - deprecated and unsupported
  5701. DeprecatedCryptoServiceArc4GetContextSize,
  5702. DeprecatedCryptoServiceArc4Init,
  5703. DeprecatedCryptoServiceArc4Encrypt,
  5704. DeprecatedCryptoServiceArc4Decrypt,
  5705. DeprecatedCryptoServiceArc4Reset,
  5706. /// SM3
  5707. CryptoServiceSm3GetContextSize,
  5708. CryptoServiceSm3Init,
  5709. CryptoServiceSm3Duplicate,
  5710. CryptoServiceSm3Update,
  5711. CryptoServiceSm3Final,
  5712. CryptoServiceSm3HashAll,
  5713. /// HKDF
  5714. CryptoServiceHkdfSha256ExtractAndExpand,
  5715. /// X509 (Continued)
  5716. CryptoServiceX509ConstructCertificateStackV,
  5717. /// TLS
  5718. CryptoServiceTlsInitialize,
  5719. CryptoServiceTlsCtxFree,
  5720. CryptoServiceTlsCtxNew,
  5721. CryptoServiceTlsFree,
  5722. CryptoServiceTlsNew,
  5723. CryptoServiceTlsInHandshake,
  5724. CryptoServiceTlsDoHandshake,
  5725. CryptoServiceTlsHandleAlert,
  5726. CryptoServiceTlsCloseNotify,
  5727. CryptoServiceTlsCtrlTrafficOut,
  5728. CryptoServiceTlsCtrlTrafficIn,
  5729. CryptoServiceTlsRead,
  5730. CryptoServiceTlsWrite,
  5731. /// TLS Set
  5732. CryptoServiceTlsSetVersion,
  5733. CryptoServiceTlsSetConnectionEnd,
  5734. CryptoServiceTlsSetCipherList,
  5735. CryptoServiceTlsSetCompressionMethod,
  5736. CryptoServiceTlsSetVerify,
  5737. CryptoServiceTlsSetVerifyHost,
  5738. CryptoServiceTlsSetSessionId,
  5739. CryptoServiceTlsSetCaCertificate,
  5740. CryptoServiceTlsSetHostPublicCert,
  5741. CryptoServiceTlsSetHostPrivateKey,
  5742. CryptoServiceTlsSetCertRevocationList,
  5743. /// TLS Get
  5744. CryptoServiceTlsGetVersion,
  5745. CryptoServiceTlsGetConnectionEnd,
  5746. CryptoServiceTlsGetCurrentCipher,
  5747. CryptoServiceTlsGetCurrentCompressionId,
  5748. CryptoServiceTlsGetVerify,
  5749. CryptoServiceTlsGetSessionId,
  5750. CryptoServiceTlsGetClientRandom,
  5751. CryptoServiceTlsGetServerRandom,
  5752. CryptoServiceTlsGetKeyMaterial,
  5753. CryptoServiceTlsGetCaCertificate,
  5754. CryptoServiceTlsGetHostPublicCert,
  5755. CryptoServiceTlsGetHostPrivateKey,
  5756. CryptoServiceTlsGetCertRevocationList,
  5757. /// RSA PSS
  5758. CryptoServiceRsaPssSign,
  5759. CryptoServiceRsaPssVerify,
  5760. /// Parallel hash
  5761. CryptoServiceParallelHash256HashAll,
  5762. /// HMAC SHA256 (continued)
  5763. CryptoServiceHmacSha256All,
  5764. /// HMAC SHA384
  5765. CryptoServiceHmacSha384New,
  5766. CryptoServiceHmacSha384Free,
  5767. CryptoServiceHmacSha384SetKey,
  5768. CryptoServiceHmacSha384Duplicate,
  5769. CryptoServiceHmacSha384Update,
  5770. CryptoServiceHmacSha384Final,
  5771. CryptoServiceHmacSha384All,
  5772. /// HKDF (continued)
  5773. CryptoServiceHkdfSha256Extract,
  5774. CryptoServiceHkdfSha256Expand,
  5775. CryptoServiceHkdfSha384ExtractAndExpand,
  5776. CryptoServiceHkdfSha384Extract,
  5777. CryptoServiceHkdfSha384Expand,
  5778. /// Aead Aes GCM
  5779. CryptoServiceAeadAesGcmEncrypt,
  5780. CryptoServiceAeadAesGcmDecrypt,
  5781. /// Big Numbers
  5782. CryptoServiceBigNumInit,
  5783. CryptoServiceBigNumFromBin,
  5784. CryptoServiceBigNumToBin,
  5785. CryptoServiceBigNumFree,
  5786. CryptoServiceBigNumAdd,
  5787. CryptoServiceBigNumSub,
  5788. CryptoServiceBigNumMod,
  5789. CryptoServiceBigNumExpMod,
  5790. CryptoServiceBigNumInverseMod,
  5791. CryptoServiceBigNumDiv,
  5792. CryptoServiceBigNumMulMod,
  5793. CryptoServiceBigNumCmp,
  5794. CryptoServiceBigNumBits,
  5795. CryptoServiceBigNumBytes,
  5796. CryptoServiceBigNumIsWord,
  5797. CryptoServiceBigNumIsOdd,
  5798. CryptoServiceBigNumCopy,
  5799. CryptoServiceBigNumValueOne,
  5800. CryptoServiceBigNumRShift,
  5801. CryptoServiceBigNumConstTime,
  5802. CryptoServiceBigNumSqrMod,
  5803. CryptoServiceBigNumNewContext,
  5804. CryptoServiceBigNumContextFree,
  5805. CryptoServiceBigNumSetUint,
  5806. CryptoServiceBigNumAddMod,
  5807. /// EC
  5808. CryptoServiceEcGroupInit,
  5809. CryptoServiceEcGroupGetCurve,
  5810. CryptoServiceEcGroupGetOrder,
  5811. CryptoServiceEcGroupFree,
  5812. CryptoServiceEcPointInit,
  5813. CryptoServiceEcPointDeInit,
  5814. CryptoServiceEcPointGetAffineCoordinates,
  5815. CryptoServiceEcPointSetAffineCoordinates,
  5816. CryptoServiceEcPointAdd,
  5817. CryptoServiceEcPointMul,
  5818. CryptoServiceEcPointInvert,
  5819. CryptoServiceEcPointIsOnCurve,
  5820. CryptoServiceEcPointIsAtInfinity,
  5821. CryptoServiceEcPointEqual,
  5822. CryptoServiceEcPointSetCompressedCoordinates,
  5823. CryptoServiceEcNewByNid,
  5824. CryptoServiceEcFree,
  5825. CryptoServiceEcGenerateKey,
  5826. CryptoServiceEcGetPubKey,
  5827. CryptoServiceEcDhComputeKey,
  5828. /// TLS (continued)
  5829. CryptoServiceTlsShutdown,
  5830. /// TLS Set (continued)
  5831. CryptoServiceTlsSetHostPrivateKeyEx,
  5832. CryptoServiceTlsSetSignatureAlgoList,
  5833. CryptoServiceTlsSetEcCurve,
  5834. /// TLS Get (continued)
  5835. CryptoServiceTlsGetExportKey,
  5836. /// Ec (Continued)
  5837. CryptoServiceEcGetPublicKeyFromX509,
  5838. CryptoServiceEcGetPrivateKeyFromPem,
  5839. CryptoServiceEcDsaSign,
  5840. CryptoServiceEcDsaVerify,
  5841. /// X509 (Continued)
  5842. CryptoServiceX509GetVersion,
  5843. CryptoServiceX509GetSerialNumber,
  5844. CryptoServiceX509GetIssuerName,
  5845. CryptoServiceX509GetSignatureAlgorithm,
  5846. CryptoServiceX509GetExtensionData,
  5847. CryptoServiceX509GetExtendedKeyUsage,
  5848. CryptoServiceX509GetValidity,
  5849. CryptoServiceX509FormatDateTime,
  5850. CryptoServiceX509CompareDateTime,
  5851. CryptoServiceX509GetKeyUsage,
  5852. CryptoServiceX509VerifyCertChain,
  5853. CryptoServiceX509GetCertFromCertChain,
  5854. CryptoServiceAsn1GetTag,
  5855. CryptoServiceX509GetExtendedBasicConstraints
  5856. };