hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/bcm/cipher.c
....@@ -1,17 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2016 Broadcom
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License, version 2, as
6
- * published by the Free Software Foundation (the "GPL").
7
- *
8
- * This program is distributed in the hope that it will be useful, but
9
- * WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- * General Public License version 2 (GPLv2) for more details.
12
- *
13
- * You should have received a copy of the GNU General Public License
14
- * version 2 (GPLv2) along with this source code.
154 */
165
176 #include <linux/err.h>
....@@ -35,7 +24,7 @@
3524 #include <crypto/aead.h>
3625 #include <crypto/internal/aead.h>
3726 #include <crypto/aes.h>
38
-#include <crypto/des.h>
27
+#include <crypto/internal/des.h>
3928 #include <crypto/hmac.h>
4029 #include <crypto/sha.h>
4130 #include <crypto/md5.h>
....@@ -96,7 +85,7 @@
9685 * 0x70 - ring 2
9786 * 0x78 - ring 3
9887 */
99
-char BCMHEADER[] = { 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28 };
88
+static char BCMHEADER[] = { 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28 };
10089 /*
10190 * Some SPU hw does not use BCM header on SPU messages. So BCM_HDR_LEN
10291 * is set dynamically after reading SPU type from device tree.
....@@ -121,8 +110,8 @@
121110 }
122111
123112 /**
124
- * spu_ablkcipher_rx_sg_create() - Build up the scatterlist of buffers used to
125
- * receive a SPU response message for an ablkcipher request. Includes buffers to
113
+ * spu_skcipher_rx_sg_create() - Build up the scatterlist of buffers used to
114
+ * receive a SPU response message for an skcipher request. Includes buffers to
126115 * catch SPU message headers and the response data.
127116 * @mssg: mailbox message containing the receive sg
128117 * @rctx: crypto request context
....@@ -141,7 +130,7 @@
141130 * < 0 if an error
142131 */
143132 static int
144
-spu_ablkcipher_rx_sg_create(struct brcm_message *mssg,
133
+spu_skcipher_rx_sg_create(struct brcm_message *mssg,
145134 struct iproc_reqctx_s *rctx,
146135 u8 rx_frag_num,
147136 unsigned int chunksize, u32 stat_pad_len)
....@@ -176,10 +165,6 @@
176165 return -EFAULT;
177166 }
178167
179
- if (ctx->cipher.alg == CIPHER_ALG_RC4)
180
- /* Add buffer to catch 260-byte SUPDT field for RC4 */
181
- sg_set_buf(sg++, rctx->msg_buf.c.supdt_tweak, SPU_SUPDT_LEN);
182
-
183168 if (stat_pad_len)
184169 sg_set_buf(sg++, rctx->msg_buf.rx_stat_pad, stat_pad_len);
185170
....@@ -190,8 +175,8 @@
190175 }
191176
192177 /**
193
- * spu_ablkcipher_tx_sg_create() - Build up the scatterlist of buffers used to
194
- * send a SPU request message for an ablkcipher request. Includes SPU message
178
+ * spu_skcipher_tx_sg_create() - Build up the scatterlist of buffers used to
179
+ * send a SPU request message for an skcipher request. Includes SPU message
195180 * headers and the request data.
196181 * @mssg: mailbox message containing the transmit sg
197182 * @rctx: crypto request context
....@@ -209,7 +194,7 @@
209194 * < 0 if an error
210195 */
211196 static int
212
-spu_ablkcipher_tx_sg_create(struct brcm_message *mssg,
197
+spu_skcipher_tx_sg_create(struct brcm_message *mssg,
213198 struct iproc_reqctx_s *rctx,
214199 u8 tx_frag_num, unsigned int chunksize, u32 pad_len)
215200 {
....@@ -294,7 +279,7 @@
294279 }
295280
296281 /**
297
- * handle_ablkcipher_req() - Submit as much of a block cipher request as fits in
282
+ * handle_skcipher_req() - Submit as much of a block cipher request as fits in
298283 * a single SPU request message, starting at the current position in the request
299284 * data.
300285 * @rctx: Crypto request context
....@@ -311,24 +296,23 @@
311296 * asynchronously
312297 * Any other value indicates an error
313298 */
314
-static int handle_ablkcipher_req(struct iproc_reqctx_s *rctx)
299
+static int handle_skcipher_req(struct iproc_reqctx_s *rctx)
315300 {
316301 struct spu_hw *spu = &iproc_priv.spu;
317302 struct crypto_async_request *areq = rctx->parent;
318
- struct ablkcipher_request *req =
319
- container_of(areq, struct ablkcipher_request, base);
303
+ struct skcipher_request *req =
304
+ container_of(areq, struct skcipher_request, base);
320305 struct iproc_ctx_s *ctx = rctx->ctx;
321306 struct spu_cipher_parms cipher_parms;
322
- int err = 0;
323
- unsigned int chunksize = 0; /* Num bytes of request to submit */
324
- int remaining = 0; /* Bytes of request still to process */
307
+ int err;
308
+ unsigned int chunksize; /* Num bytes of request to submit */
309
+ int remaining; /* Bytes of request still to process */
325310 int chunk_start; /* Beginning of data for current SPU msg */
326311
327312 /* IV or ctr value to use in this SPU msg */
328313 u8 local_iv_ctr[MAX_IV_SIZE];
329314 u32 stat_pad_len; /* num bytes to align status field */
330315 u32 pad_len; /* total length of all padding */
331
- bool update_key = false;
332316 struct brcm_message *mssg; /* mailbox message */
333317
334318 /* number of entries in src and dst sg in mailbox message. */
....@@ -402,28 +386,6 @@
402386 }
403387 }
404388
405
- if (ctx->cipher.alg == CIPHER_ALG_RC4) {
406
- rx_frag_num++;
407
- if (chunk_start) {
408
- /*
409
- * for non-first RC4 chunks, use SUPDT from previous
410
- * response as key for this chunk.
411
- */
412
- cipher_parms.key_buf = rctx->msg_buf.c.supdt_tweak;
413
- update_key = true;
414
- cipher_parms.type = CIPHER_TYPE_UPDT;
415
- } else if (!rctx->is_encrypt) {
416
- /*
417
- * First RC4 chunk. For decrypt, key in pre-built msg
418
- * header may have been changed if encrypt required
419
- * multiple chunks. So revert the key to the
420
- * ctx->enckey value.
421
- */
422
- update_key = true;
423
- cipher_parms.type = CIPHER_TYPE_INIT;
424
- }
425
- }
426
-
427389 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF)
428390 flow_log("max_payload infinite\n");
429391 else
....@@ -436,14 +398,9 @@
436398 memcpy(rctx->msg_buf.bcm_spu_req_hdr, ctx->bcm_spu_req_hdr,
437399 sizeof(rctx->msg_buf.bcm_spu_req_hdr));
438400
439
- /*
440
- * Pass SUPDT field as key. Key field in finish() call is only used
441
- * when update_key has been set above for RC4. Will be ignored in
442
- * all other cases.
443
- */
444401 spu->spu_cipher_req_finish(rctx->msg_buf.bcm_spu_req_hdr + BCM_HDR_LEN,
445402 ctx->spu_req_hdr_len, !(rctx->is_encrypt),
446
- &cipher_parms, update_key, chunksize);
403
+ &cipher_parms, chunksize);
447404
448405 atomic64_add(chunksize, &iproc_priv.bytes_out);
449406
....@@ -479,7 +436,7 @@
479436 spu->spu_xts_tweak_in_payload())
480437 rx_frag_num++; /* extra sg to insert tweak */
481438
482
- err = spu_ablkcipher_rx_sg_create(mssg, rctx, rx_frag_num, chunksize,
439
+ err = spu_skcipher_rx_sg_create(mssg, rctx, rx_frag_num, chunksize,
483440 stat_pad_len);
484441 if (err)
485442 return err;
....@@ -493,7 +450,7 @@
493450 spu->spu_xts_tweak_in_payload())
494451 tx_frag_num++; /* extra sg to insert tweak */
495452
496
- err = spu_ablkcipher_tx_sg_create(mssg, rctx, tx_frag_num, chunksize,
453
+ err = spu_skcipher_tx_sg_create(mssg, rctx, tx_frag_num, chunksize,
497454 pad_len);
498455 if (err)
499456 return err;
....@@ -506,16 +463,16 @@
506463 }
507464
508465 /**
509
- * handle_ablkcipher_resp() - Process a block cipher SPU response. Updates the
466
+ * handle_skcipher_resp() - Process a block cipher SPU response. Updates the
510467 * total received count for the request and updates global stats.
511468 * @rctx: Crypto request context
512469 */
513
-static void handle_ablkcipher_resp(struct iproc_reqctx_s *rctx)
470
+static void handle_skcipher_resp(struct iproc_reqctx_s *rctx)
514471 {
515472 struct spu_hw *spu = &iproc_priv.spu;
516473 #ifdef DEBUG
517474 struct crypto_async_request *areq = rctx->parent;
518
- struct ablkcipher_request *req = ablkcipher_request_cast(areq);
475
+ struct skcipher_request *req = skcipher_request_cast(areq);
519476 #endif
520477 struct iproc_ctx_s *ctx = rctx->ctx;
521478 u32 payload_len;
....@@ -538,9 +495,6 @@
538495 __func__, rctx->total_received, payload_len);
539496
540497 dump_sg(req->dst, rctx->total_received, payload_len);
541
- if (ctx->cipher.alg == CIPHER_ALG_RC4)
542
- packet_dump(" supdt ", rctx->msg_buf.c.supdt_tweak,
543
- SPU_SUPDT_LEN);
544498
545499 rctx->total_received += payload_len;
546500 if (rctx->total_received == rctx->total_todo) {
....@@ -709,7 +663,7 @@
709663
710664 /* number of bytes still to be hashed in this req */
711665 unsigned int nbytes_to_hash = 0;
712
- int err = 0;
666
+ int err;
713667 unsigned int chunksize = 0; /* length of hash carry + new data */
714668 /*
715669 * length of new data, not from hash carry, to be submitted in
....@@ -1675,7 +1629,7 @@
16751629 struct spu_hw *spu = &iproc_priv.spu;
16761630 struct brcm_message *mssg = msg;
16771631 struct iproc_reqctx_s *rctx;
1678
- int err = 0;
1632
+ int err;
16791633
16801634 rctx = mssg->ctx;
16811635 if (unlikely(!rctx)) {
....@@ -1696,8 +1650,8 @@
16961650
16971651 /* Process the SPU response message */
16981652 switch (rctx->ctx->alg->type) {
1699
- case CRYPTO_ALG_TYPE_ABLKCIPHER:
1700
- handle_ablkcipher_resp(rctx);
1653
+ case CRYPTO_ALG_TYPE_SKCIPHER:
1654
+ handle_skcipher_resp(rctx);
17011655 break;
17021656 case CRYPTO_ALG_TYPE_AHASH:
17031657 handle_ahash_resp(rctx);
....@@ -1719,8 +1673,8 @@
17191673 spu_chunk_cleanup(rctx);
17201674
17211675 switch (rctx->ctx->alg->type) {
1722
- case CRYPTO_ALG_TYPE_ABLKCIPHER:
1723
- err = handle_ablkcipher_req(rctx);
1676
+ case CRYPTO_ALG_TYPE_SKCIPHER:
1677
+ err = handle_skcipher_req(rctx);
17241678 break;
17251679 case CRYPTO_ALG_TYPE_AHASH:
17261680 err = handle_ahash_req(rctx);
....@@ -1750,7 +1704,7 @@
17501704 /* ==================== Kernel Cryptographic API ==================== */
17511705
17521706 /**
1753
- * ablkcipher_enqueue() - Handle ablkcipher encrypt or decrypt request.
1707
+ * skcipher_enqueue() - Handle skcipher encrypt or decrypt request.
17541708 * @req: Crypto API request
17551709 * @encrypt: true if encrypting; false if decrypting
17561710 *
....@@ -1758,11 +1712,11 @@
17581712 * asynchronously
17591713 * < 0 if an error
17601714 */
1761
-static int ablkcipher_enqueue(struct ablkcipher_request *req, bool encrypt)
1715
+static int skcipher_enqueue(struct skcipher_request *req, bool encrypt)
17621716 {
1763
- struct iproc_reqctx_s *rctx = ablkcipher_request_ctx(req);
1717
+ struct iproc_reqctx_s *rctx = skcipher_request_ctx(req);
17641718 struct iproc_ctx_s *ctx =
1765
- crypto_ablkcipher_ctx(crypto_ablkcipher_reqtfm(req));
1719
+ crypto_skcipher_ctx(crypto_skcipher_reqtfm(req));
17661720 int err;
17671721
17681722 flow_log("%s() enc:%u\n", __func__, encrypt);
....@@ -1772,7 +1726,7 @@
17721726 rctx->parent = &req->base;
17731727 rctx->is_encrypt = encrypt;
17741728 rctx->bd_suppress = false;
1775
- rctx->total_todo = req->nbytes;
1729
+ rctx->total_todo = req->cryptlen;
17761730 rctx->src_sent = 0;
17771731 rctx->total_sent = 0;
17781732 rctx->total_received = 0;
....@@ -1793,15 +1747,15 @@
17931747 ctx->cipher.mode == CIPHER_MODE_GCM ||
17941748 ctx->cipher.mode == CIPHER_MODE_CCM) {
17951749 rctx->iv_ctr_len =
1796
- crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req));
1797
- memcpy(rctx->msg_buf.iv_ctr, req->info, rctx->iv_ctr_len);
1750
+ crypto_skcipher_ivsize(crypto_skcipher_reqtfm(req));
1751
+ memcpy(rctx->msg_buf.iv_ctr, req->iv, rctx->iv_ctr_len);
17981752 } else {
17991753 rctx->iv_ctr_len = 0;
18001754 }
18011755
18021756 /* Choose a SPU to process this request */
18031757 rctx->chan_idx = select_channel();
1804
- err = handle_ablkcipher_req(rctx);
1758
+ err = handle_skcipher_req(rctx);
18051759 if (err != -EINPROGRESS)
18061760 /* synchronous result */
18071761 spu_chunk_cleanup(rctx);
....@@ -1809,58 +1763,38 @@
18091763 return err;
18101764 }
18111765
1812
-static int des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
1766
+static int des_setkey(struct crypto_skcipher *cipher, const u8 *key,
18131767 unsigned int keylen)
18141768 {
1815
- struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher);
1816
- u32 tmp[DES_EXPKEY_WORDS];
1769
+ struct iproc_ctx_s *ctx = crypto_skcipher_ctx(cipher);
1770
+ int err;
18171771
1818
- if (keylen == DES_KEY_SIZE) {
1819
- if (des_ekey(tmp, key) == 0) {
1820
- if (crypto_ablkcipher_get_flags(cipher) &
1821
- CRYPTO_TFM_REQ_WEAK_KEY) {
1822
- u32 flags = CRYPTO_TFM_RES_WEAK_KEY;
1772
+ err = verify_skcipher_des_key(cipher, key);
1773
+ if (err)
1774
+ return err;
18231775
1824
- crypto_ablkcipher_set_flags(cipher, flags);
1825
- return -EINVAL;
1826
- }
1827
- }
1828
-
1829
- ctx->cipher_type = CIPHER_TYPE_DES;
1830
- } else {
1831
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
1832
- return -EINVAL;
1833
- }
1776
+ ctx->cipher_type = CIPHER_TYPE_DES;
18341777 return 0;
18351778 }
18361779
1837
-static int threedes_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
1780
+static int threedes_setkey(struct crypto_skcipher *cipher, const u8 *key,
18381781 unsigned int keylen)
18391782 {
1840
- struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher);
1783
+ struct iproc_ctx_s *ctx = crypto_skcipher_ctx(cipher);
1784
+ int err;
18411785
1842
- if (keylen == (DES_KEY_SIZE * 3)) {
1843
- const u32 *K = (const u32 *)key;
1844
- u32 flags = CRYPTO_TFM_RES_BAD_KEY_SCHED;
1786
+ err = verify_skcipher_des3_key(cipher, key);
1787
+ if (err)
1788
+ return err;
18451789
1846
- if (!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
1847
- !((K[2] ^ K[4]) | (K[3] ^ K[5]))) {
1848
- crypto_ablkcipher_set_flags(cipher, flags);
1849
- return -EINVAL;
1850
- }
1851
-
1852
- ctx->cipher_type = CIPHER_TYPE_3DES;
1853
- } else {
1854
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
1855
- return -EINVAL;
1856
- }
1790
+ ctx->cipher_type = CIPHER_TYPE_3DES;
18571791 return 0;
18581792 }
18591793
1860
-static int aes_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
1794
+static int aes_setkey(struct crypto_skcipher *cipher, const u8 *key,
18611795 unsigned int keylen)
18621796 {
1863
- struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher);
1797
+ struct iproc_ctx_s *ctx = crypto_skcipher_ctx(cipher);
18641798
18651799 if (ctx->cipher.mode == CIPHER_MODE_XTS)
18661800 /* XTS includes two keys of equal length */
....@@ -1877,7 +1811,6 @@
18771811 ctx->cipher_type = CIPHER_TYPE_AES256;
18781812 break;
18791813 default:
1880
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
18811814 return -EINVAL;
18821815 }
18831816 WARN_ON((ctx->max_payload != SPU_MAX_PAYLOAD_INF) &&
....@@ -1885,36 +1818,16 @@
18851818 return 0;
18861819 }
18871820
1888
-static int rc4_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
1889
- unsigned int keylen)
1890
-{
1891
- struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher);
1892
- int i;
1893
-
1894
- ctx->enckeylen = ARC4_MAX_KEY_SIZE + ARC4_STATE_SIZE;
1895
-
1896
- ctx->enckey[0] = 0x00; /* 0x00 */
1897
- ctx->enckey[1] = 0x00; /* i */
1898
- ctx->enckey[2] = 0x00; /* 0x00 */
1899
- ctx->enckey[3] = 0x00; /* j */
1900
- for (i = 0; i < ARC4_MAX_KEY_SIZE; i++)
1901
- ctx->enckey[i + ARC4_STATE_SIZE] = key[i % keylen];
1902
-
1903
- ctx->cipher_type = CIPHER_TYPE_INIT;
1904
-
1905
- return 0;
1906
-}
1907
-
1908
-static int ablkcipher_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
1821
+static int skcipher_setkey(struct crypto_skcipher *cipher, const u8 *key,
19091822 unsigned int keylen)
19101823 {
19111824 struct spu_hw *spu = &iproc_priv.spu;
1912
- struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher);
1825
+ struct iproc_ctx_s *ctx = crypto_skcipher_ctx(cipher);
19131826 struct spu_cipher_parms cipher_parms;
19141827 u32 alloc_len = 0;
19151828 int err;
19161829
1917
- flow_log("ablkcipher_setkey() keylen: %d\n", keylen);
1830
+ flow_log("skcipher_setkey() keylen: %d\n", keylen);
19181831 flow_dump(" key: ", key, keylen);
19191832
19201833 switch (ctx->cipher.alg) {
....@@ -1927,9 +1840,6 @@
19271840 case CIPHER_ALG_AES:
19281841 err = aes_setkey(cipher, key, keylen);
19291842 break;
1930
- case CIPHER_ALG_RC4:
1931
- err = rc4_setkey(cipher, key, keylen);
1932
- break;
19331843 default:
19341844 pr_err("%s() Error: unknown cipher alg\n", __func__);
19351845 err = -EINVAL;
....@@ -1937,11 +1847,9 @@
19371847 if (err)
19381848 return err;
19391849
1940
- /* RC4 already populated ctx->enkey */
1941
- if (ctx->cipher.alg != CIPHER_ALG_RC4) {
1942
- memcpy(ctx->enckey, key, keylen);
1943
- ctx->enckeylen = keylen;
1944
- }
1850
+ memcpy(ctx->enckey, key, keylen);
1851
+ ctx->enckeylen = keylen;
1852
+
19451853 /* SPU needs XTS keys in the reverse order the crypto API presents */
19461854 if ((ctx->cipher.alg == CIPHER_ALG_AES) &&
19471855 (ctx->cipher.mode == CIPHER_MODE_XTS)) {
....@@ -1957,7 +1865,7 @@
19571865 alloc_len = BCM_HDR_LEN + SPU2_HEADER_ALLOC_LEN;
19581866 memset(ctx->bcm_spu_req_hdr, 0, alloc_len);
19591867 cipher_parms.iv_buf = NULL;
1960
- cipher_parms.iv_len = crypto_ablkcipher_ivsize(cipher);
1868
+ cipher_parms.iv_len = crypto_skcipher_ivsize(cipher);
19611869 flow_log("%s: iv_len %u\n", __func__, cipher_parms.iv_len);
19621870
19631871 cipher_parms.alg = ctx->cipher.alg;
....@@ -1981,17 +1889,17 @@
19811889 return 0;
19821890 }
19831891
1984
-static int ablkcipher_encrypt(struct ablkcipher_request *req)
1892
+static int skcipher_encrypt(struct skcipher_request *req)
19851893 {
1986
- flow_log("ablkcipher_encrypt() nbytes:%u\n", req->nbytes);
1894
+ flow_log("skcipher_encrypt() nbytes:%u\n", req->cryptlen);
19871895
1988
- return ablkcipher_enqueue(req, true);
1896
+ return skcipher_enqueue(req, true);
19891897 }
19901898
1991
-static int ablkcipher_decrypt(struct ablkcipher_request *req)
1899
+static int skcipher_decrypt(struct skcipher_request *req)
19921900 {
1993
- flow_log("ablkcipher_decrypt() nbytes:%u\n", req->nbytes);
1994
- return ablkcipher_enqueue(req, false);
1901
+ flow_log("skcipher_decrypt() nbytes:%u\n", req->cryptlen);
1902
+ return skcipher_enqueue(req, false);
19951903 }
19961904
19971905 static int ahash_enqueue(struct ahash_request *req)
....@@ -1999,7 +1907,7 @@
19991907 struct iproc_reqctx_s *rctx = ahash_request_ctx(req);
20001908 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
20011909 struct iproc_ctx_s *ctx = crypto_ahash_ctx(tfm);
2002
- int err = 0;
1910
+ int err;
20031911 const char *alg_name;
20041912
20051913 flow_log("ahash_enqueue() nbytes:%u\n", req->nbytes);
....@@ -2093,7 +2001,7 @@
20932001 * Return: true if incremental hashing is not supported
20942002 * false otherwise
20952003 */
2096
-bool spu_no_incr_hash(struct iproc_ctx_s *ctx)
2004
+static bool spu_no_incr_hash(struct iproc_ctx_s *ctx)
20972005 {
20982006 struct spu_hw *spu = &iproc_priv.spu;
20992007
....@@ -2139,7 +2047,6 @@
21392047 goto err_hash;
21402048 }
21412049 ctx->shash->tfm = hash;
2142
- ctx->shash->flags = 0;
21432050
21442051 /* Set the key using data we already have from setkey */
21452052 if (ctx->authkeylen > 0) {
....@@ -2332,7 +2239,7 @@
23322239
23332240 static int ahash_digest(struct ahash_request *req)
23342241 {
2335
- int err = 0;
2242
+ int err;
23362243
23372244 flow_log("ahash_digest() nbytes:%u\n", req->nbytes);
23382245
....@@ -2640,6 +2547,19 @@
26402547 return 1;
26412548 }
26422549
2550
+ /*
2551
+ * RFC4106 and RFC4543 cannot handle the case where AAD is other than
2552
+ * 16 or 20 bytes long. So use fallback in this case.
2553
+ */
2554
+ if (ctx->cipher.mode == CIPHER_MODE_GCM &&
2555
+ ctx->cipher.alg == CIPHER_ALG_AES &&
2556
+ rctx->iv_ctr_len == GCM_RFC4106_IV_SIZE &&
2557
+ req->assoclen != 16 && req->assoclen != 20) {
2558
+ flow_log("RFC4106/RFC4543 needs fallback for assoclen"
2559
+ " other than 16 or 20 bytes\n");
2560
+ return 1;
2561
+ }
2562
+
26432563 payload_len = req->cryptlen;
26442564 if (spu->spu_type == SPU_TYPE_SPUM)
26452565 payload_len += req->assoclen;
....@@ -2866,40 +2786,16 @@
28662786
28672787 switch (ctx->alg->cipher_info.alg) {
28682788 case CIPHER_ALG_DES:
2869
- if (ctx->enckeylen == DES_KEY_SIZE) {
2870
- u32 tmp[DES_EXPKEY_WORDS];
2871
- u32 flags = CRYPTO_TFM_RES_WEAK_KEY;
2789
+ if (verify_aead_des_key(cipher, keys.enckey, keys.enckeylen))
2790
+ return -EINVAL;
28722791
2873
- if (des_ekey(tmp, keys.enckey) == 0) {
2874
- if (crypto_aead_get_flags(cipher) &
2875
- CRYPTO_TFM_REQ_WEAK_KEY) {
2876
- crypto_aead_set_flags(cipher, flags);
2877
- return -EINVAL;
2878
- }
2879
- }
2880
-
2881
- ctx->cipher_type = CIPHER_TYPE_DES;
2882
- } else {
2883
- goto badkey;
2884
- }
2792
+ ctx->cipher_type = CIPHER_TYPE_DES;
28852793 break;
28862794 case CIPHER_ALG_3DES:
2887
- if (ctx->enckeylen == (DES_KEY_SIZE * 3)) {
2888
- const u32 *K = (const u32 *)keys.enckey;
2889
- u32 flags = CRYPTO_TFM_RES_BAD_KEY_SCHED;
2890
-
2891
- if (!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
2892
- !((K[2] ^ K[4]) | (K[3] ^ K[5]))) {
2893
- crypto_aead_set_flags(cipher, flags);
2894
- return -EINVAL;
2895
- }
2896
-
2897
- ctx->cipher_type = CIPHER_TYPE_3DES;
2898
- } else {
2899
- crypto_aead_set_flags(cipher,
2900
- CRYPTO_TFM_RES_BAD_KEY_LEN);
2795
+ if (verify_aead_des3_key(cipher, keys.enckey, keys.enckeylen))
29012796 return -EINVAL;
2902
- }
2797
+
2798
+ ctx->cipher_type = CIPHER_TYPE_3DES;
29032799 break;
29042800 case CIPHER_ALG_AES:
29052801 switch (ctx->enckeylen) {
....@@ -2915,9 +2811,6 @@
29152811 default:
29162812 goto badkey;
29172813 }
2918
- break;
2919
- case CIPHER_ALG_RC4:
2920
- ctx->cipher_type = CIPHER_TYPE_INIT;
29212814 break;
29222815 default:
29232816 pr_err("%s() Error: Unknown cipher alg\n", __func__);
....@@ -2937,13 +2830,8 @@
29372830 ctx->fallback_cipher->base.crt_flags |=
29382831 tfm->crt_flags & CRYPTO_TFM_REQ_MASK;
29392832 ret = crypto_aead_setkey(ctx->fallback_cipher, key, keylen);
2940
- if (ret) {
2833
+ if (ret)
29412834 flow_log(" fallback setkey() returned:%d\n", ret);
2942
- tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
2943
- tfm->crt_flags |=
2944
- (ctx->fallback_cipher->base.crt_flags &
2945
- CRYPTO_TFM_RES_MASK);
2946
- }
29472835 }
29482836
29492837 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen,
....@@ -2959,7 +2847,6 @@
29592847 ctx->authkeylen = 0;
29602848 ctx->digestsize = 0;
29612849
2962
- crypto_aead_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
29632850 return -EINVAL;
29642851 }
29652852
....@@ -3011,13 +2898,8 @@
30112898 tfm->crt_flags & CRYPTO_TFM_REQ_MASK;
30122899 ret = crypto_aead_setkey(ctx->fallback_cipher, key,
30132900 keylen + ctx->salt_len);
3014
- if (ret) {
2901
+ if (ret)
30152902 flow_log(" fallback setkey() returned:%d\n", ret);
3016
- tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
3017
- tfm->crt_flags |=
3018
- (ctx->fallback_cipher->base.crt_flags &
3019
- CRYPTO_TFM_RES_MASK);
3020
- }
30212903 }
30222904
30232905 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen,
....@@ -3036,7 +2918,6 @@
30362918 ctx->authkeylen = 0;
30372919 ctx->digestsize = 0;
30382920
3039
- crypto_aead_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
30402921 return -EINVAL;
30412922 }
30422923
....@@ -3302,7 +3183,9 @@
33023183 .cra_name = "authenc(hmac(md5),cbc(aes))",
33033184 .cra_driver_name = "authenc-hmac-md5-cbc-aes-iproc",
33043185 .cra_blocksize = AES_BLOCK_SIZE,
3305
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3186
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3187
+ CRYPTO_ALG_ASYNC |
3188
+ CRYPTO_ALG_ALLOCATES_MEMORY
33063189 },
33073190 .setkey = aead_authenc_setkey,
33083191 .ivsize = AES_BLOCK_SIZE,
....@@ -3325,7 +3208,9 @@
33253208 .cra_name = "authenc(hmac(sha1),cbc(aes))",
33263209 .cra_driver_name = "authenc-hmac-sha1-cbc-aes-iproc",
33273210 .cra_blocksize = AES_BLOCK_SIZE,
3328
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3211
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3212
+ CRYPTO_ALG_ASYNC |
3213
+ CRYPTO_ALG_ALLOCATES_MEMORY
33293214 },
33303215 .setkey = aead_authenc_setkey,
33313216 .ivsize = AES_BLOCK_SIZE,
....@@ -3348,7 +3233,9 @@
33483233 .cra_name = "authenc(hmac(sha256),cbc(aes))",
33493234 .cra_driver_name = "authenc-hmac-sha256-cbc-aes-iproc",
33503235 .cra_blocksize = AES_BLOCK_SIZE,
3351
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3236
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3237
+ CRYPTO_ALG_ASYNC |
3238
+ CRYPTO_ALG_ALLOCATES_MEMORY
33523239 },
33533240 .setkey = aead_authenc_setkey,
33543241 .ivsize = AES_BLOCK_SIZE,
....@@ -3371,7 +3258,9 @@
33713258 .cra_name = "authenc(hmac(md5),cbc(des))",
33723259 .cra_driver_name = "authenc-hmac-md5-cbc-des-iproc",
33733260 .cra_blocksize = DES_BLOCK_SIZE,
3374
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3261
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3262
+ CRYPTO_ALG_ASYNC |
3263
+ CRYPTO_ALG_ALLOCATES_MEMORY
33753264 },
33763265 .setkey = aead_authenc_setkey,
33773266 .ivsize = DES_BLOCK_SIZE,
....@@ -3394,7 +3283,9 @@
33943283 .cra_name = "authenc(hmac(sha1),cbc(des))",
33953284 .cra_driver_name = "authenc-hmac-sha1-cbc-des-iproc",
33963285 .cra_blocksize = DES_BLOCK_SIZE,
3397
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3286
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3287
+ CRYPTO_ALG_ASYNC |
3288
+ CRYPTO_ALG_ALLOCATES_MEMORY
33983289 },
33993290 .setkey = aead_authenc_setkey,
34003291 .ivsize = DES_BLOCK_SIZE,
....@@ -3417,7 +3308,9 @@
34173308 .cra_name = "authenc(hmac(sha224),cbc(des))",
34183309 .cra_driver_name = "authenc-hmac-sha224-cbc-des-iproc",
34193310 .cra_blocksize = DES_BLOCK_SIZE,
3420
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3311
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3312
+ CRYPTO_ALG_ASYNC |
3313
+ CRYPTO_ALG_ALLOCATES_MEMORY
34213314 },
34223315 .setkey = aead_authenc_setkey,
34233316 .ivsize = DES_BLOCK_SIZE,
....@@ -3440,7 +3333,9 @@
34403333 .cra_name = "authenc(hmac(sha256),cbc(des))",
34413334 .cra_driver_name = "authenc-hmac-sha256-cbc-des-iproc",
34423335 .cra_blocksize = DES_BLOCK_SIZE,
3443
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3336
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3337
+ CRYPTO_ALG_ASYNC |
3338
+ CRYPTO_ALG_ALLOCATES_MEMORY
34443339 },
34453340 .setkey = aead_authenc_setkey,
34463341 .ivsize = DES_BLOCK_SIZE,
....@@ -3463,7 +3358,9 @@
34633358 .cra_name = "authenc(hmac(sha384),cbc(des))",
34643359 .cra_driver_name = "authenc-hmac-sha384-cbc-des-iproc",
34653360 .cra_blocksize = DES_BLOCK_SIZE,
3466
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3361
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3362
+ CRYPTO_ALG_ASYNC |
3363
+ CRYPTO_ALG_ALLOCATES_MEMORY
34673364 },
34683365 .setkey = aead_authenc_setkey,
34693366 .ivsize = DES_BLOCK_SIZE,
....@@ -3486,7 +3383,9 @@
34863383 .cra_name = "authenc(hmac(sha512),cbc(des))",
34873384 .cra_driver_name = "authenc-hmac-sha512-cbc-des-iproc",
34883385 .cra_blocksize = DES_BLOCK_SIZE,
3489
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3386
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3387
+ CRYPTO_ALG_ASYNC |
3388
+ CRYPTO_ALG_ALLOCATES_MEMORY
34903389 },
34913390 .setkey = aead_authenc_setkey,
34923391 .ivsize = DES_BLOCK_SIZE,
....@@ -3509,7 +3408,9 @@
35093408 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
35103409 .cra_driver_name = "authenc-hmac-md5-cbc-des3-iproc",
35113410 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3512
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3411
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3412
+ CRYPTO_ALG_ASYNC |
3413
+ CRYPTO_ALG_ALLOCATES_MEMORY
35133414 },
35143415 .setkey = aead_authenc_setkey,
35153416 .ivsize = DES3_EDE_BLOCK_SIZE,
....@@ -3532,7 +3433,9 @@
35323433 .cra_name = "authenc(hmac(sha1),cbc(des3_ede))",
35333434 .cra_driver_name = "authenc-hmac-sha1-cbc-des3-iproc",
35343435 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3535
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3436
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3437
+ CRYPTO_ALG_ASYNC |
3438
+ CRYPTO_ALG_ALLOCATES_MEMORY
35363439 },
35373440 .setkey = aead_authenc_setkey,
35383441 .ivsize = DES3_EDE_BLOCK_SIZE,
....@@ -3555,7 +3458,9 @@
35553458 .cra_name = "authenc(hmac(sha224),cbc(des3_ede))",
35563459 .cra_driver_name = "authenc-hmac-sha224-cbc-des3-iproc",
35573460 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3558
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3461
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3462
+ CRYPTO_ALG_ASYNC |
3463
+ CRYPTO_ALG_ALLOCATES_MEMORY
35593464 },
35603465 .setkey = aead_authenc_setkey,
35613466 .ivsize = DES3_EDE_BLOCK_SIZE,
....@@ -3578,7 +3483,9 @@
35783483 .cra_name = "authenc(hmac(sha256),cbc(des3_ede))",
35793484 .cra_driver_name = "authenc-hmac-sha256-cbc-des3-iproc",
35803485 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3581
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3486
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3487
+ CRYPTO_ALG_ASYNC |
3488
+ CRYPTO_ALG_ALLOCATES_MEMORY
35823489 },
35833490 .setkey = aead_authenc_setkey,
35843491 .ivsize = DES3_EDE_BLOCK_SIZE,
....@@ -3601,7 +3508,9 @@
36013508 .cra_name = "authenc(hmac(sha384),cbc(des3_ede))",
36023509 .cra_driver_name = "authenc-hmac-sha384-cbc-des3-iproc",
36033510 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3604
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3511
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3512
+ CRYPTO_ALG_ASYNC |
3513
+ CRYPTO_ALG_ALLOCATES_MEMORY
36053514 },
36063515 .setkey = aead_authenc_setkey,
36073516 .ivsize = DES3_EDE_BLOCK_SIZE,
....@@ -3624,7 +3533,9 @@
36243533 .cra_name = "authenc(hmac(sha512),cbc(des3_ede))",
36253534 .cra_driver_name = "authenc-hmac-sha512-cbc-des3-iproc",
36263535 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3627
- .cra_flags = CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC
3536
+ .cra_flags = CRYPTO_ALG_NEED_FALLBACK |
3537
+ CRYPTO_ALG_ASYNC |
3538
+ CRYPTO_ALG_ALLOCATES_MEMORY
36283539 },
36293540 .setkey = aead_authenc_setkey,
36303541 .ivsize = DES3_EDE_BLOCK_SIZE,
....@@ -3641,39 +3552,16 @@
36413552 .auth_first = 0,
36423553 },
36433554
3644
-/* ABLKCIPHER algorithms. */
3555
+/* SKCIPHER algorithms. */
36453556 {
3646
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3647
- .alg.crypto = {
3648
- .cra_name = "ecb(arc4)",
3649
- .cra_driver_name = "ecb-arc4-iproc",
3650
- .cra_blocksize = ARC4_BLOCK_SIZE,
3651
- .cra_ablkcipher = {
3652
- .min_keysize = ARC4_MIN_KEY_SIZE,
3653
- .max_keysize = ARC4_MAX_KEY_SIZE,
3654
- .ivsize = 0,
3655
- }
3656
- },
3657
- .cipher_info = {
3658
- .alg = CIPHER_ALG_RC4,
3659
- .mode = CIPHER_MODE_NONE,
3660
- },
3661
- .auth_info = {
3662
- .alg = HASH_ALG_NONE,
3663
- .mode = HASH_MODE_NONE,
3664
- },
3665
- },
3666
- {
3667
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3668
- .alg.crypto = {
3669
- .cra_name = "ofb(des)",
3670
- .cra_driver_name = "ofb-des-iproc",
3671
- .cra_blocksize = DES_BLOCK_SIZE,
3672
- .cra_ablkcipher = {
3673
- .min_keysize = DES_KEY_SIZE,
3674
- .max_keysize = DES_KEY_SIZE,
3675
- .ivsize = DES_BLOCK_SIZE,
3676
- }
3557
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3558
+ .alg.skcipher = {
3559
+ .base.cra_name = "ofb(des)",
3560
+ .base.cra_driver_name = "ofb-des-iproc",
3561
+ .base.cra_blocksize = DES_BLOCK_SIZE,
3562
+ .min_keysize = DES_KEY_SIZE,
3563
+ .max_keysize = DES_KEY_SIZE,
3564
+ .ivsize = DES_BLOCK_SIZE,
36773565 },
36783566 .cipher_info = {
36793567 .alg = CIPHER_ALG_DES,
....@@ -3685,16 +3573,14 @@
36853573 },
36863574 },
36873575 {
3688
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3689
- .alg.crypto = {
3690
- .cra_name = "cbc(des)",
3691
- .cra_driver_name = "cbc-des-iproc",
3692
- .cra_blocksize = DES_BLOCK_SIZE,
3693
- .cra_ablkcipher = {
3694
- .min_keysize = DES_KEY_SIZE,
3695
- .max_keysize = DES_KEY_SIZE,
3696
- .ivsize = DES_BLOCK_SIZE,
3697
- }
3576
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3577
+ .alg.skcipher = {
3578
+ .base.cra_name = "cbc(des)",
3579
+ .base.cra_driver_name = "cbc-des-iproc",
3580
+ .base.cra_blocksize = DES_BLOCK_SIZE,
3581
+ .min_keysize = DES_KEY_SIZE,
3582
+ .max_keysize = DES_KEY_SIZE,
3583
+ .ivsize = DES_BLOCK_SIZE,
36983584 },
36993585 .cipher_info = {
37003586 .alg = CIPHER_ALG_DES,
....@@ -3706,16 +3592,14 @@
37063592 },
37073593 },
37083594 {
3709
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3710
- .alg.crypto = {
3711
- .cra_name = "ecb(des)",
3712
- .cra_driver_name = "ecb-des-iproc",
3713
- .cra_blocksize = DES_BLOCK_SIZE,
3714
- .cra_ablkcipher = {
3715
- .min_keysize = DES_KEY_SIZE,
3716
- .max_keysize = DES_KEY_SIZE,
3717
- .ivsize = 0,
3718
- }
3595
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3596
+ .alg.skcipher = {
3597
+ .base.cra_name = "ecb(des)",
3598
+ .base.cra_driver_name = "ecb-des-iproc",
3599
+ .base.cra_blocksize = DES_BLOCK_SIZE,
3600
+ .min_keysize = DES_KEY_SIZE,
3601
+ .max_keysize = DES_KEY_SIZE,
3602
+ .ivsize = 0,
37193603 },
37203604 .cipher_info = {
37213605 .alg = CIPHER_ALG_DES,
....@@ -3727,16 +3611,14 @@
37273611 },
37283612 },
37293613 {
3730
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3731
- .alg.crypto = {
3732
- .cra_name = "ofb(des3_ede)",
3733
- .cra_driver_name = "ofb-des3-iproc",
3734
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3735
- .cra_ablkcipher = {
3736
- .min_keysize = DES3_EDE_KEY_SIZE,
3737
- .max_keysize = DES3_EDE_KEY_SIZE,
3738
- .ivsize = DES3_EDE_BLOCK_SIZE,
3739
- }
3614
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3615
+ .alg.skcipher = {
3616
+ .base.cra_name = "ofb(des3_ede)",
3617
+ .base.cra_driver_name = "ofb-des3-iproc",
3618
+ .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
3619
+ .min_keysize = DES3_EDE_KEY_SIZE,
3620
+ .max_keysize = DES3_EDE_KEY_SIZE,
3621
+ .ivsize = DES3_EDE_BLOCK_SIZE,
37403622 },
37413623 .cipher_info = {
37423624 .alg = CIPHER_ALG_3DES,
....@@ -3748,16 +3630,14 @@
37483630 },
37493631 },
37503632 {
3751
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3752
- .alg.crypto = {
3753
- .cra_name = "cbc(des3_ede)",
3754
- .cra_driver_name = "cbc-des3-iproc",
3755
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3756
- .cra_ablkcipher = {
3757
- .min_keysize = DES3_EDE_KEY_SIZE,
3758
- .max_keysize = DES3_EDE_KEY_SIZE,
3759
- .ivsize = DES3_EDE_BLOCK_SIZE,
3760
- }
3633
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3634
+ .alg.skcipher = {
3635
+ .base.cra_name = "cbc(des3_ede)",
3636
+ .base.cra_driver_name = "cbc-des3-iproc",
3637
+ .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
3638
+ .min_keysize = DES3_EDE_KEY_SIZE,
3639
+ .max_keysize = DES3_EDE_KEY_SIZE,
3640
+ .ivsize = DES3_EDE_BLOCK_SIZE,
37613641 },
37623642 .cipher_info = {
37633643 .alg = CIPHER_ALG_3DES,
....@@ -3769,16 +3649,14 @@
37693649 },
37703650 },
37713651 {
3772
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3773
- .alg.crypto = {
3774
- .cra_name = "ecb(des3_ede)",
3775
- .cra_driver_name = "ecb-des3-iproc",
3776
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3777
- .cra_ablkcipher = {
3778
- .min_keysize = DES3_EDE_KEY_SIZE,
3779
- .max_keysize = DES3_EDE_KEY_SIZE,
3780
- .ivsize = 0,
3781
- }
3652
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3653
+ .alg.skcipher = {
3654
+ .base.cra_name = "ecb(des3_ede)",
3655
+ .base.cra_driver_name = "ecb-des3-iproc",
3656
+ .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
3657
+ .min_keysize = DES3_EDE_KEY_SIZE,
3658
+ .max_keysize = DES3_EDE_KEY_SIZE,
3659
+ .ivsize = 0,
37823660 },
37833661 .cipher_info = {
37843662 .alg = CIPHER_ALG_3DES,
....@@ -3790,16 +3668,14 @@
37903668 },
37913669 },
37923670 {
3793
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3794
- .alg.crypto = {
3795
- .cra_name = "ofb(aes)",
3796
- .cra_driver_name = "ofb-aes-iproc",
3797
- .cra_blocksize = AES_BLOCK_SIZE,
3798
- .cra_ablkcipher = {
3799
- .min_keysize = AES_MIN_KEY_SIZE,
3800
- .max_keysize = AES_MAX_KEY_SIZE,
3801
- .ivsize = AES_BLOCK_SIZE,
3802
- }
3671
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3672
+ .alg.skcipher = {
3673
+ .base.cra_name = "ofb(aes)",
3674
+ .base.cra_driver_name = "ofb-aes-iproc",
3675
+ .base.cra_blocksize = AES_BLOCK_SIZE,
3676
+ .min_keysize = AES_MIN_KEY_SIZE,
3677
+ .max_keysize = AES_MAX_KEY_SIZE,
3678
+ .ivsize = AES_BLOCK_SIZE,
38033679 },
38043680 .cipher_info = {
38053681 .alg = CIPHER_ALG_AES,
....@@ -3811,16 +3687,14 @@
38113687 },
38123688 },
38133689 {
3814
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3815
- .alg.crypto = {
3816
- .cra_name = "cbc(aes)",
3817
- .cra_driver_name = "cbc-aes-iproc",
3818
- .cra_blocksize = AES_BLOCK_SIZE,
3819
- .cra_ablkcipher = {
3820
- .min_keysize = AES_MIN_KEY_SIZE,
3821
- .max_keysize = AES_MAX_KEY_SIZE,
3822
- .ivsize = AES_BLOCK_SIZE,
3823
- }
3690
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3691
+ .alg.skcipher = {
3692
+ .base.cra_name = "cbc(aes)",
3693
+ .base.cra_driver_name = "cbc-aes-iproc",
3694
+ .base.cra_blocksize = AES_BLOCK_SIZE,
3695
+ .min_keysize = AES_MIN_KEY_SIZE,
3696
+ .max_keysize = AES_MAX_KEY_SIZE,
3697
+ .ivsize = AES_BLOCK_SIZE,
38243698 },
38253699 .cipher_info = {
38263700 .alg = CIPHER_ALG_AES,
....@@ -3832,16 +3706,14 @@
38323706 },
38333707 },
38343708 {
3835
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3836
- .alg.crypto = {
3837
- .cra_name = "ecb(aes)",
3838
- .cra_driver_name = "ecb-aes-iproc",
3839
- .cra_blocksize = AES_BLOCK_SIZE,
3840
- .cra_ablkcipher = {
3841
- .min_keysize = AES_MIN_KEY_SIZE,
3842
- .max_keysize = AES_MAX_KEY_SIZE,
3843
- .ivsize = 0,
3844
- }
3709
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3710
+ .alg.skcipher = {
3711
+ .base.cra_name = "ecb(aes)",
3712
+ .base.cra_driver_name = "ecb-aes-iproc",
3713
+ .base.cra_blocksize = AES_BLOCK_SIZE,
3714
+ .min_keysize = AES_MIN_KEY_SIZE,
3715
+ .max_keysize = AES_MAX_KEY_SIZE,
3716
+ .ivsize = 0,
38453717 },
38463718 .cipher_info = {
38473719 .alg = CIPHER_ALG_AES,
....@@ -3853,17 +3725,14 @@
38533725 },
38543726 },
38553727 {
3856
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3857
- .alg.crypto = {
3858
- .cra_name = "ctr(aes)",
3859
- .cra_driver_name = "ctr-aes-iproc",
3860
- .cra_blocksize = AES_BLOCK_SIZE,
3861
- .cra_ablkcipher = {
3862
- /* .geniv = "chainiv", */
3863
- .min_keysize = AES_MIN_KEY_SIZE,
3864
- .max_keysize = AES_MAX_KEY_SIZE,
3865
- .ivsize = AES_BLOCK_SIZE,
3866
- }
3728
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3729
+ .alg.skcipher = {
3730
+ .base.cra_name = "ctr(aes)",
3731
+ .base.cra_driver_name = "ctr-aes-iproc",
3732
+ .base.cra_blocksize = AES_BLOCK_SIZE,
3733
+ .min_keysize = AES_MIN_KEY_SIZE,
3734
+ .max_keysize = AES_MAX_KEY_SIZE,
3735
+ .ivsize = AES_BLOCK_SIZE,
38673736 },
38683737 .cipher_info = {
38693738 .alg = CIPHER_ALG_AES,
....@@ -3875,16 +3744,14 @@
38753744 },
38763745 },
38773746 {
3878
- .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
3879
- .alg.crypto = {
3880
- .cra_name = "xts(aes)",
3881
- .cra_driver_name = "xts-aes-iproc",
3882
- .cra_blocksize = AES_BLOCK_SIZE,
3883
- .cra_ablkcipher = {
3884
- .min_keysize = 2 * AES_MIN_KEY_SIZE,
3885
- .max_keysize = 2 * AES_MAX_KEY_SIZE,
3886
- .ivsize = AES_BLOCK_SIZE,
3887
- }
3747
+ .type = CRYPTO_ALG_TYPE_SKCIPHER,
3748
+ .alg.skcipher = {
3749
+ .base.cra_name = "xts(aes)",
3750
+ .base.cra_driver_name = "xts-aes-iproc",
3751
+ .base.cra_blocksize = AES_BLOCK_SIZE,
3752
+ .min_keysize = 2 * AES_MIN_KEY_SIZE,
3753
+ .max_keysize = 2 * AES_MAX_KEY_SIZE,
3754
+ .ivsize = AES_BLOCK_SIZE,
38883755 },
38893756 .cipher_info = {
38903757 .alg = CIPHER_ALG_AES,
....@@ -3905,7 +3772,8 @@
39053772 .cra_name = "md5",
39063773 .cra_driver_name = "md5-iproc",
39073774 .cra_blocksize = MD5_BLOCK_WORDS * 4,
3908
- .cra_flags = CRYPTO_ALG_ASYNC,
3775
+ .cra_flags = CRYPTO_ALG_ASYNC |
3776
+ CRYPTO_ALG_ALLOCATES_MEMORY,
39093777 }
39103778 },
39113779 .cipher_info = {
....@@ -4339,16 +4207,17 @@
43394207 return 0;
43404208 }
43414209
4342
-static int ablkcipher_cra_init(struct crypto_tfm *tfm)
4210
+static int skcipher_init_tfm(struct crypto_skcipher *skcipher)
43434211 {
4344
- struct crypto_alg *alg = tfm->__crt_alg;
4212
+ struct crypto_tfm *tfm = crypto_skcipher_tfm(skcipher);
4213
+ struct skcipher_alg *alg = crypto_skcipher_alg(skcipher);
43454214 struct iproc_alg_s *cipher_alg;
43464215
43474216 flow_log("%s()\n", __func__);
43484217
4349
- tfm->crt_ablkcipher.reqsize = sizeof(struct iproc_reqctx_s);
4218
+ crypto_skcipher_set_reqsize(skcipher, sizeof(struct iproc_reqctx_s));
43504219
4351
- cipher_alg = container_of(alg, struct iproc_alg_s, alg.crypto);
4220
+ cipher_alg = container_of(alg, struct iproc_alg_s, alg.skcipher);
43524221 return generic_cra_init(tfm, cipher_alg);
43534222 }
43544223
....@@ -4418,6 +4287,11 @@
44184287 static void generic_cra_exit(struct crypto_tfm *tfm)
44194288 {
44204289 atomic_dec(&iproc_priv.session_count);
4290
+}
4291
+
4292
+static void skcipher_exit_tfm(struct crypto_skcipher *tfm)
4293
+{
4294
+ generic_cra_exit(crypto_skcipher_tfm(tfm));
44214295 }
44224296
44234297 static void aead_cra_exit(struct crypto_aead *aead)
....@@ -4524,7 +4398,7 @@
45244398 for (i = 0; i < iproc_priv.spu.num_chan; i++) {
45254399 iproc_priv.mbox[i] = mbox_request_channel(mcl, i);
45264400 if (IS_ERR(iproc_priv.mbox[i])) {
4527
- err = (int)PTR_ERR(iproc_priv.mbox[i]);
4401
+ err = PTR_ERR(iproc_priv.mbox[i]);
45284402 dev_err(dev,
45294403 "Mbox channel %d request failed with err %d",
45304404 i, err);
....@@ -4581,38 +4455,30 @@
45814455 atomic_set(&iproc_priv.bad_icv, 0);
45824456 }
45834457
4584
-static int spu_register_ablkcipher(struct iproc_alg_s *driver_alg)
4458
+static int spu_register_skcipher(struct iproc_alg_s *driver_alg)
45854459 {
4586
- struct spu_hw *spu = &iproc_priv.spu;
4587
- struct crypto_alg *crypto = &driver_alg->alg.crypto;
4460
+ struct skcipher_alg *crypto = &driver_alg->alg.skcipher;
45884461 int err;
45894462
4590
- /* SPU2 does not support RC4 */
4591
- if ((driver_alg->cipher_info.alg == CIPHER_ALG_RC4) &&
4592
- (spu->spu_type == SPU_TYPE_SPU2))
4593
- return 0;
4463
+ crypto->base.cra_module = THIS_MODULE;
4464
+ crypto->base.cra_priority = cipher_pri;
4465
+ crypto->base.cra_alignmask = 0;
4466
+ crypto->base.cra_ctxsize = sizeof(struct iproc_ctx_s);
4467
+ crypto->base.cra_flags = CRYPTO_ALG_ASYNC |
4468
+ CRYPTO_ALG_ALLOCATES_MEMORY |
4469
+ CRYPTO_ALG_KERN_DRIVER_ONLY;
45944470
4595
- crypto->cra_module = THIS_MODULE;
4596
- crypto->cra_priority = cipher_pri;
4597
- crypto->cra_alignmask = 0;
4598
- crypto->cra_ctxsize = sizeof(struct iproc_ctx_s);
4599
- INIT_LIST_HEAD(&crypto->cra_list);
4471
+ crypto->init = skcipher_init_tfm;
4472
+ crypto->exit = skcipher_exit_tfm;
4473
+ crypto->setkey = skcipher_setkey;
4474
+ crypto->encrypt = skcipher_encrypt;
4475
+ crypto->decrypt = skcipher_decrypt;
46004476
4601
- crypto->cra_init = ablkcipher_cra_init;
4602
- crypto->cra_exit = generic_cra_exit;
4603
- crypto->cra_type = &crypto_ablkcipher_type;
4604
- crypto->cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC |
4605
- CRYPTO_ALG_KERN_DRIVER_ONLY;
4606
-
4607
- crypto->cra_ablkcipher.setkey = ablkcipher_setkey;
4608
- crypto->cra_ablkcipher.encrypt = ablkcipher_encrypt;
4609
- crypto->cra_ablkcipher.decrypt = ablkcipher_decrypt;
4610
-
4611
- err = crypto_register_alg(crypto);
4477
+ err = crypto_register_skcipher(crypto);
46124478 /* Mark alg as having been registered, if successful */
46134479 if (err == 0)
46144480 driver_alg->registered = true;
4615
- pr_debug(" registered ablkcipher %s\n", crypto->cra_driver_name);
4481
+ pr_debug(" registered skcipher %s\n", crypto->base.cra_driver_name);
46164482 return err;
46174483 }
46184484
....@@ -4639,7 +4505,8 @@
46394505 hash->halg.base.cra_ctxsize = sizeof(struct iproc_ctx_s);
46404506 hash->halg.base.cra_init = ahash_cra_init;
46414507 hash->halg.base.cra_exit = generic_cra_exit;
4642
- hash->halg.base.cra_flags = CRYPTO_ALG_ASYNC;
4508
+ hash->halg.base.cra_flags = CRYPTO_ALG_ASYNC |
4509
+ CRYPTO_ALG_ALLOCATES_MEMORY;
46434510 hash->halg.statesize = sizeof(struct spu_hash_export_s);
46444511
46454512 if (driver_alg->auth_info.mode != HASH_MODE_HMAC) {
....@@ -4682,9 +4549,8 @@
46824549 aead->base.cra_priority = aead_pri;
46834550 aead->base.cra_alignmask = 0;
46844551 aead->base.cra_ctxsize = sizeof(struct iproc_ctx_s);
4685
- INIT_LIST_HEAD(&aead->base.cra_list);
46864552
4687
- aead->base.cra_flags |= CRYPTO_ALG_ASYNC;
4553
+ aead->base.cra_flags |= CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY;
46884554 /* setkey set in alg initialization */
46894555 aead->setauthsize = aead_setauthsize;
46904556 aead->encrypt = aead_encrypt;
....@@ -4708,8 +4574,8 @@
47084574
47094575 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
47104576 switch (driver_algs[i].type) {
4711
- case CRYPTO_ALG_TYPE_ABLKCIPHER:
4712
- err = spu_register_ablkcipher(&driver_algs[i]);
4577
+ case CRYPTO_ALG_TYPE_SKCIPHER:
4578
+ err = spu_register_skcipher(&driver_algs[i]);
47134579 break;
47144580 case CRYPTO_ALG_TYPE_AHASH:
47154581 err = spu_register_ahash(&driver_algs[i]);
....@@ -4739,8 +4605,8 @@
47394605 if (!driver_algs[j].registered)
47404606 continue;
47414607 switch (driver_algs[j].type) {
4742
- case CRYPTO_ALG_TYPE_ABLKCIPHER:
4743
- crypto_unregister_alg(&driver_algs[j].alg.crypto);
4608
+ case CRYPTO_ALG_TYPE_SKCIPHER:
4609
+ crypto_unregister_skcipher(&driver_algs[j].alg.skcipher);
47444610 driver_algs[j].registered = false;
47454611 break;
47464612 case CRYPTO_ALG_TYPE_AHASH:
....@@ -4810,21 +4676,20 @@
48104676
48114677 matched_spu_type = of_device_get_match_data(dev);
48124678 if (!matched_spu_type) {
4813
- dev_err(&pdev->dev, "Failed to match device\n");
4679
+ dev_err(dev, "Failed to match device\n");
48144680 return -ENODEV;
48154681 }
48164682
48174683 spu->spu_type = matched_spu_type->type;
48184684 spu->spu_subtype = matched_spu_type->subtype;
48194685
4820
- i = 0;
48214686 for (i = 0; (i < MAX_SPUS) && ((spu_ctrl_regs =
48224687 platform_get_resource(pdev, IORESOURCE_MEM, i)) != NULL); i++) {
48234688
48244689 spu->reg_vbase[i] = devm_ioremap_resource(dev, spu_ctrl_regs);
48254690 if (IS_ERR(spu->reg_vbase[i])) {
48264691 err = PTR_ERR(spu->reg_vbase[i]);
4827
- dev_err(&pdev->dev, "Failed to map registers: %d\n",
4692
+ dev_err(dev, "Failed to map registers: %d\n",
48284693 err);
48294694 spu->reg_vbase[i] = NULL;
48304695 return err;
....@@ -4836,11 +4701,11 @@
48364701 return 0;
48374702 }
48384703
4839
-int bcm_spu_probe(struct platform_device *pdev)
4704
+static int bcm_spu_probe(struct platform_device *pdev)
48404705 {
48414706 struct device *dev = &pdev->dev;
48424707 struct spu_hw *spu = &iproc_priv.spu;
4843
- int err = 0;
4708
+ int err;
48444709
48454710 iproc_priv.pdev = pdev;
48464711 platform_set_drvdata(iproc_priv.pdev,
....@@ -4850,7 +4715,7 @@
48504715 if (err < 0)
48514716 goto failure;
48524717
4853
- err = spu_mb_init(&pdev->dev);
4718
+ err = spu_mb_init(dev);
48544719 if (err < 0)
48554720 goto failure;
48564721
....@@ -4859,7 +4724,7 @@
48594724 else if (spu->spu_type == SPU_TYPE_SPU2)
48604725 iproc_priv.bcm_hdr_len = 0;
48614726
4862
- spu_functions_register(&pdev->dev, spu->spu_type, spu->spu_subtype);
4727
+ spu_functions_register(dev, spu->spu_type, spu->spu_subtype);
48634728
48644729 spu_counters_init();
48654730
....@@ -4880,7 +4745,7 @@
48804745 return err;
48814746 }
48824747
4883
-int bcm_spu_remove(struct platform_device *pdev)
4748
+static int bcm_spu_remove(struct platform_device *pdev)
48844749 {
48854750 int i;
48864751 struct device *dev = &pdev->dev;
....@@ -4896,10 +4761,10 @@
48964761 continue;
48974762
48984763 switch (driver_algs[i].type) {
4899
- case CRYPTO_ALG_TYPE_ABLKCIPHER:
4900
- crypto_unregister_alg(&driver_algs[i].alg.crypto);
4764
+ case CRYPTO_ALG_TYPE_SKCIPHER:
4765
+ crypto_unregister_skcipher(&driver_algs[i].alg.skcipher);
49014766 dev_dbg(dev, " unregistered cipher %s\n",
4902
- driver_algs[i].alg.crypto.cra_driver_name);
4767
+ driver_algs[i].alg.skcipher.base.cra_driver_name);
49034768 driver_algs[i].registered = false;
49044769 break;
49054770 case CRYPTO_ALG_TYPE_AHASH: