hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/picoxcell_crypto.c
....@@ -1,25 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) 2010-2011 Picochip Ltd., Jamie Iles
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 as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
174 */
185 #include <crypto/internal/aead.h>
196 #include <crypto/aes.h>
207 #include <crypto/algapi.h>
218 #include <crypto/authenc.h>
22
-#include <crypto/des.h>
9
+#include <crypto/internal/des.h>
2310 #include <crypto/md5.h>
2411 #include <crypto/sha.h>
2512 #include <crypto/internal/skcipher.h>
....@@ -99,6 +86,7 @@
9986 dma_addr_t src_addr, dst_addr;
10087 struct spacc_ddt *src_ddt, *dst_ddt;
10188 void (*complete)(struct spacc_req *req);
89
+ struct skcipher_request fallback_req; // keep at the end
10290 };
10391
10492 struct spacc_aead {
....@@ -147,7 +135,7 @@
147135 struct spacc_alg {
148136 unsigned long ctrl_default;
149137 unsigned long type;
150
- struct crypto_alg alg;
138
+ struct skcipher_alg alg;
151139 struct spacc_engine *engine;
152140 struct list_head entry;
153141 int key_offs;
....@@ -186,7 +174,7 @@
186174
187175 static int spacc_ablk_submit(struct spacc_req *req);
188176
189
-static inline struct spacc_alg *to_spacc_alg(struct crypto_alg *alg)
177
+static inline struct spacc_alg *to_spacc_skcipher(struct skcipher_alg *alg)
190178 {
191179 return alg ? container_of(alg, struct spacc_alg, alg) : NULL;
192180 }
....@@ -478,9 +466,6 @@
478466 crypto_aead_set_flags(ctx->sw_cipher, crypto_aead_get_flags(tfm) &
479467 CRYPTO_TFM_REQ_MASK);
480468 err = crypto_aead_setkey(ctx->sw_cipher, key, keylen);
481
- crypto_aead_clear_flags(tfm, CRYPTO_TFM_RES_MASK);
482
- crypto_aead_set_flags(tfm, crypto_aead_get_flags(ctx->sw_cipher) &
483
- CRYPTO_TFM_RES_MASK);
484469 if (err)
485470 return err;
486471
....@@ -503,7 +488,6 @@
503488 return 0;
504489
505490 badkey:
506
- crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
507491 memzero_explicit(&keys, sizeof(keys));
508492 return -EINVAL;
509493 }
....@@ -746,23 +730,35 @@
746730 * Set the DES key for a block cipher transform. This also performs weak key
747731 * checking if the transform has requested it.
748732 */
749
-static int spacc_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
733
+static int spacc_des_setkey(struct crypto_skcipher *cipher, const u8 *key,
750734 unsigned int len)
751735 {
752
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
753
- struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
754
- u32 tmp[DES_EXPKEY_WORDS];
736
+ struct spacc_ablk_ctx *ctx = crypto_skcipher_ctx(cipher);
737
+ int err;
755738
756
- if (len > DES3_EDE_KEY_SIZE) {
757
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
758
- return -EINVAL;
759
- }
739
+ err = verify_skcipher_des_key(cipher, key);
740
+ if (err)
741
+ return err;
760742
761
- if (unlikely(!des_ekey(tmp, key)) &&
762
- (crypto_ablkcipher_get_flags(cipher) & CRYPTO_TFM_REQ_WEAK_KEY)) {
763
- tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
764
- return -EINVAL;
765
- }
743
+ memcpy(ctx->key, key, len);
744
+ ctx->key_len = len;
745
+
746
+ return 0;
747
+}
748
+
749
+/*
750
+ * Set the 3DES key for a block cipher transform. This also performs weak key
751
+ * checking if the transform has requested it.
752
+ */
753
+static int spacc_des3_setkey(struct crypto_skcipher *cipher, const u8 *key,
754
+ unsigned int len)
755
+{
756
+ struct spacc_ablk_ctx *ctx = crypto_skcipher_ctx(cipher);
757
+ int err;
758
+
759
+ err = verify_skcipher_des3_key(cipher, key);
760
+ if (err)
761
+ return err;
766762
767763 memcpy(ctx->key, key, len);
768764 ctx->key_len = len;
....@@ -774,17 +770,15 @@
774770 * Set the key for an AES block cipher. Some key lengths are not supported in
775771 * hardware so this must also check whether a fallback is needed.
776772 */
777
-static int spacc_aes_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
773
+static int spacc_aes_setkey(struct crypto_skcipher *cipher, const u8 *key,
778774 unsigned int len)
779775 {
780
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
776
+ struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
781777 struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
782778 int err = 0;
783779
784
- if (len > AES_MAX_KEY_SIZE) {
785
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
780
+ if (len > AES_MAX_KEY_SIZE)
786781 return -EINVAL;
787
- }
788782
789783 /*
790784 * IPSec engine only supports 128 and 256 bit AES keys. If we get a
....@@ -806,12 +800,6 @@
806800 CRYPTO_TFM_REQ_MASK);
807801
808802 err = crypto_skcipher_setkey(ctx->sw_cipher, key, len);
809
-
810
- tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
811
- tfm->crt_flags |=
812
- crypto_skcipher_get_flags(ctx->sw_cipher) &
813
- CRYPTO_TFM_RES_MASK;
814
-
815803 if (err)
816804 goto sw_setkey_failed;
817805 }
....@@ -823,15 +811,14 @@
823811 return err;
824812 }
825813
826
-static int spacc_kasumi_f8_setkey(struct crypto_ablkcipher *cipher,
814
+static int spacc_kasumi_f8_setkey(struct crypto_skcipher *cipher,
827815 const u8 *key, unsigned int len)
828816 {
829
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
817
+ struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
830818 struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
831819 int err = 0;
832820
833821 if (len > AES_MAX_KEY_SIZE) {
834
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
835822 err = -EINVAL;
836823 goto out;
837824 }
....@@ -845,12 +832,12 @@
845832
846833 static int spacc_ablk_need_fallback(struct spacc_req *req)
847834 {
835
+ struct skcipher_request *ablk_req = skcipher_request_cast(req->req);
836
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ablk_req);
837
+ struct spacc_alg *spacc_alg = to_spacc_skcipher(crypto_skcipher_alg(tfm));
848838 struct spacc_ablk_ctx *ctx;
849
- struct crypto_tfm *tfm = req->req->tfm;
850
- struct crypto_alg *alg = req->req->tfm->__crt_alg;
851
- struct spacc_alg *spacc_alg = to_spacc_alg(alg);
852839
853
- ctx = crypto_tfm_ctx(tfm);
840
+ ctx = crypto_skcipher_ctx(tfm);
854841
855842 return (spacc_alg->ctrl_default & SPACC_CRYPTO_ALG_MASK) ==
856843 SPA_CTRL_CIPH_ALG_AES &&
....@@ -860,39 +847,39 @@
860847
861848 static void spacc_ablk_complete(struct spacc_req *req)
862849 {
863
- struct ablkcipher_request *ablk_req = ablkcipher_request_cast(req->req);
850
+ struct skcipher_request *ablk_req = skcipher_request_cast(req->req);
864851
865852 if (ablk_req->src != ablk_req->dst) {
866853 spacc_free_ddt(req, req->src_ddt, req->src_addr, ablk_req->src,
867
- ablk_req->nbytes, DMA_TO_DEVICE);
854
+ ablk_req->cryptlen, DMA_TO_DEVICE);
868855 spacc_free_ddt(req, req->dst_ddt, req->dst_addr, ablk_req->dst,
869
- ablk_req->nbytes, DMA_FROM_DEVICE);
856
+ ablk_req->cryptlen, DMA_FROM_DEVICE);
870857 } else
871858 spacc_free_ddt(req, req->dst_ddt, req->dst_addr, ablk_req->dst,
872
- ablk_req->nbytes, DMA_BIDIRECTIONAL);
859
+ ablk_req->cryptlen, DMA_BIDIRECTIONAL);
873860
874861 req->req->complete(req->req, req->result);
875862 }
876863
877864 static int spacc_ablk_submit(struct spacc_req *req)
878865 {
879
- struct crypto_tfm *tfm = req->req->tfm;
880
- struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
881
- struct ablkcipher_request *ablk_req = ablkcipher_request_cast(req->req);
882
- struct crypto_alg *alg = req->req->tfm->__crt_alg;
883
- struct spacc_alg *spacc_alg = to_spacc_alg(alg);
866
+ struct skcipher_request *ablk_req = skcipher_request_cast(req->req);
867
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ablk_req);
868
+ struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
869
+ struct spacc_alg *spacc_alg = to_spacc_skcipher(alg);
870
+ struct spacc_ablk_ctx *ctx = crypto_skcipher_ctx(tfm);
884871 struct spacc_engine *engine = ctx->generic.engine;
885872 u32 ctrl;
886873
887874 req->ctx_id = spacc_load_ctx(&ctx->generic, ctx->key,
888
- ctx->key_len, ablk_req->info, alg->cra_ablkcipher.ivsize,
875
+ ctx->key_len, ablk_req->iv, alg->ivsize,
889876 NULL, 0);
890877
891878 writel(req->src_addr, engine->regs + SPA_SRC_PTR_REG_OFFSET);
892879 writel(req->dst_addr, engine->regs + SPA_DST_PTR_REG_OFFSET);
893880 writel(0, engine->regs + SPA_OFFSET_REG_OFFSET);
894881
895
- writel(ablk_req->nbytes, engine->regs + SPA_PROC_LEN_REG_OFFSET);
882
+ writel(ablk_req->cryptlen, engine->regs + SPA_PROC_LEN_REG_OFFSET);
896883 writel(0, engine->regs + SPA_ICV_OFFSET_REG_OFFSET);
897884 writel(0, engine->regs + SPA_AUX_INFO_REG_OFFSET);
898885 writel(0, engine->regs + SPA_AAD_LEN_REG_OFFSET);
....@@ -908,13 +895,13 @@
908895 return -EINPROGRESS;
909896 }
910897
911
-static int spacc_ablk_do_fallback(struct ablkcipher_request *req,
898
+static int spacc_ablk_do_fallback(struct skcipher_request *req,
912899 unsigned alg_type, bool is_encrypt)
913900 {
914901 struct crypto_tfm *old_tfm =
915
- crypto_ablkcipher_tfm(crypto_ablkcipher_reqtfm(req));
902
+ crypto_skcipher_tfm(crypto_skcipher_reqtfm(req));
916903 struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(old_tfm);
917
- SKCIPHER_REQUEST_ON_STACK(subreq, ctx->sw_cipher);
904
+ struct spacc_req *dev_req = skcipher_request_ctx(req);
918905 int err;
919906
920907 /*
....@@ -922,23 +909,24 @@
922909 * the ciphering has completed, put the old transform back into the
923910 * request.
924911 */
925
- skcipher_request_set_tfm(subreq, ctx->sw_cipher);
926
- skcipher_request_set_callback(subreq, req->base.flags, NULL, NULL);
927
- skcipher_request_set_crypt(subreq, req->src, req->dst,
928
- req->nbytes, req->info);
929
- err = is_encrypt ? crypto_skcipher_encrypt(subreq) :
930
- crypto_skcipher_decrypt(subreq);
931
- skcipher_request_zero(subreq);
912
+ skcipher_request_set_tfm(&dev_req->fallback_req, ctx->sw_cipher);
913
+ skcipher_request_set_callback(&dev_req->fallback_req, req->base.flags,
914
+ req->base.complete, req->base.data);
915
+ skcipher_request_set_crypt(&dev_req->fallback_req, req->src, req->dst,
916
+ req->cryptlen, req->iv);
917
+ err = is_encrypt ? crypto_skcipher_encrypt(&dev_req->fallback_req) :
918
+ crypto_skcipher_decrypt(&dev_req->fallback_req);
932919
933920 return err;
934921 }
935922
936
-static int spacc_ablk_setup(struct ablkcipher_request *req, unsigned alg_type,
923
+static int spacc_ablk_setup(struct skcipher_request *req, unsigned alg_type,
937924 bool is_encrypt)
938925 {
939
- struct crypto_alg *alg = req->base.tfm->__crt_alg;
940
- struct spacc_engine *engine = to_spacc_alg(alg)->engine;
941
- struct spacc_req *dev_req = ablkcipher_request_ctx(req);
926
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
927
+ struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
928
+ struct spacc_engine *engine = to_spacc_skcipher(alg)->engine;
929
+ struct spacc_req *dev_req = skcipher_request_ctx(req);
942930 unsigned long flags;
943931 int err = -ENOMEM;
944932
....@@ -957,17 +945,17 @@
957945 */
958946 if (req->src != req->dst) {
959947 dev_req->src_ddt = spacc_sg_to_ddt(engine, req->src,
960
- req->nbytes, DMA_TO_DEVICE, &dev_req->src_addr);
948
+ req->cryptlen, DMA_TO_DEVICE, &dev_req->src_addr);
961949 if (!dev_req->src_ddt)
962950 goto out;
963951
964952 dev_req->dst_ddt = spacc_sg_to_ddt(engine, req->dst,
965
- req->nbytes, DMA_FROM_DEVICE, &dev_req->dst_addr);
953
+ req->cryptlen, DMA_FROM_DEVICE, &dev_req->dst_addr);
966954 if (!dev_req->dst_ddt)
967955 goto out_free_src;
968956 } else {
969957 dev_req->dst_ddt = spacc_sg_to_ddt(engine, req->dst,
970
- req->nbytes, DMA_BIDIRECTIONAL, &dev_req->dst_addr);
958
+ req->cryptlen, DMA_BIDIRECTIONAL, &dev_req->dst_addr);
971959 if (!dev_req->dst_ddt)
972960 goto out;
973961
....@@ -1000,66 +988,70 @@
1000988
1001989 out_free_ddts:
1002990 spacc_free_ddt(dev_req, dev_req->dst_ddt, dev_req->dst_addr, req->dst,
1003
- req->nbytes, req->src == req->dst ?
991
+ req->cryptlen, req->src == req->dst ?
1004992 DMA_BIDIRECTIONAL : DMA_FROM_DEVICE);
1005993 out_free_src:
1006994 if (req->src != req->dst)
1007995 spacc_free_ddt(dev_req, dev_req->src_ddt, dev_req->src_addr,
1008
- req->src, req->nbytes, DMA_TO_DEVICE);
996
+ req->src, req->cryptlen, DMA_TO_DEVICE);
1009997 out:
1010998 return err;
1011999 }
10121000
1013
-static int spacc_ablk_cra_init(struct crypto_tfm *tfm)
1001
+static int spacc_ablk_init_tfm(struct crypto_skcipher *tfm)
10141002 {
1015
- struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
1016
- struct crypto_alg *alg = tfm->__crt_alg;
1017
- struct spacc_alg *spacc_alg = to_spacc_alg(alg);
1003
+ struct spacc_ablk_ctx *ctx = crypto_skcipher_ctx(tfm);
1004
+ struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
1005
+ struct spacc_alg *spacc_alg = to_spacc_skcipher(alg);
10181006 struct spacc_engine *engine = spacc_alg->engine;
10191007
10201008 ctx->generic.flags = spacc_alg->type;
10211009 ctx->generic.engine = engine;
1022
- if (alg->cra_flags & CRYPTO_ALG_NEED_FALLBACK) {
1023
- ctx->sw_cipher = crypto_alloc_skcipher(
1024
- alg->cra_name, 0, CRYPTO_ALG_ASYNC |
1025
- CRYPTO_ALG_NEED_FALLBACK);
1010
+ if (alg->base.cra_flags & CRYPTO_ALG_NEED_FALLBACK) {
1011
+ ctx->sw_cipher = crypto_alloc_skcipher(alg->base.cra_name, 0,
1012
+ CRYPTO_ALG_NEED_FALLBACK);
10261013 if (IS_ERR(ctx->sw_cipher)) {
10271014 dev_warn(engine->dev, "failed to allocate fallback for %s\n",
1028
- alg->cra_name);
1015
+ alg->base.cra_name);
10291016 return PTR_ERR(ctx->sw_cipher);
10301017 }
1018
+ crypto_skcipher_set_reqsize(tfm, sizeof(struct spacc_req) +
1019
+ crypto_skcipher_reqsize(ctx->sw_cipher));
1020
+ } else {
1021
+ /* take the size without the fallback skcipher_request at the end */
1022
+ crypto_skcipher_set_reqsize(tfm, offsetof(struct spacc_req,
1023
+ fallback_req));
10311024 }
1025
+
10321026 ctx->generic.key_offs = spacc_alg->key_offs;
10331027 ctx->generic.iv_offs = spacc_alg->iv_offs;
1034
-
1035
- tfm->crt_ablkcipher.reqsize = sizeof(struct spacc_req);
10361028
10371029 return 0;
10381030 }
10391031
1040
-static void spacc_ablk_cra_exit(struct crypto_tfm *tfm)
1032
+static void spacc_ablk_exit_tfm(struct crypto_skcipher *tfm)
10411033 {
1042
- struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
1034
+ struct spacc_ablk_ctx *ctx = crypto_skcipher_ctx(tfm);
10431035
10441036 crypto_free_skcipher(ctx->sw_cipher);
10451037 }
10461038
1047
-static int spacc_ablk_encrypt(struct ablkcipher_request *req)
1039
+static int spacc_ablk_encrypt(struct skcipher_request *req)
10481040 {
1049
- struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(req);
1050
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
1051
- struct spacc_alg *alg = to_spacc_alg(tfm->__crt_alg);
1041
+ struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req);
1042
+ struct skcipher_alg *alg = crypto_skcipher_alg(cipher);
1043
+ struct spacc_alg *spacc_alg = to_spacc_skcipher(alg);
10521044
1053
- return spacc_ablk_setup(req, alg->type, 1);
1045
+ return spacc_ablk_setup(req, spacc_alg->type, 1);
10541046 }
10551047
1056
-static int spacc_ablk_decrypt(struct ablkcipher_request *req)
1048
+static int spacc_ablk_decrypt(struct skcipher_request *req)
10571049 {
1058
- struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(req);
1059
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
1060
- struct spacc_alg *alg = to_spacc_alg(tfm->__crt_alg);
1050
+ struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req);
1051
+ struct skcipher_alg *alg = crypto_skcipher_alg(cipher);
1052
+ struct spacc_alg *spacc_alg = to_spacc_skcipher(alg);
10611053
1062
- return spacc_ablk_setup(req, alg->type, 0);
1054
+ return spacc_ablk_setup(req, spacc_alg->type, 0);
10631055 }
10641056
10651057 static inline int spacc_fifo_stat_empty(struct spacc_engine *engine)
....@@ -1196,7 +1188,7 @@
11961188
11971189 static inline struct spacc_engine *spacc_dev_to_engine(struct device *dev)
11981190 {
1199
- return dev ? platform_get_drvdata(to_platform_device(dev)) : NULL;
1191
+ return dev ? dev_get_drvdata(dev) : NULL;
12001192 }
12011193
12021194 static ssize_t spacc_stat_irq_thresh_show(struct device *dev,
....@@ -1235,27 +1227,25 @@
12351227 .key_offs = 0,
12361228 .iv_offs = AES_MAX_KEY_SIZE,
12371229 .alg = {
1238
- .cra_name = "cbc(aes)",
1239
- .cra_driver_name = "cbc-aes-picoxcell",
1240
- .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1241
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1242
- CRYPTO_ALG_KERN_DRIVER_ONLY |
1243
- CRYPTO_ALG_ASYNC |
1244
- CRYPTO_ALG_NEED_FALLBACK,
1245
- .cra_blocksize = AES_BLOCK_SIZE,
1246
- .cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1247
- .cra_type = &crypto_ablkcipher_type,
1248
- .cra_module = THIS_MODULE,
1249
- .cra_ablkcipher = {
1250
- .setkey = spacc_aes_setkey,
1251
- .encrypt = spacc_ablk_encrypt,
1252
- .decrypt = spacc_ablk_decrypt,
1253
- .min_keysize = AES_MIN_KEY_SIZE,
1254
- .max_keysize = AES_MAX_KEY_SIZE,
1255
- .ivsize = AES_BLOCK_SIZE,
1256
- },
1257
- .cra_init = spacc_ablk_cra_init,
1258
- .cra_exit = spacc_ablk_cra_exit,
1230
+ .base.cra_name = "cbc(aes)",
1231
+ .base.cra_driver_name = "cbc-aes-picoxcell",
1232
+ .base.cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1233
+ .base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
1234
+ CRYPTO_ALG_ASYNC |
1235
+ CRYPTO_ALG_ALLOCATES_MEMORY |
1236
+ CRYPTO_ALG_NEED_FALLBACK,
1237
+ .base.cra_blocksize = AES_BLOCK_SIZE,
1238
+ .base.cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1239
+ .base.cra_module = THIS_MODULE,
1240
+
1241
+ .setkey = spacc_aes_setkey,
1242
+ .encrypt = spacc_ablk_encrypt,
1243
+ .decrypt = spacc_ablk_decrypt,
1244
+ .min_keysize = AES_MIN_KEY_SIZE,
1245
+ .max_keysize = AES_MAX_KEY_SIZE,
1246
+ .ivsize = AES_BLOCK_SIZE,
1247
+ .init = spacc_ablk_init_tfm,
1248
+ .exit = spacc_ablk_exit_tfm,
12591249 },
12601250 },
12611251 {
....@@ -1263,25 +1253,24 @@
12631253 .iv_offs = AES_MAX_KEY_SIZE,
12641254 .ctrl_default = SPA_CTRL_CIPH_ALG_AES | SPA_CTRL_CIPH_MODE_ECB,
12651255 .alg = {
1266
- .cra_name = "ecb(aes)",
1267
- .cra_driver_name = "ecb-aes-picoxcell",
1268
- .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1269
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1270
- CRYPTO_ALG_KERN_DRIVER_ONLY |
1271
- CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
1272
- .cra_blocksize = AES_BLOCK_SIZE,
1273
- .cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1274
- .cra_type = &crypto_ablkcipher_type,
1275
- .cra_module = THIS_MODULE,
1276
- .cra_ablkcipher = {
1277
- .setkey = spacc_aes_setkey,
1278
- .encrypt = spacc_ablk_encrypt,
1279
- .decrypt = spacc_ablk_decrypt,
1280
- .min_keysize = AES_MIN_KEY_SIZE,
1281
- .max_keysize = AES_MAX_KEY_SIZE,
1282
- },
1283
- .cra_init = spacc_ablk_cra_init,
1284
- .cra_exit = spacc_ablk_cra_exit,
1256
+ .base.cra_name = "ecb(aes)",
1257
+ .base.cra_driver_name = "ecb-aes-picoxcell",
1258
+ .base.cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1259
+ .base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
1260
+ CRYPTO_ALG_ASYNC |
1261
+ CRYPTO_ALG_ALLOCATES_MEMORY |
1262
+ CRYPTO_ALG_NEED_FALLBACK,
1263
+ .base.cra_blocksize = AES_BLOCK_SIZE,
1264
+ .base.cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1265
+ .base.cra_module = THIS_MODULE,
1266
+
1267
+ .setkey = spacc_aes_setkey,
1268
+ .encrypt = spacc_ablk_encrypt,
1269
+ .decrypt = spacc_ablk_decrypt,
1270
+ .min_keysize = AES_MIN_KEY_SIZE,
1271
+ .max_keysize = AES_MAX_KEY_SIZE,
1272
+ .init = spacc_ablk_init_tfm,
1273
+ .exit = spacc_ablk_exit_tfm,
12851274 },
12861275 },
12871276 {
....@@ -1289,26 +1278,24 @@
12891278 .iv_offs = 0,
12901279 .ctrl_default = SPA_CTRL_CIPH_ALG_DES | SPA_CTRL_CIPH_MODE_CBC,
12911280 .alg = {
1292
- .cra_name = "cbc(des)",
1293
- .cra_driver_name = "cbc-des-picoxcell",
1294
- .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1295
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1296
- CRYPTO_ALG_ASYNC |
1297
- CRYPTO_ALG_KERN_DRIVER_ONLY,
1298
- .cra_blocksize = DES_BLOCK_SIZE,
1299
- .cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1300
- .cra_type = &crypto_ablkcipher_type,
1301
- .cra_module = THIS_MODULE,
1302
- .cra_ablkcipher = {
1303
- .setkey = spacc_des_setkey,
1304
- .encrypt = spacc_ablk_encrypt,
1305
- .decrypt = spacc_ablk_decrypt,
1306
- .min_keysize = DES_KEY_SIZE,
1307
- .max_keysize = DES_KEY_SIZE,
1308
- .ivsize = DES_BLOCK_SIZE,
1309
- },
1310
- .cra_init = spacc_ablk_cra_init,
1311
- .cra_exit = spacc_ablk_cra_exit,
1281
+ .base.cra_name = "cbc(des)",
1282
+ .base.cra_driver_name = "cbc-des-picoxcell",
1283
+ .base.cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1284
+ .base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
1285
+ CRYPTO_ALG_ASYNC |
1286
+ CRYPTO_ALG_ALLOCATES_MEMORY,
1287
+ .base.cra_blocksize = DES_BLOCK_SIZE,
1288
+ .base.cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1289
+ .base.cra_module = THIS_MODULE,
1290
+
1291
+ .setkey = spacc_des_setkey,
1292
+ .encrypt = spacc_ablk_encrypt,
1293
+ .decrypt = spacc_ablk_decrypt,
1294
+ .min_keysize = DES_KEY_SIZE,
1295
+ .max_keysize = DES_KEY_SIZE,
1296
+ .ivsize = DES_BLOCK_SIZE,
1297
+ .init = spacc_ablk_init_tfm,
1298
+ .exit = spacc_ablk_exit_tfm,
13121299 },
13131300 },
13141301 {
....@@ -1316,25 +1303,23 @@
13161303 .iv_offs = 0,
13171304 .ctrl_default = SPA_CTRL_CIPH_ALG_DES | SPA_CTRL_CIPH_MODE_ECB,
13181305 .alg = {
1319
- .cra_name = "ecb(des)",
1320
- .cra_driver_name = "ecb-des-picoxcell",
1321
- .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1322
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1323
- CRYPTO_ALG_ASYNC |
1324
- CRYPTO_ALG_KERN_DRIVER_ONLY,
1325
- .cra_blocksize = DES_BLOCK_SIZE,
1326
- .cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1327
- .cra_type = &crypto_ablkcipher_type,
1328
- .cra_module = THIS_MODULE,
1329
- .cra_ablkcipher = {
1330
- .setkey = spacc_des_setkey,
1331
- .encrypt = spacc_ablk_encrypt,
1332
- .decrypt = spacc_ablk_decrypt,
1333
- .min_keysize = DES_KEY_SIZE,
1334
- .max_keysize = DES_KEY_SIZE,
1335
- },
1336
- .cra_init = spacc_ablk_cra_init,
1337
- .cra_exit = spacc_ablk_cra_exit,
1306
+ .base.cra_name = "ecb(des)",
1307
+ .base.cra_driver_name = "ecb-des-picoxcell",
1308
+ .base.cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1309
+ .base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY |
1310
+ CRYPTO_ALG_ASYNC |
1311
+ CRYPTO_ALG_ALLOCATES_MEMORY,
1312
+ .base.cra_blocksize = DES_BLOCK_SIZE,
1313
+ .base.cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1314
+ .base.cra_module = THIS_MODULE,
1315
+
1316
+ .setkey = spacc_des_setkey,
1317
+ .encrypt = spacc_ablk_encrypt,
1318
+ .decrypt = spacc_ablk_decrypt,
1319
+ .min_keysize = DES_KEY_SIZE,
1320
+ .max_keysize = DES_KEY_SIZE,
1321
+ .init = spacc_ablk_init_tfm,
1322
+ .exit = spacc_ablk_exit_tfm,
13381323 },
13391324 },
13401325 {
....@@ -1342,26 +1327,24 @@
13421327 .iv_offs = 0,
13431328 .ctrl_default = SPA_CTRL_CIPH_ALG_DES | SPA_CTRL_CIPH_MODE_CBC,
13441329 .alg = {
1345
- .cra_name = "cbc(des3_ede)",
1346
- .cra_driver_name = "cbc-des3-ede-picoxcell",
1347
- .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1348
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1349
- CRYPTO_ALG_ASYNC |
1350
- CRYPTO_ALG_KERN_DRIVER_ONLY,
1351
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1352
- .cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1353
- .cra_type = &crypto_ablkcipher_type,
1354
- .cra_module = THIS_MODULE,
1355
- .cra_ablkcipher = {
1356
- .setkey = spacc_des_setkey,
1357
- .encrypt = spacc_ablk_encrypt,
1358
- .decrypt = spacc_ablk_decrypt,
1359
- .min_keysize = DES3_EDE_KEY_SIZE,
1360
- .max_keysize = DES3_EDE_KEY_SIZE,
1361
- .ivsize = DES3_EDE_BLOCK_SIZE,
1362
- },
1363
- .cra_init = spacc_ablk_cra_init,
1364
- .cra_exit = spacc_ablk_cra_exit,
1330
+ .base.cra_name = "cbc(des3_ede)",
1331
+ .base.cra_driver_name = "cbc-des3-ede-picoxcell",
1332
+ .base.cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1333
+ .base.cra_flags = CRYPTO_ALG_ASYNC |
1334
+ CRYPTO_ALG_ALLOCATES_MEMORY |
1335
+ CRYPTO_ALG_KERN_DRIVER_ONLY,
1336
+ .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
1337
+ .base.cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1338
+ .base.cra_module = THIS_MODULE,
1339
+
1340
+ .setkey = spacc_des3_setkey,
1341
+ .encrypt = spacc_ablk_encrypt,
1342
+ .decrypt = spacc_ablk_decrypt,
1343
+ .min_keysize = DES3_EDE_KEY_SIZE,
1344
+ .max_keysize = DES3_EDE_KEY_SIZE,
1345
+ .ivsize = DES3_EDE_BLOCK_SIZE,
1346
+ .init = spacc_ablk_init_tfm,
1347
+ .exit = spacc_ablk_exit_tfm,
13651348 },
13661349 },
13671350 {
....@@ -1369,25 +1352,23 @@
13691352 .iv_offs = 0,
13701353 .ctrl_default = SPA_CTRL_CIPH_ALG_DES | SPA_CTRL_CIPH_MODE_ECB,
13711354 .alg = {
1372
- .cra_name = "ecb(des3_ede)",
1373
- .cra_driver_name = "ecb-des3-ede-picoxcell",
1374
- .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1375
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1376
- CRYPTO_ALG_ASYNC |
1377
- CRYPTO_ALG_KERN_DRIVER_ONLY,
1378
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1379
- .cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1380
- .cra_type = &crypto_ablkcipher_type,
1381
- .cra_module = THIS_MODULE,
1382
- .cra_ablkcipher = {
1383
- .setkey = spacc_des_setkey,
1384
- .encrypt = spacc_ablk_encrypt,
1385
- .decrypt = spacc_ablk_decrypt,
1386
- .min_keysize = DES3_EDE_KEY_SIZE,
1387
- .max_keysize = DES3_EDE_KEY_SIZE,
1388
- },
1389
- .cra_init = spacc_ablk_cra_init,
1390
- .cra_exit = spacc_ablk_cra_exit,
1355
+ .base.cra_name = "ecb(des3_ede)",
1356
+ .base.cra_driver_name = "ecb-des3-ede-picoxcell",
1357
+ .base.cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1358
+ .base.cra_flags = CRYPTO_ALG_ASYNC |
1359
+ CRYPTO_ALG_ALLOCATES_MEMORY |
1360
+ CRYPTO_ALG_KERN_DRIVER_ONLY,
1361
+ .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
1362
+ .base.cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1363
+ .base.cra_module = THIS_MODULE,
1364
+
1365
+ .setkey = spacc_des3_setkey,
1366
+ .encrypt = spacc_ablk_encrypt,
1367
+ .decrypt = spacc_ablk_decrypt,
1368
+ .min_keysize = DES3_EDE_KEY_SIZE,
1369
+ .max_keysize = DES3_EDE_KEY_SIZE,
1370
+ .init = spacc_ablk_init_tfm,
1371
+ .exit = spacc_ablk_exit_tfm,
13911372 },
13921373 },
13931374 };
....@@ -1407,6 +1388,7 @@
14071388 "cbc-aes-picoxcell",
14081389 .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
14091390 .cra_flags = CRYPTO_ALG_ASYNC |
1391
+ CRYPTO_ALG_ALLOCATES_MEMORY |
14101392 CRYPTO_ALG_NEED_FALLBACK |
14111393 CRYPTO_ALG_KERN_DRIVER_ONLY,
14121394 .cra_blocksize = AES_BLOCK_SIZE,
....@@ -1437,6 +1419,7 @@
14371419 "cbc-aes-picoxcell",
14381420 .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
14391421 .cra_flags = CRYPTO_ALG_ASYNC |
1422
+ CRYPTO_ALG_ALLOCATES_MEMORY |
14401423 CRYPTO_ALG_NEED_FALLBACK |
14411424 CRYPTO_ALG_KERN_DRIVER_ONLY,
14421425 .cra_blocksize = AES_BLOCK_SIZE,
....@@ -1467,6 +1450,7 @@
14671450 "cbc-aes-picoxcell",
14681451 .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
14691452 .cra_flags = CRYPTO_ALG_ASYNC |
1453
+ CRYPTO_ALG_ALLOCATES_MEMORY |
14701454 CRYPTO_ALG_NEED_FALLBACK |
14711455 CRYPTO_ALG_KERN_DRIVER_ONLY,
14721456 .cra_blocksize = AES_BLOCK_SIZE,
....@@ -1497,6 +1481,7 @@
14971481 "cbc-3des-picoxcell",
14981482 .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
14991483 .cra_flags = CRYPTO_ALG_ASYNC |
1484
+ CRYPTO_ALG_ALLOCATES_MEMORY |
15001485 CRYPTO_ALG_NEED_FALLBACK |
15011486 CRYPTO_ALG_KERN_DRIVER_ONLY,
15021487 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
....@@ -1528,6 +1513,7 @@
15281513 "cbc-3des-picoxcell",
15291514 .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
15301515 .cra_flags = CRYPTO_ALG_ASYNC |
1516
+ CRYPTO_ALG_ALLOCATES_MEMORY |
15311517 CRYPTO_ALG_NEED_FALLBACK |
15321518 CRYPTO_ALG_KERN_DRIVER_ONLY,
15331519 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
....@@ -1558,6 +1544,7 @@
15581544 "cbc-3des-picoxcell",
15591545 .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
15601546 .cra_flags = CRYPTO_ALG_ASYNC |
1547
+ CRYPTO_ALG_ALLOCATES_MEMORY |
15611548 CRYPTO_ALG_NEED_FALLBACK |
15621549 CRYPTO_ALG_KERN_DRIVER_ONLY,
15631550 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
....@@ -1583,26 +1570,24 @@
15831570 .ctrl_default = SPA_CTRL_CIPH_ALG_KASUMI |
15841571 SPA_CTRL_CIPH_MODE_F8,
15851572 .alg = {
1586
- .cra_name = "f8(kasumi)",
1587
- .cra_driver_name = "f8-kasumi-picoxcell",
1588
- .cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1589
- .cra_flags = CRYPTO_ALG_TYPE_GIVCIPHER |
1590
- CRYPTO_ALG_ASYNC |
1591
- CRYPTO_ALG_KERN_DRIVER_ONLY,
1592
- .cra_blocksize = 8,
1593
- .cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1594
- .cra_type = &crypto_ablkcipher_type,
1595
- .cra_module = THIS_MODULE,
1596
- .cra_ablkcipher = {
1597
- .setkey = spacc_kasumi_f8_setkey,
1598
- .encrypt = spacc_ablk_encrypt,
1599
- .decrypt = spacc_ablk_decrypt,
1600
- .min_keysize = 16,
1601
- .max_keysize = 16,
1602
- .ivsize = 8,
1603
- },
1604
- .cra_init = spacc_ablk_cra_init,
1605
- .cra_exit = spacc_ablk_cra_exit,
1573
+ .base.cra_name = "f8(kasumi)",
1574
+ .base.cra_driver_name = "f8-kasumi-picoxcell",
1575
+ .base.cra_priority = SPACC_CRYPTO_ALG_PRIORITY,
1576
+ .base.cra_flags = CRYPTO_ALG_ASYNC |
1577
+ CRYPTO_ALG_ALLOCATES_MEMORY |
1578
+ CRYPTO_ALG_KERN_DRIVER_ONLY,
1579
+ .base.cra_blocksize = 8,
1580
+ .base.cra_ctxsize = sizeof(struct spacc_ablk_ctx),
1581
+ .base.cra_module = THIS_MODULE,
1582
+
1583
+ .setkey = spacc_kasumi_f8_setkey,
1584
+ .encrypt = spacc_ablk_encrypt,
1585
+ .decrypt = spacc_ablk_decrypt,
1586
+ .min_keysize = 16,
1587
+ .max_keysize = 16,
1588
+ .ivsize = 8,
1589
+ .init = spacc_ablk_init_tfm,
1590
+ .exit = spacc_ablk_exit_tfm,
16061591 },
16071592 },
16081593 };
....@@ -1624,7 +1609,7 @@
16241609 static int spacc_probe(struct platform_device *pdev)
16251610 {
16261611 int i, err, ret;
1627
- struct resource *mem, *irq;
1612
+ struct resource *irq;
16281613 struct device_node *np = pdev->dev.of_node;
16291614 struct spacc_engine *engine = devm_kzalloc(&pdev->dev, sizeof(*engine),
16301615 GFP_KERNEL);
....@@ -1653,8 +1638,7 @@
16531638
16541639 engine->name = dev_name(&pdev->dev);
16551640
1656
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1657
- engine->regs = devm_ioremap_resource(&pdev->dev, mem);
1641
+ engine->regs = devm_platform_ioremap_resource(pdev, 0);
16581642 if (IS_ERR(engine->regs))
16591643 return PTR_ERR(engine->regs);
16601644
....@@ -1735,7 +1719,7 @@
17351719 INIT_LIST_HEAD(&engine->registered_algs);
17361720 for (i = 0; i < engine->num_algs; ++i) {
17371721 engine->algs[i].engine = engine;
1738
- err = crypto_register_alg(&engine->algs[i].alg);
1722
+ err = crypto_register_skcipher(&engine->algs[i].alg);
17391723 if (!err) {
17401724 list_add_tail(&engine->algs[i].entry,
17411725 &engine->registered_algs);
....@@ -1743,10 +1727,10 @@
17431727 }
17441728 if (err)
17451729 dev_err(engine->dev, "failed to register alg \"%s\"\n",
1746
- engine->algs[i].alg.cra_name);
1730
+ engine->algs[i].alg.base.cra_name);
17471731 else
17481732 dev_dbg(engine->dev, "registered alg \"%s\"\n",
1749
- engine->algs[i].alg.cra_name);
1733
+ engine->algs[i].alg.base.cra_name);
17501734 }
17511735
17521736 INIT_LIST_HEAD(&engine->registered_aeads);
....@@ -1795,7 +1779,7 @@
17951779
17961780 list_for_each_entry_safe(alg, next, &engine->registered_algs, entry) {
17971781 list_del(&alg->entry);
1798
- crypto_unregister_alg(&alg->alg);
1782
+ crypto_unregister_skcipher(&alg->alg);
17991783 }
18001784
18011785 clk_disable_unprepare(engine->clk);