12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515 |
- /*
- * caam - Freescale FSL CAAM support for crypto API
- *
- * Copyright 2008-2011 Freescale Semiconductor, Inc.
- * Copyright 2016 NXP
- *
- * Based on talitos crypto API driver.
- *
- * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008):
- *
- * --------------- ---------------
- * | JobDesc #1 |-------------------->| ShareDesc |
- * | *(packet 1) | | (PDB) |
- * --------------- |------------->| (hashKey) |
- * . | | (cipherKey) |
- * . | |-------->| (operation) |
- * --------------- | | ---------------
- * | JobDesc #2 |------| |
- * | *(packet 2) | |
- * --------------- |
- * . |
- * . |
- * --------------- |
- * | JobDesc #3 |------------
- * | *(packet 3) |
- * ---------------
- *
- * The SharedDesc never changes for a connection unless rekeyed, but
- * each packet will likely be in a different place. So all we need
- * to know to process the packet is where the input is, where the
- * output goes, and what context we want to process with. Context is
- * in the SharedDesc, packet references in the JobDesc.
- *
- * So, a job desc looks like:
- *
- * ---------------------
- * | Header |
- * | ShareDesc Pointer |
- * | SEQ_OUT_PTR |
- * | (output buffer) |
- * | (output length) |
- * | SEQ_IN_PTR |
- * | (input buffer) |
- * | (input length) |
- * ---------------------
- */
- #include "compat.h"
- #include "regs.h"
- #include "intern.h"
- #include "desc_constr.h"
- #include "jr.h"
- #include "error.h"
- #include "sg_sw_sec4.h"
- #include "key_gen.h"
- #include "caamalg_desc.h"
- /*
- * crypto alg
- */
- #define CAAM_CRA_PRIORITY 3000
- /* max key is sum of AES_MAX_KEY_SIZE, max split key size */
- #define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \
- CTR_RFC3686_NONCE_SIZE + \
- SHA512_DIGEST_SIZE * 2)
- #define AEAD_DESC_JOB_IO_LEN (DESC_JOB_IO_LEN + CAAM_CMD_SZ * 2)
- #define GCM_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
- CAAM_CMD_SZ * 4)
- #define AUTHENC_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
- CAAM_CMD_SZ * 5)
- #define DESC_MAX_USED_BYTES (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN)
- #define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
- #ifdef DEBUG
- /* for print_hex_dumps with line references */
- #define debug(format, arg...) printk(format, arg)
- #else
- #define debug(format, arg...)
- #endif
- static struct list_head alg_list;
- struct caam_alg_entry {
- int class1_alg_type;
- int class2_alg_type;
- bool rfc3686;
- bool geniv;
- };
- struct caam_aead_alg {
- struct aead_alg aead;
- struct caam_alg_entry caam;
- bool registered;
- };
- /*
- * per-session context
- */
- struct caam_ctx {
- u32 sh_desc_enc[DESC_MAX_USED_LEN];
- u32 sh_desc_dec[DESC_MAX_USED_LEN];
- u32 sh_desc_givenc[DESC_MAX_USED_LEN];
- u8 key[CAAM_MAX_KEY_SIZE];
- dma_addr_t sh_desc_enc_dma;
- dma_addr_t sh_desc_dec_dma;
- dma_addr_t sh_desc_givenc_dma;
- dma_addr_t key_dma;
- struct device *jrdev;
- struct alginfo adata;
- struct alginfo cdata;
- unsigned int authsize;
- };
- static int aead_null_set_sh_desc(struct crypto_aead *aead)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- int rem_bytes = CAAM_DESC_BYTES_MAX - AEAD_DESC_JOB_IO_LEN -
- ctx->adata.keylen_pad;
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_AEAD_NULL_ENC_LEN) {
- ctx->adata.key_inline = true;
- ctx->adata.key_virt = ctx->key;
- } else {
- ctx->adata.key_inline = false;
- ctx->adata.key_dma = ctx->key_dma;
- }
- /* aead_encrypt shared descriptor */
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_aead_null_encap(desc, &ctx->adata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_AEAD_NULL_DEC_LEN) {
- ctx->adata.key_inline = true;
- ctx->adata.key_virt = ctx->key;
- } else {
- ctx->adata.key_inline = false;
- ctx->adata.key_dma = ctx->key_dma;
- }
- /* aead_decrypt shared descriptor */
- desc = ctx->sh_desc_dec;
- cnstr_shdsc_aead_null_decap(desc, &ctx->adata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- return 0;
- }
- static int aead_set_sh_desc(struct crypto_aead *aead)
- {
- struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
- struct caam_aead_alg, aead);
- unsigned int ivsize = crypto_aead_ivsize(aead);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- u32 ctx1_iv_off = 0;
- u32 *desc, *nonce = NULL;
- u32 inl_mask;
- unsigned int data_len[2];
- const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
- OP_ALG_AAI_CTR_MOD128);
- const bool is_rfc3686 = alg->caam.rfc3686;
- if (!ctx->authsize)
- return 0;
- /* NULL encryption / decryption */
- if (!ctx->cdata.keylen)
- return aead_null_set_sh_desc(aead);
- /*
- * AES-CTR needs to load IV in CONTEXT1 reg
- * at an offset of 128bits (16bytes)
- * CONTEXT1[255:128] = IV
- */
- if (ctr_mode)
- ctx1_iv_off = 16;
- /*
- * RFC3686 specific:
- * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
- */
- if (is_rfc3686) {
- ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
- nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
- ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
- }
- data_len[0] = ctx->adata.keylen_pad;
- data_len[1] = ctx->cdata.keylen;
- if (alg->caam.geniv)
- goto skip_enc;
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (desc_inline_query(DESC_AEAD_ENC_LEN +
- (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
- AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
- ARRAY_SIZE(data_len)) < 0)
- return -EINVAL;
- if (inl_mask & 1)
- ctx->adata.key_virt = ctx->key;
- else
- ctx->adata.key_dma = ctx->key_dma;
- if (inl_mask & 2)
- ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
- else
- ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
- ctx->adata.key_inline = !!(inl_mask & 1);
- ctx->cdata.key_inline = !!(inl_mask & 2);
- /* aead_encrypt shared descriptor */
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_aead_encap(desc, &ctx->cdata, &ctx->adata, ivsize,
- ctx->authsize, is_rfc3686, nonce, ctx1_iv_off,
- false);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- skip_enc:
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (desc_inline_query(DESC_AEAD_DEC_LEN +
- (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
- AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
- ARRAY_SIZE(data_len)) < 0)
- return -EINVAL;
- if (inl_mask & 1)
- ctx->adata.key_virt = ctx->key;
- else
- ctx->adata.key_dma = ctx->key_dma;
- if (inl_mask & 2)
- ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
- else
- ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
- ctx->adata.key_inline = !!(inl_mask & 1);
- ctx->cdata.key_inline = !!(inl_mask & 2);
- /* aead_decrypt shared descriptor */
- desc = ctx->sh_desc_dec;
- cnstr_shdsc_aead_decap(desc, &ctx->cdata, &ctx->adata, ivsize,
- ctx->authsize, alg->caam.geniv, is_rfc3686,
- nonce, ctx1_iv_off, false);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- if (!alg->caam.geniv)
- goto skip_givenc;
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (desc_inline_query(DESC_AEAD_GIVENC_LEN +
- (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
- AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
- ARRAY_SIZE(data_len)) < 0)
- return -EINVAL;
- if (inl_mask & 1)
- ctx->adata.key_virt = ctx->key;
- else
- ctx->adata.key_dma = ctx->key_dma;
- if (inl_mask & 2)
- ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
- else
- ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
- ctx->adata.key_inline = !!(inl_mask & 1);
- ctx->cdata.key_inline = !!(inl_mask & 2);
- /* aead_givencrypt shared descriptor */
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_aead_givencap(desc, &ctx->cdata, &ctx->adata, ivsize,
- ctx->authsize, is_rfc3686, nonce,
- ctx1_iv_off, false);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- skip_givenc:
- return 0;
- }
- static int aead_setauthsize(struct crypto_aead *authenc,
- unsigned int authsize)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(authenc);
- ctx->authsize = authsize;
- aead_set_sh_desc(authenc);
- return 0;
- }
- static int gcm_set_sh_desc(struct crypto_aead *aead)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
- ctx->cdata.keylen;
- if (!ctx->cdata.keylen || !ctx->authsize)
- return 0;
- /*
- * AES GCM encrypt shared descriptor
- * Job Descriptor and Shared Descriptor
- * must fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_GCM_ENC_LEN) {
- ctx->cdata.key_inline = true;
- ctx->cdata.key_virt = ctx->key;
- } else {
- ctx->cdata.key_inline = false;
- ctx->cdata.key_dma = ctx->key_dma;
- }
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_GCM_DEC_LEN) {
- ctx->cdata.key_inline = true;
- ctx->cdata.key_virt = ctx->key;
- } else {
- ctx->cdata.key_inline = false;
- ctx->cdata.key_dma = ctx->key_dma;
- }
- desc = ctx->sh_desc_dec;
- cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- return 0;
- }
- static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(authenc);
- ctx->authsize = authsize;
- gcm_set_sh_desc(authenc);
- return 0;
- }
- static int rfc4106_set_sh_desc(struct crypto_aead *aead)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
- ctx->cdata.keylen;
- if (!ctx->cdata.keylen || !ctx->authsize)
- return 0;
- /*
- * RFC4106 encrypt shared descriptor
- * Job Descriptor and Shared Descriptor
- * must fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_RFC4106_ENC_LEN) {
- ctx->cdata.key_inline = true;
- ctx->cdata.key_virt = ctx->key;
- } else {
- ctx->cdata.key_inline = false;
- ctx->cdata.key_dma = ctx->key_dma;
- }
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_RFC4106_DEC_LEN) {
- ctx->cdata.key_inline = true;
- ctx->cdata.key_virt = ctx->key;
- } else {
- ctx->cdata.key_inline = false;
- ctx->cdata.key_dma = ctx->key_dma;
- }
- desc = ctx->sh_desc_dec;
- cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- return 0;
- }
- static int rfc4106_setauthsize(struct crypto_aead *authenc,
- unsigned int authsize)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(authenc);
- ctx->authsize = authsize;
- rfc4106_set_sh_desc(authenc);
- return 0;
- }
- static int rfc4543_set_sh_desc(struct crypto_aead *aead)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
- ctx->cdata.keylen;
- if (!ctx->cdata.keylen || !ctx->authsize)
- return 0;
- /*
- * RFC4543 encrypt shared descriptor
- * Job Descriptor and Shared Descriptor
- * must fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_RFC4543_ENC_LEN) {
- ctx->cdata.key_inline = true;
- ctx->cdata.key_virt = ctx->key;
- } else {
- ctx->cdata.key_inline = false;
- ctx->cdata.key_dma = ctx->key_dma;
- }
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- /*
- * Job Descriptor and Shared Descriptors
- * must all fit into the 64-word Descriptor h/w Buffer
- */
- if (rem_bytes >= DESC_RFC4543_DEC_LEN) {
- ctx->cdata.key_inline = true;
- ctx->cdata.key_virt = ctx->key;
- } else {
- ctx->cdata.key_inline = false;
- ctx->cdata.key_dma = ctx->key_dma;
- }
- desc = ctx->sh_desc_dec;
- cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ctx->authsize);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- return 0;
- }
- static int rfc4543_setauthsize(struct crypto_aead *authenc,
- unsigned int authsize)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(authenc);
- ctx->authsize = authsize;
- rfc4543_set_sh_desc(authenc);
- return 0;
- }
- static int aead_setkey(struct crypto_aead *aead,
- const u8 *key, unsigned int keylen)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- struct crypto_authenc_keys keys;
- int ret = 0;
- if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
- goto badkey;
- #ifdef DEBUG
- printk(KERN_ERR "keylen %d enckeylen %d authkeylen %d\n",
- keys.authkeylen + keys.enckeylen, keys.enckeylen,
- keys.authkeylen);
- print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
- #endif
- ret = gen_split_key(ctx->jrdev, ctx->key, &ctx->adata, keys.authkey,
- keys.authkeylen, CAAM_MAX_KEY_SIZE -
- keys.enckeylen);
- if (ret) {
- goto badkey;
- }
- /* postpend encryption key to auth split key */
- memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
- dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
- keys.enckeylen, DMA_TO_DEVICE);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
- ctx->adata.keylen_pad + keys.enckeylen, 1);
- #endif
- ctx->cdata.keylen = keys.enckeylen;
- return aead_set_sh_desc(aead);
- badkey:
- crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
- return -EINVAL;
- }
- static int gcm_setkey(struct crypto_aead *aead,
- const u8 *key, unsigned int keylen)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
- #endif
- memcpy(ctx->key, key, keylen);
- dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
- ctx->cdata.keylen = keylen;
- return gcm_set_sh_desc(aead);
- }
- static int rfc4106_setkey(struct crypto_aead *aead,
- const u8 *key, unsigned int keylen)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- if (keylen < 4)
- return -EINVAL;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
- #endif
- memcpy(ctx->key, key, keylen);
- /*
- * The last four bytes of the key material are used as the salt value
- * in the nonce. Update the AES key length.
- */
- ctx->cdata.keylen = keylen - 4;
- dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
- DMA_TO_DEVICE);
- return rfc4106_set_sh_desc(aead);
- }
- static int rfc4543_setkey(struct crypto_aead *aead,
- const u8 *key, unsigned int keylen)
- {
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- if (keylen < 4)
- return -EINVAL;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
- #endif
- memcpy(ctx->key, key, keylen);
- /*
- * The last four bytes of the key material are used as the salt value
- * in the nonce. Update the AES key length.
- */
- ctx->cdata.keylen = keylen - 4;
- dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
- DMA_TO_DEVICE);
- return rfc4543_set_sh_desc(aead);
- }
- static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
- const u8 *key, unsigned int keylen)
- {
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher);
- const char *alg_name = crypto_tfm_alg_name(tfm);
- struct device *jrdev = ctx->jrdev;
- unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- u32 *desc;
- u32 ctx1_iv_off = 0;
- const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
- OP_ALG_AAI_CTR_MOD128);
- const bool is_rfc3686 = (ctr_mode &&
- (strstr(alg_name, "rfc3686") != NULL));
- memcpy(ctx->key, key, keylen);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
- #endif
- /*
- * AES-CTR needs to load IV in CONTEXT1 reg
- * at an offset of 128bits (16bytes)
- * CONTEXT1[255:128] = IV
- */
- if (ctr_mode)
- ctx1_iv_off = 16;
- /*
- * RFC3686 specific:
- * | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
- * | *key = {KEY, NONCE}
- */
- if (is_rfc3686) {
- ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
- keylen -= CTR_RFC3686_NONCE_SIZE;
- }
- dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
- ctx->cdata.keylen = keylen;
- ctx->cdata.key_virt = ctx->key;
- ctx->cdata.key_inline = true;
- /* ablkcipher_encrypt shared descriptor */
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686,
- ctx1_iv_off);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- /* ablkcipher_decrypt shared descriptor */
- desc = ctx->sh_desc_dec;
- cnstr_shdsc_ablkcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686,
- ctx1_iv_off);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- /* ablkcipher_givencrypt shared descriptor */
- desc = ctx->sh_desc_givenc;
- cnstr_shdsc_ablkcipher_givencap(desc, &ctx->cdata, ivsize, is_rfc3686,
- ctx1_iv_off);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_givenc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- return 0;
- }
- static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
- const u8 *key, unsigned int keylen)
- {
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
- crypto_ablkcipher_set_flags(ablkcipher,
- CRYPTO_TFM_RES_BAD_KEY_LEN);
- dev_err(jrdev, "key size mismatch\n");
- return -EINVAL;
- }
- memcpy(ctx->key, key, keylen);
- dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
- ctx->cdata.keylen = keylen;
- ctx->cdata.key_virt = ctx->key;
- ctx->cdata.key_inline = true;
- /* xts_ablkcipher_encrypt shared descriptor */
- desc = ctx->sh_desc_enc;
- cnstr_shdsc_xts_ablkcipher_encap(desc, &ctx->cdata);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- /* xts_ablkcipher_decrypt shared descriptor */
- desc = ctx->sh_desc_dec;
- cnstr_shdsc_xts_ablkcipher_decap(desc, &ctx->cdata);
- dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
- desc_bytes(desc), DMA_TO_DEVICE);
- return 0;
- }
- /*
- * aead_edesc - s/w-extended aead descriptor
- * @src_nents: number of segments in input s/w scatterlist
- * @dst_nents: number of segments in output s/w scatterlist
- * @sec4_sg_bytes: length of dma mapped sec4_sg space
- * @sec4_sg_dma: bus physical mapped address of h/w link table
- * @sec4_sg: pointer to h/w link table
- * @hw_desc: the h/w job descriptor followed by any referenced link tables
- */
- struct aead_edesc {
- int src_nents;
- int dst_nents;
- int sec4_sg_bytes;
- dma_addr_t sec4_sg_dma;
- struct sec4_sg_entry *sec4_sg;
- u32 hw_desc[];
- };
- /*
- * ablkcipher_edesc - s/w-extended ablkcipher descriptor
- * @src_nents: number of segments in input s/w scatterlist
- * @dst_nents: number of segments in output s/w scatterlist
- * @iv_dma: dma address of iv for checking continuity and link table
- * @iv_dir: DMA mapping direction for IV
- * @sec4_sg_bytes: length of dma mapped sec4_sg space
- * @sec4_sg_dma: bus physical mapped address of h/w link table
- * @sec4_sg: pointer to h/w link table
- * @hw_desc: the h/w job descriptor followed by any referenced link tables
- * and IV
- */
- struct ablkcipher_edesc {
- int src_nents;
- int dst_nents;
- dma_addr_t iv_dma;
- enum dma_data_direction iv_dir;
- int sec4_sg_bytes;
- dma_addr_t sec4_sg_dma;
- struct sec4_sg_entry *sec4_sg;
- u32 hw_desc[0];
- };
- static void caam_unmap(struct device *dev, struct scatterlist *src,
- struct scatterlist *dst, int src_nents,
- int dst_nents,
- dma_addr_t iv_dma, int ivsize,
- enum dma_data_direction iv_dir, dma_addr_t sec4_sg_dma,
- int sec4_sg_bytes)
- {
- if (dst != src) {
- if (src_nents)
- dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
- dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
- } else {
- dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
- }
- if (iv_dma)
- dma_unmap_single(dev, iv_dma, ivsize, iv_dir);
- if (sec4_sg_bytes)
- dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes,
- DMA_TO_DEVICE);
- }
- static void aead_unmap(struct device *dev,
- struct aead_edesc *edesc,
- struct aead_request *req)
- {
- caam_unmap(dev, req->src, req->dst,
- edesc->src_nents, edesc->dst_nents, 0, 0, DMA_NONE,
- edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
- }
- static void ablkcipher_unmap(struct device *dev,
- struct ablkcipher_edesc *edesc,
- struct ablkcipher_request *req)
- {
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- caam_unmap(dev, req->src, req->dst,
- edesc->src_nents, edesc->dst_nents,
- edesc->iv_dma, ivsize, edesc->iv_dir,
- edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
- }
- static void aead_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
- void *context)
- {
- struct aead_request *req = context;
- struct aead_edesc *edesc;
- #ifdef DEBUG
- dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
- #endif
- edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
- if (err)
- caam_jr_strstatus(jrdev, err);
- aead_unmap(jrdev, edesc, req);
- kfree(edesc);
- aead_request_complete(req, err);
- }
- static void aead_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
- void *context)
- {
- struct aead_request *req = context;
- struct aead_edesc *edesc;
- #ifdef DEBUG
- dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
- #endif
- edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
- if (err)
- caam_jr_strstatus(jrdev, err);
- aead_unmap(jrdev, edesc, req);
- /*
- * verify hw auth check passed else return -EBADMSG
- */
- if ((err & JRSTA_CCBERR_ERRID_MASK) == JRSTA_CCBERR_ERRID_ICVCHK)
- err = -EBADMSG;
- kfree(edesc);
- aead_request_complete(req, err);
- }
- static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
- void *context)
- {
- struct ablkcipher_request *req = context;
- struct ablkcipher_edesc *edesc;
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- #ifdef DEBUG
- dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
- #endif
- edesc = container_of(desc, struct ablkcipher_edesc, hw_desc[0]);
- if (err)
- caam_jr_strstatus(jrdev, err);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->info,
- edesc->src_nents > 1 ? 100 : ivsize, 1);
- #endif
- caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
- edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
- ablkcipher_unmap(jrdev, edesc, req);
- /*
- * The crypto API expects us to set the IV (req->info) to the last
- * ciphertext block when running in CBC mode.
- */
- if ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC)
- scatterwalk_map_and_copy(req->info, req->dst, req->nbytes -
- ivsize, ivsize, 0);
- /* In case initial IV was generated, copy it in GIVCIPHER request */
- if (edesc->iv_dir == DMA_FROM_DEVICE) {
- u8 *iv;
- struct skcipher_givcrypt_request *greq;
- greq = container_of(req, struct skcipher_givcrypt_request,
- creq);
- iv = (u8 *)edesc->hw_desc + desc_bytes(edesc->hw_desc) +
- edesc->sec4_sg_bytes;
- memcpy(greq->giv, iv, ivsize);
- }
- kfree(edesc);
- ablkcipher_request_complete(req, err);
- }
- static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
- void *context)
- {
- struct ablkcipher_request *req = context;
- struct ablkcipher_edesc *edesc;
- #ifdef DEBUG
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
- #endif
- edesc = container_of(desc, struct ablkcipher_edesc, hw_desc[0]);
- if (err)
- caam_jr_strstatus(jrdev, err);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->info,
- ivsize, 1);
- #endif
- caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
- edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
- ablkcipher_unmap(jrdev, edesc, req);
- kfree(edesc);
- ablkcipher_request_complete(req, err);
- }
- /*
- * Fill in aead job descriptor
- */
- static void init_aead_job(struct aead_request *req,
- struct aead_edesc *edesc,
- bool all_contig, bool encrypt)
- {
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- int authsize = ctx->authsize;
- u32 *desc = edesc->hw_desc;
- u32 out_options, in_options;
- dma_addr_t dst_dma, src_dma;
- int len, sec4_sg_index = 0;
- dma_addr_t ptr;
- u32 *sh_desc;
- sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
- ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
- len = desc_len(sh_desc);
- init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
- if (all_contig) {
- src_dma = edesc->src_nents ? sg_dma_address(req->src) : 0;
- in_options = 0;
- } else {
- src_dma = edesc->sec4_sg_dma;
- sec4_sg_index += edesc->src_nents;
- in_options = LDST_SGF;
- }
- append_seq_in_ptr(desc, src_dma, req->assoclen + req->cryptlen,
- in_options);
- dst_dma = src_dma;
- out_options = in_options;
- if (unlikely(req->src != req->dst)) {
- if (edesc->dst_nents == 1) {
- dst_dma = sg_dma_address(req->dst);
- } else {
- dst_dma = edesc->sec4_sg_dma +
- sec4_sg_index *
- sizeof(struct sec4_sg_entry);
- out_options = LDST_SGF;
- }
- }
- if (encrypt)
- append_seq_out_ptr(desc, dst_dma,
- req->assoclen + req->cryptlen + authsize,
- out_options);
- else
- append_seq_out_ptr(desc, dst_dma,
- req->assoclen + req->cryptlen - authsize,
- out_options);
- /* REG3 = assoclen */
- append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
- }
- static void init_gcm_job(struct aead_request *req,
- struct aead_edesc *edesc,
- bool all_contig, bool encrypt)
- {
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- unsigned int ivsize = crypto_aead_ivsize(aead);
- u32 *desc = edesc->hw_desc;
- bool generic_gcm = (ivsize == 12);
- unsigned int last;
- init_aead_job(req, edesc, all_contig, encrypt);
- /* BUG This should not be specific to generic GCM. */
- last = 0;
- if (encrypt && generic_gcm && !(req->assoclen + req->cryptlen))
- last = FIFOLD_TYPE_LAST1;
- /* Read GCM IV */
- append_cmd(desc, CMD_FIFO_LOAD | FIFOLD_CLASS_CLASS1 | IMMEDIATE |
- FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | 12 | last);
- /* Append Salt */
- if (!generic_gcm)
- append_data(desc, ctx->key + ctx->cdata.keylen, 4);
- /* Append IV */
- append_data(desc, req->iv, ivsize);
- /* End of blank commands */
- }
- static void init_authenc_job(struct aead_request *req,
- struct aead_edesc *edesc,
- bool all_contig, bool encrypt)
- {
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
- struct caam_aead_alg, aead);
- unsigned int ivsize = crypto_aead_ivsize(aead);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
- OP_ALG_AAI_CTR_MOD128);
- const bool is_rfc3686 = alg->caam.rfc3686;
- u32 *desc = edesc->hw_desc;
- u32 ivoffset = 0;
- /*
- * AES-CTR needs to load IV in CONTEXT1 reg
- * at an offset of 128bits (16bytes)
- * CONTEXT1[255:128] = IV
- */
- if (ctr_mode)
- ivoffset = 16;
- /*
- * RFC3686 specific:
- * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
- */
- if (is_rfc3686)
- ivoffset = 16 + CTR_RFC3686_NONCE_SIZE;
- init_aead_job(req, edesc, all_contig, encrypt);
- if (ivsize && ((is_rfc3686 && encrypt) || !alg->caam.geniv))
- append_load_as_imm(desc, req->iv, ivsize,
- LDST_CLASS_1_CCB |
- LDST_SRCDST_BYTE_CONTEXT |
- (ivoffset << LDST_OFFSET_SHIFT));
- }
- /*
- * Fill in ablkcipher job descriptor
- */
- static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
- struct ablkcipher_edesc *edesc,
- struct ablkcipher_request *req)
- {
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- u32 *desc = edesc->hw_desc;
- u32 out_options = 0;
- dma_addr_t dst_dma;
- int len;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->info,
- ivsize, 1);
- pr_err("asked=%d, nbytes%d\n",
- (int)edesc->src_nents > 1 ? 100 : req->nbytes, req->nbytes);
- #endif
- caam_dump_sg(KERN_ERR, "src @" __stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->src,
- edesc->src_nents > 1 ? 100 : req->nbytes, 1);
- len = desc_len(sh_desc);
- init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
- append_seq_in_ptr(desc, edesc->sec4_sg_dma, req->nbytes + ivsize,
- LDST_SGF);
- if (likely(req->src == req->dst)) {
- dst_dma = edesc->sec4_sg_dma + sizeof(struct sec4_sg_entry);
- out_options = LDST_SGF;
- } else {
- if (edesc->dst_nents == 1) {
- dst_dma = sg_dma_address(req->dst);
- out_options = 0;
- } else {
- dst_dma = edesc->sec4_sg_dma + (edesc->src_nents + 1) *
- sizeof(struct sec4_sg_entry);
- out_options = LDST_SGF;
- }
- }
- append_seq_out_ptr(desc, dst_dma, req->nbytes, out_options);
- }
- /*
- * Fill in ablkcipher givencrypt job descriptor
- */
- static void init_ablkcipher_giv_job(u32 *sh_desc, dma_addr_t ptr,
- struct ablkcipher_edesc *edesc,
- struct ablkcipher_request *req)
- {
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- u32 *desc = edesc->hw_desc;
- u32 in_options;
- dma_addr_t dst_dma, src_dma;
- int len, sec4_sg_index = 0;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->info,
- ivsize, 1);
- #endif
- caam_dump_sg(KERN_ERR, "src @" __stringify(__LINE__) ": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->src,
- edesc->src_nents > 1 ? 100 : req->nbytes, 1);
- len = desc_len(sh_desc);
- init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
- if (edesc->src_nents == 1) {
- src_dma = sg_dma_address(req->src);
- in_options = 0;
- } else {
- src_dma = edesc->sec4_sg_dma;
- sec4_sg_index += edesc->src_nents;
- in_options = LDST_SGF;
- }
- append_seq_in_ptr(desc, src_dma, req->nbytes, in_options);
- dst_dma = edesc->sec4_sg_dma + sec4_sg_index *
- sizeof(struct sec4_sg_entry);
- append_seq_out_ptr(desc, dst_dma, req->nbytes + ivsize, LDST_SGF);
- }
- /*
- * allocate and map the aead extended descriptor
- */
- static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
- int desc_bytes, bool *all_contig_ptr,
- bool encrypt)
- {
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
- GFP_KERNEL : GFP_ATOMIC;
- int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
- struct aead_edesc *edesc;
- int sec4_sg_index, sec4_sg_len, sec4_sg_bytes;
- unsigned int authsize = ctx->authsize;
- if (unlikely(req->dst != req->src)) {
- src_nents = sg_nents_for_len(req->src, req->assoclen +
- req->cryptlen);
- if (unlikely(src_nents < 0)) {
- dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
- req->assoclen + req->cryptlen);
- return ERR_PTR(src_nents);
- }
- dst_nents = sg_nents_for_len(req->dst, req->assoclen +
- req->cryptlen +
- (encrypt ? authsize :
- (-authsize)));
- if (unlikely(dst_nents < 0)) {
- dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
- req->assoclen + req->cryptlen +
- (encrypt ? authsize : (-authsize)));
- return ERR_PTR(dst_nents);
- }
- } else {
- src_nents = sg_nents_for_len(req->src, req->assoclen +
- req->cryptlen +
- (encrypt ? authsize : 0));
- if (unlikely(src_nents < 0)) {
- dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
- req->assoclen + req->cryptlen +
- (encrypt ? authsize : 0));
- return ERR_PTR(src_nents);
- }
- }
- if (likely(req->src == req->dst)) {
- mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
- DMA_BIDIRECTIONAL);
- if (unlikely(!mapped_src_nents)) {
- dev_err(jrdev, "unable to map source\n");
- return ERR_PTR(-ENOMEM);
- }
- } else {
- /* Cover also the case of null (zero length) input data */
- if (src_nents) {
- mapped_src_nents = dma_map_sg(jrdev, req->src,
- src_nents, DMA_TO_DEVICE);
- if (unlikely(!mapped_src_nents)) {
- dev_err(jrdev, "unable to map source\n");
- return ERR_PTR(-ENOMEM);
- }
- } else {
- mapped_src_nents = 0;
- }
- mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
- DMA_FROM_DEVICE);
- if (unlikely(!mapped_dst_nents)) {
- dev_err(jrdev, "unable to map destination\n");
- dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
- return ERR_PTR(-ENOMEM);
- }
- }
- sec4_sg_len = mapped_src_nents > 1 ? mapped_src_nents : 0;
- sec4_sg_len += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
- sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
- /* allocate space for base edesc and hw desc commands, link tables */
- edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
- GFP_DMA | flags);
- if (!edesc) {
- caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
- 0, DMA_NONE, 0, 0);
- return ERR_PTR(-ENOMEM);
- }
- edesc->src_nents = src_nents;
- edesc->dst_nents = dst_nents;
- edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
- desc_bytes;
- *all_contig_ptr = !(mapped_src_nents > 1);
- sec4_sg_index = 0;
- if (mapped_src_nents > 1) {
- sg_to_sec4_sg_last(req->src, mapped_src_nents,
- edesc->sec4_sg + sec4_sg_index, 0);
- sec4_sg_index += mapped_src_nents;
- }
- if (mapped_dst_nents > 1) {
- sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
- edesc->sec4_sg + sec4_sg_index, 0);
- }
- if (!sec4_sg_bytes)
- return edesc;
- edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
- sec4_sg_bytes, DMA_TO_DEVICE);
- if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
- dev_err(jrdev, "unable to map S/G table\n");
- aead_unmap(jrdev, edesc, req);
- kfree(edesc);
- return ERR_PTR(-ENOMEM);
- }
- edesc->sec4_sg_bytes = sec4_sg_bytes;
- return edesc;
- }
- static int gcm_encrypt(struct aead_request *req)
- {
- struct aead_edesc *edesc;
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- bool all_contig;
- u32 *desc;
- int ret = 0;
- /* allocate extended descriptor */
- edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, true);
- if (IS_ERR(edesc))
- return PTR_ERR(edesc);
- /* Create and submit job descriptor */
- init_gcm_job(req, edesc, all_contig, true);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
- desc_bytes(edesc->hw_desc), 1);
- #endif
- desc = edesc->hw_desc;
- ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
- if (!ret) {
- ret = -EINPROGRESS;
- } else {
- aead_unmap(jrdev, edesc, req);
- kfree(edesc);
- }
- return ret;
- }
- static int ipsec_gcm_encrypt(struct aead_request *req)
- {
- if (req->assoclen < 8)
- return -EINVAL;
- return gcm_encrypt(req);
- }
- static int aead_encrypt(struct aead_request *req)
- {
- struct aead_edesc *edesc;
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- bool all_contig;
- u32 *desc;
- int ret = 0;
- /* allocate extended descriptor */
- edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
- &all_contig, true);
- if (IS_ERR(edesc))
- return PTR_ERR(edesc);
- /* Create and submit job descriptor */
- init_authenc_job(req, edesc, all_contig, true);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
- desc_bytes(edesc->hw_desc), 1);
- #endif
- desc = edesc->hw_desc;
- ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
- if (!ret) {
- ret = -EINPROGRESS;
- } else {
- aead_unmap(jrdev, edesc, req);
- kfree(edesc);
- }
- return ret;
- }
- static int gcm_decrypt(struct aead_request *req)
- {
- struct aead_edesc *edesc;
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- bool all_contig;
- u32 *desc;
- int ret = 0;
- /* allocate extended descriptor */
- edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, false);
- if (IS_ERR(edesc))
- return PTR_ERR(edesc);
- /* Create and submit job descriptor*/
- init_gcm_job(req, edesc, all_contig, false);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
- desc_bytes(edesc->hw_desc), 1);
- #endif
- desc = edesc->hw_desc;
- ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
- if (!ret) {
- ret = -EINPROGRESS;
- } else {
- aead_unmap(jrdev, edesc, req);
- kfree(edesc);
- }
- return ret;
- }
- static int ipsec_gcm_decrypt(struct aead_request *req)
- {
- if (req->assoclen < 8)
- return -EINVAL;
- return gcm_decrypt(req);
- }
- static int aead_decrypt(struct aead_request *req)
- {
- struct aead_edesc *edesc;
- struct crypto_aead *aead = crypto_aead_reqtfm(req);
- struct caam_ctx *ctx = crypto_aead_ctx(aead);
- struct device *jrdev = ctx->jrdev;
- bool all_contig;
- u32 *desc;
- int ret = 0;
- caam_dump_sg(KERN_ERR, "dec src@" __stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, req->src,
- req->assoclen + req->cryptlen, 1);
- /* allocate extended descriptor */
- edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
- &all_contig, false);
- if (IS_ERR(edesc))
- return PTR_ERR(edesc);
- /* Create and submit job descriptor*/
- init_authenc_job(req, edesc, all_contig, false);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
- desc_bytes(edesc->hw_desc), 1);
- #endif
- desc = edesc->hw_desc;
- ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
- if (!ret) {
- ret = -EINPROGRESS;
- } else {
- aead_unmap(jrdev, edesc, req);
- kfree(edesc);
- }
- return ret;
- }
- /*
- * allocate and map the ablkcipher extended descriptor for ablkcipher
- */
- static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
- *req, int desc_bytes)
- {
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- struct device *jrdev = ctx->jrdev;
- gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
- GFP_KERNEL : GFP_ATOMIC;
- int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
- struct ablkcipher_edesc *edesc;
- dma_addr_t iv_dma;
- u8 *iv;
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
- src_nents = sg_nents_for_len(req->src, req->nbytes);
- if (unlikely(src_nents < 0)) {
- dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
- req->nbytes);
- return ERR_PTR(src_nents);
- }
- if (req->dst != req->src) {
- dst_nents = sg_nents_for_len(req->dst, req->nbytes);
- if (unlikely(dst_nents < 0)) {
- dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
- req->nbytes);
- return ERR_PTR(dst_nents);
- }
- }
- if (likely(req->src == req->dst)) {
- mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
- DMA_BIDIRECTIONAL);
- if (unlikely(!mapped_src_nents)) {
- dev_err(jrdev, "unable to map source\n");
- return ERR_PTR(-ENOMEM);
- }
- } else {
- mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
- DMA_TO_DEVICE);
- if (unlikely(!mapped_src_nents)) {
- dev_err(jrdev, "unable to map source\n");
- return ERR_PTR(-ENOMEM);
- }
- mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
- DMA_FROM_DEVICE);
- if (unlikely(!mapped_dst_nents)) {
- dev_err(jrdev, "unable to map destination\n");
- dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
- return ERR_PTR(-ENOMEM);
- }
- }
- sec4_sg_ents = 1 + mapped_src_nents;
- dst_sg_idx = sec4_sg_ents;
- sec4_sg_ents += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
- sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
- /*
- * allocate space for base edesc and hw desc commands, link tables, IV
- */
- edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes + ivsize,
- GFP_DMA | flags);
- if (!edesc) {
- dev_err(jrdev, "could not allocate extended descriptor\n");
- caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
- 0, DMA_NONE, 0, 0);
- return ERR_PTR(-ENOMEM);
- }
- edesc->src_nents = src_nents;
- edesc->dst_nents = dst_nents;
- edesc->sec4_sg_bytes = sec4_sg_bytes;
- edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc +
- desc_bytes);
- edesc->iv_dir = DMA_TO_DEVICE;
- /* Make sure IV is located in a DMAable area */
- iv = (u8 *)edesc->hw_desc + desc_bytes + sec4_sg_bytes;
- memcpy(iv, req->info, ivsize);
- iv_dma = dma_map_single(jrdev, iv, ivsize, DMA_TO_DEVICE);
- if (dma_mapping_error(jrdev, iv_dma)) {
- dev_err(jrdev, "unable to map IV\n");
- caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
- 0, DMA_NONE, 0, 0);
- kfree(edesc);
- return ERR_PTR(-ENOMEM);
- }
- dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0);
- sg_to_sec4_sg_last(req->src, mapped_src_nents, edesc->sec4_sg + 1, 0);
- if (mapped_dst_nents > 1) {
- sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
- edesc->sec4_sg + dst_sg_idx, 0);
- }
- edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
- sec4_sg_bytes, DMA_TO_DEVICE);
- if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
- dev_err(jrdev, "unable to map S/G table\n");
- caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
- iv_dma, ivsize, DMA_TO_DEVICE, 0, 0);
- kfree(edesc);
- return ERR_PTR(-ENOMEM);
- }
- edesc->iv_dma = iv_dma;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "ablkcipher sec4_sg@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
- sec4_sg_bytes, 1);
- #endif
- return edesc;
- }
- static int ablkcipher_encrypt(struct ablkcipher_request *req)
- {
- struct ablkcipher_edesc *edesc;
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- int ret = 0;
- /* allocate extended descriptor */
- edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ);
- if (IS_ERR(edesc))
- return PTR_ERR(edesc);
- /* Create and submit job descriptor*/
- init_ablkcipher_job(ctx->sh_desc_enc, ctx->sh_desc_enc_dma, edesc, req);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
- desc_bytes(edesc->hw_desc), 1);
- #endif
- desc = edesc->hw_desc;
- ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
- if (!ret) {
- ret = -EINPROGRESS;
- } else {
- ablkcipher_unmap(jrdev, edesc, req);
- kfree(edesc);
- }
- return ret;
- }
- static int ablkcipher_decrypt(struct ablkcipher_request *req)
- {
- struct ablkcipher_edesc *edesc;
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- int ret = 0;
- /* allocate extended descriptor */
- edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ);
- if (IS_ERR(edesc))
- return PTR_ERR(edesc);
- /*
- * The crypto API expects us to set the IV (req->info) to the last
- * ciphertext block when running in CBC mode.
- */
- if ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC)
- scatterwalk_map_and_copy(req->info, req->src, req->nbytes -
- ivsize, ivsize, 0);
- /* Create and submit job descriptor*/
- init_ablkcipher_job(ctx->sh_desc_dec, ctx->sh_desc_dec_dma, edesc, req);
- desc = edesc->hw_desc;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
- desc_bytes(edesc->hw_desc), 1);
- #endif
- ret = caam_jr_enqueue(jrdev, desc, ablkcipher_decrypt_done, req);
- if (!ret) {
- ret = -EINPROGRESS;
- } else {
- ablkcipher_unmap(jrdev, edesc, req);
- kfree(edesc);
- }
- return ret;
- }
- /*
- * allocate and map the ablkcipher extended descriptor
- * for ablkcipher givencrypt
- */
- static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
- struct skcipher_givcrypt_request *greq,
- int desc_bytes)
- {
- struct ablkcipher_request *req = &greq->creq;
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- struct device *jrdev = ctx->jrdev;
- gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
- GFP_KERNEL : GFP_ATOMIC;
- int src_nents, mapped_src_nents, dst_nents, mapped_dst_nents;
- struct ablkcipher_edesc *edesc;
- dma_addr_t iv_dma;
- u8 *iv;
- int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
- int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
- src_nents = sg_nents_for_len(req->src, req->nbytes);
- if (unlikely(src_nents < 0)) {
- dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
- req->nbytes);
- return ERR_PTR(src_nents);
- }
- if (likely(req->src == req->dst)) {
- mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
- DMA_BIDIRECTIONAL);
- if (unlikely(!mapped_src_nents)) {
- dev_err(jrdev, "unable to map source\n");
- return ERR_PTR(-ENOMEM);
- }
- dst_nents = src_nents;
- mapped_dst_nents = src_nents;
- } else {
- mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
- DMA_TO_DEVICE);
- if (unlikely(!mapped_src_nents)) {
- dev_err(jrdev, "unable to map source\n");
- return ERR_PTR(-ENOMEM);
- }
- dst_nents = sg_nents_for_len(req->dst, req->nbytes);
- if (unlikely(dst_nents < 0)) {
- dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
- req->nbytes);
- return ERR_PTR(dst_nents);
- }
- mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
- DMA_FROM_DEVICE);
- if (unlikely(!mapped_dst_nents)) {
- dev_err(jrdev, "unable to map destination\n");
- dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
- return ERR_PTR(-ENOMEM);
- }
- }
- sec4_sg_ents = mapped_src_nents > 1 ? mapped_src_nents : 0;
- dst_sg_idx = sec4_sg_ents;
- sec4_sg_ents += 1 + mapped_dst_nents;
- /*
- * allocate space for base edesc and hw desc commands, link tables, IV
- */
- sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
- edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes + ivsize,
- GFP_DMA | flags);
- if (!edesc) {
- dev_err(jrdev, "could not allocate extended descriptor\n");
- caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
- 0, DMA_NONE, 0, 0);
- return ERR_PTR(-ENOMEM);
- }
- edesc->src_nents = src_nents;
- edesc->dst_nents = dst_nents;
- edesc->sec4_sg_bytes = sec4_sg_bytes;
- edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc +
- desc_bytes);
- edesc->iv_dir = DMA_FROM_DEVICE;
- /* Make sure IV is located in a DMAable area */
- iv = (u8 *)edesc->hw_desc + desc_bytes + sec4_sg_bytes;
- iv_dma = dma_map_single(jrdev, iv, ivsize, DMA_FROM_DEVICE);
- if (dma_mapping_error(jrdev, iv_dma)) {
- dev_err(jrdev, "unable to map IV\n");
- caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
- 0, DMA_NONE, 0, 0);
- kfree(edesc);
- return ERR_PTR(-ENOMEM);
- }
- if (mapped_src_nents > 1)
- sg_to_sec4_sg_last(req->src, mapped_src_nents, edesc->sec4_sg,
- 0);
- dma_to_sec4_sg_one(edesc->sec4_sg + dst_sg_idx, iv_dma, ivsize, 0);
- sg_to_sec4_sg_last(req->dst, mapped_dst_nents, edesc->sec4_sg +
- dst_sg_idx + 1, 0);
- edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
- sec4_sg_bytes, DMA_TO_DEVICE);
- if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
- dev_err(jrdev, "unable to map S/G table\n");
- caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
- iv_dma, ivsize, DMA_FROM_DEVICE, 0, 0);
- kfree(edesc);
- return ERR_PTR(-ENOMEM);
- }
- edesc->iv_dma = iv_dma;
- #ifdef DEBUG
- print_hex_dump(KERN_ERR,
- "ablkcipher sec4_sg@" __stringify(__LINE__) ": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
- sec4_sg_bytes, 1);
- #endif
- return edesc;
- }
- static int ablkcipher_givencrypt(struct skcipher_givcrypt_request *creq)
- {
- struct ablkcipher_request *req = &creq->creq;
- struct ablkcipher_edesc *edesc;
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
- struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
- struct device *jrdev = ctx->jrdev;
- u32 *desc;
- int ret = 0;
- /* allocate extended descriptor */
- edesc = ablkcipher_giv_edesc_alloc(creq, DESC_JOB_IO_LEN * CAAM_CMD_SZ);
- if (IS_ERR(edesc))
- return PTR_ERR(edesc);
- /* Create and submit job descriptor*/
- init_ablkcipher_giv_job(ctx->sh_desc_givenc, ctx->sh_desc_givenc_dma,
- edesc, req);
- #ifdef DEBUG
- print_hex_dump(KERN_ERR,
- "ablkcipher jobdesc@" __stringify(__LINE__) ": ",
- DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
- desc_bytes(edesc->hw_desc), 1);
- #endif
- desc = edesc->hw_desc;
- ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
- if (!ret) {
- ret = -EINPROGRESS;
- } else {
- ablkcipher_unmap(jrdev, edesc, req);
- kfree(edesc);
- }
- return ret;
- }
- #define template_aead template_u.aead
- #define template_ablkcipher template_u.ablkcipher
- struct caam_alg_template {
- char name[CRYPTO_MAX_ALG_NAME];
- char driver_name[CRYPTO_MAX_ALG_NAME];
- unsigned int blocksize;
- u32 type;
- union {
- struct ablkcipher_alg ablkcipher;
- } template_u;
- u32 class1_alg_type;
- u32 class2_alg_type;
- };
- static struct caam_alg_template driver_algs[] = {
- /* ablkcipher descriptor */
- {
- .name = "cbc(aes)",
- .driver_name = "cbc-aes-caam",
- .blocksize = AES_BLOCK_SIZE,
- .type = CRYPTO_ALG_TYPE_GIVCIPHER,
- .template_ablkcipher = {
- .setkey = ablkcipher_setkey,
- .encrypt = ablkcipher_encrypt,
- .decrypt = ablkcipher_decrypt,
- .givencrypt = ablkcipher_givencrypt,
- .geniv = "<built-in>",
- .min_keysize = AES_MIN_KEY_SIZE,
- .max_keysize = AES_MAX_KEY_SIZE,
- .ivsize = AES_BLOCK_SIZE,
- },
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- },
- {
- .name = "cbc(des3_ede)",
- .driver_name = "cbc-3des-caam",
- .blocksize = DES3_EDE_BLOCK_SIZE,
- .type = CRYPTO_ALG_TYPE_GIVCIPHER,
- .template_ablkcipher = {
- .setkey = ablkcipher_setkey,
- .encrypt = ablkcipher_encrypt,
- .decrypt = ablkcipher_decrypt,
- .givencrypt = ablkcipher_givencrypt,
- .geniv = "<built-in>",
- .min_keysize = DES3_EDE_KEY_SIZE,
- .max_keysize = DES3_EDE_KEY_SIZE,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- },
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- },
- {
- .name = "cbc(des)",
- .driver_name = "cbc-des-caam",
- .blocksize = DES_BLOCK_SIZE,
- .type = CRYPTO_ALG_TYPE_GIVCIPHER,
- .template_ablkcipher = {
- .setkey = ablkcipher_setkey,
- .encrypt = ablkcipher_encrypt,
- .decrypt = ablkcipher_decrypt,
- .givencrypt = ablkcipher_givencrypt,
- .geniv = "<built-in>",
- .min_keysize = DES_KEY_SIZE,
- .max_keysize = DES_KEY_SIZE,
- .ivsize = DES_BLOCK_SIZE,
- },
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- },
- {
- .name = "ctr(aes)",
- .driver_name = "ctr-aes-caam",
- .blocksize = 1,
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
- .template_ablkcipher = {
- .setkey = ablkcipher_setkey,
- .encrypt = ablkcipher_encrypt,
- .decrypt = ablkcipher_decrypt,
- .geniv = "chainiv",
- .min_keysize = AES_MIN_KEY_SIZE,
- .max_keysize = AES_MAX_KEY_SIZE,
- .ivsize = AES_BLOCK_SIZE,
- },
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
- },
- {
- .name = "rfc3686(ctr(aes))",
- .driver_name = "rfc3686-ctr-aes-caam",
- .blocksize = 1,
- .type = CRYPTO_ALG_TYPE_GIVCIPHER,
- .template_ablkcipher = {
- .setkey = ablkcipher_setkey,
- .encrypt = ablkcipher_encrypt,
- .decrypt = ablkcipher_decrypt,
- .givencrypt = ablkcipher_givencrypt,
- .geniv = "<built-in>",
- .min_keysize = AES_MIN_KEY_SIZE +
- CTR_RFC3686_NONCE_SIZE,
- .max_keysize = AES_MAX_KEY_SIZE +
- CTR_RFC3686_NONCE_SIZE,
- .ivsize = CTR_RFC3686_IV_SIZE,
- },
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
- },
- {
- .name = "xts(aes)",
- .driver_name = "xts-aes-caam",
- .blocksize = AES_BLOCK_SIZE,
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
- .template_ablkcipher = {
- .setkey = xts_ablkcipher_setkey,
- .encrypt = ablkcipher_encrypt,
- .decrypt = ablkcipher_decrypt,
- .geniv = "eseqiv",
- .min_keysize = 2 * AES_MIN_KEY_SIZE,
- .max_keysize = 2 * AES_MAX_KEY_SIZE,
- .ivsize = AES_BLOCK_SIZE,
- },
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
- },
- };
- static struct caam_aead_alg driver_aeads[] = {
- {
- .aead = {
- .base = {
- .cra_name = "rfc4106(gcm(aes))",
- .cra_driver_name = "rfc4106-gcm-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = rfc4106_setkey,
- .setauthsize = rfc4106_setauthsize,
- .encrypt = ipsec_gcm_encrypt,
- .decrypt = ipsec_gcm_decrypt,
- .ivsize = 8,
- .maxauthsize = AES_BLOCK_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "rfc4543(gcm(aes))",
- .cra_driver_name = "rfc4543-gcm-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = rfc4543_setkey,
- .setauthsize = rfc4543_setauthsize,
- .encrypt = ipsec_gcm_encrypt,
- .decrypt = ipsec_gcm_decrypt,
- .ivsize = 8,
- .maxauthsize = AES_BLOCK_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
- },
- },
- /* Galois Counter Mode */
- {
- .aead = {
- .base = {
- .cra_name = "gcm(aes)",
- .cra_driver_name = "gcm-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = gcm_setkey,
- .setauthsize = gcm_setauthsize,
- .encrypt = gcm_encrypt,
- .decrypt = gcm_decrypt,
- .ivsize = 12,
- .maxauthsize = AES_BLOCK_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
- },
- },
- /* single-pass ipsec_esp descriptor */
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(md5),"
- "ecb(cipher_null))",
- .cra_driver_name = "authenc-hmac-md5-"
- "ecb-cipher_null-caam",
- .cra_blocksize = NULL_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = NULL_IV_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha1),"
- "ecb(cipher_null))",
- .cra_driver_name = "authenc-hmac-sha1-"
- "ecb-cipher_null-caam",
- .cra_blocksize = NULL_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = NULL_IV_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha224),"
- "ecb(cipher_null))",
- .cra_driver_name = "authenc-hmac-sha224-"
- "ecb-cipher_null-caam",
- .cra_blocksize = NULL_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = NULL_IV_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha256),"
- "ecb(cipher_null))",
- .cra_driver_name = "authenc-hmac-sha256-"
- "ecb-cipher_null-caam",
- .cra_blocksize = NULL_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = NULL_IV_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha384),"
- "ecb(cipher_null))",
- .cra_driver_name = "authenc-hmac-sha384-"
- "ecb-cipher_null-caam",
- .cra_blocksize = NULL_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = NULL_IV_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha512),"
- "ecb(cipher_null))",
- .cra_driver_name = "authenc-hmac-sha512-"
- "ecb-cipher_null-caam",
- .cra_blocksize = NULL_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = NULL_IV_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(md5),cbc(aes))",
- .cra_driver_name = "authenc-hmac-md5-"
- "cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(md5),"
- "cbc(aes)))",
- .cra_driver_name = "echainiv-authenc-hmac-md5-"
- "cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha1),cbc(aes))",
- .cra_driver_name = "authenc-hmac-sha1-"
- "cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha1),"
- "cbc(aes)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha1-cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha224),cbc(aes))",
- .cra_driver_name = "authenc-hmac-sha224-"
- "cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha224),"
- "cbc(aes)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha224-cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha256),cbc(aes))",
- .cra_driver_name = "authenc-hmac-sha256-"
- "cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha256),"
- "cbc(aes)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha256-cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha384),cbc(aes))",
- .cra_driver_name = "authenc-hmac-sha384-"
- "cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha384),"
- "cbc(aes)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha384-cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha512),cbc(aes))",
- .cra_driver_name = "authenc-hmac-sha512-"
- "cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha512),"
- "cbc(aes)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha512-cbc-aes-caam",
- .cra_blocksize = AES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = AES_BLOCK_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
- .cra_driver_name = "authenc-hmac-md5-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- }
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(md5),"
- "cbc(des3_ede)))",
- .cra_driver_name = "echainiv-authenc-hmac-md5-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- }
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha1),"
- "cbc(des3_ede))",
- .cra_driver_name = "authenc-hmac-sha1-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha1),"
- "cbc(des3_ede)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha1-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha224),"
- "cbc(des3_ede))",
- .cra_driver_name = "authenc-hmac-sha224-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha224),"
- "cbc(des3_ede)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha224-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha256),"
- "cbc(des3_ede))",
- .cra_driver_name = "authenc-hmac-sha256-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha256),"
- "cbc(des3_ede)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha256-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha384),"
- "cbc(des3_ede))",
- .cra_driver_name = "authenc-hmac-sha384-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha384),"
- "cbc(des3_ede)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha384-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha512),"
- "cbc(des3_ede))",
- .cra_driver_name = "authenc-hmac-sha512-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha512),"
- "cbc(des3_ede)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha512-"
- "cbc-des3_ede-caam",
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(md5),cbc(des))",
- .cra_driver_name = "authenc-hmac-md5-"
- "cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(md5),"
- "cbc(des)))",
- .cra_driver_name = "echainiv-authenc-hmac-md5-"
- "cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha1),cbc(des))",
- .cra_driver_name = "authenc-hmac-sha1-"
- "cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha1),"
- "cbc(des)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha1-cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha224),cbc(des))",
- .cra_driver_name = "authenc-hmac-sha224-"
- "cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha224),"
- "cbc(des)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha224-cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha256),cbc(des))",
- .cra_driver_name = "authenc-hmac-sha256-"
- "cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha256),"
- "cbc(des)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha256-cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha384),cbc(des))",
- .cra_driver_name = "authenc-hmac-sha384-"
- "cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha384),"
- "cbc(des)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha384-cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha512),cbc(des))",
- .cra_driver_name = "authenc-hmac-sha512-"
- "cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "echainiv(authenc(hmac(sha512),"
- "cbc(des)))",
- .cra_driver_name = "echainiv-authenc-"
- "hmac-sha512-cbc-des-caam",
- .cra_blocksize = DES_BLOCK_SIZE,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = DES_BLOCK_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(md5),"
- "rfc3686(ctr(aes)))",
- .cra_driver_name = "authenc-hmac-md5-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "seqiv(authenc("
- "hmac(md5),rfc3686(ctr(aes))))",
- .cra_driver_name = "seqiv-authenc-hmac-md5-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = MD5_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_MD5 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha1),"
- "rfc3686(ctr(aes)))",
- .cra_driver_name = "authenc-hmac-sha1-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "seqiv(authenc("
- "hmac(sha1),rfc3686(ctr(aes))))",
- .cra_driver_name = "seqiv-authenc-hmac-sha1-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA1_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha224),"
- "rfc3686(ctr(aes)))",
- .cra_driver_name = "authenc-hmac-sha224-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "seqiv(authenc("
- "hmac(sha224),rfc3686(ctr(aes))))",
- .cra_driver_name = "seqiv-authenc-hmac-sha224-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA224_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha256),"
- "rfc3686(ctr(aes)))",
- .cra_driver_name = "authenc-hmac-sha256-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "seqiv(authenc(hmac(sha256),"
- "rfc3686(ctr(aes))))",
- .cra_driver_name = "seqiv-authenc-hmac-sha256-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA256_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha384),"
- "rfc3686(ctr(aes)))",
- .cra_driver_name = "authenc-hmac-sha384-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "seqiv(authenc(hmac(sha384),"
- "rfc3686(ctr(aes))))",
- .cra_driver_name = "seqiv-authenc-hmac-sha384-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA384_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- .geniv = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "authenc(hmac(sha512),"
- "rfc3686(ctr(aes)))",
- .cra_driver_name = "authenc-hmac-sha512-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- },
- },
- {
- .aead = {
- .base = {
- .cra_name = "seqiv(authenc(hmac(sha512),"
- "rfc3686(ctr(aes))))",
- .cra_driver_name = "seqiv-authenc-hmac-sha512-"
- "rfc3686-ctr-aes-caam",
- .cra_blocksize = 1,
- },
- .setkey = aead_setkey,
- .setauthsize = aead_setauthsize,
- .encrypt = aead_encrypt,
- .decrypt = aead_decrypt,
- .ivsize = CTR_RFC3686_IV_SIZE,
- .maxauthsize = SHA512_DIGEST_SIZE,
- },
- .caam = {
- .class1_alg_type = OP_ALG_ALGSEL_AES |
- OP_ALG_AAI_CTR_MOD128,
- .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
- OP_ALG_AAI_HMAC_PRECOMP,
- .rfc3686 = true,
- .geniv = true,
- },
- },
- };
- struct caam_crypto_alg {
- struct crypto_alg crypto_alg;
- struct list_head entry;
- struct caam_alg_entry caam;
- };
- static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam)
- {
- dma_addr_t dma_addr;
- ctx->jrdev = caam_jr_alloc();
- if (IS_ERR(ctx->jrdev)) {
- pr_err("Job Ring Device allocation for transform failed\n");
- return PTR_ERR(ctx->jrdev);
- }
- dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_enc,
- offsetof(struct caam_ctx,
- sh_desc_enc_dma),
- DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
- if (dma_mapping_error(ctx->jrdev, dma_addr)) {
- dev_err(ctx->jrdev, "unable to map key, shared descriptors\n");
- caam_jr_free(ctx->jrdev);
- return -ENOMEM;
- }
- ctx->sh_desc_enc_dma = dma_addr;
- ctx->sh_desc_dec_dma = dma_addr + offsetof(struct caam_ctx,
- sh_desc_dec);
- ctx->sh_desc_givenc_dma = dma_addr + offsetof(struct caam_ctx,
- sh_desc_givenc);
- ctx->key_dma = dma_addr + offsetof(struct caam_ctx, key);
- /* copy descriptor header template value */
- ctx->cdata.algtype = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
- ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
- return 0;
- }
- static int caam_cra_init(struct crypto_tfm *tfm)
- {
- struct crypto_alg *alg = tfm->__crt_alg;
- struct caam_crypto_alg *caam_alg =
- container_of(alg, struct caam_crypto_alg, crypto_alg);
- struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
- return caam_init_common(ctx, &caam_alg->caam);
- }
- static int caam_aead_init(struct crypto_aead *tfm)
- {
- struct aead_alg *alg = crypto_aead_alg(tfm);
- struct caam_aead_alg *caam_alg =
- container_of(alg, struct caam_aead_alg, aead);
- struct caam_ctx *ctx = crypto_aead_ctx(tfm);
- return caam_init_common(ctx, &caam_alg->caam);
- }
- static void caam_exit_common(struct caam_ctx *ctx)
- {
- dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_enc_dma,
- offsetof(struct caam_ctx, sh_desc_enc_dma),
- DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
- caam_jr_free(ctx->jrdev);
- }
- static void caam_cra_exit(struct crypto_tfm *tfm)
- {
- caam_exit_common(crypto_tfm_ctx(tfm));
- }
- static void caam_aead_exit(struct crypto_aead *tfm)
- {
- caam_exit_common(crypto_aead_ctx(tfm));
- }
- static void __exit caam_algapi_exit(void)
- {
- struct caam_crypto_alg *t_alg, *n;
- int i;
- for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
- struct caam_aead_alg *t_alg = driver_aeads + i;
- if (t_alg->registered)
- crypto_unregister_aead(&t_alg->aead);
- }
- if (!alg_list.next)
- return;
- list_for_each_entry_safe(t_alg, n, &alg_list, entry) {
- crypto_unregister_alg(&t_alg->crypto_alg);
- list_del(&t_alg->entry);
- kfree(t_alg);
- }
- }
- static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template
- *template)
- {
- struct caam_crypto_alg *t_alg;
- struct crypto_alg *alg;
- t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
- if (!t_alg) {
- pr_err("failed to allocate t_alg\n");
- return ERR_PTR(-ENOMEM);
- }
- alg = &t_alg->crypto_alg;
- snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
- snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
- template->driver_name);
- alg->cra_module = THIS_MODULE;
- alg->cra_init = caam_cra_init;
- alg->cra_exit = caam_cra_exit;
- alg->cra_priority = CAAM_CRA_PRIORITY;
- alg->cra_blocksize = template->blocksize;
- alg->cra_alignmask = 0;
- alg->cra_ctxsize = sizeof(struct caam_ctx);
- alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
- template->type;
- switch (template->type) {
- case CRYPTO_ALG_TYPE_GIVCIPHER:
- alg->cra_type = &crypto_givcipher_type;
- alg->cra_ablkcipher = template->template_ablkcipher;
- break;
- case CRYPTO_ALG_TYPE_ABLKCIPHER:
- alg->cra_type = &crypto_ablkcipher_type;
- alg->cra_ablkcipher = template->template_ablkcipher;
- break;
- }
- t_alg->caam.class1_alg_type = template->class1_alg_type;
- t_alg->caam.class2_alg_type = template->class2_alg_type;
- return t_alg;
- }
- static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
- {
- struct aead_alg *alg = &t_alg->aead;
- alg->base.cra_module = THIS_MODULE;
- alg->base.cra_priority = CAAM_CRA_PRIORITY;
- alg->base.cra_ctxsize = sizeof(struct caam_ctx);
- alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
- alg->init = caam_aead_init;
- alg->exit = caam_aead_exit;
- }
- static int __init caam_algapi_init(void)
- {
- struct device_node *dev_node;
- struct platform_device *pdev;
- struct device *ctrldev;
- struct caam_drv_private *priv;
- int i = 0, err = 0;
- u32 cha_vid, cha_inst, des_inst, aes_inst, md_inst;
- unsigned int md_limit = SHA512_DIGEST_SIZE;
- bool registered = false;
- dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
- if (!dev_node) {
- dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
- if (!dev_node)
- return -ENODEV;
- }
- pdev = of_find_device_by_node(dev_node);
- if (!pdev) {
- of_node_put(dev_node);
- return -ENODEV;
- }
- ctrldev = &pdev->dev;
- priv = dev_get_drvdata(ctrldev);
- of_node_put(dev_node);
- /*
- * If priv is NULL, it's probably because the caam driver wasn't
- * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
- */
- if (!priv)
- return -ENODEV;
- INIT_LIST_HEAD(&alg_list);
- /*
- * Register crypto algorithms the device supports.
- * First, detect presence and attributes of DES, AES, and MD blocks.
- */
- cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls);
- cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls);
- des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >> CHA_ID_LS_DES_SHIFT;
- aes_inst = (cha_inst & CHA_ID_LS_AES_MASK) >> CHA_ID_LS_AES_SHIFT;
- md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
- /* If MD is present, limit digest size based on LP256 */
- if (md_inst && ((cha_vid & CHA_ID_LS_MD_MASK) == CHA_ID_LS_MD_LP256))
- md_limit = SHA256_DIGEST_SIZE;
- for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
- struct caam_crypto_alg *t_alg;
- struct caam_alg_template *alg = driver_algs + i;
- u32 alg_sel = alg->class1_alg_type & OP_ALG_ALGSEL_MASK;
- /* Skip DES algorithms if not supported by device */
- if (!des_inst &&
- ((alg_sel == OP_ALG_ALGSEL_3DES) ||
- (alg_sel == OP_ALG_ALGSEL_DES)))
- continue;
- /* Skip AES algorithms if not supported by device */
- if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
- continue;
- /*
- * Check support for AES modes not available
- * on LP devices.
- */
- if ((cha_vid & CHA_ID_LS_AES_MASK) == CHA_ID_LS_AES_LP)
- if ((alg->class1_alg_type & OP_ALG_AAI_MASK) ==
- OP_ALG_AAI_XTS)
- continue;
- t_alg = caam_alg_alloc(alg);
- if (IS_ERR(t_alg)) {
- err = PTR_ERR(t_alg);
- pr_warn("%s alg allocation failed\n", alg->driver_name);
- continue;
- }
- err = crypto_register_alg(&t_alg->crypto_alg);
- if (err) {
- pr_warn("%s alg registration failed\n",
- t_alg->crypto_alg.cra_driver_name);
- kfree(t_alg);
- continue;
- }
- list_add_tail(&t_alg->entry, &alg_list);
- registered = true;
- }
- for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
- struct caam_aead_alg *t_alg = driver_aeads + i;
- u32 c1_alg_sel = t_alg->caam.class1_alg_type &
- OP_ALG_ALGSEL_MASK;
- u32 c2_alg_sel = t_alg->caam.class2_alg_type &
- OP_ALG_ALGSEL_MASK;
- u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
- /* Skip DES algorithms if not supported by device */
- if (!des_inst &&
- ((c1_alg_sel == OP_ALG_ALGSEL_3DES) ||
- (c1_alg_sel == OP_ALG_ALGSEL_DES)))
- continue;
- /* Skip AES algorithms if not supported by device */
- if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES))
- continue;
- /*
- * Check support for AES algorithms not available
- * on LP devices.
- */
- if ((cha_vid & CHA_ID_LS_AES_MASK) == CHA_ID_LS_AES_LP)
- if (alg_aai == OP_ALG_AAI_GCM)
- continue;
- /*
- * Skip algorithms requiring message digests
- * if MD or MD size is not supported by device.
- */
- if (c2_alg_sel &&
- (!md_inst || (t_alg->aead.maxauthsize > md_limit)))
- continue;
- caam_aead_alg_init(t_alg);
- err = crypto_register_aead(&t_alg->aead);
- if (err) {
- pr_warn("%s alg registration failed\n",
- t_alg->aead.base.cra_driver_name);
- continue;
- }
- t_alg->registered = true;
- registered = true;
- }
- if (registered)
- pr_info("caam algorithms registered in /proc/crypto\n");
- return err;
- }
- module_init(caam_algapi_init);
- module_exit(caam_algapi_exit);
- MODULE_LICENSE("GPL");
- MODULE_DESCRIPTION("FSL CAAM support for crypto API");
- MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");
|