caamalg.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * caam - Freescale FSL CAAM support for crypto API
  4. *
  5. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  6. * Copyright 2016-2019, 2023 NXP
  7. *
  8. * Based on talitos crypto API driver.
  9. *
  10. * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008):
  11. *
  12. * --------------- ---------------
  13. * | JobDesc #1 |-------------------->| ShareDesc |
  14. * | *(packet 1) | | (PDB) |
  15. * --------------- |------------->| (hashKey) |
  16. * . | | (cipherKey) |
  17. * . | |-------->| (operation) |
  18. * --------------- | | ---------------
  19. * | JobDesc #2 |------| |
  20. * | *(packet 2) | |
  21. * --------------- |
  22. * . |
  23. * . |
  24. * --------------- |
  25. * | JobDesc #3 |------------
  26. * | *(packet 3) |
  27. * ---------------
  28. *
  29. * The SharedDesc never changes for a connection unless rekeyed, but
  30. * each packet will likely be in a different place. So all we need
  31. * to know to process the packet is where the input is, where the
  32. * output goes, and what context we want to process with. Context is
  33. * in the SharedDesc, packet references in the JobDesc.
  34. *
  35. * So, a job desc looks like:
  36. *
  37. * ---------------------
  38. * | Header |
  39. * | ShareDesc Pointer |
  40. * | SEQ_OUT_PTR |
  41. * | (output buffer) |
  42. * | (output length) |
  43. * | SEQ_IN_PTR |
  44. * | (input buffer) |
  45. * | (input length) |
  46. * ---------------------
  47. */
  48. #include "compat.h"
  49. #include "regs.h"
  50. #include "intern.h"
  51. #include "desc_constr.h"
  52. #include "jr.h"
  53. #include "error.h"
  54. #include "sg_sw_sec4.h"
  55. #include "key_gen.h"
  56. #include "caamalg_desc.h"
  57. #include <linux/unaligned.h>
  58. #include <crypto/internal/aead.h>
  59. #include <crypto/internal/engine.h>
  60. #include <crypto/internal/skcipher.h>
  61. #include <crypto/xts.h>
  62. #include <linux/dma-mapping.h>
  63. #include <linux/device.h>
  64. #include <linux/err.h>
  65. #include <linux/module.h>
  66. #include <linux/kernel.h>
  67. #include <linux/slab.h>
  68. #include <linux/string.h>
  69. /*
  70. * crypto alg
  71. */
  72. #define CAAM_CRA_PRIORITY 3000
  73. /* max key is sum of AES_MAX_KEY_SIZE, max split key size */
  74. #define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \
  75. CTR_RFC3686_NONCE_SIZE + \
  76. SHA512_DIGEST_SIZE * 2)
  77. #define AEAD_DESC_JOB_IO_LEN (DESC_JOB_IO_LEN + CAAM_CMD_SZ * 2)
  78. #define GCM_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
  79. CAAM_CMD_SZ * 4)
  80. #define AUTHENC_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
  81. CAAM_CMD_SZ * 5)
  82. #define CHACHAPOLY_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + CAAM_CMD_SZ * 6)
  83. #define DESC_MAX_USED_BYTES (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN_MIN)
  84. #define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
  85. struct caam_alg_entry {
  86. int class1_alg_type;
  87. int class2_alg_type;
  88. bool rfc3686;
  89. bool geniv;
  90. bool nodkp;
  91. };
  92. struct caam_aead_alg {
  93. struct aead_engine_alg aead;
  94. struct caam_alg_entry caam;
  95. bool registered;
  96. };
  97. struct caam_skcipher_alg {
  98. struct skcipher_engine_alg skcipher;
  99. struct caam_alg_entry caam;
  100. bool registered;
  101. };
  102. /*
  103. * per-session context
  104. */
  105. struct caam_ctx {
  106. u32 sh_desc_enc[DESC_MAX_USED_LEN];
  107. u32 sh_desc_dec[DESC_MAX_USED_LEN];
  108. u8 key[CAAM_MAX_KEY_SIZE];
  109. dma_addr_t sh_desc_enc_dma;
  110. dma_addr_t sh_desc_dec_dma;
  111. dma_addr_t key_dma;
  112. enum dma_data_direction dir;
  113. struct device *jrdev;
  114. struct alginfo adata;
  115. struct alginfo cdata;
  116. unsigned int authsize;
  117. bool xts_key_fallback;
  118. struct crypto_skcipher *fallback;
  119. };
  120. struct caam_skcipher_req_ctx {
  121. struct skcipher_edesc *edesc;
  122. struct skcipher_request fallback_req;
  123. };
  124. struct caam_aead_req_ctx {
  125. struct aead_edesc *edesc;
  126. };
  127. static int aead_null_set_sh_desc(struct crypto_aead *aead)
  128. {
  129. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  130. struct device *jrdev = ctx->jrdev;
  131. struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
  132. u32 *desc;
  133. int rem_bytes = CAAM_DESC_BYTES_MAX - AEAD_DESC_JOB_IO_LEN -
  134. ctx->adata.keylen_pad;
  135. /*
  136. * Job Descriptor and Shared Descriptors
  137. * must all fit into the 64-word Descriptor h/w Buffer
  138. */
  139. if (rem_bytes >= DESC_AEAD_NULL_ENC_LEN) {
  140. ctx->adata.key_inline = true;
  141. ctx->adata.key_virt = ctx->key;
  142. } else {
  143. ctx->adata.key_inline = false;
  144. ctx->adata.key_dma = ctx->key_dma;
  145. }
  146. /* aead_encrypt shared descriptor */
  147. desc = ctx->sh_desc_enc;
  148. cnstr_shdsc_aead_null_encap(desc, &ctx->adata, ctx->authsize,
  149. ctrlpriv->era);
  150. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  151. desc_bytes(desc), ctx->dir);
  152. /*
  153. * Job Descriptor and Shared Descriptors
  154. * must all fit into the 64-word Descriptor h/w Buffer
  155. */
  156. if (rem_bytes >= DESC_AEAD_NULL_DEC_LEN) {
  157. ctx->adata.key_inline = true;
  158. ctx->adata.key_virt = ctx->key;
  159. } else {
  160. ctx->adata.key_inline = false;
  161. ctx->adata.key_dma = ctx->key_dma;
  162. }
  163. /* aead_decrypt shared descriptor */
  164. desc = ctx->sh_desc_dec;
  165. cnstr_shdsc_aead_null_decap(desc, &ctx->adata, ctx->authsize,
  166. ctrlpriv->era);
  167. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  168. desc_bytes(desc), ctx->dir);
  169. return 0;
  170. }
  171. static int aead_set_sh_desc(struct crypto_aead *aead)
  172. {
  173. struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
  174. struct caam_aead_alg,
  175. aead.base);
  176. unsigned int ivsize = crypto_aead_ivsize(aead);
  177. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  178. struct device *jrdev = ctx->jrdev;
  179. struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
  180. u32 ctx1_iv_off = 0;
  181. u32 *desc, *nonce = NULL;
  182. u32 inl_mask;
  183. unsigned int data_len[2];
  184. const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
  185. OP_ALG_AAI_CTR_MOD128);
  186. const bool is_rfc3686 = alg->caam.rfc3686;
  187. if (!ctx->authsize)
  188. return 0;
  189. /* NULL encryption / decryption */
  190. if (!ctx->cdata.keylen)
  191. return aead_null_set_sh_desc(aead);
  192. /*
  193. * AES-CTR needs to load IV in CONTEXT1 reg
  194. * at an offset of 128bits (16bytes)
  195. * CONTEXT1[255:128] = IV
  196. */
  197. if (ctr_mode)
  198. ctx1_iv_off = 16;
  199. /*
  200. * RFC3686 specific:
  201. * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
  202. */
  203. if (is_rfc3686) {
  204. ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
  205. nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
  206. ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
  207. }
  208. /*
  209. * In case |user key| > |derived key|, using DKP<imm,imm>
  210. * would result in invalid opcodes (last bytes of user key) in
  211. * the resulting descriptor. Use DKP<ptr,imm> instead => both
  212. * virtual and dma key addresses are needed.
  213. */
  214. ctx->adata.key_virt = ctx->key;
  215. ctx->adata.key_dma = ctx->key_dma;
  216. ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
  217. ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
  218. data_len[0] = ctx->adata.keylen_pad;
  219. data_len[1] = ctx->cdata.keylen;
  220. if (alg->caam.geniv)
  221. goto skip_enc;
  222. /*
  223. * Job Descriptor and Shared Descriptors
  224. * must all fit into the 64-word Descriptor h/w Buffer
  225. */
  226. if (desc_inline_query(DESC_AEAD_ENC_LEN +
  227. (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
  228. AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
  229. ARRAY_SIZE(data_len)) < 0)
  230. return -EINVAL;
  231. ctx->adata.key_inline = !!(inl_mask & 1);
  232. ctx->cdata.key_inline = !!(inl_mask & 2);
  233. /* aead_encrypt shared descriptor */
  234. desc = ctx->sh_desc_enc;
  235. cnstr_shdsc_aead_encap(desc, &ctx->cdata, &ctx->adata, ivsize,
  236. ctx->authsize, is_rfc3686, nonce, ctx1_iv_off,
  237. false, ctrlpriv->era);
  238. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  239. desc_bytes(desc), ctx->dir);
  240. skip_enc:
  241. /*
  242. * Job Descriptor and Shared Descriptors
  243. * must all fit into the 64-word Descriptor h/w Buffer
  244. */
  245. if (desc_inline_query(DESC_AEAD_DEC_LEN +
  246. (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
  247. AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
  248. ARRAY_SIZE(data_len)) < 0)
  249. return -EINVAL;
  250. ctx->adata.key_inline = !!(inl_mask & 1);
  251. ctx->cdata.key_inline = !!(inl_mask & 2);
  252. /* aead_decrypt shared descriptor */
  253. desc = ctx->sh_desc_dec;
  254. cnstr_shdsc_aead_decap(desc, &ctx->cdata, &ctx->adata, ivsize,
  255. ctx->authsize, alg->caam.geniv, is_rfc3686,
  256. nonce, ctx1_iv_off, false, ctrlpriv->era);
  257. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  258. desc_bytes(desc), ctx->dir);
  259. if (!alg->caam.geniv)
  260. goto skip_givenc;
  261. /*
  262. * Job Descriptor and Shared Descriptors
  263. * must all fit into the 64-word Descriptor h/w Buffer
  264. */
  265. if (desc_inline_query(DESC_AEAD_GIVENC_LEN +
  266. (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
  267. AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
  268. ARRAY_SIZE(data_len)) < 0)
  269. return -EINVAL;
  270. ctx->adata.key_inline = !!(inl_mask & 1);
  271. ctx->cdata.key_inline = !!(inl_mask & 2);
  272. /* aead_givencrypt shared descriptor */
  273. desc = ctx->sh_desc_enc;
  274. cnstr_shdsc_aead_givencap(desc, &ctx->cdata, &ctx->adata, ivsize,
  275. ctx->authsize, is_rfc3686, nonce,
  276. ctx1_iv_off, false, ctrlpriv->era);
  277. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  278. desc_bytes(desc), ctx->dir);
  279. skip_givenc:
  280. return 0;
  281. }
  282. static int aead_setauthsize(struct crypto_aead *authenc,
  283. unsigned int authsize)
  284. {
  285. struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
  286. ctx->authsize = authsize;
  287. aead_set_sh_desc(authenc);
  288. return 0;
  289. }
  290. static int gcm_set_sh_desc(struct crypto_aead *aead)
  291. {
  292. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  293. struct device *jrdev = ctx->jrdev;
  294. unsigned int ivsize = crypto_aead_ivsize(aead);
  295. u32 *desc;
  296. int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
  297. ctx->cdata.keylen;
  298. if (!ctx->cdata.keylen || !ctx->authsize)
  299. return 0;
  300. /*
  301. * AES GCM encrypt shared descriptor
  302. * Job Descriptor and Shared Descriptor
  303. * must fit into the 64-word Descriptor h/w Buffer
  304. */
  305. if (rem_bytes >= DESC_GCM_ENC_LEN) {
  306. ctx->cdata.key_inline = true;
  307. ctx->cdata.key_virt = ctx->key;
  308. } else {
  309. ctx->cdata.key_inline = false;
  310. ctx->cdata.key_dma = ctx->key_dma;
  311. }
  312. desc = ctx->sh_desc_enc;
  313. cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ivsize, ctx->authsize, false);
  314. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  315. desc_bytes(desc), ctx->dir);
  316. /*
  317. * Job Descriptor and Shared Descriptors
  318. * must all fit into the 64-word Descriptor h/w Buffer
  319. */
  320. if (rem_bytes >= DESC_GCM_DEC_LEN) {
  321. ctx->cdata.key_inline = true;
  322. ctx->cdata.key_virt = ctx->key;
  323. } else {
  324. ctx->cdata.key_inline = false;
  325. ctx->cdata.key_dma = ctx->key_dma;
  326. }
  327. desc = ctx->sh_desc_dec;
  328. cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ivsize, ctx->authsize, false);
  329. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  330. desc_bytes(desc), ctx->dir);
  331. return 0;
  332. }
  333. static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
  334. {
  335. struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
  336. int err;
  337. err = crypto_gcm_check_authsize(authsize);
  338. if (err)
  339. return err;
  340. ctx->authsize = authsize;
  341. gcm_set_sh_desc(authenc);
  342. return 0;
  343. }
  344. static int rfc4106_set_sh_desc(struct crypto_aead *aead)
  345. {
  346. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  347. struct device *jrdev = ctx->jrdev;
  348. unsigned int ivsize = crypto_aead_ivsize(aead);
  349. u32 *desc;
  350. int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
  351. ctx->cdata.keylen;
  352. if (!ctx->cdata.keylen || !ctx->authsize)
  353. return 0;
  354. /*
  355. * RFC4106 encrypt shared descriptor
  356. * Job Descriptor and Shared Descriptor
  357. * must fit into the 64-word Descriptor h/w Buffer
  358. */
  359. if (rem_bytes >= DESC_RFC4106_ENC_LEN) {
  360. ctx->cdata.key_inline = true;
  361. ctx->cdata.key_virt = ctx->key;
  362. } else {
  363. ctx->cdata.key_inline = false;
  364. ctx->cdata.key_dma = ctx->key_dma;
  365. }
  366. desc = ctx->sh_desc_enc;
  367. cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
  368. false);
  369. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  370. desc_bytes(desc), ctx->dir);
  371. /*
  372. * Job Descriptor and Shared Descriptors
  373. * must all fit into the 64-word Descriptor h/w Buffer
  374. */
  375. if (rem_bytes >= DESC_RFC4106_DEC_LEN) {
  376. ctx->cdata.key_inline = true;
  377. ctx->cdata.key_virt = ctx->key;
  378. } else {
  379. ctx->cdata.key_inline = false;
  380. ctx->cdata.key_dma = ctx->key_dma;
  381. }
  382. desc = ctx->sh_desc_dec;
  383. cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
  384. false);
  385. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  386. desc_bytes(desc), ctx->dir);
  387. return 0;
  388. }
  389. static int rfc4106_setauthsize(struct crypto_aead *authenc,
  390. unsigned int authsize)
  391. {
  392. struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
  393. int err;
  394. err = crypto_rfc4106_check_authsize(authsize);
  395. if (err)
  396. return err;
  397. ctx->authsize = authsize;
  398. rfc4106_set_sh_desc(authenc);
  399. return 0;
  400. }
  401. static int rfc4543_set_sh_desc(struct crypto_aead *aead)
  402. {
  403. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  404. struct device *jrdev = ctx->jrdev;
  405. unsigned int ivsize = crypto_aead_ivsize(aead);
  406. u32 *desc;
  407. int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
  408. ctx->cdata.keylen;
  409. if (!ctx->cdata.keylen || !ctx->authsize)
  410. return 0;
  411. /*
  412. * RFC4543 encrypt shared descriptor
  413. * Job Descriptor and Shared Descriptor
  414. * must fit into the 64-word Descriptor h/w Buffer
  415. */
  416. if (rem_bytes >= DESC_RFC4543_ENC_LEN) {
  417. ctx->cdata.key_inline = true;
  418. ctx->cdata.key_virt = ctx->key;
  419. } else {
  420. ctx->cdata.key_inline = false;
  421. ctx->cdata.key_dma = ctx->key_dma;
  422. }
  423. desc = ctx->sh_desc_enc;
  424. cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
  425. false);
  426. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  427. desc_bytes(desc), ctx->dir);
  428. /*
  429. * Job Descriptor and Shared Descriptors
  430. * must all fit into the 64-word Descriptor h/w Buffer
  431. */
  432. if (rem_bytes >= DESC_RFC4543_DEC_LEN) {
  433. ctx->cdata.key_inline = true;
  434. ctx->cdata.key_virt = ctx->key;
  435. } else {
  436. ctx->cdata.key_inline = false;
  437. ctx->cdata.key_dma = ctx->key_dma;
  438. }
  439. desc = ctx->sh_desc_dec;
  440. cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
  441. false);
  442. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  443. desc_bytes(desc), ctx->dir);
  444. return 0;
  445. }
  446. static int rfc4543_setauthsize(struct crypto_aead *authenc,
  447. unsigned int authsize)
  448. {
  449. struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
  450. if (authsize != 16)
  451. return -EINVAL;
  452. ctx->authsize = authsize;
  453. rfc4543_set_sh_desc(authenc);
  454. return 0;
  455. }
  456. static int chachapoly_set_sh_desc(struct crypto_aead *aead)
  457. {
  458. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  459. struct device *jrdev = ctx->jrdev;
  460. unsigned int ivsize = crypto_aead_ivsize(aead);
  461. u32 *desc;
  462. if (!ctx->cdata.keylen || !ctx->authsize)
  463. return 0;
  464. desc = ctx->sh_desc_enc;
  465. cnstr_shdsc_chachapoly(desc, &ctx->cdata, &ctx->adata, ivsize,
  466. ctx->authsize, true, false);
  467. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  468. desc_bytes(desc), ctx->dir);
  469. desc = ctx->sh_desc_dec;
  470. cnstr_shdsc_chachapoly(desc, &ctx->cdata, &ctx->adata, ivsize,
  471. ctx->authsize, false, false);
  472. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  473. desc_bytes(desc), ctx->dir);
  474. return 0;
  475. }
  476. static int chachapoly_setauthsize(struct crypto_aead *aead,
  477. unsigned int authsize)
  478. {
  479. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  480. if (authsize != POLY1305_DIGEST_SIZE)
  481. return -EINVAL;
  482. ctx->authsize = authsize;
  483. return chachapoly_set_sh_desc(aead);
  484. }
  485. static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key,
  486. unsigned int keylen)
  487. {
  488. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  489. unsigned int ivsize = crypto_aead_ivsize(aead);
  490. unsigned int saltlen = CHACHAPOLY_IV_SIZE - ivsize;
  491. if (keylen != CHACHA_KEY_SIZE + saltlen)
  492. return -EINVAL;
  493. memcpy(ctx->key, key, keylen);
  494. ctx->cdata.key_virt = ctx->key;
  495. ctx->cdata.keylen = keylen - saltlen;
  496. return chachapoly_set_sh_desc(aead);
  497. }
  498. static int aead_setkey(struct crypto_aead *aead,
  499. const u8 *key, unsigned int keylen)
  500. {
  501. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  502. struct device *jrdev = ctx->jrdev;
  503. struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
  504. struct crypto_authenc_keys keys;
  505. int ret = 0;
  506. if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
  507. goto badkey;
  508. dev_dbg(jrdev, "keylen %d enckeylen %d authkeylen %d\n",
  509. keys.authkeylen + keys.enckeylen, keys.enckeylen,
  510. keys.authkeylen);
  511. print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
  512. DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
  513. /*
  514. * If DKP is supported, use it in the shared descriptor to generate
  515. * the split key.
  516. */
  517. if (ctrlpriv->era >= 6) {
  518. ctx->adata.keylen = keys.authkeylen;
  519. ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
  520. OP_ALG_ALGSEL_MASK);
  521. if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE)
  522. goto badkey;
  523. memcpy(ctx->key, keys.authkey, keys.authkeylen);
  524. memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey,
  525. keys.enckeylen);
  526. dma_sync_single_for_device(jrdev, ctx->key_dma,
  527. ctx->adata.keylen_pad +
  528. keys.enckeylen, ctx->dir);
  529. goto skip_split_key;
  530. }
  531. ret = gen_split_key(ctx->jrdev, ctx->key, &ctx->adata, keys.authkey,
  532. keys.authkeylen, CAAM_MAX_KEY_SIZE -
  533. keys.enckeylen);
  534. if (ret) {
  535. goto badkey;
  536. }
  537. /* postpend encryption key to auth split key */
  538. memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
  539. dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
  540. keys.enckeylen, ctx->dir);
  541. print_hex_dump_debug("ctx.key@"__stringify(__LINE__)": ",
  542. DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
  543. ctx->adata.keylen_pad + keys.enckeylen, 1);
  544. skip_split_key:
  545. ctx->cdata.keylen = keys.enckeylen;
  546. memzero_explicit(&keys, sizeof(keys));
  547. return aead_set_sh_desc(aead);
  548. badkey:
  549. memzero_explicit(&keys, sizeof(keys));
  550. return -EINVAL;
  551. }
  552. static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key,
  553. unsigned int keylen)
  554. {
  555. struct crypto_authenc_keys keys;
  556. int err;
  557. err = crypto_authenc_extractkeys(&keys, key, keylen);
  558. if (unlikely(err))
  559. return err;
  560. err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?:
  561. aead_setkey(aead, key, keylen);
  562. memzero_explicit(&keys, sizeof(keys));
  563. return err;
  564. }
  565. static int gcm_setkey(struct crypto_aead *aead,
  566. const u8 *key, unsigned int keylen)
  567. {
  568. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  569. struct device *jrdev = ctx->jrdev;
  570. int err;
  571. err = aes_check_keylen(keylen);
  572. if (err)
  573. return err;
  574. print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
  575. DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
  576. memcpy(ctx->key, key, keylen);
  577. dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, ctx->dir);
  578. ctx->cdata.keylen = keylen;
  579. return gcm_set_sh_desc(aead);
  580. }
  581. static int rfc4106_setkey(struct crypto_aead *aead,
  582. const u8 *key, unsigned int keylen)
  583. {
  584. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  585. struct device *jrdev = ctx->jrdev;
  586. int err;
  587. err = aes_check_keylen(keylen - 4);
  588. if (err)
  589. return err;
  590. print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
  591. DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
  592. memcpy(ctx->key, key, keylen);
  593. /*
  594. * The last four bytes of the key material are used as the salt value
  595. * in the nonce. Update the AES key length.
  596. */
  597. ctx->cdata.keylen = keylen - 4;
  598. dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
  599. ctx->dir);
  600. return rfc4106_set_sh_desc(aead);
  601. }
  602. static int rfc4543_setkey(struct crypto_aead *aead,
  603. const u8 *key, unsigned int keylen)
  604. {
  605. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  606. struct device *jrdev = ctx->jrdev;
  607. int err;
  608. err = aes_check_keylen(keylen - 4);
  609. if (err)
  610. return err;
  611. print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
  612. DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
  613. memcpy(ctx->key, key, keylen);
  614. /*
  615. * The last four bytes of the key material are used as the salt value
  616. * in the nonce. Update the AES key length.
  617. */
  618. ctx->cdata.keylen = keylen - 4;
  619. dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
  620. ctx->dir);
  621. return rfc4543_set_sh_desc(aead);
  622. }
  623. static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
  624. unsigned int keylen, const u32 ctx1_iv_off)
  625. {
  626. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
  627. struct caam_skcipher_alg *alg =
  628. container_of(crypto_skcipher_alg(skcipher), typeof(*alg),
  629. skcipher.base);
  630. struct device *jrdev = ctx->jrdev;
  631. unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
  632. u32 *desc;
  633. const bool is_rfc3686 = alg->caam.rfc3686;
  634. print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
  635. DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
  636. ctx->cdata.keylen = keylen;
  637. ctx->cdata.key_virt = key;
  638. ctx->cdata.key_inline = true;
  639. /* skcipher_encrypt shared descriptor */
  640. desc = ctx->sh_desc_enc;
  641. cnstr_shdsc_skcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686,
  642. ctx1_iv_off);
  643. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  644. desc_bytes(desc), ctx->dir);
  645. /* skcipher_decrypt shared descriptor */
  646. desc = ctx->sh_desc_dec;
  647. cnstr_shdsc_skcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686,
  648. ctx1_iv_off);
  649. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  650. desc_bytes(desc), ctx->dir);
  651. return 0;
  652. }
  653. static int aes_skcipher_setkey(struct crypto_skcipher *skcipher,
  654. const u8 *key, unsigned int keylen)
  655. {
  656. int err;
  657. err = aes_check_keylen(keylen);
  658. if (err)
  659. return err;
  660. return skcipher_setkey(skcipher, key, keylen, 0);
  661. }
  662. static int rfc3686_skcipher_setkey(struct crypto_skcipher *skcipher,
  663. const u8 *key, unsigned int keylen)
  664. {
  665. u32 ctx1_iv_off;
  666. int err;
  667. /*
  668. * RFC3686 specific:
  669. * | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
  670. * | *key = {KEY, NONCE}
  671. */
  672. ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
  673. keylen -= CTR_RFC3686_NONCE_SIZE;
  674. err = aes_check_keylen(keylen);
  675. if (err)
  676. return err;
  677. return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
  678. }
  679. static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher,
  680. const u8 *key, unsigned int keylen)
  681. {
  682. u32 ctx1_iv_off;
  683. int err;
  684. /*
  685. * AES-CTR needs to load IV in CONTEXT1 reg
  686. * at an offset of 128bits (16bytes)
  687. * CONTEXT1[255:128] = IV
  688. */
  689. ctx1_iv_off = 16;
  690. err = aes_check_keylen(keylen);
  691. if (err)
  692. return err;
  693. return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
  694. }
  695. static int des_skcipher_setkey(struct crypto_skcipher *skcipher,
  696. const u8 *key, unsigned int keylen)
  697. {
  698. return verify_skcipher_des_key(skcipher, key) ?:
  699. skcipher_setkey(skcipher, key, keylen, 0);
  700. }
  701. static int des3_skcipher_setkey(struct crypto_skcipher *skcipher,
  702. const u8 *key, unsigned int keylen)
  703. {
  704. return verify_skcipher_des3_key(skcipher, key) ?:
  705. skcipher_setkey(skcipher, key, keylen, 0);
  706. }
  707. static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
  708. unsigned int keylen)
  709. {
  710. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
  711. struct device *jrdev = ctx->jrdev;
  712. struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
  713. u32 *desc;
  714. int err;
  715. err = xts_verify_key(skcipher, key, keylen);
  716. if (err) {
  717. dev_dbg(jrdev, "key size mismatch\n");
  718. return err;
  719. }
  720. if (keylen != 2 * AES_KEYSIZE_128 && keylen != 2 * AES_KEYSIZE_256)
  721. ctx->xts_key_fallback = true;
  722. if (ctrlpriv->era <= 8 || ctx->xts_key_fallback) {
  723. err = crypto_skcipher_setkey(ctx->fallback, key, keylen);
  724. if (err)
  725. return err;
  726. }
  727. ctx->cdata.keylen = keylen;
  728. ctx->cdata.key_virt = key;
  729. ctx->cdata.key_inline = true;
  730. /* xts_skcipher_encrypt shared descriptor */
  731. desc = ctx->sh_desc_enc;
  732. cnstr_shdsc_xts_skcipher_encap(desc, &ctx->cdata);
  733. dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
  734. desc_bytes(desc), ctx->dir);
  735. /* xts_skcipher_decrypt shared descriptor */
  736. desc = ctx->sh_desc_dec;
  737. cnstr_shdsc_xts_skcipher_decap(desc, &ctx->cdata);
  738. dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
  739. desc_bytes(desc), ctx->dir);
  740. return 0;
  741. }
  742. /*
  743. * aead_edesc - s/w-extended aead descriptor
  744. * @src_nents: number of segments in input s/w scatterlist
  745. * @dst_nents: number of segments in output s/w scatterlist
  746. * @mapped_src_nents: number of segments in input h/w link table
  747. * @mapped_dst_nents: number of segments in output h/w link table
  748. * @sec4_sg_bytes: length of dma mapped sec4_sg space
  749. * @bklog: stored to determine if the request needs backlog
  750. * @sec4_sg_dma: bus physical mapped address of h/w link table
  751. * @sec4_sg: pointer to h/w link table
  752. * @hw_desc: the h/w job descriptor followed by any referenced link tables
  753. */
  754. struct aead_edesc {
  755. int src_nents;
  756. int dst_nents;
  757. int mapped_src_nents;
  758. int mapped_dst_nents;
  759. int sec4_sg_bytes;
  760. bool bklog;
  761. dma_addr_t sec4_sg_dma;
  762. struct sec4_sg_entry *sec4_sg;
  763. u32 hw_desc[];
  764. };
  765. /*
  766. * skcipher_edesc - s/w-extended skcipher descriptor
  767. * @src_nents: number of segments in input s/w scatterlist
  768. * @dst_nents: number of segments in output s/w scatterlist
  769. * @mapped_src_nents: number of segments in input h/w link table
  770. * @mapped_dst_nents: number of segments in output h/w link table
  771. * @iv_dma: dma address of iv for checking continuity and link table
  772. * @sec4_sg_bytes: length of dma mapped sec4_sg space
  773. * @bklog: stored to determine if the request needs backlog
  774. * @sec4_sg_dma: bus physical mapped address of h/w link table
  775. * @sec4_sg: pointer to h/w link table
  776. * @hw_desc: the h/w job descriptor followed by any referenced link tables
  777. * and IV
  778. */
  779. struct skcipher_edesc {
  780. int src_nents;
  781. int dst_nents;
  782. int mapped_src_nents;
  783. int mapped_dst_nents;
  784. dma_addr_t iv_dma;
  785. int sec4_sg_bytes;
  786. bool bklog;
  787. dma_addr_t sec4_sg_dma;
  788. struct sec4_sg_entry *sec4_sg;
  789. u32 hw_desc[];
  790. };
  791. static void caam_unmap(struct device *dev, struct scatterlist *src,
  792. struct scatterlist *dst, int src_nents,
  793. int dst_nents,
  794. dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma,
  795. int sec4_sg_bytes)
  796. {
  797. if (dst != src) {
  798. if (src_nents)
  799. dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
  800. if (dst_nents)
  801. dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
  802. } else {
  803. dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
  804. }
  805. if (iv_dma)
  806. dma_unmap_single(dev, iv_dma, ivsize, DMA_BIDIRECTIONAL);
  807. if (sec4_sg_bytes)
  808. dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes,
  809. DMA_TO_DEVICE);
  810. }
  811. static void aead_unmap(struct device *dev,
  812. struct aead_edesc *edesc,
  813. struct aead_request *req)
  814. {
  815. caam_unmap(dev, req->src, req->dst,
  816. edesc->src_nents, edesc->dst_nents, 0, 0,
  817. edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
  818. }
  819. static void skcipher_unmap(struct device *dev, struct skcipher_edesc *edesc,
  820. struct skcipher_request *req)
  821. {
  822. struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
  823. int ivsize = crypto_skcipher_ivsize(skcipher);
  824. caam_unmap(dev, req->src, req->dst,
  825. edesc->src_nents, edesc->dst_nents,
  826. edesc->iv_dma, ivsize,
  827. edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
  828. }
  829. static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err,
  830. void *context)
  831. {
  832. struct aead_request *req = context;
  833. struct caam_aead_req_ctx *rctx = aead_request_ctx(req);
  834. struct caam_drv_private_jr *jrp = dev_get_drvdata(jrdev);
  835. struct aead_edesc *edesc;
  836. int ecode = 0;
  837. bool has_bklog;
  838. dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
  839. edesc = rctx->edesc;
  840. has_bklog = edesc->bklog;
  841. if (err)
  842. ecode = caam_jr_strstatus(jrdev, err);
  843. aead_unmap(jrdev, edesc, req);
  844. kfree(edesc);
  845. /*
  846. * If no backlog flag, the completion of the request is done
  847. * by CAAM, not crypto engine.
  848. */
  849. if (!has_bklog)
  850. aead_request_complete(req, ecode);
  851. else
  852. crypto_finalize_aead_request(jrp->engine, req, ecode);
  853. }
  854. static inline u8 *skcipher_edesc_iv(struct skcipher_edesc *edesc)
  855. {
  856. return PTR_ALIGN((u8 *)edesc->sec4_sg + edesc->sec4_sg_bytes,
  857. dma_get_cache_alignment());
  858. }
  859. static void skcipher_crypt_done(struct device *jrdev, u32 *desc, u32 err,
  860. void *context)
  861. {
  862. struct skcipher_request *req = context;
  863. struct skcipher_edesc *edesc;
  864. struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req);
  865. struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
  866. struct caam_drv_private_jr *jrp = dev_get_drvdata(jrdev);
  867. int ivsize = crypto_skcipher_ivsize(skcipher);
  868. int ecode = 0;
  869. bool has_bklog;
  870. dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
  871. edesc = rctx->edesc;
  872. has_bklog = edesc->bklog;
  873. if (err)
  874. ecode = caam_jr_strstatus(jrdev, err);
  875. skcipher_unmap(jrdev, edesc, req);
  876. /*
  877. * The crypto API expects us to set the IV (req->iv) to the last
  878. * ciphertext block (CBC mode) or last counter (CTR mode).
  879. * This is used e.g. by the CTS mode.
  880. */
  881. if (ivsize && !ecode) {
  882. memcpy(req->iv, skcipher_edesc_iv(edesc), ivsize);
  883. print_hex_dump_debug("dstiv @" __stringify(__LINE__)": ",
  884. DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
  885. ivsize, 1);
  886. }
  887. caam_dump_sg("dst @" __stringify(__LINE__)": ",
  888. DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
  889. edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
  890. kfree(edesc);
  891. /*
  892. * If no backlog flag, the completion of the request is done
  893. * by CAAM, not crypto engine.
  894. */
  895. if (!has_bklog)
  896. skcipher_request_complete(req, ecode);
  897. else
  898. crypto_finalize_skcipher_request(jrp->engine, req, ecode);
  899. }
  900. /*
  901. * Fill in aead job descriptor
  902. */
  903. static void init_aead_job(struct aead_request *req,
  904. struct aead_edesc *edesc,
  905. bool all_contig, bool encrypt)
  906. {
  907. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  908. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  909. int authsize = ctx->authsize;
  910. u32 *desc = edesc->hw_desc;
  911. u32 out_options, in_options;
  912. dma_addr_t dst_dma, src_dma;
  913. int len, sec4_sg_index = 0;
  914. dma_addr_t ptr;
  915. u32 *sh_desc;
  916. sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
  917. ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
  918. len = desc_len(sh_desc);
  919. init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
  920. if (all_contig) {
  921. src_dma = edesc->mapped_src_nents ? sg_dma_address(req->src) :
  922. 0;
  923. in_options = 0;
  924. } else {
  925. src_dma = edesc->sec4_sg_dma;
  926. sec4_sg_index += edesc->mapped_src_nents;
  927. in_options = LDST_SGF;
  928. }
  929. append_seq_in_ptr(desc, src_dma, req->assoclen + req->cryptlen,
  930. in_options);
  931. dst_dma = src_dma;
  932. out_options = in_options;
  933. if (unlikely(req->src != req->dst)) {
  934. if (!edesc->mapped_dst_nents) {
  935. dst_dma = 0;
  936. out_options = 0;
  937. } else if (edesc->mapped_dst_nents == 1) {
  938. dst_dma = sg_dma_address(req->dst);
  939. out_options = 0;
  940. } else {
  941. dst_dma = edesc->sec4_sg_dma +
  942. sec4_sg_index *
  943. sizeof(struct sec4_sg_entry);
  944. out_options = LDST_SGF;
  945. }
  946. }
  947. if (encrypt)
  948. append_seq_out_ptr(desc, dst_dma,
  949. req->assoclen + req->cryptlen + authsize,
  950. out_options);
  951. else
  952. append_seq_out_ptr(desc, dst_dma,
  953. req->assoclen + req->cryptlen - authsize,
  954. out_options);
  955. }
  956. static void init_gcm_job(struct aead_request *req,
  957. struct aead_edesc *edesc,
  958. bool all_contig, bool encrypt)
  959. {
  960. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  961. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  962. unsigned int ivsize = crypto_aead_ivsize(aead);
  963. u32 *desc = edesc->hw_desc;
  964. bool generic_gcm = (ivsize == GCM_AES_IV_SIZE);
  965. unsigned int last;
  966. init_aead_job(req, edesc, all_contig, encrypt);
  967. append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
  968. /* BUG This should not be specific to generic GCM. */
  969. last = 0;
  970. if (encrypt && generic_gcm && !(req->assoclen + req->cryptlen))
  971. last = FIFOLD_TYPE_LAST1;
  972. /* Read GCM IV */
  973. append_cmd(desc, CMD_FIFO_LOAD | FIFOLD_CLASS_CLASS1 | IMMEDIATE |
  974. FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | GCM_AES_IV_SIZE | last);
  975. /* Append Salt */
  976. if (!generic_gcm)
  977. append_data(desc, ctx->key + ctx->cdata.keylen, 4);
  978. /* Append IV */
  979. append_data(desc, req->iv, ivsize);
  980. /* End of blank commands */
  981. }
  982. static void init_chachapoly_job(struct aead_request *req,
  983. struct aead_edesc *edesc, bool all_contig,
  984. bool encrypt)
  985. {
  986. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  987. unsigned int ivsize = crypto_aead_ivsize(aead);
  988. unsigned int assoclen = req->assoclen;
  989. u32 *desc = edesc->hw_desc;
  990. u32 ctx_iv_off = 4;
  991. init_aead_job(req, edesc, all_contig, encrypt);
  992. if (ivsize != CHACHAPOLY_IV_SIZE) {
  993. /* IPsec specific: CONTEXT1[223:128] = {NONCE, IV} */
  994. ctx_iv_off += 4;
  995. /*
  996. * The associated data comes already with the IV but we need
  997. * to skip it when we authenticate or encrypt...
  998. */
  999. assoclen -= ivsize;
  1000. }
  1001. append_math_add_imm_u32(desc, REG3, ZERO, IMM, assoclen);
  1002. /*
  1003. * For IPsec load the IV further in the same register.
  1004. * For RFC7539 simply load the 12 bytes nonce in a single operation
  1005. */
  1006. append_load_as_imm(desc, req->iv, ivsize, LDST_CLASS_1_CCB |
  1007. LDST_SRCDST_BYTE_CONTEXT |
  1008. ctx_iv_off << LDST_OFFSET_SHIFT);
  1009. }
  1010. static void init_authenc_job(struct aead_request *req,
  1011. struct aead_edesc *edesc,
  1012. bool all_contig, bool encrypt)
  1013. {
  1014. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  1015. struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
  1016. struct caam_aead_alg,
  1017. aead.base);
  1018. unsigned int ivsize = crypto_aead_ivsize(aead);
  1019. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  1020. struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
  1021. const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
  1022. OP_ALG_AAI_CTR_MOD128);
  1023. const bool is_rfc3686 = alg->caam.rfc3686;
  1024. u32 *desc = edesc->hw_desc;
  1025. u32 ivoffset = 0;
  1026. /*
  1027. * AES-CTR needs to load IV in CONTEXT1 reg
  1028. * at an offset of 128bits (16bytes)
  1029. * CONTEXT1[255:128] = IV
  1030. */
  1031. if (ctr_mode)
  1032. ivoffset = 16;
  1033. /*
  1034. * RFC3686 specific:
  1035. * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
  1036. */
  1037. if (is_rfc3686)
  1038. ivoffset = 16 + CTR_RFC3686_NONCE_SIZE;
  1039. init_aead_job(req, edesc, all_contig, encrypt);
  1040. /*
  1041. * {REG3, DPOVRD} = assoclen, depending on whether MATH command supports
  1042. * having DPOVRD as destination.
  1043. */
  1044. if (ctrlpriv->era < 3)
  1045. append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
  1046. else
  1047. append_math_add_imm_u32(desc, DPOVRD, ZERO, IMM, req->assoclen);
  1048. if (ivsize && ((is_rfc3686 && encrypt) || !alg->caam.geniv))
  1049. append_load_as_imm(desc, req->iv, ivsize,
  1050. LDST_CLASS_1_CCB |
  1051. LDST_SRCDST_BYTE_CONTEXT |
  1052. (ivoffset << LDST_OFFSET_SHIFT));
  1053. }
  1054. /*
  1055. * Fill in skcipher job descriptor
  1056. */
  1057. static void init_skcipher_job(struct skcipher_request *req,
  1058. struct skcipher_edesc *edesc,
  1059. const bool encrypt)
  1060. {
  1061. struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
  1062. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
  1063. struct device *jrdev = ctx->jrdev;
  1064. int ivsize = crypto_skcipher_ivsize(skcipher);
  1065. u32 *desc = edesc->hw_desc;
  1066. u32 *sh_desc;
  1067. u32 in_options = 0, out_options = 0;
  1068. dma_addr_t src_dma, dst_dma, ptr;
  1069. int len, sec4_sg_index = 0;
  1070. print_hex_dump_debug("presciv@"__stringify(__LINE__)": ",
  1071. DUMP_PREFIX_ADDRESS, 16, 4, req->iv, ivsize, 1);
  1072. dev_dbg(jrdev, "asked=%d, cryptlen%d\n",
  1073. (int)edesc->src_nents > 1 ? 100 : req->cryptlen, req->cryptlen);
  1074. caam_dump_sg("src @" __stringify(__LINE__)": ",
  1075. DUMP_PREFIX_ADDRESS, 16, 4, req->src,
  1076. edesc->src_nents > 1 ? 100 : req->cryptlen, 1);
  1077. sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
  1078. ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
  1079. len = desc_len(sh_desc);
  1080. init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
  1081. if (ivsize || edesc->mapped_src_nents > 1) {
  1082. src_dma = edesc->sec4_sg_dma;
  1083. sec4_sg_index = edesc->mapped_src_nents + !!ivsize;
  1084. in_options = LDST_SGF;
  1085. } else {
  1086. src_dma = sg_dma_address(req->src);
  1087. }
  1088. append_seq_in_ptr(desc, src_dma, req->cryptlen + ivsize, in_options);
  1089. if (likely(req->src == req->dst)) {
  1090. dst_dma = src_dma + !!ivsize * sizeof(struct sec4_sg_entry);
  1091. out_options = in_options;
  1092. } else if (!ivsize && edesc->mapped_dst_nents == 1) {
  1093. dst_dma = sg_dma_address(req->dst);
  1094. } else {
  1095. dst_dma = edesc->sec4_sg_dma + sec4_sg_index *
  1096. sizeof(struct sec4_sg_entry);
  1097. out_options = LDST_SGF;
  1098. }
  1099. append_seq_out_ptr(desc, dst_dma, req->cryptlen + ivsize, out_options);
  1100. }
  1101. /*
  1102. * allocate and map the aead extended descriptor
  1103. */
  1104. static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
  1105. int desc_bytes, bool *all_contig_ptr,
  1106. bool encrypt)
  1107. {
  1108. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  1109. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  1110. struct device *jrdev = ctx->jrdev;
  1111. struct caam_aead_req_ctx *rctx = aead_request_ctx(req);
  1112. gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
  1113. GFP_KERNEL : GFP_ATOMIC;
  1114. int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
  1115. int src_len, dst_len = 0;
  1116. struct aead_edesc *edesc;
  1117. int sec4_sg_index, sec4_sg_len, sec4_sg_bytes;
  1118. unsigned int authsize = ctx->authsize;
  1119. if (unlikely(req->dst != req->src)) {
  1120. src_len = req->assoclen + req->cryptlen;
  1121. dst_len = src_len + (encrypt ? authsize : (-authsize));
  1122. src_nents = sg_nents_for_len(req->src, src_len);
  1123. if (unlikely(src_nents < 0)) {
  1124. dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
  1125. src_len);
  1126. return ERR_PTR(src_nents);
  1127. }
  1128. dst_nents = sg_nents_for_len(req->dst, dst_len);
  1129. if (unlikely(dst_nents < 0)) {
  1130. dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
  1131. dst_len);
  1132. return ERR_PTR(dst_nents);
  1133. }
  1134. } else {
  1135. src_len = req->assoclen + req->cryptlen +
  1136. (encrypt ? authsize : 0);
  1137. src_nents = sg_nents_for_len(req->src, src_len);
  1138. if (unlikely(src_nents < 0)) {
  1139. dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
  1140. src_len);
  1141. return ERR_PTR(src_nents);
  1142. }
  1143. }
  1144. if (likely(req->src == req->dst)) {
  1145. mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
  1146. DMA_BIDIRECTIONAL);
  1147. if (unlikely(!mapped_src_nents)) {
  1148. dev_err(jrdev, "unable to map source\n");
  1149. return ERR_PTR(-ENOMEM);
  1150. }
  1151. } else {
  1152. /* Cover also the case of null (zero length) input data */
  1153. if (src_nents) {
  1154. mapped_src_nents = dma_map_sg(jrdev, req->src,
  1155. src_nents, DMA_TO_DEVICE);
  1156. if (unlikely(!mapped_src_nents)) {
  1157. dev_err(jrdev, "unable to map source\n");
  1158. return ERR_PTR(-ENOMEM);
  1159. }
  1160. } else {
  1161. mapped_src_nents = 0;
  1162. }
  1163. /* Cover also the case of null (zero length) output data */
  1164. if (dst_nents) {
  1165. mapped_dst_nents = dma_map_sg(jrdev, req->dst,
  1166. dst_nents,
  1167. DMA_FROM_DEVICE);
  1168. if (unlikely(!mapped_dst_nents)) {
  1169. dev_err(jrdev, "unable to map destination\n");
  1170. dma_unmap_sg(jrdev, req->src, src_nents,
  1171. DMA_TO_DEVICE);
  1172. return ERR_PTR(-ENOMEM);
  1173. }
  1174. } else {
  1175. mapped_dst_nents = 0;
  1176. }
  1177. }
  1178. /*
  1179. * HW reads 4 S/G entries at a time; make sure the reads don't go beyond
  1180. * the end of the table by allocating more S/G entries.
  1181. */
  1182. sec4_sg_len = mapped_src_nents > 1 ? mapped_src_nents : 0;
  1183. if (mapped_dst_nents > 1)
  1184. sec4_sg_len += pad_sg_nents(mapped_dst_nents);
  1185. else
  1186. sec4_sg_len = pad_sg_nents(sec4_sg_len);
  1187. sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
  1188. /* allocate space for base edesc and hw desc commands, link tables */
  1189. edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes, flags);
  1190. if (!edesc) {
  1191. caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
  1192. 0, 0, 0);
  1193. return ERR_PTR(-ENOMEM);
  1194. }
  1195. edesc->src_nents = src_nents;
  1196. edesc->dst_nents = dst_nents;
  1197. edesc->mapped_src_nents = mapped_src_nents;
  1198. edesc->mapped_dst_nents = mapped_dst_nents;
  1199. edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
  1200. desc_bytes;
  1201. rctx->edesc = edesc;
  1202. *all_contig_ptr = !(mapped_src_nents > 1);
  1203. sec4_sg_index = 0;
  1204. if (mapped_src_nents > 1) {
  1205. sg_to_sec4_sg_last(req->src, src_len,
  1206. edesc->sec4_sg + sec4_sg_index, 0);
  1207. sec4_sg_index += mapped_src_nents;
  1208. }
  1209. if (mapped_dst_nents > 1) {
  1210. sg_to_sec4_sg_last(req->dst, dst_len,
  1211. edesc->sec4_sg + sec4_sg_index, 0);
  1212. }
  1213. if (!sec4_sg_bytes)
  1214. return edesc;
  1215. edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
  1216. sec4_sg_bytes, DMA_TO_DEVICE);
  1217. if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
  1218. dev_err(jrdev, "unable to map S/G table\n");
  1219. aead_unmap(jrdev, edesc, req);
  1220. kfree(edesc);
  1221. return ERR_PTR(-ENOMEM);
  1222. }
  1223. edesc->sec4_sg_bytes = sec4_sg_bytes;
  1224. return edesc;
  1225. }
  1226. static int aead_enqueue_req(struct device *jrdev, struct aead_request *req)
  1227. {
  1228. struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev);
  1229. struct caam_aead_req_ctx *rctx = aead_request_ctx(req);
  1230. struct aead_edesc *edesc = rctx->edesc;
  1231. u32 *desc = edesc->hw_desc;
  1232. int ret;
  1233. /*
  1234. * Only the backlog request are sent to crypto-engine since the others
  1235. * can be handled by CAAM, if free, especially since JR has up to 1024
  1236. * entries (more than the 10 entries from crypto-engine).
  1237. */
  1238. if (req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)
  1239. ret = crypto_transfer_aead_request_to_engine(jrpriv->engine,
  1240. req);
  1241. else
  1242. ret = caam_jr_enqueue(jrdev, desc, aead_crypt_done, req);
  1243. if ((ret != -EINPROGRESS) && (ret != -EBUSY)) {
  1244. aead_unmap(jrdev, edesc, req);
  1245. kfree(rctx->edesc);
  1246. }
  1247. return ret;
  1248. }
  1249. static inline int chachapoly_crypt(struct aead_request *req, bool encrypt)
  1250. {
  1251. struct aead_edesc *edesc;
  1252. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  1253. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  1254. struct device *jrdev = ctx->jrdev;
  1255. bool all_contig;
  1256. u32 *desc;
  1257. edesc = aead_edesc_alloc(req, CHACHAPOLY_DESC_JOB_IO_LEN, &all_contig,
  1258. encrypt);
  1259. if (IS_ERR(edesc))
  1260. return PTR_ERR(edesc);
  1261. desc = edesc->hw_desc;
  1262. init_chachapoly_job(req, edesc, all_contig, encrypt);
  1263. print_hex_dump_debug("chachapoly jobdesc@" __stringify(__LINE__)": ",
  1264. DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
  1265. 1);
  1266. return aead_enqueue_req(jrdev, req);
  1267. }
  1268. static int chachapoly_encrypt(struct aead_request *req)
  1269. {
  1270. return chachapoly_crypt(req, true);
  1271. }
  1272. static int chachapoly_decrypt(struct aead_request *req)
  1273. {
  1274. return chachapoly_crypt(req, false);
  1275. }
  1276. static inline int aead_crypt(struct aead_request *req, bool encrypt)
  1277. {
  1278. struct aead_edesc *edesc;
  1279. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  1280. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  1281. struct device *jrdev = ctx->jrdev;
  1282. bool all_contig;
  1283. /* allocate extended descriptor */
  1284. edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
  1285. &all_contig, encrypt);
  1286. if (IS_ERR(edesc))
  1287. return PTR_ERR(edesc);
  1288. /* Create and submit job descriptor */
  1289. init_authenc_job(req, edesc, all_contig, encrypt);
  1290. print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ",
  1291. DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
  1292. desc_bytes(edesc->hw_desc), 1);
  1293. return aead_enqueue_req(jrdev, req);
  1294. }
  1295. static int aead_encrypt(struct aead_request *req)
  1296. {
  1297. return aead_crypt(req, true);
  1298. }
  1299. static int aead_decrypt(struct aead_request *req)
  1300. {
  1301. return aead_crypt(req, false);
  1302. }
  1303. static int aead_do_one_req(struct crypto_engine *engine, void *areq)
  1304. {
  1305. struct aead_request *req = aead_request_cast(areq);
  1306. struct caam_ctx *ctx = crypto_aead_ctx_dma(crypto_aead_reqtfm(req));
  1307. struct caam_aead_req_ctx *rctx = aead_request_ctx(req);
  1308. u32 *desc = rctx->edesc->hw_desc;
  1309. int ret;
  1310. rctx->edesc->bklog = true;
  1311. ret = caam_jr_enqueue(ctx->jrdev, desc, aead_crypt_done, req);
  1312. if (ret == -ENOSPC && engine->retry_support)
  1313. return ret;
  1314. if (ret != -EINPROGRESS) {
  1315. aead_unmap(ctx->jrdev, rctx->edesc, req);
  1316. kfree(rctx->edesc);
  1317. } else {
  1318. ret = 0;
  1319. }
  1320. return ret;
  1321. }
  1322. static inline int gcm_crypt(struct aead_request *req, bool encrypt)
  1323. {
  1324. struct aead_edesc *edesc;
  1325. struct crypto_aead *aead = crypto_aead_reqtfm(req);
  1326. struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
  1327. struct device *jrdev = ctx->jrdev;
  1328. bool all_contig;
  1329. /* allocate extended descriptor */
  1330. edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig,
  1331. encrypt);
  1332. if (IS_ERR(edesc))
  1333. return PTR_ERR(edesc);
  1334. /* Create and submit job descriptor */
  1335. init_gcm_job(req, edesc, all_contig, encrypt);
  1336. print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ",
  1337. DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
  1338. desc_bytes(edesc->hw_desc), 1);
  1339. return aead_enqueue_req(jrdev, req);
  1340. }
  1341. static int gcm_encrypt(struct aead_request *req)
  1342. {
  1343. return gcm_crypt(req, true);
  1344. }
  1345. static int gcm_decrypt(struct aead_request *req)
  1346. {
  1347. return gcm_crypt(req, false);
  1348. }
  1349. static int ipsec_gcm_encrypt(struct aead_request *req)
  1350. {
  1351. return crypto_ipsec_check_assoclen(req->assoclen) ? : gcm_encrypt(req);
  1352. }
  1353. static int ipsec_gcm_decrypt(struct aead_request *req)
  1354. {
  1355. return crypto_ipsec_check_assoclen(req->assoclen) ? : gcm_decrypt(req);
  1356. }
  1357. /*
  1358. * allocate and map the skcipher extended descriptor for skcipher
  1359. */
  1360. static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req,
  1361. int desc_bytes)
  1362. {
  1363. struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
  1364. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
  1365. struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req);
  1366. struct device *jrdev = ctx->jrdev;
  1367. gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
  1368. GFP_KERNEL : GFP_ATOMIC;
  1369. int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
  1370. struct skcipher_edesc *edesc;
  1371. dma_addr_t iv_dma = 0;
  1372. u8 *iv;
  1373. int ivsize = crypto_skcipher_ivsize(skcipher);
  1374. int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
  1375. unsigned int aligned_size;
  1376. src_nents = sg_nents_for_len(req->src, req->cryptlen);
  1377. if (unlikely(src_nents < 0)) {
  1378. dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
  1379. req->cryptlen);
  1380. return ERR_PTR(src_nents);
  1381. }
  1382. if (req->dst != req->src) {
  1383. dst_nents = sg_nents_for_len(req->dst, req->cryptlen);
  1384. if (unlikely(dst_nents < 0)) {
  1385. dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
  1386. req->cryptlen);
  1387. return ERR_PTR(dst_nents);
  1388. }
  1389. }
  1390. if (likely(req->src == req->dst)) {
  1391. mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
  1392. DMA_BIDIRECTIONAL);
  1393. if (unlikely(!mapped_src_nents)) {
  1394. dev_err(jrdev, "unable to map source\n");
  1395. return ERR_PTR(-ENOMEM);
  1396. }
  1397. } else {
  1398. mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
  1399. DMA_TO_DEVICE);
  1400. if (unlikely(!mapped_src_nents)) {
  1401. dev_err(jrdev, "unable to map source\n");
  1402. return ERR_PTR(-ENOMEM);
  1403. }
  1404. mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
  1405. DMA_FROM_DEVICE);
  1406. if (unlikely(!mapped_dst_nents)) {
  1407. dev_err(jrdev, "unable to map destination\n");
  1408. dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
  1409. return ERR_PTR(-ENOMEM);
  1410. }
  1411. }
  1412. if (!ivsize && mapped_src_nents == 1)
  1413. sec4_sg_ents = 0; // no need for an input hw s/g table
  1414. else
  1415. sec4_sg_ents = mapped_src_nents + !!ivsize;
  1416. dst_sg_idx = sec4_sg_ents;
  1417. /*
  1418. * Input, output HW S/G tables: [IV, src][dst, IV]
  1419. * IV entries point to the same buffer
  1420. * If src == dst, S/G entries are reused (S/G tables overlap)
  1421. *
  1422. * HW reads 4 S/G entries at a time; make sure the reads don't go beyond
  1423. * the end of the table by allocating more S/G entries. Logic:
  1424. * if (output S/G)
  1425. * pad output S/G, if needed
  1426. * else if (input S/G) ...
  1427. * pad input S/G, if needed
  1428. */
  1429. if (ivsize || mapped_dst_nents > 1) {
  1430. if (req->src == req->dst)
  1431. sec4_sg_ents = !!ivsize + pad_sg_nents(sec4_sg_ents);
  1432. else
  1433. sec4_sg_ents += pad_sg_nents(mapped_dst_nents +
  1434. !!ivsize);
  1435. } else {
  1436. sec4_sg_ents = pad_sg_nents(sec4_sg_ents);
  1437. }
  1438. sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
  1439. /*
  1440. * allocate space for base edesc and hw desc commands, link tables, IV
  1441. */
  1442. aligned_size = sizeof(*edesc) + desc_bytes + sec4_sg_bytes;
  1443. aligned_size = ALIGN(aligned_size, dma_get_cache_alignment());
  1444. aligned_size += ~(ARCH_KMALLOC_MINALIGN - 1) &
  1445. (dma_get_cache_alignment() - 1);
  1446. aligned_size += ALIGN(ivsize, dma_get_cache_alignment());
  1447. edesc = kzalloc(aligned_size, flags);
  1448. if (!edesc) {
  1449. dev_err(jrdev, "could not allocate extended descriptor\n");
  1450. caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
  1451. 0, 0, 0);
  1452. return ERR_PTR(-ENOMEM);
  1453. }
  1454. edesc->src_nents = src_nents;
  1455. edesc->dst_nents = dst_nents;
  1456. edesc->mapped_src_nents = mapped_src_nents;
  1457. edesc->mapped_dst_nents = mapped_dst_nents;
  1458. edesc->sec4_sg_bytes = sec4_sg_bytes;
  1459. edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc +
  1460. desc_bytes);
  1461. rctx->edesc = edesc;
  1462. /* Make sure IV is located in a DMAable area */
  1463. if (ivsize) {
  1464. iv = skcipher_edesc_iv(edesc);
  1465. memcpy(iv, req->iv, ivsize);
  1466. iv_dma = dma_map_single(jrdev, iv, ivsize, DMA_BIDIRECTIONAL);
  1467. if (dma_mapping_error(jrdev, iv_dma)) {
  1468. dev_err(jrdev, "unable to map IV\n");
  1469. caam_unmap(jrdev, req->src, req->dst, src_nents,
  1470. dst_nents, 0, 0, 0, 0);
  1471. kfree(edesc);
  1472. return ERR_PTR(-ENOMEM);
  1473. }
  1474. dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0);
  1475. }
  1476. if (dst_sg_idx)
  1477. sg_to_sec4_sg(req->src, req->cryptlen, edesc->sec4_sg +
  1478. !!ivsize, 0);
  1479. if (req->src != req->dst && (ivsize || mapped_dst_nents > 1))
  1480. sg_to_sec4_sg(req->dst, req->cryptlen, edesc->sec4_sg +
  1481. dst_sg_idx, 0);
  1482. if (ivsize)
  1483. dma_to_sec4_sg_one(edesc->sec4_sg + dst_sg_idx +
  1484. mapped_dst_nents, iv_dma, ivsize, 0);
  1485. if (ivsize || mapped_dst_nents > 1)
  1486. sg_to_sec4_set_last(edesc->sec4_sg + dst_sg_idx +
  1487. mapped_dst_nents - 1 + !!ivsize);
  1488. if (sec4_sg_bytes) {
  1489. edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
  1490. sec4_sg_bytes,
  1491. DMA_TO_DEVICE);
  1492. if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
  1493. dev_err(jrdev, "unable to map S/G table\n");
  1494. caam_unmap(jrdev, req->src, req->dst, src_nents,
  1495. dst_nents, iv_dma, ivsize, 0, 0);
  1496. kfree(edesc);
  1497. return ERR_PTR(-ENOMEM);
  1498. }
  1499. }
  1500. edesc->iv_dma = iv_dma;
  1501. print_hex_dump_debug("skcipher sec4_sg@" __stringify(__LINE__)": ",
  1502. DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
  1503. sec4_sg_bytes, 1);
  1504. return edesc;
  1505. }
  1506. static int skcipher_do_one_req(struct crypto_engine *engine, void *areq)
  1507. {
  1508. struct skcipher_request *req = skcipher_request_cast(areq);
  1509. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(crypto_skcipher_reqtfm(req));
  1510. struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req);
  1511. u32 *desc = rctx->edesc->hw_desc;
  1512. int ret;
  1513. rctx->edesc->bklog = true;
  1514. ret = caam_jr_enqueue(ctx->jrdev, desc, skcipher_crypt_done, req);
  1515. if (ret == -ENOSPC && engine->retry_support)
  1516. return ret;
  1517. if (ret != -EINPROGRESS) {
  1518. skcipher_unmap(ctx->jrdev, rctx->edesc, req);
  1519. kfree(rctx->edesc);
  1520. } else {
  1521. ret = 0;
  1522. }
  1523. return ret;
  1524. }
  1525. static inline bool xts_skcipher_ivsize(struct skcipher_request *req)
  1526. {
  1527. struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
  1528. unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
  1529. return !!get_unaligned((u64 *)(req->iv + (ivsize / 2)));
  1530. }
  1531. static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
  1532. {
  1533. struct skcipher_edesc *edesc;
  1534. struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
  1535. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
  1536. struct device *jrdev = ctx->jrdev;
  1537. struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev);
  1538. struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
  1539. u32 *desc;
  1540. int ret = 0;
  1541. /*
  1542. * XTS is expected to return an error even for input length = 0
  1543. * Note that the case input length < block size will be caught during
  1544. * HW offloading and return an error.
  1545. */
  1546. if (!req->cryptlen && !ctx->fallback)
  1547. return 0;
  1548. if (ctx->fallback && ((ctrlpriv->era <= 8 && xts_skcipher_ivsize(req)) ||
  1549. ctx->xts_key_fallback)) {
  1550. struct caam_skcipher_req_ctx *rctx = skcipher_request_ctx(req);
  1551. skcipher_request_set_tfm(&rctx->fallback_req, ctx->fallback);
  1552. skcipher_request_set_callback(&rctx->fallback_req,
  1553. req->base.flags,
  1554. req->base.complete,
  1555. req->base.data);
  1556. skcipher_request_set_crypt(&rctx->fallback_req, req->src,
  1557. req->dst, req->cryptlen, req->iv);
  1558. return encrypt ? crypto_skcipher_encrypt(&rctx->fallback_req) :
  1559. crypto_skcipher_decrypt(&rctx->fallback_req);
  1560. }
  1561. /* allocate extended descriptor */
  1562. edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ);
  1563. if (IS_ERR(edesc))
  1564. return PTR_ERR(edesc);
  1565. /* Create and submit job descriptor*/
  1566. init_skcipher_job(req, edesc, encrypt);
  1567. print_hex_dump_debug("skcipher jobdesc@" __stringify(__LINE__)": ",
  1568. DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
  1569. desc_bytes(edesc->hw_desc), 1);
  1570. desc = edesc->hw_desc;
  1571. /*
  1572. * Only the backlog request are sent to crypto-engine since the others
  1573. * can be handled by CAAM, if free, especially since JR has up to 1024
  1574. * entries (more than the 10 entries from crypto-engine).
  1575. */
  1576. if (req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)
  1577. ret = crypto_transfer_skcipher_request_to_engine(jrpriv->engine,
  1578. req);
  1579. else
  1580. ret = caam_jr_enqueue(jrdev, desc, skcipher_crypt_done, req);
  1581. if ((ret != -EINPROGRESS) && (ret != -EBUSY)) {
  1582. skcipher_unmap(jrdev, edesc, req);
  1583. kfree(edesc);
  1584. }
  1585. return ret;
  1586. }
  1587. static int skcipher_encrypt(struct skcipher_request *req)
  1588. {
  1589. return skcipher_crypt(req, true);
  1590. }
  1591. static int skcipher_decrypt(struct skcipher_request *req)
  1592. {
  1593. return skcipher_crypt(req, false);
  1594. }
  1595. static struct caam_skcipher_alg driver_algs[] = {
  1596. {
  1597. .skcipher.base = {
  1598. .base = {
  1599. .cra_name = "cbc(aes)",
  1600. .cra_driver_name = "cbc-aes-caam",
  1601. .cra_blocksize = AES_BLOCK_SIZE,
  1602. },
  1603. .setkey = aes_skcipher_setkey,
  1604. .encrypt = skcipher_encrypt,
  1605. .decrypt = skcipher_decrypt,
  1606. .min_keysize = AES_MIN_KEY_SIZE,
  1607. .max_keysize = AES_MAX_KEY_SIZE,
  1608. .ivsize = AES_BLOCK_SIZE,
  1609. },
  1610. .skcipher.op = {
  1611. .do_one_request = skcipher_do_one_req,
  1612. },
  1613. .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  1614. },
  1615. {
  1616. .skcipher.base = {
  1617. .base = {
  1618. .cra_name = "cbc(des3_ede)",
  1619. .cra_driver_name = "cbc-3des-caam",
  1620. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1621. },
  1622. .setkey = des3_skcipher_setkey,
  1623. .encrypt = skcipher_encrypt,
  1624. .decrypt = skcipher_decrypt,
  1625. .min_keysize = DES3_EDE_KEY_SIZE,
  1626. .max_keysize = DES3_EDE_KEY_SIZE,
  1627. .ivsize = DES3_EDE_BLOCK_SIZE,
  1628. },
  1629. .skcipher.op = {
  1630. .do_one_request = skcipher_do_one_req,
  1631. },
  1632. .caam.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  1633. },
  1634. {
  1635. .skcipher.base = {
  1636. .base = {
  1637. .cra_name = "cbc(des)",
  1638. .cra_driver_name = "cbc-des-caam",
  1639. .cra_blocksize = DES_BLOCK_SIZE,
  1640. },
  1641. .setkey = des_skcipher_setkey,
  1642. .encrypt = skcipher_encrypt,
  1643. .decrypt = skcipher_decrypt,
  1644. .min_keysize = DES_KEY_SIZE,
  1645. .max_keysize = DES_KEY_SIZE,
  1646. .ivsize = DES_BLOCK_SIZE,
  1647. },
  1648. .skcipher.op = {
  1649. .do_one_request = skcipher_do_one_req,
  1650. },
  1651. .caam.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  1652. },
  1653. {
  1654. .skcipher.base = {
  1655. .base = {
  1656. .cra_name = "ctr(aes)",
  1657. .cra_driver_name = "ctr-aes-caam",
  1658. .cra_blocksize = 1,
  1659. },
  1660. .setkey = ctr_skcipher_setkey,
  1661. .encrypt = skcipher_encrypt,
  1662. .decrypt = skcipher_decrypt,
  1663. .min_keysize = AES_MIN_KEY_SIZE,
  1664. .max_keysize = AES_MAX_KEY_SIZE,
  1665. .ivsize = AES_BLOCK_SIZE,
  1666. .chunksize = AES_BLOCK_SIZE,
  1667. },
  1668. .skcipher.op = {
  1669. .do_one_request = skcipher_do_one_req,
  1670. },
  1671. .caam.class1_alg_type = OP_ALG_ALGSEL_AES |
  1672. OP_ALG_AAI_CTR_MOD128,
  1673. },
  1674. {
  1675. .skcipher.base = {
  1676. .base = {
  1677. .cra_name = "rfc3686(ctr(aes))",
  1678. .cra_driver_name = "rfc3686-ctr-aes-caam",
  1679. .cra_blocksize = 1,
  1680. },
  1681. .setkey = rfc3686_skcipher_setkey,
  1682. .encrypt = skcipher_encrypt,
  1683. .decrypt = skcipher_decrypt,
  1684. .min_keysize = AES_MIN_KEY_SIZE +
  1685. CTR_RFC3686_NONCE_SIZE,
  1686. .max_keysize = AES_MAX_KEY_SIZE +
  1687. CTR_RFC3686_NONCE_SIZE,
  1688. .ivsize = CTR_RFC3686_IV_SIZE,
  1689. .chunksize = AES_BLOCK_SIZE,
  1690. },
  1691. .skcipher.op = {
  1692. .do_one_request = skcipher_do_one_req,
  1693. },
  1694. .caam = {
  1695. .class1_alg_type = OP_ALG_ALGSEL_AES |
  1696. OP_ALG_AAI_CTR_MOD128,
  1697. .rfc3686 = true,
  1698. },
  1699. },
  1700. {
  1701. .skcipher.base = {
  1702. .base = {
  1703. .cra_name = "xts(aes)",
  1704. .cra_driver_name = "xts-aes-caam",
  1705. .cra_flags = CRYPTO_ALG_NEED_FALLBACK,
  1706. .cra_blocksize = AES_BLOCK_SIZE,
  1707. },
  1708. .setkey = xts_skcipher_setkey,
  1709. .encrypt = skcipher_encrypt,
  1710. .decrypt = skcipher_decrypt,
  1711. .min_keysize = 2 * AES_MIN_KEY_SIZE,
  1712. .max_keysize = 2 * AES_MAX_KEY_SIZE,
  1713. .ivsize = AES_BLOCK_SIZE,
  1714. },
  1715. .skcipher.op = {
  1716. .do_one_request = skcipher_do_one_req,
  1717. },
  1718. .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
  1719. },
  1720. {
  1721. .skcipher.base = {
  1722. .base = {
  1723. .cra_name = "ecb(des)",
  1724. .cra_driver_name = "ecb-des-caam",
  1725. .cra_blocksize = DES_BLOCK_SIZE,
  1726. },
  1727. .setkey = des_skcipher_setkey,
  1728. .encrypt = skcipher_encrypt,
  1729. .decrypt = skcipher_decrypt,
  1730. .min_keysize = DES_KEY_SIZE,
  1731. .max_keysize = DES_KEY_SIZE,
  1732. },
  1733. .skcipher.op = {
  1734. .do_one_request = skcipher_do_one_req,
  1735. },
  1736. .caam.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_ECB,
  1737. },
  1738. {
  1739. .skcipher.base = {
  1740. .base = {
  1741. .cra_name = "ecb(aes)",
  1742. .cra_driver_name = "ecb-aes-caam",
  1743. .cra_blocksize = AES_BLOCK_SIZE,
  1744. },
  1745. .setkey = aes_skcipher_setkey,
  1746. .encrypt = skcipher_encrypt,
  1747. .decrypt = skcipher_decrypt,
  1748. .min_keysize = AES_MIN_KEY_SIZE,
  1749. .max_keysize = AES_MAX_KEY_SIZE,
  1750. },
  1751. .skcipher.op = {
  1752. .do_one_request = skcipher_do_one_req,
  1753. },
  1754. .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_ECB,
  1755. },
  1756. {
  1757. .skcipher.base = {
  1758. .base = {
  1759. .cra_name = "ecb(des3_ede)",
  1760. .cra_driver_name = "ecb-des3-caam",
  1761. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  1762. },
  1763. .setkey = des3_skcipher_setkey,
  1764. .encrypt = skcipher_encrypt,
  1765. .decrypt = skcipher_decrypt,
  1766. .min_keysize = DES3_EDE_KEY_SIZE,
  1767. .max_keysize = DES3_EDE_KEY_SIZE,
  1768. },
  1769. .skcipher.op = {
  1770. .do_one_request = skcipher_do_one_req,
  1771. },
  1772. .caam.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_ECB,
  1773. },
  1774. };
  1775. static struct caam_aead_alg driver_aeads[] = {
  1776. {
  1777. .aead.base = {
  1778. .base = {
  1779. .cra_name = "rfc4106(gcm(aes))",
  1780. .cra_driver_name = "rfc4106-gcm-aes-caam",
  1781. .cra_blocksize = 1,
  1782. },
  1783. .setkey = rfc4106_setkey,
  1784. .setauthsize = rfc4106_setauthsize,
  1785. .encrypt = ipsec_gcm_encrypt,
  1786. .decrypt = ipsec_gcm_decrypt,
  1787. .ivsize = GCM_RFC4106_IV_SIZE,
  1788. .maxauthsize = AES_BLOCK_SIZE,
  1789. },
  1790. .aead.op = {
  1791. .do_one_request = aead_do_one_req,
  1792. },
  1793. .caam = {
  1794. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
  1795. .nodkp = true,
  1796. },
  1797. },
  1798. {
  1799. .aead.base = {
  1800. .base = {
  1801. .cra_name = "rfc4543(gcm(aes))",
  1802. .cra_driver_name = "rfc4543-gcm-aes-caam",
  1803. .cra_blocksize = 1,
  1804. },
  1805. .setkey = rfc4543_setkey,
  1806. .setauthsize = rfc4543_setauthsize,
  1807. .encrypt = ipsec_gcm_encrypt,
  1808. .decrypt = ipsec_gcm_decrypt,
  1809. .ivsize = GCM_RFC4543_IV_SIZE,
  1810. .maxauthsize = AES_BLOCK_SIZE,
  1811. },
  1812. .aead.op = {
  1813. .do_one_request = aead_do_one_req,
  1814. },
  1815. .caam = {
  1816. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
  1817. .nodkp = true,
  1818. },
  1819. },
  1820. /* Galois Counter Mode */
  1821. {
  1822. .aead.base = {
  1823. .base = {
  1824. .cra_name = "gcm(aes)",
  1825. .cra_driver_name = "gcm-aes-caam",
  1826. .cra_blocksize = 1,
  1827. },
  1828. .setkey = gcm_setkey,
  1829. .setauthsize = gcm_setauthsize,
  1830. .encrypt = gcm_encrypt,
  1831. .decrypt = gcm_decrypt,
  1832. .ivsize = GCM_AES_IV_SIZE,
  1833. .maxauthsize = AES_BLOCK_SIZE,
  1834. },
  1835. .aead.op = {
  1836. .do_one_request = aead_do_one_req,
  1837. },
  1838. .caam = {
  1839. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
  1840. .nodkp = true,
  1841. },
  1842. },
  1843. /* single-pass ipsec_esp descriptor */
  1844. {
  1845. .aead.base = {
  1846. .base = {
  1847. .cra_name = "authenc(hmac(md5),"
  1848. "ecb(cipher_null))",
  1849. .cra_driver_name = "authenc-hmac-md5-"
  1850. "ecb-cipher_null-caam",
  1851. .cra_blocksize = NULL_BLOCK_SIZE,
  1852. },
  1853. .setkey = aead_setkey,
  1854. .setauthsize = aead_setauthsize,
  1855. .encrypt = aead_encrypt,
  1856. .decrypt = aead_decrypt,
  1857. .ivsize = NULL_IV_SIZE,
  1858. .maxauthsize = MD5_DIGEST_SIZE,
  1859. },
  1860. .aead.op = {
  1861. .do_one_request = aead_do_one_req,
  1862. },
  1863. .caam = {
  1864. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  1865. OP_ALG_AAI_HMAC_PRECOMP,
  1866. },
  1867. },
  1868. {
  1869. .aead.base = {
  1870. .base = {
  1871. .cra_name = "authenc(hmac(sha1),"
  1872. "ecb(cipher_null))",
  1873. .cra_driver_name = "authenc-hmac-sha1-"
  1874. "ecb-cipher_null-caam",
  1875. .cra_blocksize = NULL_BLOCK_SIZE,
  1876. },
  1877. .setkey = aead_setkey,
  1878. .setauthsize = aead_setauthsize,
  1879. .encrypt = aead_encrypt,
  1880. .decrypt = aead_decrypt,
  1881. .ivsize = NULL_IV_SIZE,
  1882. .maxauthsize = SHA1_DIGEST_SIZE,
  1883. },
  1884. .aead.op = {
  1885. .do_one_request = aead_do_one_req,
  1886. },
  1887. .caam = {
  1888. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  1889. OP_ALG_AAI_HMAC_PRECOMP,
  1890. },
  1891. },
  1892. {
  1893. .aead.base = {
  1894. .base = {
  1895. .cra_name = "authenc(hmac(sha224),"
  1896. "ecb(cipher_null))",
  1897. .cra_driver_name = "authenc-hmac-sha224-"
  1898. "ecb-cipher_null-caam",
  1899. .cra_blocksize = NULL_BLOCK_SIZE,
  1900. },
  1901. .setkey = aead_setkey,
  1902. .setauthsize = aead_setauthsize,
  1903. .encrypt = aead_encrypt,
  1904. .decrypt = aead_decrypt,
  1905. .ivsize = NULL_IV_SIZE,
  1906. .maxauthsize = SHA224_DIGEST_SIZE,
  1907. },
  1908. .aead.op = {
  1909. .do_one_request = aead_do_one_req,
  1910. },
  1911. .caam = {
  1912. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  1913. OP_ALG_AAI_HMAC_PRECOMP,
  1914. },
  1915. },
  1916. {
  1917. .aead.base = {
  1918. .base = {
  1919. .cra_name = "authenc(hmac(sha256),"
  1920. "ecb(cipher_null))",
  1921. .cra_driver_name = "authenc-hmac-sha256-"
  1922. "ecb-cipher_null-caam",
  1923. .cra_blocksize = NULL_BLOCK_SIZE,
  1924. },
  1925. .setkey = aead_setkey,
  1926. .setauthsize = aead_setauthsize,
  1927. .encrypt = aead_encrypt,
  1928. .decrypt = aead_decrypt,
  1929. .ivsize = NULL_IV_SIZE,
  1930. .maxauthsize = SHA256_DIGEST_SIZE,
  1931. },
  1932. .aead.op = {
  1933. .do_one_request = aead_do_one_req,
  1934. },
  1935. .caam = {
  1936. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  1937. OP_ALG_AAI_HMAC_PRECOMP,
  1938. },
  1939. },
  1940. {
  1941. .aead.base = {
  1942. .base = {
  1943. .cra_name = "authenc(hmac(sha384),"
  1944. "ecb(cipher_null))",
  1945. .cra_driver_name = "authenc-hmac-sha384-"
  1946. "ecb-cipher_null-caam",
  1947. .cra_blocksize = NULL_BLOCK_SIZE,
  1948. },
  1949. .setkey = aead_setkey,
  1950. .setauthsize = aead_setauthsize,
  1951. .encrypt = aead_encrypt,
  1952. .decrypt = aead_decrypt,
  1953. .ivsize = NULL_IV_SIZE,
  1954. .maxauthsize = SHA384_DIGEST_SIZE,
  1955. },
  1956. .aead.op = {
  1957. .do_one_request = aead_do_one_req,
  1958. },
  1959. .caam = {
  1960. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  1961. OP_ALG_AAI_HMAC_PRECOMP,
  1962. },
  1963. },
  1964. {
  1965. .aead.base = {
  1966. .base = {
  1967. .cra_name = "authenc(hmac(sha512),"
  1968. "ecb(cipher_null))",
  1969. .cra_driver_name = "authenc-hmac-sha512-"
  1970. "ecb-cipher_null-caam",
  1971. .cra_blocksize = NULL_BLOCK_SIZE,
  1972. },
  1973. .setkey = aead_setkey,
  1974. .setauthsize = aead_setauthsize,
  1975. .encrypt = aead_encrypt,
  1976. .decrypt = aead_decrypt,
  1977. .ivsize = NULL_IV_SIZE,
  1978. .maxauthsize = SHA512_DIGEST_SIZE,
  1979. },
  1980. .aead.op = {
  1981. .do_one_request = aead_do_one_req,
  1982. },
  1983. .caam = {
  1984. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  1985. OP_ALG_AAI_HMAC_PRECOMP,
  1986. },
  1987. },
  1988. {
  1989. .aead.base = {
  1990. .base = {
  1991. .cra_name = "authenc(hmac(md5),cbc(aes))",
  1992. .cra_driver_name = "authenc-hmac-md5-"
  1993. "cbc-aes-caam",
  1994. .cra_blocksize = AES_BLOCK_SIZE,
  1995. },
  1996. .setkey = aead_setkey,
  1997. .setauthsize = aead_setauthsize,
  1998. .encrypt = aead_encrypt,
  1999. .decrypt = aead_decrypt,
  2000. .ivsize = AES_BLOCK_SIZE,
  2001. .maxauthsize = MD5_DIGEST_SIZE,
  2002. },
  2003. .aead.op = {
  2004. .do_one_request = aead_do_one_req,
  2005. },
  2006. .caam = {
  2007. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2008. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2009. OP_ALG_AAI_HMAC_PRECOMP,
  2010. },
  2011. },
  2012. {
  2013. .aead.base = {
  2014. .base = {
  2015. .cra_name = "echainiv(authenc(hmac(md5),"
  2016. "cbc(aes)))",
  2017. .cra_driver_name = "echainiv-authenc-hmac-md5-"
  2018. "cbc-aes-caam",
  2019. .cra_blocksize = AES_BLOCK_SIZE,
  2020. },
  2021. .setkey = aead_setkey,
  2022. .setauthsize = aead_setauthsize,
  2023. .encrypt = aead_encrypt,
  2024. .decrypt = aead_decrypt,
  2025. .ivsize = AES_BLOCK_SIZE,
  2026. .maxauthsize = MD5_DIGEST_SIZE,
  2027. },
  2028. .aead.op = {
  2029. .do_one_request = aead_do_one_req,
  2030. },
  2031. .caam = {
  2032. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2033. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2034. OP_ALG_AAI_HMAC_PRECOMP,
  2035. .geniv = true,
  2036. },
  2037. },
  2038. {
  2039. .aead.base = {
  2040. .base = {
  2041. .cra_name = "authenc(hmac(sha1),cbc(aes))",
  2042. .cra_driver_name = "authenc-hmac-sha1-"
  2043. "cbc-aes-caam",
  2044. .cra_blocksize = AES_BLOCK_SIZE,
  2045. },
  2046. .setkey = aead_setkey,
  2047. .setauthsize = aead_setauthsize,
  2048. .encrypt = aead_encrypt,
  2049. .decrypt = aead_decrypt,
  2050. .ivsize = AES_BLOCK_SIZE,
  2051. .maxauthsize = SHA1_DIGEST_SIZE,
  2052. },
  2053. .aead.op = {
  2054. .do_one_request = aead_do_one_req,
  2055. },
  2056. .caam = {
  2057. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2058. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  2059. OP_ALG_AAI_HMAC_PRECOMP,
  2060. },
  2061. },
  2062. {
  2063. .aead.base = {
  2064. .base = {
  2065. .cra_name = "echainiv(authenc(hmac(sha1),"
  2066. "cbc(aes)))",
  2067. .cra_driver_name = "echainiv-authenc-"
  2068. "hmac-sha1-cbc-aes-caam",
  2069. .cra_blocksize = AES_BLOCK_SIZE,
  2070. },
  2071. .setkey = aead_setkey,
  2072. .setauthsize = aead_setauthsize,
  2073. .encrypt = aead_encrypt,
  2074. .decrypt = aead_decrypt,
  2075. .ivsize = AES_BLOCK_SIZE,
  2076. .maxauthsize = SHA1_DIGEST_SIZE,
  2077. },
  2078. .aead.op = {
  2079. .do_one_request = aead_do_one_req,
  2080. },
  2081. .caam = {
  2082. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2083. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  2084. OP_ALG_AAI_HMAC_PRECOMP,
  2085. .geniv = true,
  2086. },
  2087. },
  2088. {
  2089. .aead.base = {
  2090. .base = {
  2091. .cra_name = "authenc(hmac(sha224),cbc(aes))",
  2092. .cra_driver_name = "authenc-hmac-sha224-"
  2093. "cbc-aes-caam",
  2094. .cra_blocksize = AES_BLOCK_SIZE,
  2095. },
  2096. .setkey = aead_setkey,
  2097. .setauthsize = aead_setauthsize,
  2098. .encrypt = aead_encrypt,
  2099. .decrypt = aead_decrypt,
  2100. .ivsize = AES_BLOCK_SIZE,
  2101. .maxauthsize = SHA224_DIGEST_SIZE,
  2102. },
  2103. .aead.op = {
  2104. .do_one_request = aead_do_one_req,
  2105. },
  2106. .caam = {
  2107. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2108. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  2109. OP_ALG_AAI_HMAC_PRECOMP,
  2110. },
  2111. },
  2112. {
  2113. .aead.base = {
  2114. .base = {
  2115. .cra_name = "echainiv(authenc(hmac(sha224),"
  2116. "cbc(aes)))",
  2117. .cra_driver_name = "echainiv-authenc-"
  2118. "hmac-sha224-cbc-aes-caam",
  2119. .cra_blocksize = AES_BLOCK_SIZE,
  2120. },
  2121. .setkey = aead_setkey,
  2122. .setauthsize = aead_setauthsize,
  2123. .encrypt = aead_encrypt,
  2124. .decrypt = aead_decrypt,
  2125. .ivsize = AES_BLOCK_SIZE,
  2126. .maxauthsize = SHA224_DIGEST_SIZE,
  2127. },
  2128. .aead.op = {
  2129. .do_one_request = aead_do_one_req,
  2130. },
  2131. .caam = {
  2132. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2133. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  2134. OP_ALG_AAI_HMAC_PRECOMP,
  2135. .geniv = true,
  2136. },
  2137. },
  2138. {
  2139. .aead.base = {
  2140. .base = {
  2141. .cra_name = "authenc(hmac(sha256),cbc(aes))",
  2142. .cra_driver_name = "authenc-hmac-sha256-"
  2143. "cbc-aes-caam",
  2144. .cra_blocksize = AES_BLOCK_SIZE,
  2145. },
  2146. .setkey = aead_setkey,
  2147. .setauthsize = aead_setauthsize,
  2148. .encrypt = aead_encrypt,
  2149. .decrypt = aead_decrypt,
  2150. .ivsize = AES_BLOCK_SIZE,
  2151. .maxauthsize = SHA256_DIGEST_SIZE,
  2152. },
  2153. .aead.op = {
  2154. .do_one_request = aead_do_one_req,
  2155. },
  2156. .caam = {
  2157. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2158. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  2159. OP_ALG_AAI_HMAC_PRECOMP,
  2160. },
  2161. },
  2162. {
  2163. .aead.base = {
  2164. .base = {
  2165. .cra_name = "echainiv(authenc(hmac(sha256),"
  2166. "cbc(aes)))",
  2167. .cra_driver_name = "echainiv-authenc-"
  2168. "hmac-sha256-cbc-aes-caam",
  2169. .cra_blocksize = AES_BLOCK_SIZE,
  2170. },
  2171. .setkey = aead_setkey,
  2172. .setauthsize = aead_setauthsize,
  2173. .encrypt = aead_encrypt,
  2174. .decrypt = aead_decrypt,
  2175. .ivsize = AES_BLOCK_SIZE,
  2176. .maxauthsize = SHA256_DIGEST_SIZE,
  2177. },
  2178. .aead.op = {
  2179. .do_one_request = aead_do_one_req,
  2180. },
  2181. .caam = {
  2182. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2183. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  2184. OP_ALG_AAI_HMAC_PRECOMP,
  2185. .geniv = true,
  2186. },
  2187. },
  2188. {
  2189. .aead.base = {
  2190. .base = {
  2191. .cra_name = "authenc(hmac(sha384),cbc(aes))",
  2192. .cra_driver_name = "authenc-hmac-sha384-"
  2193. "cbc-aes-caam",
  2194. .cra_blocksize = AES_BLOCK_SIZE,
  2195. },
  2196. .setkey = aead_setkey,
  2197. .setauthsize = aead_setauthsize,
  2198. .encrypt = aead_encrypt,
  2199. .decrypt = aead_decrypt,
  2200. .ivsize = AES_BLOCK_SIZE,
  2201. .maxauthsize = SHA384_DIGEST_SIZE,
  2202. },
  2203. .aead.op = {
  2204. .do_one_request = aead_do_one_req,
  2205. },
  2206. .caam = {
  2207. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2208. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  2209. OP_ALG_AAI_HMAC_PRECOMP,
  2210. },
  2211. },
  2212. {
  2213. .aead.base = {
  2214. .base = {
  2215. .cra_name = "echainiv(authenc(hmac(sha384),"
  2216. "cbc(aes)))",
  2217. .cra_driver_name = "echainiv-authenc-"
  2218. "hmac-sha384-cbc-aes-caam",
  2219. .cra_blocksize = AES_BLOCK_SIZE,
  2220. },
  2221. .setkey = aead_setkey,
  2222. .setauthsize = aead_setauthsize,
  2223. .encrypt = aead_encrypt,
  2224. .decrypt = aead_decrypt,
  2225. .ivsize = AES_BLOCK_SIZE,
  2226. .maxauthsize = SHA384_DIGEST_SIZE,
  2227. },
  2228. .aead.op = {
  2229. .do_one_request = aead_do_one_req,
  2230. },
  2231. .caam = {
  2232. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2233. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  2234. OP_ALG_AAI_HMAC_PRECOMP,
  2235. .geniv = true,
  2236. },
  2237. },
  2238. {
  2239. .aead.base = {
  2240. .base = {
  2241. .cra_name = "authenc(hmac(sha512),cbc(aes))",
  2242. .cra_driver_name = "authenc-hmac-sha512-"
  2243. "cbc-aes-caam",
  2244. .cra_blocksize = AES_BLOCK_SIZE,
  2245. },
  2246. .setkey = aead_setkey,
  2247. .setauthsize = aead_setauthsize,
  2248. .encrypt = aead_encrypt,
  2249. .decrypt = aead_decrypt,
  2250. .ivsize = AES_BLOCK_SIZE,
  2251. .maxauthsize = SHA512_DIGEST_SIZE,
  2252. },
  2253. .aead.op = {
  2254. .do_one_request = aead_do_one_req,
  2255. },
  2256. .caam = {
  2257. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2258. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  2259. OP_ALG_AAI_HMAC_PRECOMP,
  2260. },
  2261. },
  2262. {
  2263. .aead.base = {
  2264. .base = {
  2265. .cra_name = "echainiv(authenc(hmac(sha512),"
  2266. "cbc(aes)))",
  2267. .cra_driver_name = "echainiv-authenc-"
  2268. "hmac-sha512-cbc-aes-caam",
  2269. .cra_blocksize = AES_BLOCK_SIZE,
  2270. },
  2271. .setkey = aead_setkey,
  2272. .setauthsize = aead_setauthsize,
  2273. .encrypt = aead_encrypt,
  2274. .decrypt = aead_decrypt,
  2275. .ivsize = AES_BLOCK_SIZE,
  2276. .maxauthsize = SHA512_DIGEST_SIZE,
  2277. },
  2278. .aead.op = {
  2279. .do_one_request = aead_do_one_req,
  2280. },
  2281. .caam = {
  2282. .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
  2283. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  2284. OP_ALG_AAI_HMAC_PRECOMP,
  2285. .geniv = true,
  2286. },
  2287. },
  2288. {
  2289. .aead.base = {
  2290. .base = {
  2291. .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
  2292. .cra_driver_name = "authenc-hmac-md5-"
  2293. "cbc-des3_ede-caam",
  2294. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2295. },
  2296. .setkey = des3_aead_setkey,
  2297. .setauthsize = aead_setauthsize,
  2298. .encrypt = aead_encrypt,
  2299. .decrypt = aead_decrypt,
  2300. .ivsize = DES3_EDE_BLOCK_SIZE,
  2301. .maxauthsize = MD5_DIGEST_SIZE,
  2302. },
  2303. .aead.op = {
  2304. .do_one_request = aead_do_one_req,
  2305. },
  2306. .caam = {
  2307. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2308. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2309. OP_ALG_AAI_HMAC_PRECOMP,
  2310. }
  2311. },
  2312. {
  2313. .aead.base = {
  2314. .base = {
  2315. .cra_name = "echainiv(authenc(hmac(md5),"
  2316. "cbc(des3_ede)))",
  2317. .cra_driver_name = "echainiv-authenc-hmac-md5-"
  2318. "cbc-des3_ede-caam",
  2319. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2320. },
  2321. .setkey = des3_aead_setkey,
  2322. .setauthsize = aead_setauthsize,
  2323. .encrypt = aead_encrypt,
  2324. .decrypt = aead_decrypt,
  2325. .ivsize = DES3_EDE_BLOCK_SIZE,
  2326. .maxauthsize = MD5_DIGEST_SIZE,
  2327. },
  2328. .aead.op = {
  2329. .do_one_request = aead_do_one_req,
  2330. },
  2331. .caam = {
  2332. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2333. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2334. OP_ALG_AAI_HMAC_PRECOMP,
  2335. .geniv = true,
  2336. }
  2337. },
  2338. {
  2339. .aead.base = {
  2340. .base = {
  2341. .cra_name = "authenc(hmac(sha1),"
  2342. "cbc(des3_ede))",
  2343. .cra_driver_name = "authenc-hmac-sha1-"
  2344. "cbc-des3_ede-caam",
  2345. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2346. },
  2347. .setkey = des3_aead_setkey,
  2348. .setauthsize = aead_setauthsize,
  2349. .encrypt = aead_encrypt,
  2350. .decrypt = aead_decrypt,
  2351. .ivsize = DES3_EDE_BLOCK_SIZE,
  2352. .maxauthsize = SHA1_DIGEST_SIZE,
  2353. },
  2354. .aead.op = {
  2355. .do_one_request = aead_do_one_req,
  2356. },
  2357. .caam = {
  2358. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2359. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  2360. OP_ALG_AAI_HMAC_PRECOMP,
  2361. },
  2362. },
  2363. {
  2364. .aead.base = {
  2365. .base = {
  2366. .cra_name = "echainiv(authenc(hmac(sha1),"
  2367. "cbc(des3_ede)))",
  2368. .cra_driver_name = "echainiv-authenc-"
  2369. "hmac-sha1-"
  2370. "cbc-des3_ede-caam",
  2371. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2372. },
  2373. .setkey = des3_aead_setkey,
  2374. .setauthsize = aead_setauthsize,
  2375. .encrypt = aead_encrypt,
  2376. .decrypt = aead_decrypt,
  2377. .ivsize = DES3_EDE_BLOCK_SIZE,
  2378. .maxauthsize = SHA1_DIGEST_SIZE,
  2379. },
  2380. .aead.op = {
  2381. .do_one_request = aead_do_one_req,
  2382. },
  2383. .caam = {
  2384. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2385. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  2386. OP_ALG_AAI_HMAC_PRECOMP,
  2387. .geniv = true,
  2388. },
  2389. },
  2390. {
  2391. .aead.base = {
  2392. .base = {
  2393. .cra_name = "authenc(hmac(sha224),"
  2394. "cbc(des3_ede))",
  2395. .cra_driver_name = "authenc-hmac-sha224-"
  2396. "cbc-des3_ede-caam",
  2397. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2398. },
  2399. .setkey = des3_aead_setkey,
  2400. .setauthsize = aead_setauthsize,
  2401. .encrypt = aead_encrypt,
  2402. .decrypt = aead_decrypt,
  2403. .ivsize = DES3_EDE_BLOCK_SIZE,
  2404. .maxauthsize = SHA224_DIGEST_SIZE,
  2405. },
  2406. .aead.op = {
  2407. .do_one_request = aead_do_one_req,
  2408. },
  2409. .caam = {
  2410. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2411. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  2412. OP_ALG_AAI_HMAC_PRECOMP,
  2413. },
  2414. },
  2415. {
  2416. .aead.base = {
  2417. .base = {
  2418. .cra_name = "echainiv(authenc(hmac(sha224),"
  2419. "cbc(des3_ede)))",
  2420. .cra_driver_name = "echainiv-authenc-"
  2421. "hmac-sha224-"
  2422. "cbc-des3_ede-caam",
  2423. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2424. },
  2425. .setkey = des3_aead_setkey,
  2426. .setauthsize = aead_setauthsize,
  2427. .encrypt = aead_encrypt,
  2428. .decrypt = aead_decrypt,
  2429. .ivsize = DES3_EDE_BLOCK_SIZE,
  2430. .maxauthsize = SHA224_DIGEST_SIZE,
  2431. },
  2432. .aead.op = {
  2433. .do_one_request = aead_do_one_req,
  2434. },
  2435. .caam = {
  2436. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2437. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  2438. OP_ALG_AAI_HMAC_PRECOMP,
  2439. .geniv = true,
  2440. },
  2441. },
  2442. {
  2443. .aead.base = {
  2444. .base = {
  2445. .cra_name = "authenc(hmac(sha256),"
  2446. "cbc(des3_ede))",
  2447. .cra_driver_name = "authenc-hmac-sha256-"
  2448. "cbc-des3_ede-caam",
  2449. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2450. },
  2451. .setkey = des3_aead_setkey,
  2452. .setauthsize = aead_setauthsize,
  2453. .encrypt = aead_encrypt,
  2454. .decrypt = aead_decrypt,
  2455. .ivsize = DES3_EDE_BLOCK_SIZE,
  2456. .maxauthsize = SHA256_DIGEST_SIZE,
  2457. },
  2458. .aead.op = {
  2459. .do_one_request = aead_do_one_req,
  2460. },
  2461. .caam = {
  2462. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2463. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  2464. OP_ALG_AAI_HMAC_PRECOMP,
  2465. },
  2466. },
  2467. {
  2468. .aead.base = {
  2469. .base = {
  2470. .cra_name = "echainiv(authenc(hmac(sha256),"
  2471. "cbc(des3_ede)))",
  2472. .cra_driver_name = "echainiv-authenc-"
  2473. "hmac-sha256-"
  2474. "cbc-des3_ede-caam",
  2475. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2476. },
  2477. .setkey = des3_aead_setkey,
  2478. .setauthsize = aead_setauthsize,
  2479. .encrypt = aead_encrypt,
  2480. .decrypt = aead_decrypt,
  2481. .ivsize = DES3_EDE_BLOCK_SIZE,
  2482. .maxauthsize = SHA256_DIGEST_SIZE,
  2483. },
  2484. .aead.op = {
  2485. .do_one_request = aead_do_one_req,
  2486. },
  2487. .caam = {
  2488. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2489. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  2490. OP_ALG_AAI_HMAC_PRECOMP,
  2491. .geniv = true,
  2492. },
  2493. },
  2494. {
  2495. .aead.base = {
  2496. .base = {
  2497. .cra_name = "authenc(hmac(sha384),"
  2498. "cbc(des3_ede))",
  2499. .cra_driver_name = "authenc-hmac-sha384-"
  2500. "cbc-des3_ede-caam",
  2501. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2502. },
  2503. .setkey = des3_aead_setkey,
  2504. .setauthsize = aead_setauthsize,
  2505. .encrypt = aead_encrypt,
  2506. .decrypt = aead_decrypt,
  2507. .ivsize = DES3_EDE_BLOCK_SIZE,
  2508. .maxauthsize = SHA384_DIGEST_SIZE,
  2509. },
  2510. .aead.op = {
  2511. .do_one_request = aead_do_one_req,
  2512. },
  2513. .caam = {
  2514. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2515. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  2516. OP_ALG_AAI_HMAC_PRECOMP,
  2517. },
  2518. },
  2519. {
  2520. .aead.base = {
  2521. .base = {
  2522. .cra_name = "echainiv(authenc(hmac(sha384),"
  2523. "cbc(des3_ede)))",
  2524. .cra_driver_name = "echainiv-authenc-"
  2525. "hmac-sha384-"
  2526. "cbc-des3_ede-caam",
  2527. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2528. },
  2529. .setkey = des3_aead_setkey,
  2530. .setauthsize = aead_setauthsize,
  2531. .encrypt = aead_encrypt,
  2532. .decrypt = aead_decrypt,
  2533. .ivsize = DES3_EDE_BLOCK_SIZE,
  2534. .maxauthsize = SHA384_DIGEST_SIZE,
  2535. },
  2536. .aead.op = {
  2537. .do_one_request = aead_do_one_req,
  2538. },
  2539. .caam = {
  2540. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2541. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  2542. OP_ALG_AAI_HMAC_PRECOMP,
  2543. .geniv = true,
  2544. },
  2545. },
  2546. {
  2547. .aead.base = {
  2548. .base = {
  2549. .cra_name = "authenc(hmac(sha512),"
  2550. "cbc(des3_ede))",
  2551. .cra_driver_name = "authenc-hmac-sha512-"
  2552. "cbc-des3_ede-caam",
  2553. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2554. },
  2555. .setkey = des3_aead_setkey,
  2556. .setauthsize = aead_setauthsize,
  2557. .encrypt = aead_encrypt,
  2558. .decrypt = aead_decrypt,
  2559. .ivsize = DES3_EDE_BLOCK_SIZE,
  2560. .maxauthsize = SHA512_DIGEST_SIZE,
  2561. },
  2562. .aead.op = {
  2563. .do_one_request = aead_do_one_req,
  2564. },
  2565. .caam = {
  2566. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2567. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  2568. OP_ALG_AAI_HMAC_PRECOMP,
  2569. },
  2570. },
  2571. {
  2572. .aead.base = {
  2573. .base = {
  2574. .cra_name = "echainiv(authenc(hmac(sha512),"
  2575. "cbc(des3_ede)))",
  2576. .cra_driver_name = "echainiv-authenc-"
  2577. "hmac-sha512-"
  2578. "cbc-des3_ede-caam",
  2579. .cra_blocksize = DES3_EDE_BLOCK_SIZE,
  2580. },
  2581. .setkey = des3_aead_setkey,
  2582. .setauthsize = aead_setauthsize,
  2583. .encrypt = aead_encrypt,
  2584. .decrypt = aead_decrypt,
  2585. .ivsize = DES3_EDE_BLOCK_SIZE,
  2586. .maxauthsize = SHA512_DIGEST_SIZE,
  2587. },
  2588. .aead.op = {
  2589. .do_one_request = aead_do_one_req,
  2590. },
  2591. .caam = {
  2592. .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
  2593. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  2594. OP_ALG_AAI_HMAC_PRECOMP,
  2595. .geniv = true,
  2596. },
  2597. },
  2598. {
  2599. .aead.base = {
  2600. .base = {
  2601. .cra_name = "authenc(hmac(md5),cbc(des))",
  2602. .cra_driver_name = "authenc-hmac-md5-"
  2603. "cbc-des-caam",
  2604. .cra_blocksize = DES_BLOCK_SIZE,
  2605. },
  2606. .setkey = aead_setkey,
  2607. .setauthsize = aead_setauthsize,
  2608. .encrypt = aead_encrypt,
  2609. .decrypt = aead_decrypt,
  2610. .ivsize = DES_BLOCK_SIZE,
  2611. .maxauthsize = MD5_DIGEST_SIZE,
  2612. },
  2613. .aead.op = {
  2614. .do_one_request = aead_do_one_req,
  2615. },
  2616. .caam = {
  2617. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2618. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2619. OP_ALG_AAI_HMAC_PRECOMP,
  2620. },
  2621. },
  2622. {
  2623. .aead.base = {
  2624. .base = {
  2625. .cra_name = "echainiv(authenc(hmac(md5),"
  2626. "cbc(des)))",
  2627. .cra_driver_name = "echainiv-authenc-hmac-md5-"
  2628. "cbc-des-caam",
  2629. .cra_blocksize = DES_BLOCK_SIZE,
  2630. },
  2631. .setkey = aead_setkey,
  2632. .setauthsize = aead_setauthsize,
  2633. .encrypt = aead_encrypt,
  2634. .decrypt = aead_decrypt,
  2635. .ivsize = DES_BLOCK_SIZE,
  2636. .maxauthsize = MD5_DIGEST_SIZE,
  2637. },
  2638. .aead.op = {
  2639. .do_one_request = aead_do_one_req,
  2640. },
  2641. .caam = {
  2642. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2643. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2644. OP_ALG_AAI_HMAC_PRECOMP,
  2645. .geniv = true,
  2646. },
  2647. },
  2648. {
  2649. .aead.base = {
  2650. .base = {
  2651. .cra_name = "authenc(hmac(sha1),cbc(des))",
  2652. .cra_driver_name = "authenc-hmac-sha1-"
  2653. "cbc-des-caam",
  2654. .cra_blocksize = DES_BLOCK_SIZE,
  2655. },
  2656. .setkey = aead_setkey,
  2657. .setauthsize = aead_setauthsize,
  2658. .encrypt = aead_encrypt,
  2659. .decrypt = aead_decrypt,
  2660. .ivsize = DES_BLOCK_SIZE,
  2661. .maxauthsize = SHA1_DIGEST_SIZE,
  2662. },
  2663. .aead.op = {
  2664. .do_one_request = aead_do_one_req,
  2665. },
  2666. .caam = {
  2667. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2668. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  2669. OP_ALG_AAI_HMAC_PRECOMP,
  2670. },
  2671. },
  2672. {
  2673. .aead.base = {
  2674. .base = {
  2675. .cra_name = "echainiv(authenc(hmac(sha1),"
  2676. "cbc(des)))",
  2677. .cra_driver_name = "echainiv-authenc-"
  2678. "hmac-sha1-cbc-des-caam",
  2679. .cra_blocksize = DES_BLOCK_SIZE,
  2680. },
  2681. .setkey = aead_setkey,
  2682. .setauthsize = aead_setauthsize,
  2683. .encrypt = aead_encrypt,
  2684. .decrypt = aead_decrypt,
  2685. .ivsize = DES_BLOCK_SIZE,
  2686. .maxauthsize = SHA1_DIGEST_SIZE,
  2687. },
  2688. .aead.op = {
  2689. .do_one_request = aead_do_one_req,
  2690. },
  2691. .caam = {
  2692. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2693. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  2694. OP_ALG_AAI_HMAC_PRECOMP,
  2695. .geniv = true,
  2696. },
  2697. },
  2698. {
  2699. .aead.base = {
  2700. .base = {
  2701. .cra_name = "authenc(hmac(sha224),cbc(des))",
  2702. .cra_driver_name = "authenc-hmac-sha224-"
  2703. "cbc-des-caam",
  2704. .cra_blocksize = DES_BLOCK_SIZE,
  2705. },
  2706. .setkey = aead_setkey,
  2707. .setauthsize = aead_setauthsize,
  2708. .encrypt = aead_encrypt,
  2709. .decrypt = aead_decrypt,
  2710. .ivsize = DES_BLOCK_SIZE,
  2711. .maxauthsize = SHA224_DIGEST_SIZE,
  2712. },
  2713. .aead.op = {
  2714. .do_one_request = aead_do_one_req,
  2715. },
  2716. .caam = {
  2717. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2718. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  2719. OP_ALG_AAI_HMAC_PRECOMP,
  2720. },
  2721. },
  2722. {
  2723. .aead.base = {
  2724. .base = {
  2725. .cra_name = "echainiv(authenc(hmac(sha224),"
  2726. "cbc(des)))",
  2727. .cra_driver_name = "echainiv-authenc-"
  2728. "hmac-sha224-cbc-des-caam",
  2729. .cra_blocksize = DES_BLOCK_SIZE,
  2730. },
  2731. .setkey = aead_setkey,
  2732. .setauthsize = aead_setauthsize,
  2733. .encrypt = aead_encrypt,
  2734. .decrypt = aead_decrypt,
  2735. .ivsize = DES_BLOCK_SIZE,
  2736. .maxauthsize = SHA224_DIGEST_SIZE,
  2737. },
  2738. .aead.op = {
  2739. .do_one_request = aead_do_one_req,
  2740. },
  2741. .caam = {
  2742. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2743. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  2744. OP_ALG_AAI_HMAC_PRECOMP,
  2745. .geniv = true,
  2746. },
  2747. },
  2748. {
  2749. .aead.base = {
  2750. .base = {
  2751. .cra_name = "authenc(hmac(sha256),cbc(des))",
  2752. .cra_driver_name = "authenc-hmac-sha256-"
  2753. "cbc-des-caam",
  2754. .cra_blocksize = DES_BLOCK_SIZE,
  2755. },
  2756. .setkey = aead_setkey,
  2757. .setauthsize = aead_setauthsize,
  2758. .encrypt = aead_encrypt,
  2759. .decrypt = aead_decrypt,
  2760. .ivsize = DES_BLOCK_SIZE,
  2761. .maxauthsize = SHA256_DIGEST_SIZE,
  2762. },
  2763. .aead.op = {
  2764. .do_one_request = aead_do_one_req,
  2765. },
  2766. .caam = {
  2767. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2768. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  2769. OP_ALG_AAI_HMAC_PRECOMP,
  2770. },
  2771. },
  2772. {
  2773. .aead.base = {
  2774. .base = {
  2775. .cra_name = "echainiv(authenc(hmac(sha256),"
  2776. "cbc(des)))",
  2777. .cra_driver_name = "echainiv-authenc-"
  2778. "hmac-sha256-cbc-des-caam",
  2779. .cra_blocksize = DES_BLOCK_SIZE,
  2780. },
  2781. .setkey = aead_setkey,
  2782. .setauthsize = aead_setauthsize,
  2783. .encrypt = aead_encrypt,
  2784. .decrypt = aead_decrypt,
  2785. .ivsize = DES_BLOCK_SIZE,
  2786. .maxauthsize = SHA256_DIGEST_SIZE,
  2787. },
  2788. .aead.op = {
  2789. .do_one_request = aead_do_one_req,
  2790. },
  2791. .caam = {
  2792. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2793. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  2794. OP_ALG_AAI_HMAC_PRECOMP,
  2795. .geniv = true,
  2796. },
  2797. },
  2798. {
  2799. .aead.base = {
  2800. .base = {
  2801. .cra_name = "authenc(hmac(sha384),cbc(des))",
  2802. .cra_driver_name = "authenc-hmac-sha384-"
  2803. "cbc-des-caam",
  2804. .cra_blocksize = DES_BLOCK_SIZE,
  2805. },
  2806. .setkey = aead_setkey,
  2807. .setauthsize = aead_setauthsize,
  2808. .encrypt = aead_encrypt,
  2809. .decrypt = aead_decrypt,
  2810. .ivsize = DES_BLOCK_SIZE,
  2811. .maxauthsize = SHA384_DIGEST_SIZE,
  2812. },
  2813. .aead.op = {
  2814. .do_one_request = aead_do_one_req,
  2815. },
  2816. .caam = {
  2817. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2818. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  2819. OP_ALG_AAI_HMAC_PRECOMP,
  2820. },
  2821. },
  2822. {
  2823. .aead.base = {
  2824. .base = {
  2825. .cra_name = "echainiv(authenc(hmac(sha384),"
  2826. "cbc(des)))",
  2827. .cra_driver_name = "echainiv-authenc-"
  2828. "hmac-sha384-cbc-des-caam",
  2829. .cra_blocksize = DES_BLOCK_SIZE,
  2830. },
  2831. .setkey = aead_setkey,
  2832. .setauthsize = aead_setauthsize,
  2833. .encrypt = aead_encrypt,
  2834. .decrypt = aead_decrypt,
  2835. .ivsize = DES_BLOCK_SIZE,
  2836. .maxauthsize = SHA384_DIGEST_SIZE,
  2837. },
  2838. .aead.op = {
  2839. .do_one_request = aead_do_one_req,
  2840. },
  2841. .caam = {
  2842. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2843. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  2844. OP_ALG_AAI_HMAC_PRECOMP,
  2845. .geniv = true,
  2846. },
  2847. },
  2848. {
  2849. .aead.base = {
  2850. .base = {
  2851. .cra_name = "authenc(hmac(sha512),cbc(des))",
  2852. .cra_driver_name = "authenc-hmac-sha512-"
  2853. "cbc-des-caam",
  2854. .cra_blocksize = DES_BLOCK_SIZE,
  2855. },
  2856. .setkey = aead_setkey,
  2857. .setauthsize = aead_setauthsize,
  2858. .encrypt = aead_encrypt,
  2859. .decrypt = aead_decrypt,
  2860. .ivsize = DES_BLOCK_SIZE,
  2861. .maxauthsize = SHA512_DIGEST_SIZE,
  2862. },
  2863. .aead.op = {
  2864. .do_one_request = aead_do_one_req,
  2865. },
  2866. .caam = {
  2867. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2868. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  2869. OP_ALG_AAI_HMAC_PRECOMP,
  2870. },
  2871. },
  2872. {
  2873. .aead.base = {
  2874. .base = {
  2875. .cra_name = "echainiv(authenc(hmac(sha512),"
  2876. "cbc(des)))",
  2877. .cra_driver_name = "echainiv-authenc-"
  2878. "hmac-sha512-cbc-des-caam",
  2879. .cra_blocksize = DES_BLOCK_SIZE,
  2880. },
  2881. .setkey = aead_setkey,
  2882. .setauthsize = aead_setauthsize,
  2883. .encrypt = aead_encrypt,
  2884. .decrypt = aead_decrypt,
  2885. .ivsize = DES_BLOCK_SIZE,
  2886. .maxauthsize = SHA512_DIGEST_SIZE,
  2887. },
  2888. .aead.op = {
  2889. .do_one_request = aead_do_one_req,
  2890. },
  2891. .caam = {
  2892. .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
  2893. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  2894. OP_ALG_AAI_HMAC_PRECOMP,
  2895. .geniv = true,
  2896. },
  2897. },
  2898. {
  2899. .aead.base = {
  2900. .base = {
  2901. .cra_name = "authenc(hmac(md5),"
  2902. "rfc3686(ctr(aes)))",
  2903. .cra_driver_name = "authenc-hmac-md5-"
  2904. "rfc3686-ctr-aes-caam",
  2905. .cra_blocksize = 1,
  2906. },
  2907. .setkey = aead_setkey,
  2908. .setauthsize = aead_setauthsize,
  2909. .encrypt = aead_encrypt,
  2910. .decrypt = aead_decrypt,
  2911. .ivsize = CTR_RFC3686_IV_SIZE,
  2912. .maxauthsize = MD5_DIGEST_SIZE,
  2913. },
  2914. .aead.op = {
  2915. .do_one_request = aead_do_one_req,
  2916. },
  2917. .caam = {
  2918. .class1_alg_type = OP_ALG_ALGSEL_AES |
  2919. OP_ALG_AAI_CTR_MOD128,
  2920. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2921. OP_ALG_AAI_HMAC_PRECOMP,
  2922. .rfc3686 = true,
  2923. },
  2924. },
  2925. {
  2926. .aead.base = {
  2927. .base = {
  2928. .cra_name = "seqiv(authenc("
  2929. "hmac(md5),rfc3686(ctr(aes))))",
  2930. .cra_driver_name = "seqiv-authenc-hmac-md5-"
  2931. "rfc3686-ctr-aes-caam",
  2932. .cra_blocksize = 1,
  2933. },
  2934. .setkey = aead_setkey,
  2935. .setauthsize = aead_setauthsize,
  2936. .encrypt = aead_encrypt,
  2937. .decrypt = aead_decrypt,
  2938. .ivsize = CTR_RFC3686_IV_SIZE,
  2939. .maxauthsize = MD5_DIGEST_SIZE,
  2940. },
  2941. .aead.op = {
  2942. .do_one_request = aead_do_one_req,
  2943. },
  2944. .caam = {
  2945. .class1_alg_type = OP_ALG_ALGSEL_AES |
  2946. OP_ALG_AAI_CTR_MOD128,
  2947. .class2_alg_type = OP_ALG_ALGSEL_MD5 |
  2948. OP_ALG_AAI_HMAC_PRECOMP,
  2949. .rfc3686 = true,
  2950. .geniv = true,
  2951. },
  2952. },
  2953. {
  2954. .aead.base = {
  2955. .base = {
  2956. .cra_name = "authenc(hmac(sha1),"
  2957. "rfc3686(ctr(aes)))",
  2958. .cra_driver_name = "authenc-hmac-sha1-"
  2959. "rfc3686-ctr-aes-caam",
  2960. .cra_blocksize = 1,
  2961. },
  2962. .setkey = aead_setkey,
  2963. .setauthsize = aead_setauthsize,
  2964. .encrypt = aead_encrypt,
  2965. .decrypt = aead_decrypt,
  2966. .ivsize = CTR_RFC3686_IV_SIZE,
  2967. .maxauthsize = SHA1_DIGEST_SIZE,
  2968. },
  2969. .aead.op = {
  2970. .do_one_request = aead_do_one_req,
  2971. },
  2972. .caam = {
  2973. .class1_alg_type = OP_ALG_ALGSEL_AES |
  2974. OP_ALG_AAI_CTR_MOD128,
  2975. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  2976. OP_ALG_AAI_HMAC_PRECOMP,
  2977. .rfc3686 = true,
  2978. },
  2979. },
  2980. {
  2981. .aead.base = {
  2982. .base = {
  2983. .cra_name = "seqiv(authenc("
  2984. "hmac(sha1),rfc3686(ctr(aes))))",
  2985. .cra_driver_name = "seqiv-authenc-hmac-sha1-"
  2986. "rfc3686-ctr-aes-caam",
  2987. .cra_blocksize = 1,
  2988. },
  2989. .setkey = aead_setkey,
  2990. .setauthsize = aead_setauthsize,
  2991. .encrypt = aead_encrypt,
  2992. .decrypt = aead_decrypt,
  2993. .ivsize = CTR_RFC3686_IV_SIZE,
  2994. .maxauthsize = SHA1_DIGEST_SIZE,
  2995. },
  2996. .aead.op = {
  2997. .do_one_request = aead_do_one_req,
  2998. },
  2999. .caam = {
  3000. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3001. OP_ALG_AAI_CTR_MOD128,
  3002. .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
  3003. OP_ALG_AAI_HMAC_PRECOMP,
  3004. .rfc3686 = true,
  3005. .geniv = true,
  3006. },
  3007. },
  3008. {
  3009. .aead.base = {
  3010. .base = {
  3011. .cra_name = "authenc(hmac(sha224),"
  3012. "rfc3686(ctr(aes)))",
  3013. .cra_driver_name = "authenc-hmac-sha224-"
  3014. "rfc3686-ctr-aes-caam",
  3015. .cra_blocksize = 1,
  3016. },
  3017. .setkey = aead_setkey,
  3018. .setauthsize = aead_setauthsize,
  3019. .encrypt = aead_encrypt,
  3020. .decrypt = aead_decrypt,
  3021. .ivsize = CTR_RFC3686_IV_SIZE,
  3022. .maxauthsize = SHA224_DIGEST_SIZE,
  3023. },
  3024. .aead.op = {
  3025. .do_one_request = aead_do_one_req,
  3026. },
  3027. .caam = {
  3028. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3029. OP_ALG_AAI_CTR_MOD128,
  3030. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  3031. OP_ALG_AAI_HMAC_PRECOMP,
  3032. .rfc3686 = true,
  3033. },
  3034. },
  3035. {
  3036. .aead.base = {
  3037. .base = {
  3038. .cra_name = "seqiv(authenc("
  3039. "hmac(sha224),rfc3686(ctr(aes))))",
  3040. .cra_driver_name = "seqiv-authenc-hmac-sha224-"
  3041. "rfc3686-ctr-aes-caam",
  3042. .cra_blocksize = 1,
  3043. },
  3044. .setkey = aead_setkey,
  3045. .setauthsize = aead_setauthsize,
  3046. .encrypt = aead_encrypt,
  3047. .decrypt = aead_decrypt,
  3048. .ivsize = CTR_RFC3686_IV_SIZE,
  3049. .maxauthsize = SHA224_DIGEST_SIZE,
  3050. },
  3051. .aead.op = {
  3052. .do_one_request = aead_do_one_req,
  3053. },
  3054. .caam = {
  3055. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3056. OP_ALG_AAI_CTR_MOD128,
  3057. .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
  3058. OP_ALG_AAI_HMAC_PRECOMP,
  3059. .rfc3686 = true,
  3060. .geniv = true,
  3061. },
  3062. },
  3063. {
  3064. .aead.base = {
  3065. .base = {
  3066. .cra_name = "authenc(hmac(sha256),"
  3067. "rfc3686(ctr(aes)))",
  3068. .cra_driver_name = "authenc-hmac-sha256-"
  3069. "rfc3686-ctr-aes-caam",
  3070. .cra_blocksize = 1,
  3071. },
  3072. .setkey = aead_setkey,
  3073. .setauthsize = aead_setauthsize,
  3074. .encrypt = aead_encrypt,
  3075. .decrypt = aead_decrypt,
  3076. .ivsize = CTR_RFC3686_IV_SIZE,
  3077. .maxauthsize = SHA256_DIGEST_SIZE,
  3078. },
  3079. .aead.op = {
  3080. .do_one_request = aead_do_one_req,
  3081. },
  3082. .caam = {
  3083. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3084. OP_ALG_AAI_CTR_MOD128,
  3085. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  3086. OP_ALG_AAI_HMAC_PRECOMP,
  3087. .rfc3686 = true,
  3088. },
  3089. },
  3090. {
  3091. .aead.base = {
  3092. .base = {
  3093. .cra_name = "seqiv(authenc(hmac(sha256),"
  3094. "rfc3686(ctr(aes))))",
  3095. .cra_driver_name = "seqiv-authenc-hmac-sha256-"
  3096. "rfc3686-ctr-aes-caam",
  3097. .cra_blocksize = 1,
  3098. },
  3099. .setkey = aead_setkey,
  3100. .setauthsize = aead_setauthsize,
  3101. .encrypt = aead_encrypt,
  3102. .decrypt = aead_decrypt,
  3103. .ivsize = CTR_RFC3686_IV_SIZE,
  3104. .maxauthsize = SHA256_DIGEST_SIZE,
  3105. },
  3106. .aead.op = {
  3107. .do_one_request = aead_do_one_req,
  3108. },
  3109. .caam = {
  3110. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3111. OP_ALG_AAI_CTR_MOD128,
  3112. .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
  3113. OP_ALG_AAI_HMAC_PRECOMP,
  3114. .rfc3686 = true,
  3115. .geniv = true,
  3116. },
  3117. },
  3118. {
  3119. .aead.base = {
  3120. .base = {
  3121. .cra_name = "authenc(hmac(sha384),"
  3122. "rfc3686(ctr(aes)))",
  3123. .cra_driver_name = "authenc-hmac-sha384-"
  3124. "rfc3686-ctr-aes-caam",
  3125. .cra_blocksize = 1,
  3126. },
  3127. .setkey = aead_setkey,
  3128. .setauthsize = aead_setauthsize,
  3129. .encrypt = aead_encrypt,
  3130. .decrypt = aead_decrypt,
  3131. .ivsize = CTR_RFC3686_IV_SIZE,
  3132. .maxauthsize = SHA384_DIGEST_SIZE,
  3133. },
  3134. .aead.op = {
  3135. .do_one_request = aead_do_one_req,
  3136. },
  3137. .caam = {
  3138. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3139. OP_ALG_AAI_CTR_MOD128,
  3140. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  3141. OP_ALG_AAI_HMAC_PRECOMP,
  3142. .rfc3686 = true,
  3143. },
  3144. },
  3145. {
  3146. .aead.base = {
  3147. .base = {
  3148. .cra_name = "seqiv(authenc(hmac(sha384),"
  3149. "rfc3686(ctr(aes))))",
  3150. .cra_driver_name = "seqiv-authenc-hmac-sha384-"
  3151. "rfc3686-ctr-aes-caam",
  3152. .cra_blocksize = 1,
  3153. },
  3154. .setkey = aead_setkey,
  3155. .setauthsize = aead_setauthsize,
  3156. .encrypt = aead_encrypt,
  3157. .decrypt = aead_decrypt,
  3158. .ivsize = CTR_RFC3686_IV_SIZE,
  3159. .maxauthsize = SHA384_DIGEST_SIZE,
  3160. },
  3161. .aead.op = {
  3162. .do_one_request = aead_do_one_req,
  3163. },
  3164. .caam = {
  3165. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3166. OP_ALG_AAI_CTR_MOD128,
  3167. .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
  3168. OP_ALG_AAI_HMAC_PRECOMP,
  3169. .rfc3686 = true,
  3170. .geniv = true,
  3171. },
  3172. },
  3173. {
  3174. .aead.base = {
  3175. .base = {
  3176. .cra_name = "authenc(hmac(sha512),"
  3177. "rfc3686(ctr(aes)))",
  3178. .cra_driver_name = "authenc-hmac-sha512-"
  3179. "rfc3686-ctr-aes-caam",
  3180. .cra_blocksize = 1,
  3181. },
  3182. .setkey = aead_setkey,
  3183. .setauthsize = aead_setauthsize,
  3184. .encrypt = aead_encrypt,
  3185. .decrypt = aead_decrypt,
  3186. .ivsize = CTR_RFC3686_IV_SIZE,
  3187. .maxauthsize = SHA512_DIGEST_SIZE,
  3188. },
  3189. .aead.op = {
  3190. .do_one_request = aead_do_one_req,
  3191. },
  3192. .caam = {
  3193. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3194. OP_ALG_AAI_CTR_MOD128,
  3195. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  3196. OP_ALG_AAI_HMAC_PRECOMP,
  3197. .rfc3686 = true,
  3198. },
  3199. },
  3200. {
  3201. .aead.base = {
  3202. .base = {
  3203. .cra_name = "seqiv(authenc(hmac(sha512),"
  3204. "rfc3686(ctr(aes))))",
  3205. .cra_driver_name = "seqiv-authenc-hmac-sha512-"
  3206. "rfc3686-ctr-aes-caam",
  3207. .cra_blocksize = 1,
  3208. },
  3209. .setkey = aead_setkey,
  3210. .setauthsize = aead_setauthsize,
  3211. .encrypt = aead_encrypt,
  3212. .decrypt = aead_decrypt,
  3213. .ivsize = CTR_RFC3686_IV_SIZE,
  3214. .maxauthsize = SHA512_DIGEST_SIZE,
  3215. },
  3216. .aead.op = {
  3217. .do_one_request = aead_do_one_req,
  3218. },
  3219. .caam = {
  3220. .class1_alg_type = OP_ALG_ALGSEL_AES |
  3221. OP_ALG_AAI_CTR_MOD128,
  3222. .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
  3223. OP_ALG_AAI_HMAC_PRECOMP,
  3224. .rfc3686 = true,
  3225. .geniv = true,
  3226. },
  3227. },
  3228. {
  3229. .aead.base = {
  3230. .base = {
  3231. .cra_name = "rfc7539(chacha20,poly1305)",
  3232. .cra_driver_name = "rfc7539-chacha20-poly1305-"
  3233. "caam",
  3234. .cra_blocksize = 1,
  3235. },
  3236. .setkey = chachapoly_setkey,
  3237. .setauthsize = chachapoly_setauthsize,
  3238. .encrypt = chachapoly_encrypt,
  3239. .decrypt = chachapoly_decrypt,
  3240. .ivsize = CHACHAPOLY_IV_SIZE,
  3241. .maxauthsize = POLY1305_DIGEST_SIZE,
  3242. },
  3243. .aead.op = {
  3244. .do_one_request = aead_do_one_req,
  3245. },
  3246. .caam = {
  3247. .class1_alg_type = OP_ALG_ALGSEL_CHACHA20 |
  3248. OP_ALG_AAI_AEAD,
  3249. .class2_alg_type = OP_ALG_ALGSEL_POLY1305 |
  3250. OP_ALG_AAI_AEAD,
  3251. .nodkp = true,
  3252. },
  3253. },
  3254. {
  3255. .aead.base = {
  3256. .base = {
  3257. .cra_name = "rfc7539esp(chacha20,poly1305)",
  3258. .cra_driver_name = "rfc7539esp-chacha20-"
  3259. "poly1305-caam",
  3260. .cra_blocksize = 1,
  3261. },
  3262. .setkey = chachapoly_setkey,
  3263. .setauthsize = chachapoly_setauthsize,
  3264. .encrypt = chachapoly_encrypt,
  3265. .decrypt = chachapoly_decrypt,
  3266. .ivsize = 8,
  3267. .maxauthsize = POLY1305_DIGEST_SIZE,
  3268. },
  3269. .aead.op = {
  3270. .do_one_request = aead_do_one_req,
  3271. },
  3272. .caam = {
  3273. .class1_alg_type = OP_ALG_ALGSEL_CHACHA20 |
  3274. OP_ALG_AAI_AEAD,
  3275. .class2_alg_type = OP_ALG_ALGSEL_POLY1305 |
  3276. OP_ALG_AAI_AEAD,
  3277. .nodkp = true,
  3278. },
  3279. },
  3280. };
  3281. static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
  3282. bool uses_dkp)
  3283. {
  3284. dma_addr_t dma_addr;
  3285. struct caam_drv_private *priv;
  3286. const size_t sh_desc_enc_offset = offsetof(struct caam_ctx,
  3287. sh_desc_enc);
  3288. ctx->jrdev = caam_jr_alloc();
  3289. if (IS_ERR(ctx->jrdev)) {
  3290. pr_err("Job Ring Device allocation for transform failed\n");
  3291. return PTR_ERR(ctx->jrdev);
  3292. }
  3293. priv = dev_get_drvdata(ctx->jrdev->parent);
  3294. if (priv->era >= 6 && uses_dkp)
  3295. ctx->dir = DMA_BIDIRECTIONAL;
  3296. else
  3297. ctx->dir = DMA_TO_DEVICE;
  3298. dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_enc,
  3299. offsetof(struct caam_ctx,
  3300. sh_desc_enc_dma) -
  3301. sh_desc_enc_offset,
  3302. ctx->dir, DMA_ATTR_SKIP_CPU_SYNC);
  3303. if (dma_mapping_error(ctx->jrdev, dma_addr)) {
  3304. dev_err(ctx->jrdev, "unable to map key, shared descriptors\n");
  3305. caam_jr_free(ctx->jrdev);
  3306. return -ENOMEM;
  3307. }
  3308. ctx->sh_desc_enc_dma = dma_addr;
  3309. ctx->sh_desc_dec_dma = dma_addr + offsetof(struct caam_ctx,
  3310. sh_desc_dec) -
  3311. sh_desc_enc_offset;
  3312. ctx->key_dma = dma_addr + offsetof(struct caam_ctx, key) -
  3313. sh_desc_enc_offset;
  3314. /* copy descriptor header template value */
  3315. ctx->cdata.algtype = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
  3316. ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
  3317. return 0;
  3318. }
  3319. static int caam_cra_init(struct crypto_skcipher *tfm)
  3320. {
  3321. struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
  3322. struct caam_skcipher_alg *caam_alg =
  3323. container_of(alg, typeof(*caam_alg), skcipher.base);
  3324. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
  3325. u32 alg_aai = caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
  3326. int ret = 0;
  3327. if (alg_aai == OP_ALG_AAI_XTS) {
  3328. const char *tfm_name = crypto_tfm_alg_name(&tfm->base);
  3329. struct crypto_skcipher *fallback;
  3330. fallback = crypto_alloc_skcipher(tfm_name, 0,
  3331. CRYPTO_ALG_NEED_FALLBACK);
  3332. if (IS_ERR(fallback)) {
  3333. pr_err("Failed to allocate %s fallback: %ld\n",
  3334. tfm_name, PTR_ERR(fallback));
  3335. return PTR_ERR(fallback);
  3336. }
  3337. ctx->fallback = fallback;
  3338. crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_skcipher_req_ctx) +
  3339. crypto_skcipher_reqsize(fallback));
  3340. } else {
  3341. crypto_skcipher_set_reqsize(tfm, sizeof(struct caam_skcipher_req_ctx));
  3342. }
  3343. ret = caam_init_common(ctx, &caam_alg->caam, false);
  3344. if (ret && ctx->fallback)
  3345. crypto_free_skcipher(ctx->fallback);
  3346. return ret;
  3347. }
  3348. static int caam_aead_init(struct crypto_aead *tfm)
  3349. {
  3350. struct aead_alg *alg = crypto_aead_alg(tfm);
  3351. struct caam_aead_alg *caam_alg =
  3352. container_of(alg, struct caam_aead_alg, aead.base);
  3353. struct caam_ctx *ctx = crypto_aead_ctx_dma(tfm);
  3354. crypto_aead_set_reqsize(tfm, sizeof(struct caam_aead_req_ctx));
  3355. return caam_init_common(ctx, &caam_alg->caam, !caam_alg->caam.nodkp);
  3356. }
  3357. static void caam_exit_common(struct caam_ctx *ctx)
  3358. {
  3359. dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_enc_dma,
  3360. offsetof(struct caam_ctx, sh_desc_enc_dma) -
  3361. offsetof(struct caam_ctx, sh_desc_enc),
  3362. ctx->dir, DMA_ATTR_SKIP_CPU_SYNC);
  3363. caam_jr_free(ctx->jrdev);
  3364. }
  3365. static void caam_cra_exit(struct crypto_skcipher *tfm)
  3366. {
  3367. struct caam_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
  3368. if (ctx->fallback)
  3369. crypto_free_skcipher(ctx->fallback);
  3370. caam_exit_common(ctx);
  3371. }
  3372. static void caam_aead_exit(struct crypto_aead *tfm)
  3373. {
  3374. caam_exit_common(crypto_aead_ctx_dma(tfm));
  3375. }
  3376. void caam_algapi_exit(void)
  3377. {
  3378. int i;
  3379. for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
  3380. struct caam_aead_alg *t_alg = driver_aeads + i;
  3381. if (t_alg->registered)
  3382. crypto_engine_unregister_aead(&t_alg->aead);
  3383. }
  3384. for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
  3385. struct caam_skcipher_alg *t_alg = driver_algs + i;
  3386. if (t_alg->registered)
  3387. crypto_engine_unregister_skcipher(&t_alg->skcipher);
  3388. }
  3389. }
  3390. static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg)
  3391. {
  3392. struct skcipher_alg *alg = &t_alg->skcipher.base;
  3393. alg->base.cra_module = THIS_MODULE;
  3394. alg->base.cra_priority = CAAM_CRA_PRIORITY;
  3395. alg->base.cra_ctxsize = sizeof(struct caam_ctx) + crypto_dma_padding();
  3396. alg->base.cra_flags |= (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY |
  3397. CRYPTO_ALG_KERN_DRIVER_ONLY);
  3398. alg->init = caam_cra_init;
  3399. alg->exit = caam_cra_exit;
  3400. }
  3401. static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
  3402. {
  3403. struct aead_alg *alg = &t_alg->aead.base;
  3404. alg->base.cra_module = THIS_MODULE;
  3405. alg->base.cra_priority = CAAM_CRA_PRIORITY;
  3406. alg->base.cra_ctxsize = sizeof(struct caam_ctx) + crypto_dma_padding();
  3407. alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY |
  3408. CRYPTO_ALG_KERN_DRIVER_ONLY;
  3409. alg->init = caam_aead_init;
  3410. alg->exit = caam_aead_exit;
  3411. }
  3412. int caam_algapi_init(struct device *ctrldev)
  3413. {
  3414. struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
  3415. int i = 0, err = 0;
  3416. u32 aes_vid, aes_inst, des_inst, md_vid, md_inst, ccha_inst, ptha_inst;
  3417. unsigned int md_limit = SHA512_DIGEST_SIZE;
  3418. bool registered = false, gcm_support;
  3419. /*
  3420. * Register crypto algorithms the device supports.
  3421. * First, detect presence and attributes of DES, AES, and MD blocks.
  3422. */
  3423. if (priv->era < 10) {
  3424. struct caam_perfmon __iomem *perfmon = &priv->jr[0]->perfmon;
  3425. u32 cha_vid, cha_inst, aes_rn;
  3426. cha_vid = rd_reg32(&perfmon->cha_id_ls);
  3427. aes_vid = cha_vid & CHA_ID_LS_AES_MASK;
  3428. md_vid = (cha_vid & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
  3429. cha_inst = rd_reg32(&perfmon->cha_num_ls);
  3430. des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >>
  3431. CHA_ID_LS_DES_SHIFT;
  3432. aes_inst = cha_inst & CHA_ID_LS_AES_MASK;
  3433. md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
  3434. ccha_inst = 0;
  3435. ptha_inst = 0;
  3436. aes_rn = rd_reg32(&perfmon->cha_rev_ls) & CHA_ID_LS_AES_MASK;
  3437. gcm_support = !(aes_vid == CHA_VER_VID_AES_LP && aes_rn < 8);
  3438. } else {
  3439. struct version_regs __iomem *vreg = &priv->jr[0]->vreg;
  3440. u32 aesa, mdha;
  3441. aesa = rd_reg32(&vreg->aesa);
  3442. mdha = rd_reg32(&vreg->mdha);
  3443. aes_vid = (aesa & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
  3444. md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
  3445. des_inst = rd_reg32(&vreg->desa) & CHA_VER_NUM_MASK;
  3446. aes_inst = aesa & CHA_VER_NUM_MASK;
  3447. md_inst = mdha & CHA_VER_NUM_MASK;
  3448. ccha_inst = rd_reg32(&vreg->ccha) & CHA_VER_NUM_MASK;
  3449. ptha_inst = rd_reg32(&vreg->ptha) & CHA_VER_NUM_MASK;
  3450. gcm_support = aesa & CHA_VER_MISC_AES_GCM;
  3451. }
  3452. /* If MD is present, limit digest size based on LP256 */
  3453. if (md_inst && md_vid == CHA_VER_VID_MD_LP256)
  3454. md_limit = SHA256_DIGEST_SIZE;
  3455. for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
  3456. struct caam_skcipher_alg *t_alg = driver_algs + i;
  3457. u32 alg_sel = t_alg->caam.class1_alg_type & OP_ALG_ALGSEL_MASK;
  3458. /* Skip DES algorithms if not supported by device */
  3459. if (!des_inst &&
  3460. ((alg_sel == OP_ALG_ALGSEL_3DES) ||
  3461. (alg_sel == OP_ALG_ALGSEL_DES)))
  3462. continue;
  3463. /* Skip AES algorithms if not supported by device */
  3464. if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
  3465. continue;
  3466. /*
  3467. * Check support for AES modes not available
  3468. * on LP devices.
  3469. */
  3470. if (aes_vid == CHA_VER_VID_AES_LP &&
  3471. (t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK) ==
  3472. OP_ALG_AAI_XTS)
  3473. continue;
  3474. caam_skcipher_alg_init(t_alg);
  3475. err = crypto_engine_register_skcipher(&t_alg->skcipher);
  3476. if (err) {
  3477. pr_warn("%s alg registration failed\n",
  3478. t_alg->skcipher.base.base.cra_driver_name);
  3479. continue;
  3480. }
  3481. t_alg->registered = true;
  3482. registered = true;
  3483. }
  3484. for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
  3485. struct caam_aead_alg *t_alg = driver_aeads + i;
  3486. u32 c1_alg_sel = t_alg->caam.class1_alg_type &
  3487. OP_ALG_ALGSEL_MASK;
  3488. u32 c2_alg_sel = t_alg->caam.class2_alg_type &
  3489. OP_ALG_ALGSEL_MASK;
  3490. u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
  3491. /* Skip DES algorithms if not supported by device */
  3492. if (!des_inst &&
  3493. ((c1_alg_sel == OP_ALG_ALGSEL_3DES) ||
  3494. (c1_alg_sel == OP_ALG_ALGSEL_DES)))
  3495. continue;
  3496. /* Skip AES algorithms if not supported by device */
  3497. if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES))
  3498. continue;
  3499. /* Skip CHACHA20 algorithms if not supported by device */
  3500. if (c1_alg_sel == OP_ALG_ALGSEL_CHACHA20 && !ccha_inst)
  3501. continue;
  3502. /* Skip POLY1305 algorithms if not supported by device */
  3503. if (c2_alg_sel == OP_ALG_ALGSEL_POLY1305 && !ptha_inst)
  3504. continue;
  3505. /* Skip GCM algorithms if not supported by device */
  3506. if (c1_alg_sel == OP_ALG_ALGSEL_AES &&
  3507. alg_aai == OP_ALG_AAI_GCM && !gcm_support)
  3508. continue;
  3509. /*
  3510. * Skip algorithms requiring message digests
  3511. * if MD or MD size is not supported by device.
  3512. */
  3513. if (is_mdha(c2_alg_sel) &&
  3514. (!md_inst || t_alg->aead.base.maxauthsize > md_limit))
  3515. continue;
  3516. caam_aead_alg_init(t_alg);
  3517. err = crypto_engine_register_aead(&t_alg->aead);
  3518. if (err) {
  3519. pr_warn("%s alg registration failed\n",
  3520. t_alg->aead.base.base.cra_driver_name);
  3521. continue;
  3522. }
  3523. t_alg->registered = true;
  3524. registered = true;
  3525. }
  3526. if (registered)
  3527. pr_info("caam algorithms registered in /proc/crypto\n");
  3528. return err;
  3529. }