hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/n2_core.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* n2_core.c: Niagara2 Stream Processing Unit (SPU) crypto support.
23 *
34 * Copyright (C) 2010, 2011 David S. Miller <davem@davemloft.net>
....@@ -16,12 +17,13 @@
1617 #include <crypto/md5.h>
1718 #include <crypto/sha.h>
1819 #include <crypto/aes.h>
19
-#include <crypto/des.h>
20
+#include <crypto/internal/des.h>
2021 #include <linux/mutex.h>
2122 #include <linux/delay.h>
2223 #include <linux/sched.h>
2324
2425 #include <crypto/internal/hash.h>
26
+#include <crypto/internal/skcipher.h>
2527 #include <crypto/scatterwalk.h>
2628 #include <crypto/algapi.h>
2729
....@@ -247,7 +249,7 @@
247249 struct n2_ahash_alg {
248250 struct list_head entry;
249251 const u8 *hash_zero;
250
- const u32 *hash_init;
252
+ const u8 *hash_init;
251253 u8 hw_op_hashsz;
252254 u8 digest_size;
253255 u8 auth_type;
....@@ -380,8 +382,8 @@
380382 fallback_tfm = crypto_alloc_ahash(fallback_driver_name, 0,
381383 CRYPTO_ALG_NEED_FALLBACK);
382384 if (IS_ERR(fallback_tfm)) {
383
- pr_warning("Fallback driver '%s' could not be loaded!\n",
384
- fallback_driver_name);
385
+ pr_warn("Fallback driver '%s' could not be loaded!\n",
386
+ fallback_driver_name);
385387 err = PTR_ERR(fallback_tfm);
386388 goto out;
387389 }
....@@ -417,16 +419,16 @@
417419 fallback_tfm = crypto_alloc_ahash(fallback_driver_name, 0,
418420 CRYPTO_ALG_NEED_FALLBACK);
419421 if (IS_ERR(fallback_tfm)) {
420
- pr_warning("Fallback driver '%s' could not be loaded!\n",
421
- fallback_driver_name);
422
+ pr_warn("Fallback driver '%s' could not be loaded!\n",
423
+ fallback_driver_name);
422424 err = PTR_ERR(fallback_tfm);
423425 goto out;
424426 }
425427
426428 child_shash = crypto_alloc_shash(n2alg->child_alg, 0, 0);
427429 if (IS_ERR(child_shash)) {
428
- pr_warning("Child shash '%s' could not be loaded!\n",
429
- n2alg->child_alg);
430
+ pr_warn("Child shash '%s' could not be loaded!\n",
431
+ n2alg->child_alg);
430432 err = PTR_ERR(child_shash);
431433 goto out_free_fallback;
432434 }
....@@ -460,7 +462,6 @@
460462 struct n2_hmac_ctx *ctx = crypto_ahash_ctx(tfm);
461463 struct crypto_shash *child_shash = ctx->child_shash;
462464 struct crypto_ahash *fallback_tfm;
463
- SHASH_DESC_ON_STACK(shash, child_shash);
464465 int err, bs, ds;
465466
466467 fallback_tfm = ctx->base.fallback_tfm;
....@@ -468,16 +469,12 @@
468469 if (err)
469470 return err;
470471
471
- shash->tfm = child_shash;
472
- shash->flags = crypto_ahash_get_flags(tfm) &
473
- CRYPTO_TFM_REQ_MAY_SLEEP;
474
-
475472 bs = crypto_shash_blocksize(child_shash);
476473 ds = crypto_shash_digestsize(child_shash);
477474 BUG_ON(ds > N2_HASH_KEY_MAX);
478475 if (keylen > bs) {
479
- err = crypto_shash_digest(shash, key, keylen,
480
- ctx->hash_key);
476
+ err = crypto_shash_tfm_digest(child_shash, key, keylen,
477
+ ctx->hash_key);
481478 if (err)
482479 return err;
483480 keylen = ds;
....@@ -658,14 +655,13 @@
658655 ctx->hash_key_len);
659656 }
660657
661
-struct n2_cipher_context {
658
+struct n2_skcipher_context {
662659 int key_len;
663660 int enc_type;
664661 union {
665662 u8 aes[AES_MAX_KEY_SIZE];
666663 u8 des[DES_KEY_SIZE];
667664 u8 des3[3 * DES_KEY_SIZE];
668
- u8 arc4[258]; /* S-box, X, Y */
669665 } key;
670666 };
671667
....@@ -684,7 +680,7 @@
684680 };
685681
686682 struct n2_request_context {
687
- struct ablkcipher_walk walk;
683
+ struct skcipher_walk walk;
688684 struct list_head chunk_list;
689685 struct n2_crypto_chunk chunk;
690686 u8 temp_iv[16];
....@@ -709,29 +705,29 @@
709705 * is not a valid sequence.
710706 */
711707
712
-struct n2_cipher_alg {
708
+struct n2_skcipher_alg {
713709 struct list_head entry;
714710 u8 enc_type;
715
- struct crypto_alg alg;
711
+ struct skcipher_alg skcipher;
716712 };
717713
718
-static inline struct n2_cipher_alg *n2_cipher_alg(struct crypto_tfm *tfm)
714
+static inline struct n2_skcipher_alg *n2_skcipher_alg(struct crypto_skcipher *tfm)
719715 {
720
- struct crypto_alg *alg = tfm->__crt_alg;
716
+ struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
721717
722
- return container_of(alg, struct n2_cipher_alg, alg);
718
+ return container_of(alg, struct n2_skcipher_alg, skcipher);
723719 }
724720
725
-struct n2_cipher_request_context {
726
- struct ablkcipher_walk walk;
721
+struct n2_skcipher_request_context {
722
+ struct skcipher_walk walk;
727723 };
728724
729
-static int n2_aes_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
725
+static int n2_aes_setkey(struct crypto_skcipher *skcipher, const u8 *key,
730726 unsigned int keylen)
731727 {
732
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
733
- struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm);
734
- struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm);
728
+ struct crypto_tfm *tfm = crypto_skcipher_tfm(skcipher);
729
+ struct n2_skcipher_context *ctx = crypto_tfm_ctx(tfm);
730
+ struct n2_skcipher_alg *n2alg = n2_skcipher_alg(skcipher);
735731
736732 ctx->enc_type = (n2alg->enc_type & ENC_TYPE_CHAINING_MASK);
737733
....@@ -746,7 +742,6 @@
746742 ctx->enc_type |= ENC_TYPE_ALG_AES256;
747743 break;
748744 default:
749
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
750745 return -EINVAL;
751746 }
752747
....@@ -755,82 +750,45 @@
755750 return 0;
756751 }
757752
758
-static int n2_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
753
+static int n2_des_setkey(struct crypto_skcipher *skcipher, const u8 *key,
759754 unsigned int keylen)
760755 {
761
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
762
- struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm);
763
- struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm);
764
- u32 tmp[DES_EXPKEY_WORDS];
756
+ struct crypto_tfm *tfm = crypto_skcipher_tfm(skcipher);
757
+ struct n2_skcipher_context *ctx = crypto_tfm_ctx(tfm);
758
+ struct n2_skcipher_alg *n2alg = n2_skcipher_alg(skcipher);
765759 int err;
766760
761
+ err = verify_skcipher_des_key(skcipher, key);
762
+ if (err)
763
+ return err;
764
+
767765 ctx->enc_type = n2alg->enc_type;
768
-
769
- if (keylen != DES_KEY_SIZE) {
770
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
771
- return -EINVAL;
772
- }
773
-
774
- err = des_ekey(tmp, key);
775
- if (err == 0 && (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
776
- tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
777
- return -EINVAL;
778
- }
779766
780767 ctx->key_len = keylen;
781768 memcpy(ctx->key.des, key, keylen);
782769 return 0;
783770 }
784771
785
-static int n2_3des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
772
+static int n2_3des_setkey(struct crypto_skcipher *skcipher, const u8 *key,
786773 unsigned int keylen)
787774 {
788
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
789
- struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm);
790
- struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm);
775
+ struct crypto_tfm *tfm = crypto_skcipher_tfm(skcipher);
776
+ struct n2_skcipher_context *ctx = crypto_tfm_ctx(tfm);
777
+ struct n2_skcipher_alg *n2alg = n2_skcipher_alg(skcipher);
778
+ int err;
779
+
780
+ err = verify_skcipher_des3_key(skcipher, key);
781
+ if (err)
782
+ return err;
791783
792784 ctx->enc_type = n2alg->enc_type;
793785
794
- if (keylen != (3 * DES_KEY_SIZE)) {
795
- crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
796
- return -EINVAL;
797
- }
798786 ctx->key_len = keylen;
799787 memcpy(ctx->key.des3, key, keylen);
800788 return 0;
801789 }
802790
803
-static int n2_arc4_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
804
- unsigned int keylen)
805
-{
806
- struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
807
- struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm);
808
- struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm);
809
- u8 *s = ctx->key.arc4;
810
- u8 *x = s + 256;
811
- u8 *y = x + 1;
812
- int i, j, k;
813
-
814
- ctx->enc_type = n2alg->enc_type;
815
-
816
- j = k = 0;
817
- *x = 0;
818
- *y = 0;
819
- for (i = 0; i < 256; i++)
820
- s[i] = i;
821
- for (i = 0; i < 256; i++) {
822
- u8 a = s[i];
823
- j = (j + key[k] + a) & 0xff;
824
- s[i] = s[j];
825
- s[j] = a;
826
- if (++k >= keylen)
827
- k = 0;
828
- }
829
-
830
- return 0;
831
-}
832
-
833
-static inline int cipher_descriptor_len(int nbytes, unsigned int block_size)
791
+static inline int skcipher_descriptor_len(int nbytes, unsigned int block_size)
834792 {
835793 int this_len = nbytes;
836794
....@@ -838,10 +796,11 @@
838796 return this_len > (1 << 16) ? (1 << 16) : this_len;
839797 }
840798
841
-static int __n2_crypt_chunk(struct crypto_tfm *tfm, struct n2_crypto_chunk *cp,
799
+static int __n2_crypt_chunk(struct crypto_skcipher *skcipher,
800
+ struct n2_crypto_chunk *cp,
842801 struct spu_queue *qp, bool encrypt)
843802 {
844
- struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm);
803
+ struct n2_skcipher_context *ctx = crypto_skcipher_ctx(skcipher);
845804 struct cwq_initial_entry *ent;
846805 bool in_place;
847806 int i;
....@@ -885,18 +844,17 @@
885844 return (spu_queue_submit(qp, ent) != HV_EOK) ? -EINVAL : 0;
886845 }
887846
888
-static int n2_compute_chunks(struct ablkcipher_request *req)
847
+static int n2_compute_chunks(struct skcipher_request *req)
889848 {
890
- struct n2_request_context *rctx = ablkcipher_request_ctx(req);
891
- struct ablkcipher_walk *walk = &rctx->walk;
849
+ struct n2_request_context *rctx = skcipher_request_ctx(req);
850
+ struct skcipher_walk *walk = &rctx->walk;
892851 struct n2_crypto_chunk *chunk;
893852 unsigned long dest_prev;
894853 unsigned int tot_len;
895854 bool prev_in_place;
896855 int err, nbytes;
897856
898
- ablkcipher_walk_init(walk, req->dst, req->src, req->nbytes);
899
- err = ablkcipher_walk_phys(req, walk);
857
+ err = skcipher_walk_async(walk, req);
900858 if (err)
901859 return err;
902860
....@@ -918,12 +876,12 @@
918876 bool in_place;
919877 int this_len;
920878
921
- src_paddr = (page_to_phys(walk->src.page) +
922
- walk->src.offset);
923
- dest_paddr = (page_to_phys(walk->dst.page) +
924
- walk->dst.offset);
879
+ src_paddr = (page_to_phys(walk->src.phys.page) +
880
+ walk->src.phys.offset);
881
+ dest_paddr = (page_to_phys(walk->dst.phys.page) +
882
+ walk->dst.phys.offset);
925883 in_place = (src_paddr == dest_paddr);
926
- this_len = cipher_descriptor_len(nbytes, walk->blocksize);
884
+ this_len = skcipher_descriptor_len(nbytes, walk->blocksize);
927885
928886 if (chunk->arr_len != 0) {
929887 if (in_place != prev_in_place ||
....@@ -954,7 +912,7 @@
954912 prev_in_place = in_place;
955913 tot_len += this_len;
956914
957
- err = ablkcipher_walk_done(req, walk, nbytes - this_len);
915
+ err = skcipher_walk_done(walk, nbytes - this_len);
958916 if (err)
959917 break;
960918 }
....@@ -966,15 +924,14 @@
966924 return err;
967925 }
968926
969
-static void n2_chunk_complete(struct ablkcipher_request *req, void *final_iv)
927
+static void n2_chunk_complete(struct skcipher_request *req, void *final_iv)
970928 {
971
- struct n2_request_context *rctx = ablkcipher_request_ctx(req);
929
+ struct n2_request_context *rctx = skcipher_request_ctx(req);
972930 struct n2_crypto_chunk *c, *tmp;
973931
974932 if (final_iv)
975933 memcpy(rctx->walk.iv, final_iv, rctx->walk.blocksize);
976934
977
- ablkcipher_walk_complete(&rctx->walk);
978935 list_for_each_entry_safe(c, tmp, &rctx->chunk_list, entry) {
979936 list_del(&c->entry);
980937 if (unlikely(c != &rctx->chunk))
....@@ -983,10 +940,10 @@
983940
984941 }
985942
986
-static int n2_do_ecb(struct ablkcipher_request *req, bool encrypt)
943
+static int n2_do_ecb(struct skcipher_request *req, bool encrypt)
987944 {
988
- struct n2_request_context *rctx = ablkcipher_request_ctx(req);
989
- struct crypto_tfm *tfm = req->base.tfm;
945
+ struct n2_request_context *rctx = skcipher_request_ctx(req);
946
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
990947 int err = n2_compute_chunks(req);
991948 struct n2_crypto_chunk *c, *tmp;
992949 unsigned long flags, hv_ret;
....@@ -1025,20 +982,20 @@
1025982 return err;
1026983 }
1027984
1028
-static int n2_encrypt_ecb(struct ablkcipher_request *req)
985
+static int n2_encrypt_ecb(struct skcipher_request *req)
1029986 {
1030987 return n2_do_ecb(req, true);
1031988 }
1032989
1033
-static int n2_decrypt_ecb(struct ablkcipher_request *req)
990
+static int n2_decrypt_ecb(struct skcipher_request *req)
1034991 {
1035992 return n2_do_ecb(req, false);
1036993 }
1037994
1038
-static int n2_do_chaining(struct ablkcipher_request *req, bool encrypt)
995
+static int n2_do_chaining(struct skcipher_request *req, bool encrypt)
1039996 {
1040
- struct n2_request_context *rctx = ablkcipher_request_ctx(req);
1041
- struct crypto_tfm *tfm = req->base.tfm;
997
+ struct n2_request_context *rctx = skcipher_request_ctx(req);
998
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1042999 unsigned long flags, hv_ret, iv_paddr;
10431000 int err = n2_compute_chunks(req);
10441001 struct n2_crypto_chunk *c, *tmp;
....@@ -1115,47 +1072,32 @@
11151072 return err;
11161073 }
11171074
1118
-static int n2_encrypt_chaining(struct ablkcipher_request *req)
1075
+static int n2_encrypt_chaining(struct skcipher_request *req)
11191076 {
11201077 return n2_do_chaining(req, true);
11211078 }
11221079
1123
-static int n2_decrypt_chaining(struct ablkcipher_request *req)
1080
+static int n2_decrypt_chaining(struct skcipher_request *req)
11241081 {
11251082 return n2_do_chaining(req, false);
11261083 }
11271084
1128
-struct n2_cipher_tmpl {
1085
+struct n2_skcipher_tmpl {
11291086 const char *name;
11301087 const char *drv_name;
11311088 u8 block_size;
11321089 u8 enc_type;
1133
- struct ablkcipher_alg ablkcipher;
1090
+ struct skcipher_alg skcipher;
11341091 };
11351092
1136
-static const struct n2_cipher_tmpl cipher_tmpls[] = {
1137
- /* ARC4: only ECB is supported (chaining bits ignored) */
1138
- { .name = "ecb(arc4)",
1139
- .drv_name = "ecb-arc4",
1140
- .block_size = 1,
1141
- .enc_type = (ENC_TYPE_ALG_RC4_STREAM |
1142
- ENC_TYPE_CHAINING_ECB),
1143
- .ablkcipher = {
1144
- .min_keysize = 1,
1145
- .max_keysize = 256,
1146
- .setkey = n2_arc4_setkey,
1147
- .encrypt = n2_encrypt_ecb,
1148
- .decrypt = n2_decrypt_ecb,
1149
- },
1150
- },
1151
-
1093
+static const struct n2_skcipher_tmpl skcipher_tmpls[] = {
11521094 /* DES: ECB CBC and CFB are supported */
11531095 { .name = "ecb(des)",
11541096 .drv_name = "ecb-des",
11551097 .block_size = DES_BLOCK_SIZE,
11561098 .enc_type = (ENC_TYPE_ALG_DES |
11571099 ENC_TYPE_CHAINING_ECB),
1158
- .ablkcipher = {
1100
+ .skcipher = {
11591101 .min_keysize = DES_KEY_SIZE,
11601102 .max_keysize = DES_KEY_SIZE,
11611103 .setkey = n2_des_setkey,
....@@ -1168,7 +1110,7 @@
11681110 .block_size = DES_BLOCK_SIZE,
11691111 .enc_type = (ENC_TYPE_ALG_DES |
11701112 ENC_TYPE_CHAINING_CBC),
1171
- .ablkcipher = {
1113
+ .skcipher = {
11721114 .ivsize = DES_BLOCK_SIZE,
11731115 .min_keysize = DES_KEY_SIZE,
11741116 .max_keysize = DES_KEY_SIZE,
....@@ -1182,7 +1124,7 @@
11821124 .block_size = DES_BLOCK_SIZE,
11831125 .enc_type = (ENC_TYPE_ALG_DES |
11841126 ENC_TYPE_CHAINING_CFB),
1185
- .ablkcipher = {
1127
+ .skcipher = {
11861128 .min_keysize = DES_KEY_SIZE,
11871129 .max_keysize = DES_KEY_SIZE,
11881130 .setkey = n2_des_setkey,
....@@ -1197,7 +1139,7 @@
11971139 .block_size = DES_BLOCK_SIZE,
11981140 .enc_type = (ENC_TYPE_ALG_3DES |
11991141 ENC_TYPE_CHAINING_ECB),
1200
- .ablkcipher = {
1142
+ .skcipher = {
12011143 .min_keysize = 3 * DES_KEY_SIZE,
12021144 .max_keysize = 3 * DES_KEY_SIZE,
12031145 .setkey = n2_3des_setkey,
....@@ -1210,7 +1152,7 @@
12101152 .block_size = DES_BLOCK_SIZE,
12111153 .enc_type = (ENC_TYPE_ALG_3DES |
12121154 ENC_TYPE_CHAINING_CBC),
1213
- .ablkcipher = {
1155
+ .skcipher = {
12141156 .ivsize = DES_BLOCK_SIZE,
12151157 .min_keysize = 3 * DES_KEY_SIZE,
12161158 .max_keysize = 3 * DES_KEY_SIZE,
....@@ -1224,7 +1166,7 @@
12241166 .block_size = DES_BLOCK_SIZE,
12251167 .enc_type = (ENC_TYPE_ALG_3DES |
12261168 ENC_TYPE_CHAINING_CFB),
1227
- .ablkcipher = {
1169
+ .skcipher = {
12281170 .min_keysize = 3 * DES_KEY_SIZE,
12291171 .max_keysize = 3 * DES_KEY_SIZE,
12301172 .setkey = n2_3des_setkey,
....@@ -1238,7 +1180,7 @@
12381180 .block_size = AES_BLOCK_SIZE,
12391181 .enc_type = (ENC_TYPE_ALG_AES128 |
12401182 ENC_TYPE_CHAINING_ECB),
1241
- .ablkcipher = {
1183
+ .skcipher = {
12421184 .min_keysize = AES_MIN_KEY_SIZE,
12431185 .max_keysize = AES_MAX_KEY_SIZE,
12441186 .setkey = n2_aes_setkey,
....@@ -1251,7 +1193,7 @@
12511193 .block_size = AES_BLOCK_SIZE,
12521194 .enc_type = (ENC_TYPE_ALG_AES128 |
12531195 ENC_TYPE_CHAINING_CBC),
1254
- .ablkcipher = {
1196
+ .skcipher = {
12551197 .ivsize = AES_BLOCK_SIZE,
12561198 .min_keysize = AES_MIN_KEY_SIZE,
12571199 .max_keysize = AES_MAX_KEY_SIZE,
....@@ -1265,7 +1207,7 @@
12651207 .block_size = AES_BLOCK_SIZE,
12661208 .enc_type = (ENC_TYPE_ALG_AES128 |
12671209 ENC_TYPE_CHAINING_COUNTER),
1268
- .ablkcipher = {
1210
+ .skcipher = {
12691211 .ivsize = AES_BLOCK_SIZE,
12701212 .min_keysize = AES_MIN_KEY_SIZE,
12711213 .max_keysize = AES_MAX_KEY_SIZE,
....@@ -1276,35 +1218,36 @@
12761218 },
12771219
12781220 };
1279
-#define NUM_CIPHER_TMPLS ARRAY_SIZE(cipher_tmpls)
1221
+#define NUM_CIPHER_TMPLS ARRAY_SIZE(skcipher_tmpls)
12801222
1281
-static LIST_HEAD(cipher_algs);
1223
+static LIST_HEAD(skcipher_algs);
12821224
12831225 struct n2_hash_tmpl {
12841226 const char *name;
12851227 const u8 *hash_zero;
1286
- const u32 *hash_init;
1228
+ const u8 *hash_init;
12871229 u8 hw_op_hashsz;
12881230 u8 digest_size;
1231
+ u8 statesize;
12891232 u8 block_size;
12901233 u8 auth_type;
12911234 u8 hmac_type;
12921235 };
12931236
1294
-static const u32 md5_init[MD5_HASH_WORDS] = {
1237
+static const __le32 n2_md5_init[MD5_HASH_WORDS] = {
12951238 cpu_to_le32(MD5_H0),
12961239 cpu_to_le32(MD5_H1),
12971240 cpu_to_le32(MD5_H2),
12981241 cpu_to_le32(MD5_H3),
12991242 };
1300
-static const u32 sha1_init[SHA1_DIGEST_SIZE / 4] = {
1243
+static const u32 n2_sha1_init[SHA1_DIGEST_SIZE / 4] = {
13011244 SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4,
13021245 };
1303
-static const u32 sha256_init[SHA256_DIGEST_SIZE / 4] = {
1246
+static const u32 n2_sha256_init[SHA256_DIGEST_SIZE / 4] = {
13041247 SHA256_H0, SHA256_H1, SHA256_H2, SHA256_H3,
13051248 SHA256_H4, SHA256_H5, SHA256_H6, SHA256_H7,
13061249 };
1307
-static const u32 sha224_init[SHA256_DIGEST_SIZE / 4] = {
1250
+static const u32 n2_sha224_init[SHA256_DIGEST_SIZE / 4] = {
13081251 SHA224_H0, SHA224_H1, SHA224_H2, SHA224_H3,
13091252 SHA224_H4, SHA224_H5, SHA224_H6, SHA224_H7,
13101253 };
....@@ -1312,35 +1255,39 @@
13121255 static const struct n2_hash_tmpl hash_tmpls[] = {
13131256 { .name = "md5",
13141257 .hash_zero = md5_zero_message_hash,
1315
- .hash_init = md5_init,
1258
+ .hash_init = (u8 *)n2_md5_init,
13161259 .auth_type = AUTH_TYPE_MD5,
13171260 .hmac_type = AUTH_TYPE_HMAC_MD5,
13181261 .hw_op_hashsz = MD5_DIGEST_SIZE,
13191262 .digest_size = MD5_DIGEST_SIZE,
1263
+ .statesize = sizeof(struct md5_state),
13201264 .block_size = MD5_HMAC_BLOCK_SIZE },
13211265 { .name = "sha1",
13221266 .hash_zero = sha1_zero_message_hash,
1323
- .hash_init = sha1_init,
1267
+ .hash_init = (u8 *)n2_sha1_init,
13241268 .auth_type = AUTH_TYPE_SHA1,
13251269 .hmac_type = AUTH_TYPE_HMAC_SHA1,
13261270 .hw_op_hashsz = SHA1_DIGEST_SIZE,
13271271 .digest_size = SHA1_DIGEST_SIZE,
1272
+ .statesize = sizeof(struct sha1_state),
13281273 .block_size = SHA1_BLOCK_SIZE },
13291274 { .name = "sha256",
13301275 .hash_zero = sha256_zero_message_hash,
1331
- .hash_init = sha256_init,
1276
+ .hash_init = (u8 *)n2_sha256_init,
13321277 .auth_type = AUTH_TYPE_SHA256,
13331278 .hmac_type = AUTH_TYPE_HMAC_SHA256,
13341279 .hw_op_hashsz = SHA256_DIGEST_SIZE,
13351280 .digest_size = SHA256_DIGEST_SIZE,
1281
+ .statesize = sizeof(struct sha256_state),
13361282 .block_size = SHA256_BLOCK_SIZE },
13371283 { .name = "sha224",
13381284 .hash_zero = sha224_zero_message_hash,
1339
- .hash_init = sha224_init,
1285
+ .hash_init = (u8 *)n2_sha224_init,
13401286 .auth_type = AUTH_TYPE_SHA256,
13411287 .hmac_type = AUTH_TYPE_RESERVED,
13421288 .hw_op_hashsz = SHA256_DIGEST_SIZE,
13431289 .digest_size = SHA224_DIGEST_SIZE,
1290
+ .statesize = sizeof(struct sha256_state),
13441291 .block_size = SHA224_BLOCK_SIZE },
13451292 };
13461293 #define NUM_HASH_TMPLS ARRAY_SIZE(hash_tmpls)
....@@ -1352,14 +1299,14 @@
13521299
13531300 static void __n2_unregister_algs(void)
13541301 {
1355
- struct n2_cipher_alg *cipher, *cipher_tmp;
1302
+ struct n2_skcipher_alg *skcipher, *skcipher_tmp;
13561303 struct n2_ahash_alg *alg, *alg_tmp;
13571304 struct n2_hmac_alg *hmac, *hmac_tmp;
13581305
1359
- list_for_each_entry_safe(cipher, cipher_tmp, &cipher_algs, entry) {
1360
- crypto_unregister_alg(&cipher->alg);
1361
- list_del(&cipher->entry);
1362
- kfree(cipher);
1306
+ list_for_each_entry_safe(skcipher, skcipher_tmp, &skcipher_algs, entry) {
1307
+ crypto_unregister_skcipher(&skcipher->skcipher);
1308
+ list_del(&skcipher->entry);
1309
+ kfree(skcipher);
13631310 }
13641311 list_for_each_entry_safe(hmac, hmac_tmp, &hmac_algs, derived.entry) {
13651312 crypto_unregister_ahash(&hmac->derived.alg);
....@@ -1373,44 +1320,43 @@
13731320 }
13741321 }
13751322
1376
-static int n2_cipher_cra_init(struct crypto_tfm *tfm)
1323
+static int n2_skcipher_init_tfm(struct crypto_skcipher *tfm)
13771324 {
1378
- tfm->crt_ablkcipher.reqsize = sizeof(struct n2_request_context);
1325
+ crypto_skcipher_set_reqsize(tfm, sizeof(struct n2_request_context));
13791326 return 0;
13801327 }
13811328
1382
-static int __n2_register_one_cipher(const struct n2_cipher_tmpl *tmpl)
1329
+static int __n2_register_one_skcipher(const struct n2_skcipher_tmpl *tmpl)
13831330 {
1384
- struct n2_cipher_alg *p = kzalloc(sizeof(*p), GFP_KERNEL);
1385
- struct crypto_alg *alg;
1331
+ struct n2_skcipher_alg *p = kzalloc(sizeof(*p), GFP_KERNEL);
1332
+ struct skcipher_alg *alg;
13861333 int err;
13871334
13881335 if (!p)
13891336 return -ENOMEM;
13901337
1391
- alg = &p->alg;
1338
+ alg = &p->skcipher;
1339
+ *alg = tmpl->skcipher;
13921340
1393
- snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", tmpl->name);
1394
- snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s-n2", tmpl->drv_name);
1395
- alg->cra_priority = N2_CRA_PRIORITY;
1396
- alg->cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1397
- CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC;
1398
- alg->cra_blocksize = tmpl->block_size;
1341
+ snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", tmpl->name);
1342
+ snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s-n2", tmpl->drv_name);
1343
+ alg->base.cra_priority = N2_CRA_PRIORITY;
1344
+ alg->base.cra_flags = CRYPTO_ALG_KERN_DRIVER_ONLY | CRYPTO_ALG_ASYNC |
1345
+ CRYPTO_ALG_ALLOCATES_MEMORY;
1346
+ alg->base.cra_blocksize = tmpl->block_size;
13991347 p->enc_type = tmpl->enc_type;
1400
- alg->cra_ctxsize = sizeof(struct n2_cipher_context);
1401
- alg->cra_type = &crypto_ablkcipher_type;
1402
- alg->cra_u.ablkcipher = tmpl->ablkcipher;
1403
- alg->cra_init = n2_cipher_cra_init;
1404
- alg->cra_module = THIS_MODULE;
1348
+ alg->base.cra_ctxsize = sizeof(struct n2_skcipher_context);
1349
+ alg->base.cra_module = THIS_MODULE;
1350
+ alg->init = n2_skcipher_init_tfm;
14051351
1406
- list_add(&p->entry, &cipher_algs);
1407
- err = crypto_register_alg(alg);
1352
+ list_add(&p->entry, &skcipher_algs);
1353
+ err = crypto_register_skcipher(alg);
14081354 if (err) {
1409
- pr_err("%s alg registration failed\n", alg->cra_name);
1355
+ pr_err("%s alg registration failed\n", alg->base.cra_name);
14101356 list_del(&p->entry);
14111357 kfree(p);
14121358 } else {
1413
- pr_info("%s alg registered\n", alg->cra_name);
1359
+ pr_info("%s alg registered\n", alg->base.cra_name);
14141360 }
14151361 return err;
14161362 }
....@@ -1482,6 +1428,7 @@
14821428
14831429 halg = &ahash->halg;
14841430 halg->digestsize = tmpl->digest_size;
1431
+ halg->statesize = tmpl->statesize;
14851432
14861433 base = &halg->base;
14871434 snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", tmpl->name);
....@@ -1525,7 +1472,7 @@
15251472 }
15261473 }
15271474 for (i = 0; i < NUM_CIPHER_TMPLS; i++) {
1528
- err = __n2_register_one_cipher(&cipher_tmpls[i]);
1475
+ err = __n2_register_one_skcipher(&skcipher_tmpls[i]);
15291476 if (err) {
15301477 __n2_unregister_algs();
15311478 goto out;