caamalg.c 104 KB

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