hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/crypto/atmel-aes.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Cryptographic API.
34 *
....@@ -5,10 +6,6 @@
56 *
67 * Copyright (c) 2012 Eukréa Electromatique - ATMEL
78 * Author: Nicolas Royer <nicolas@eukrea.com>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License version 2 as published
11
- * by the Free Software Foundation.
129 *
1310 * Some ideas are from omap-aes.c driver.
1411 */
....@@ -24,6 +21,7 @@
2421 #include <linux/platform_device.h>
2522
2623 #include <linux/device.h>
24
+#include <linux/dmaengine.h>
2725 #include <linux/init.h>
2826 #include <linux/errno.h>
2927 #include <linux/interrupt.h>
....@@ -39,8 +37,7 @@
3937 #include <crypto/gcm.h>
4038 #include <crypto/xts.h>
4139 #include <crypto/internal/aead.h>
42
-#include <linux/platform_data/crypto-atmel.h>
43
-#include <dt-bindings/dma/at91.h>
40
+#include <crypto/internal/skcipher.h>
4441 #include "atmel-aes-regs.h"
4542 #include "atmel-authenc.h"
4643
....@@ -119,10 +116,11 @@
119116 struct atmel_aes_ctr_ctx {
120117 struct atmel_aes_base_ctx base;
121118
122
- u32 iv[AES_BLOCK_SIZE / sizeof(u32)];
119
+ __be32 iv[AES_BLOCK_SIZE / sizeof(u32)];
123120 size_t offset;
124121 struct scatterlist src[2];
125122 struct scatterlist dst[2];
123
+ u32 blocks;
126124 };
127125
128126 struct atmel_aes_gcm_ctx {
....@@ -131,13 +129,13 @@
131129 struct scatterlist src[2];
132130 struct scatterlist dst[2];
133131
134
- u32 j0[AES_BLOCK_SIZE / sizeof(u32)];
132
+ __be32 j0[AES_BLOCK_SIZE / sizeof(u32)];
135133 u32 tag[AES_BLOCK_SIZE / sizeof(u32)];
136
- u32 ghash[AES_BLOCK_SIZE / sizeof(u32)];
134
+ __be32 ghash[AES_BLOCK_SIZE / sizeof(u32)];
137135 size_t textlen;
138136
139
- const u32 *ghash_in;
140
- u32 *ghash_out;
137
+ const __be32 *ghash_in;
138
+ __be32 *ghash_out;
141139 atmel_aes_fn_t ghash_resume;
142140 };
143141
....@@ -156,7 +154,7 @@
156154
157155 struct atmel_aes_reqctx {
158156 unsigned long mode;
159
- u32 lastc[AES_BLOCK_SIZE / sizeof(u32)];
157
+ u8 lastc[AES_BLOCK_SIZE];
160158 };
161159
162160 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
....@@ -390,13 +388,13 @@
390388 }
391389
392390 static inline void atmel_aes_read_block(struct atmel_aes_dev *dd, u32 offset,
393
- u32 *value)
391
+ void *value)
394392 {
395393 atmel_aes_read_n(dd, offset, value, SIZE_IN_WORDS(AES_BLOCK_SIZE));
396394 }
397395
398396 static inline void atmel_aes_write_block(struct atmel_aes_dev *dd, u32 offset,
399
- const u32 *value)
397
+ const void *value)
400398 {
401399 atmel_aes_write_n(dd, offset, value, SIZE_IN_WORDS(AES_BLOCK_SIZE));
402400 }
....@@ -494,29 +492,58 @@
494492
495493 static void atmel_aes_set_iv_as_last_ciphertext_block(struct atmel_aes_dev *dd)
496494 {
497
- struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
498
- struct atmel_aes_reqctx *rctx = ablkcipher_request_ctx(req);
499
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
500
- unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
495
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
496
+ struct atmel_aes_reqctx *rctx = skcipher_request_ctx(req);
497
+ struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
498
+ unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
501499
502
- if (req->nbytes < ivsize)
500
+ if (req->cryptlen < ivsize)
503501 return;
504502
505503 if (rctx->mode & AES_FLAGS_ENCRYPT) {
506
- scatterwalk_map_and_copy(req->info, req->dst,
507
- req->nbytes - ivsize, ivsize, 0);
504
+ scatterwalk_map_and_copy(req->iv, req->dst,
505
+ req->cryptlen - ivsize, ivsize, 0);
508506 } else {
509507 if (req->src == req->dst)
510
- memcpy(req->info, rctx->lastc, ivsize);
508
+ memcpy(req->iv, rctx->lastc, ivsize);
511509 else
512
- scatterwalk_map_and_copy(req->info, req->src,
513
- req->nbytes - ivsize,
510
+ scatterwalk_map_and_copy(req->iv, req->src,
511
+ req->cryptlen - ivsize,
514512 ivsize, 0);
515513 }
516514 }
517515
516
+static inline struct atmel_aes_ctr_ctx *
517
+atmel_aes_ctr_ctx_cast(struct atmel_aes_base_ctx *ctx)
518
+{
519
+ return container_of(ctx, struct atmel_aes_ctr_ctx, base);
520
+}
521
+
522
+static void atmel_aes_ctr_update_req_iv(struct atmel_aes_dev *dd)
523
+{
524
+ struct atmel_aes_ctr_ctx *ctx = atmel_aes_ctr_ctx_cast(dd->ctx);
525
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
526
+ struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
527
+ unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
528
+ int i;
529
+
530
+ /*
531
+ * The CTR transfer works in fragments of data of maximum 1 MByte
532
+ * because of the 16 bit CTR counter embedded in the IP. When reaching
533
+ * here, ctx->blocks contains the number of blocks of the last fragment
534
+ * processed, there is no need to explicit cast it to u16.
535
+ */
536
+ for (i = 0; i < ctx->blocks; i++)
537
+ crypto_inc((u8 *)ctx->iv, AES_BLOCK_SIZE);
538
+
539
+ memcpy(req->iv, ctx->iv, ivsize);
540
+}
541
+
518542 static inline int atmel_aes_complete(struct atmel_aes_dev *dd, int err)
519543 {
544
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
545
+ struct atmel_aes_reqctx *rctx = skcipher_request_ctx(req);
546
+
520547 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
521548 if (dd->ctx->is_aead)
522549 atmel_aes_authenc_complete(dd, err);
....@@ -525,8 +552,13 @@
525552 clk_disable(dd->iclk);
526553 dd->flags &= ~AES_FLAGS_BUSY;
527554
528
- if (!dd->ctx->is_aead)
529
- atmel_aes_set_iv_as_last_ciphertext_block(dd);
555
+ if (!err && !dd->ctx->is_aead &&
556
+ (rctx->mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_ECB) {
557
+ if ((rctx->mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_CTR)
558
+ atmel_aes_set_iv_as_last_ciphertext_block(dd);
559
+ else
560
+ atmel_aes_ctr_update_req_iv(dd);
561
+ }
530562
531563 if (dd->is_async)
532564 dd->areq->complete(dd->areq, err);
....@@ -537,7 +569,7 @@
537569 }
538570
539571 static void atmel_aes_write_ctrl_key(struct atmel_aes_dev *dd, bool use_dma,
540
- const u32 *iv, const u32 *key, int keylen)
572
+ const __be32 *iv, const u32 *key, int keylen)
541573 {
542574 u32 valmr = 0;
543575
....@@ -568,7 +600,7 @@
568600 }
569601
570602 static inline void atmel_aes_write_ctrl(struct atmel_aes_dev *dd, bool use_dma,
571
- const u32 *iv)
603
+ const __be32 *iv)
572604
573605 {
574606 atmel_aes_write_ctrl_key(dd, use_dma, iv,
....@@ -791,7 +823,6 @@
791823 int err;
792824
793825 memset(&config, 0, sizeof(config));
794
- config.direction = dir;
795826 config.src_addr_width = addr_width;
796827 config.dst_addr_width = addr_width;
797828 config.src_maxburst = maxburst;
....@@ -829,27 +860,6 @@
829860 dma_async_issue_pending(dma->chan);
830861
831862 return 0;
832
-}
833
-
834
-static void atmel_aes_dma_transfer_stop(struct atmel_aes_dev *dd,
835
- enum dma_transfer_direction dir)
836
-{
837
- struct atmel_aes_dma *dma;
838
-
839
- switch (dir) {
840
- case DMA_MEM_TO_DEV:
841
- dma = &dd->src;
842
- break;
843
-
844
- case DMA_DEV_TO_MEM:
845
- dma = &dd->dst;
846
- break;
847
-
848
- default:
849
- return;
850
- }
851
-
852
- dmaengine_terminate_all(dma->chan);
853863 }
854864
855865 static int atmel_aes_dma_start(struct atmel_aes_dev *dd,
....@@ -910,25 +920,18 @@
910920 return -EINPROGRESS;
911921
912922 output_transfer_stop:
913
- atmel_aes_dma_transfer_stop(dd, DMA_DEV_TO_MEM);
923
+ dmaengine_terminate_sync(dd->dst.chan);
914924 unmap:
915925 atmel_aes_unmap(dd);
916926 exit:
917927 return atmel_aes_complete(dd, err);
918928 }
919929
920
-static void atmel_aes_dma_stop(struct atmel_aes_dev *dd)
921
-{
922
- atmel_aes_dma_transfer_stop(dd, DMA_MEM_TO_DEV);
923
- atmel_aes_dma_transfer_stop(dd, DMA_DEV_TO_MEM);
924
- atmel_aes_unmap(dd);
925
-}
926
-
927930 static void atmel_aes_dma_callback(void *data)
928931 {
929932 struct atmel_aes_dev *dd = data;
930933
931
- atmel_aes_dma_stop(dd);
934
+ atmel_aes_unmap(dd);
932935 dd->is_async = true;
933936 (void)dd->resume(dd);
934937 }
....@@ -983,9 +986,9 @@
983986
984987 static int atmel_aes_start(struct atmel_aes_dev *dd)
985988 {
986
- struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
987
- struct atmel_aes_reqctx *rctx = ablkcipher_request_ctx(req);
988
- bool use_dma = (req->nbytes >= ATMEL_AES_DMA_THRESHOLD ||
989
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
990
+ struct atmel_aes_reqctx *rctx = skcipher_request_ctx(req);
991
+ bool use_dma = (req->cryptlen >= ATMEL_AES_DMA_THRESHOLD ||
989992 dd->ctx->block_size != AES_BLOCK_SIZE);
990993 int err;
991994
....@@ -995,46 +998,41 @@
995998 if (err)
996999 return atmel_aes_complete(dd, err);
9971000
998
- atmel_aes_write_ctrl(dd, use_dma, req->info);
1001
+ atmel_aes_write_ctrl(dd, use_dma, (void *)req->iv);
9991002 if (use_dma)
1000
- return atmel_aes_dma_start(dd, req->src, req->dst, req->nbytes,
1003
+ return atmel_aes_dma_start(dd, req->src, req->dst,
1004
+ req->cryptlen,
10011005 atmel_aes_transfer_complete);
10021006
1003
- return atmel_aes_cpu_start(dd, req->src, req->dst, req->nbytes,
1007
+ return atmel_aes_cpu_start(dd, req->src, req->dst, req->cryptlen,
10041008 atmel_aes_transfer_complete);
1005
-}
1006
-
1007
-static inline struct atmel_aes_ctr_ctx *
1008
-atmel_aes_ctr_ctx_cast(struct atmel_aes_base_ctx *ctx)
1009
-{
1010
- return container_of(ctx, struct atmel_aes_ctr_ctx, base);
10111009 }
10121010
10131011 static int atmel_aes_ctr_transfer(struct atmel_aes_dev *dd)
10141012 {
10151013 struct atmel_aes_ctr_ctx *ctx = atmel_aes_ctr_ctx_cast(dd->ctx);
1016
- struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
1014
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
10171015 struct scatterlist *src, *dst;
10181016 size_t datalen;
10191017 u32 ctr;
1020
- u16 blocks, start, end;
1018
+ u16 start, end;
10211019 bool use_dma, fragmented = false;
10221020
10231021 /* Check for transfer completion. */
10241022 ctx->offset += dd->total;
1025
- if (ctx->offset >= req->nbytes)
1023
+ if (ctx->offset >= req->cryptlen)
10261024 return atmel_aes_transfer_complete(dd);
10271025
10281026 /* Compute data length. */
1029
- datalen = req->nbytes - ctx->offset;
1030
- blocks = DIV_ROUND_UP(datalen, AES_BLOCK_SIZE);
1027
+ datalen = req->cryptlen - ctx->offset;
1028
+ ctx->blocks = DIV_ROUND_UP(datalen, AES_BLOCK_SIZE);
10311029 ctr = be32_to_cpu(ctx->iv[3]);
10321030
10331031 /* Check 16bit counter overflow. */
10341032 start = ctr & 0xffff;
1035
- end = start + blocks - 1;
1033
+ end = start + ctx->blocks - 1;
10361034
1037
- if (blocks >> 16 || end < start) {
1035
+ if (ctx->blocks >> 16 || end < start) {
10381036 ctr |= 0xffff;
10391037 datalen = AES_BLOCK_SIZE * (0x10000 - start);
10401038 fragmented = true;
....@@ -1069,8 +1067,8 @@
10691067 static int atmel_aes_ctr_start(struct atmel_aes_dev *dd)
10701068 {
10711069 struct atmel_aes_ctr_ctx *ctx = atmel_aes_ctr_ctx_cast(dd->ctx);
1072
- struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
1073
- struct atmel_aes_reqctx *rctx = ablkcipher_request_ctx(req);
1070
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
1071
+ struct atmel_aes_reqctx *rctx = skcipher_request_ctx(req);
10741072 int err;
10751073
10761074 atmel_aes_set_mode(dd, rctx);
....@@ -1079,16 +1077,16 @@
10791077 if (err)
10801078 return atmel_aes_complete(dd, err);
10811079
1082
- memcpy(ctx->iv, req->info, AES_BLOCK_SIZE);
1080
+ memcpy(ctx->iv, req->iv, AES_BLOCK_SIZE);
10831081 ctx->offset = 0;
10841082 dd->total = 0;
10851083 return atmel_aes_ctr_transfer(dd);
10861084 }
10871085
1088
-static int atmel_aes_crypt(struct ablkcipher_request *req, unsigned long mode)
1086
+static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode)
10891087 {
1090
- struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1091
- struct atmel_aes_base_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1088
+ struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1089
+ struct atmel_aes_base_ctx *ctx = crypto_skcipher_ctx(skcipher);
10921090 struct atmel_aes_reqctx *rctx;
10931091 struct atmel_aes_dev *dd;
10941092
....@@ -1119,32 +1117,31 @@
11191117 if (!dd)
11201118 return -ENODEV;
11211119
1122
- rctx = ablkcipher_request_ctx(req);
1120
+ rctx = skcipher_request_ctx(req);
11231121 rctx->mode = mode;
11241122
1125
- if (!(mode & AES_FLAGS_ENCRYPT) && (req->src == req->dst)) {
1126
- unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1123
+ if ((mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_ECB &&
1124
+ !(mode & AES_FLAGS_ENCRYPT) && req->src == req->dst) {
1125
+ unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
11271126
1128
- if (req->nbytes >= ivsize)
1127
+ if (req->cryptlen >= ivsize)
11291128 scatterwalk_map_and_copy(rctx->lastc, req->src,
1130
- req->nbytes - ivsize,
1129
+ req->cryptlen - ivsize,
11311130 ivsize, 0);
11321131 }
11331132
11341133 return atmel_aes_handle_queue(dd, &req->base);
11351134 }
11361135
1137
-static int atmel_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
1136
+static int atmel_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
11381137 unsigned int keylen)
11391138 {
1140
- struct atmel_aes_base_ctx *ctx = crypto_ablkcipher_ctx(tfm);
1139
+ struct atmel_aes_base_ctx *ctx = crypto_skcipher_ctx(tfm);
11411140
11421141 if (keylen != AES_KEYSIZE_128 &&
11431142 keylen != AES_KEYSIZE_192 &&
1144
- keylen != AES_KEYSIZE_256) {
1145
- crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
1143
+ keylen != AES_KEYSIZE_256)
11461144 return -EINVAL;
1147
- }
11481145
11491146 memcpy(ctx->key, key, keylen);
11501147 ctx->keylen = keylen;
....@@ -1152,297 +1149,243 @@
11521149 return 0;
11531150 }
11541151
1155
-static int atmel_aes_ecb_encrypt(struct ablkcipher_request *req)
1152
+static int atmel_aes_ecb_encrypt(struct skcipher_request *req)
11561153 {
11571154 return atmel_aes_crypt(req, AES_FLAGS_ECB | AES_FLAGS_ENCRYPT);
11581155 }
11591156
1160
-static int atmel_aes_ecb_decrypt(struct ablkcipher_request *req)
1157
+static int atmel_aes_ecb_decrypt(struct skcipher_request *req)
11611158 {
11621159 return atmel_aes_crypt(req, AES_FLAGS_ECB);
11631160 }
11641161
1165
-static int atmel_aes_cbc_encrypt(struct ablkcipher_request *req)
1162
+static int atmel_aes_cbc_encrypt(struct skcipher_request *req)
11661163 {
11671164 return atmel_aes_crypt(req, AES_FLAGS_CBC | AES_FLAGS_ENCRYPT);
11681165 }
11691166
1170
-static int atmel_aes_cbc_decrypt(struct ablkcipher_request *req)
1167
+static int atmel_aes_cbc_decrypt(struct skcipher_request *req)
11711168 {
11721169 return atmel_aes_crypt(req, AES_FLAGS_CBC);
11731170 }
11741171
1175
-static int atmel_aes_ofb_encrypt(struct ablkcipher_request *req)
1172
+static int atmel_aes_ofb_encrypt(struct skcipher_request *req)
11761173 {
11771174 return atmel_aes_crypt(req, AES_FLAGS_OFB | AES_FLAGS_ENCRYPT);
11781175 }
11791176
1180
-static int atmel_aes_ofb_decrypt(struct ablkcipher_request *req)
1177
+static int atmel_aes_ofb_decrypt(struct skcipher_request *req)
11811178 {
11821179 return atmel_aes_crypt(req, AES_FLAGS_OFB);
11831180 }
11841181
1185
-static int atmel_aes_cfb_encrypt(struct ablkcipher_request *req)
1182
+static int atmel_aes_cfb_encrypt(struct skcipher_request *req)
11861183 {
11871184 return atmel_aes_crypt(req, AES_FLAGS_CFB128 | AES_FLAGS_ENCRYPT);
11881185 }
11891186
1190
-static int atmel_aes_cfb_decrypt(struct ablkcipher_request *req)
1187
+static int atmel_aes_cfb_decrypt(struct skcipher_request *req)
11911188 {
11921189 return atmel_aes_crypt(req, AES_FLAGS_CFB128);
11931190 }
11941191
1195
-static int atmel_aes_cfb64_encrypt(struct ablkcipher_request *req)
1192
+static int atmel_aes_cfb64_encrypt(struct skcipher_request *req)
11961193 {
11971194 return atmel_aes_crypt(req, AES_FLAGS_CFB64 | AES_FLAGS_ENCRYPT);
11981195 }
11991196
1200
-static int atmel_aes_cfb64_decrypt(struct ablkcipher_request *req)
1197
+static int atmel_aes_cfb64_decrypt(struct skcipher_request *req)
12011198 {
12021199 return atmel_aes_crypt(req, AES_FLAGS_CFB64);
12031200 }
12041201
1205
-static int atmel_aes_cfb32_encrypt(struct ablkcipher_request *req)
1202
+static int atmel_aes_cfb32_encrypt(struct skcipher_request *req)
12061203 {
12071204 return atmel_aes_crypt(req, AES_FLAGS_CFB32 | AES_FLAGS_ENCRYPT);
12081205 }
12091206
1210
-static int atmel_aes_cfb32_decrypt(struct ablkcipher_request *req)
1207
+static int atmel_aes_cfb32_decrypt(struct skcipher_request *req)
12111208 {
12121209 return atmel_aes_crypt(req, AES_FLAGS_CFB32);
12131210 }
12141211
1215
-static int atmel_aes_cfb16_encrypt(struct ablkcipher_request *req)
1212
+static int atmel_aes_cfb16_encrypt(struct skcipher_request *req)
12161213 {
12171214 return atmel_aes_crypt(req, AES_FLAGS_CFB16 | AES_FLAGS_ENCRYPT);
12181215 }
12191216
1220
-static int atmel_aes_cfb16_decrypt(struct ablkcipher_request *req)
1217
+static int atmel_aes_cfb16_decrypt(struct skcipher_request *req)
12211218 {
12221219 return atmel_aes_crypt(req, AES_FLAGS_CFB16);
12231220 }
12241221
1225
-static int atmel_aes_cfb8_encrypt(struct ablkcipher_request *req)
1222
+static int atmel_aes_cfb8_encrypt(struct skcipher_request *req)
12261223 {
12271224 return atmel_aes_crypt(req, AES_FLAGS_CFB8 | AES_FLAGS_ENCRYPT);
12281225 }
12291226
1230
-static int atmel_aes_cfb8_decrypt(struct ablkcipher_request *req)
1227
+static int atmel_aes_cfb8_decrypt(struct skcipher_request *req)
12311228 {
12321229 return atmel_aes_crypt(req, AES_FLAGS_CFB8);
12331230 }
12341231
1235
-static int atmel_aes_ctr_encrypt(struct ablkcipher_request *req)
1232
+static int atmel_aes_ctr_encrypt(struct skcipher_request *req)
12361233 {
12371234 return atmel_aes_crypt(req, AES_FLAGS_CTR | AES_FLAGS_ENCRYPT);
12381235 }
12391236
1240
-static int atmel_aes_ctr_decrypt(struct ablkcipher_request *req)
1237
+static int atmel_aes_ctr_decrypt(struct skcipher_request *req)
12411238 {
12421239 return atmel_aes_crypt(req, AES_FLAGS_CTR);
12431240 }
12441241
1245
-static int atmel_aes_cra_init(struct crypto_tfm *tfm)
1242
+static int atmel_aes_init_tfm(struct crypto_skcipher *tfm)
12461243 {
1247
- struct atmel_aes_ctx *ctx = crypto_tfm_ctx(tfm);
1244
+ struct atmel_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
12481245
1249
- tfm->crt_ablkcipher.reqsize = sizeof(struct atmel_aes_reqctx);
1246
+ crypto_skcipher_set_reqsize(tfm, sizeof(struct atmel_aes_reqctx));
12501247 ctx->base.start = atmel_aes_start;
12511248
12521249 return 0;
12531250 }
12541251
1255
-static int atmel_aes_ctr_cra_init(struct crypto_tfm *tfm)
1252
+static int atmel_aes_ctr_init_tfm(struct crypto_skcipher *tfm)
12561253 {
1257
- struct atmel_aes_ctx *ctx = crypto_tfm_ctx(tfm);
1254
+ struct atmel_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
12581255
1259
- tfm->crt_ablkcipher.reqsize = sizeof(struct atmel_aes_reqctx);
1256
+ crypto_skcipher_set_reqsize(tfm, sizeof(struct atmel_aes_reqctx));
12601257 ctx->base.start = atmel_aes_ctr_start;
12611258
12621259 return 0;
12631260 }
12641261
1265
-static struct crypto_alg aes_algs[] = {
1262
+static struct skcipher_alg aes_algs[] = {
12661263 {
1267
- .cra_name = "ecb(aes)",
1268
- .cra_driver_name = "atmel-ecb-aes",
1269
- .cra_priority = ATMEL_AES_PRIORITY,
1270
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1271
- .cra_blocksize = AES_BLOCK_SIZE,
1272
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1273
- .cra_alignmask = 0xf,
1274
- .cra_type = &crypto_ablkcipher_type,
1275
- .cra_module = THIS_MODULE,
1276
- .cra_init = atmel_aes_cra_init,
1277
- .cra_u.ablkcipher = {
1278
- .min_keysize = AES_MIN_KEY_SIZE,
1279
- .max_keysize = AES_MAX_KEY_SIZE,
1280
- .setkey = atmel_aes_setkey,
1281
- .encrypt = atmel_aes_ecb_encrypt,
1282
- .decrypt = atmel_aes_ecb_decrypt,
1283
- }
1264
+ .base.cra_name = "ecb(aes)",
1265
+ .base.cra_driver_name = "atmel-ecb-aes",
1266
+ .base.cra_blocksize = AES_BLOCK_SIZE,
1267
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1268
+
1269
+ .init = atmel_aes_init_tfm,
1270
+ .min_keysize = AES_MIN_KEY_SIZE,
1271
+ .max_keysize = AES_MAX_KEY_SIZE,
1272
+ .setkey = atmel_aes_setkey,
1273
+ .encrypt = atmel_aes_ecb_encrypt,
1274
+ .decrypt = atmel_aes_ecb_decrypt,
12841275 },
12851276 {
1286
- .cra_name = "cbc(aes)",
1287
- .cra_driver_name = "atmel-cbc-aes",
1288
- .cra_priority = ATMEL_AES_PRIORITY,
1289
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1290
- .cra_blocksize = AES_BLOCK_SIZE,
1291
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1292
- .cra_alignmask = 0xf,
1293
- .cra_type = &crypto_ablkcipher_type,
1294
- .cra_module = THIS_MODULE,
1295
- .cra_init = atmel_aes_cra_init,
1296
- .cra_u.ablkcipher = {
1297
- .min_keysize = AES_MIN_KEY_SIZE,
1298
- .max_keysize = AES_MAX_KEY_SIZE,
1299
- .ivsize = AES_BLOCK_SIZE,
1300
- .setkey = atmel_aes_setkey,
1301
- .encrypt = atmel_aes_cbc_encrypt,
1302
- .decrypt = atmel_aes_cbc_decrypt,
1303
- }
1277
+ .base.cra_name = "cbc(aes)",
1278
+ .base.cra_driver_name = "atmel-cbc-aes",
1279
+ .base.cra_blocksize = AES_BLOCK_SIZE,
1280
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1281
+
1282
+ .init = atmel_aes_init_tfm,
1283
+ .min_keysize = AES_MIN_KEY_SIZE,
1284
+ .max_keysize = AES_MAX_KEY_SIZE,
1285
+ .setkey = atmel_aes_setkey,
1286
+ .encrypt = atmel_aes_cbc_encrypt,
1287
+ .decrypt = atmel_aes_cbc_decrypt,
1288
+ .ivsize = AES_BLOCK_SIZE,
13041289 },
13051290 {
1306
- .cra_name = "ofb(aes)",
1307
- .cra_driver_name = "atmel-ofb-aes",
1308
- .cra_priority = ATMEL_AES_PRIORITY,
1309
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1310
- .cra_blocksize = AES_BLOCK_SIZE,
1311
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1312
- .cra_alignmask = 0xf,
1313
- .cra_type = &crypto_ablkcipher_type,
1314
- .cra_module = THIS_MODULE,
1315
- .cra_init = atmel_aes_cra_init,
1316
- .cra_u.ablkcipher = {
1317
- .min_keysize = AES_MIN_KEY_SIZE,
1318
- .max_keysize = AES_MAX_KEY_SIZE,
1319
- .ivsize = AES_BLOCK_SIZE,
1320
- .setkey = atmel_aes_setkey,
1321
- .encrypt = atmel_aes_ofb_encrypt,
1322
- .decrypt = atmel_aes_ofb_decrypt,
1323
- }
1291
+ .base.cra_name = "ofb(aes)",
1292
+ .base.cra_driver_name = "atmel-ofb-aes",
1293
+ .base.cra_blocksize = AES_BLOCK_SIZE,
1294
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1295
+
1296
+ .init = atmel_aes_init_tfm,
1297
+ .min_keysize = AES_MIN_KEY_SIZE,
1298
+ .max_keysize = AES_MAX_KEY_SIZE,
1299
+ .setkey = atmel_aes_setkey,
1300
+ .encrypt = atmel_aes_ofb_encrypt,
1301
+ .decrypt = atmel_aes_ofb_decrypt,
1302
+ .ivsize = AES_BLOCK_SIZE,
13241303 },
13251304 {
1326
- .cra_name = "cfb(aes)",
1327
- .cra_driver_name = "atmel-cfb-aes",
1328
- .cra_priority = ATMEL_AES_PRIORITY,
1329
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1330
- .cra_blocksize = AES_BLOCK_SIZE,
1331
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1332
- .cra_alignmask = 0xf,
1333
- .cra_type = &crypto_ablkcipher_type,
1334
- .cra_module = THIS_MODULE,
1335
- .cra_init = atmel_aes_cra_init,
1336
- .cra_u.ablkcipher = {
1337
- .min_keysize = AES_MIN_KEY_SIZE,
1338
- .max_keysize = AES_MAX_KEY_SIZE,
1339
- .ivsize = AES_BLOCK_SIZE,
1340
- .setkey = atmel_aes_setkey,
1341
- .encrypt = atmel_aes_cfb_encrypt,
1342
- .decrypt = atmel_aes_cfb_decrypt,
1343
- }
1305
+ .base.cra_name = "cfb(aes)",
1306
+ .base.cra_driver_name = "atmel-cfb-aes",
1307
+ .base.cra_blocksize = AES_BLOCK_SIZE,
1308
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1309
+
1310
+ .init = atmel_aes_init_tfm,
1311
+ .min_keysize = AES_MIN_KEY_SIZE,
1312
+ .max_keysize = AES_MAX_KEY_SIZE,
1313
+ .setkey = atmel_aes_setkey,
1314
+ .encrypt = atmel_aes_cfb_encrypt,
1315
+ .decrypt = atmel_aes_cfb_decrypt,
1316
+ .ivsize = AES_BLOCK_SIZE,
13441317 },
13451318 {
1346
- .cra_name = "cfb32(aes)",
1347
- .cra_driver_name = "atmel-cfb32-aes",
1348
- .cra_priority = ATMEL_AES_PRIORITY,
1349
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1350
- .cra_blocksize = CFB32_BLOCK_SIZE,
1351
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1352
- .cra_alignmask = 0x3,
1353
- .cra_type = &crypto_ablkcipher_type,
1354
- .cra_module = THIS_MODULE,
1355
- .cra_init = atmel_aes_cra_init,
1356
- .cra_u.ablkcipher = {
1357
- .min_keysize = AES_MIN_KEY_SIZE,
1358
- .max_keysize = AES_MAX_KEY_SIZE,
1359
- .ivsize = AES_BLOCK_SIZE,
1360
- .setkey = atmel_aes_setkey,
1361
- .encrypt = atmel_aes_cfb32_encrypt,
1362
- .decrypt = atmel_aes_cfb32_decrypt,
1363
- }
1319
+ .base.cra_name = "cfb32(aes)",
1320
+ .base.cra_driver_name = "atmel-cfb32-aes",
1321
+ .base.cra_blocksize = CFB32_BLOCK_SIZE,
1322
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1323
+
1324
+ .init = atmel_aes_init_tfm,
1325
+ .min_keysize = AES_MIN_KEY_SIZE,
1326
+ .max_keysize = AES_MAX_KEY_SIZE,
1327
+ .setkey = atmel_aes_setkey,
1328
+ .encrypt = atmel_aes_cfb32_encrypt,
1329
+ .decrypt = atmel_aes_cfb32_decrypt,
1330
+ .ivsize = AES_BLOCK_SIZE,
13641331 },
13651332 {
1366
- .cra_name = "cfb16(aes)",
1367
- .cra_driver_name = "atmel-cfb16-aes",
1368
- .cra_priority = ATMEL_AES_PRIORITY,
1369
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1370
- .cra_blocksize = CFB16_BLOCK_SIZE,
1371
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1372
- .cra_alignmask = 0x1,
1373
- .cra_type = &crypto_ablkcipher_type,
1374
- .cra_module = THIS_MODULE,
1375
- .cra_init = atmel_aes_cra_init,
1376
- .cra_u.ablkcipher = {
1377
- .min_keysize = AES_MIN_KEY_SIZE,
1378
- .max_keysize = AES_MAX_KEY_SIZE,
1379
- .ivsize = AES_BLOCK_SIZE,
1380
- .setkey = atmel_aes_setkey,
1381
- .encrypt = atmel_aes_cfb16_encrypt,
1382
- .decrypt = atmel_aes_cfb16_decrypt,
1383
- }
1333
+ .base.cra_name = "cfb16(aes)",
1334
+ .base.cra_driver_name = "atmel-cfb16-aes",
1335
+ .base.cra_blocksize = CFB16_BLOCK_SIZE,
1336
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1337
+
1338
+ .init = atmel_aes_init_tfm,
1339
+ .min_keysize = AES_MIN_KEY_SIZE,
1340
+ .max_keysize = AES_MAX_KEY_SIZE,
1341
+ .setkey = atmel_aes_setkey,
1342
+ .encrypt = atmel_aes_cfb16_encrypt,
1343
+ .decrypt = atmel_aes_cfb16_decrypt,
1344
+ .ivsize = AES_BLOCK_SIZE,
13841345 },
13851346 {
1386
- .cra_name = "cfb8(aes)",
1387
- .cra_driver_name = "atmel-cfb8-aes",
1388
- .cra_priority = ATMEL_AES_PRIORITY,
1389
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1390
- .cra_blocksize = CFB8_BLOCK_SIZE,
1391
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1392
- .cra_alignmask = 0x0,
1393
- .cra_type = &crypto_ablkcipher_type,
1394
- .cra_module = THIS_MODULE,
1395
- .cra_init = atmel_aes_cra_init,
1396
- .cra_u.ablkcipher = {
1397
- .min_keysize = AES_MIN_KEY_SIZE,
1398
- .max_keysize = AES_MAX_KEY_SIZE,
1399
- .ivsize = AES_BLOCK_SIZE,
1400
- .setkey = atmel_aes_setkey,
1401
- .encrypt = atmel_aes_cfb8_encrypt,
1402
- .decrypt = atmel_aes_cfb8_decrypt,
1403
- }
1347
+ .base.cra_name = "cfb8(aes)",
1348
+ .base.cra_driver_name = "atmel-cfb8-aes",
1349
+ .base.cra_blocksize = CFB8_BLOCK_SIZE,
1350
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1351
+
1352
+ .init = atmel_aes_init_tfm,
1353
+ .min_keysize = AES_MIN_KEY_SIZE,
1354
+ .max_keysize = AES_MAX_KEY_SIZE,
1355
+ .setkey = atmel_aes_setkey,
1356
+ .encrypt = atmel_aes_cfb8_encrypt,
1357
+ .decrypt = atmel_aes_cfb8_decrypt,
1358
+ .ivsize = AES_BLOCK_SIZE,
14041359 },
14051360 {
1406
- .cra_name = "ctr(aes)",
1407
- .cra_driver_name = "atmel-ctr-aes",
1408
- .cra_priority = ATMEL_AES_PRIORITY,
1409
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1410
- .cra_blocksize = 1,
1411
- .cra_ctxsize = sizeof(struct atmel_aes_ctr_ctx),
1412
- .cra_alignmask = 0xf,
1413
- .cra_type = &crypto_ablkcipher_type,
1414
- .cra_module = THIS_MODULE,
1415
- .cra_init = atmel_aes_ctr_cra_init,
1416
- .cra_u.ablkcipher = {
1417
- .min_keysize = AES_MIN_KEY_SIZE,
1418
- .max_keysize = AES_MAX_KEY_SIZE,
1419
- .ivsize = AES_BLOCK_SIZE,
1420
- .setkey = atmel_aes_setkey,
1421
- .encrypt = atmel_aes_ctr_encrypt,
1422
- .decrypt = atmel_aes_ctr_decrypt,
1423
- }
1361
+ .base.cra_name = "ctr(aes)",
1362
+ .base.cra_driver_name = "atmel-ctr-aes",
1363
+ .base.cra_blocksize = 1,
1364
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctr_ctx),
1365
+
1366
+ .init = atmel_aes_ctr_init_tfm,
1367
+ .min_keysize = AES_MIN_KEY_SIZE,
1368
+ .max_keysize = AES_MAX_KEY_SIZE,
1369
+ .setkey = atmel_aes_setkey,
1370
+ .encrypt = atmel_aes_ctr_encrypt,
1371
+ .decrypt = atmel_aes_ctr_decrypt,
1372
+ .ivsize = AES_BLOCK_SIZE,
14241373 },
14251374 };
14261375
1427
-static struct crypto_alg aes_cfb64_alg = {
1428
- .cra_name = "cfb64(aes)",
1429
- .cra_driver_name = "atmel-cfb64-aes",
1430
- .cra_priority = ATMEL_AES_PRIORITY,
1431
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1432
- .cra_blocksize = CFB64_BLOCK_SIZE,
1433
- .cra_ctxsize = sizeof(struct atmel_aes_ctx),
1434
- .cra_alignmask = 0x7,
1435
- .cra_type = &crypto_ablkcipher_type,
1436
- .cra_module = THIS_MODULE,
1437
- .cra_init = atmel_aes_cra_init,
1438
- .cra_u.ablkcipher = {
1439
- .min_keysize = AES_MIN_KEY_SIZE,
1440
- .max_keysize = AES_MAX_KEY_SIZE,
1441
- .ivsize = AES_BLOCK_SIZE,
1442
- .setkey = atmel_aes_setkey,
1443
- .encrypt = atmel_aes_cfb64_encrypt,
1444
- .decrypt = atmel_aes_cfb64_decrypt,
1445
- }
1376
+static struct skcipher_alg aes_cfb64_alg = {
1377
+ .base.cra_name = "cfb64(aes)",
1378
+ .base.cra_driver_name = "atmel-cfb64-aes",
1379
+ .base.cra_blocksize = CFB64_BLOCK_SIZE,
1380
+ .base.cra_ctxsize = sizeof(struct atmel_aes_ctx),
1381
+
1382
+ .init = atmel_aes_init_tfm,
1383
+ .min_keysize = AES_MIN_KEY_SIZE,
1384
+ .max_keysize = AES_MAX_KEY_SIZE,
1385
+ .setkey = atmel_aes_setkey,
1386
+ .encrypt = atmel_aes_cfb64_encrypt,
1387
+ .decrypt = atmel_aes_cfb64_decrypt,
1388
+ .ivsize = AES_BLOCK_SIZE,
14461389 };
14471390
14481391
....@@ -1450,7 +1393,7 @@
14501393
14511394 static int atmel_aes_gcm_ghash(struct atmel_aes_dev *dd,
14521395 const u32 *data, size_t datalen,
1453
- const u32 *ghash_in, u32 *ghash_out,
1396
+ const __be32 *ghash_in, __be32 *ghash_out,
14541397 atmel_aes_fn_t resume);
14551398 static int atmel_aes_gcm_ghash_init(struct atmel_aes_dev *dd);
14561399 static int atmel_aes_gcm_ghash_finalize(struct atmel_aes_dev *dd);
....@@ -1471,7 +1414,7 @@
14711414
14721415 static int atmel_aes_gcm_ghash(struct atmel_aes_dev *dd,
14731416 const u32 *data, size_t datalen,
1474
- const u32 *ghash_in, u32 *ghash_out,
1417
+ const __be32 *ghash_in, __be32 *ghash_out,
14751418 atmel_aes_fn_t resume)
14761419 {
14771420 struct atmel_aes_gcm_ctx *ctx = atmel_aes_gcm_ctx_cast(dd->ctx);
....@@ -1558,7 +1501,7 @@
15581501
15591502 memcpy(data, iv, ivsize);
15601503 memset(data + ivsize, 0, padlen + sizeof(u64));
1561
- ((u64 *)(data + datalen))[-1] = cpu_to_be64(ivsize * 8);
1504
+ ((__be64 *)(data + datalen))[-1] = cpu_to_be64(ivsize * 8);
15621505
15631506 return atmel_aes_gcm_ghash(dd, (const u32 *)data, datalen,
15641507 NULL, ctx->j0, atmel_aes_gcm_process);
....@@ -1591,12 +1534,12 @@
15911534 {
15921535 struct atmel_aes_gcm_ctx *ctx = atmel_aes_gcm_ctx_cast(dd->ctx);
15931536 struct aead_request *req = aead_request_cast(dd->areq);
1594
- u32 j0_lsw, *j0 = ctx->j0;
1537
+ __be32 j0_lsw, *j0 = ctx->j0;
15951538 size_t padlen;
15961539
15971540 /* Write incr32(J0) into IV. */
15981541 j0_lsw = j0[3];
1599
- j0[3] = cpu_to_be32(be32_to_cpu(j0[3]) + 1);
1542
+ be32_add_cpu(&j0[3], 1);
16001543 atmel_aes_write_block(dd, AES_IVR(0), j0);
16011544 j0[3] = j0_lsw;
16021545
....@@ -1674,7 +1617,7 @@
16741617 {
16751618 struct atmel_aes_gcm_ctx *ctx = atmel_aes_gcm_ctx_cast(dd->ctx);
16761619 struct aead_request *req = aead_request_cast(dd->areq);
1677
- u64 *data = dd->buf;
1620
+ __be64 *data = dd->buf;
16781621
16791622 if (likely(dd->flags & AES_FLAGS_GTAGEN)) {
16801623 if (!(atmel_aes_read(dd, AES_ISR) & AES_INT_TAGRDY)) {
....@@ -1771,10 +1714,8 @@
17711714
17721715 if (keylen != AES_KEYSIZE_256 &&
17731716 keylen != AES_KEYSIZE_192 &&
1774
- keylen != AES_KEYSIZE_128) {
1775
- crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
1717
+ keylen != AES_KEYSIZE_128)
17761718 return -EINVAL;
1777
- }
17781719
17791720 memcpy(ctx->key, key, keylen);
17801721 ctx->keylen = keylen;
....@@ -1785,21 +1726,7 @@
17851726 static int atmel_aes_gcm_setauthsize(struct crypto_aead *tfm,
17861727 unsigned int authsize)
17871728 {
1788
- /* Same as crypto_gcm_authsize() from crypto/gcm.c */
1789
- switch (authsize) {
1790
- case 4:
1791
- case 8:
1792
- case 12:
1793
- case 13:
1794
- case 14:
1795
- case 15:
1796
- case 16:
1797
- break;
1798
- default:
1799
- return -EINVAL;
1800
- }
1801
-
1802
- return 0;
1729
+ return crypto_gcm_check_authsize(authsize);
18031730 }
18041731
18051732 static int atmel_aes_gcm_encrypt(struct aead_request *req)
....@@ -1834,12 +1761,8 @@
18341761 .base = {
18351762 .cra_name = "gcm(aes)",
18361763 .cra_driver_name = "atmel-gcm-aes",
1837
- .cra_priority = ATMEL_AES_PRIORITY,
1838
- .cra_flags = CRYPTO_ALG_ASYNC,
18391764 .cra_blocksize = 1,
18401765 .cra_ctxsize = sizeof(struct atmel_aes_gcm_ctx),
1841
- .cra_alignmask = 0xf,
1842
- .cra_module = THIS_MODULE,
18431766 },
18441767 };
18451768
....@@ -1857,8 +1780,8 @@
18571780 static int atmel_aes_xts_start(struct atmel_aes_dev *dd)
18581781 {
18591782 struct atmel_aes_xts_ctx *ctx = atmel_aes_xts_ctx_cast(dd->ctx);
1860
- struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
1861
- struct atmel_aes_reqctx *rctx = ablkcipher_request_ctx(req);
1783
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
1784
+ struct atmel_aes_reqctx *rctx = skcipher_request_ctx(req);
18621785 unsigned long flags;
18631786 int err;
18641787
....@@ -1868,7 +1791,7 @@
18681791 if (err)
18691792 return atmel_aes_complete(dd, err);
18701793
1871
- /* Compute the tweak value from req->info with ecb(aes). */
1794
+ /* Compute the tweak value from req->iv with ecb(aes). */
18721795 flags = dd->flags;
18731796 dd->flags &= ~AES_FLAGS_MODE_MASK;
18741797 dd->flags |= (AES_FLAGS_ECB | AES_FLAGS_ENCRYPT);
....@@ -1876,16 +1799,16 @@
18761799 ctx->key2, ctx->base.keylen);
18771800 dd->flags = flags;
18781801
1879
- atmel_aes_write_block(dd, AES_IDATAR(0), req->info);
1802
+ atmel_aes_write_block(dd, AES_IDATAR(0), req->iv);
18801803 return atmel_aes_wait_for_data_ready(dd, atmel_aes_xts_process_data);
18811804 }
18821805
18831806 static int atmel_aes_xts_process_data(struct atmel_aes_dev *dd)
18841807 {
1885
- struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
1886
- bool use_dma = (req->nbytes >= ATMEL_AES_DMA_THRESHOLD);
1808
+ struct skcipher_request *req = skcipher_request_cast(dd->areq);
1809
+ bool use_dma = (req->cryptlen >= ATMEL_AES_DMA_THRESHOLD);
18871810 u32 tweak[AES_BLOCK_SIZE / sizeof(u32)];
1888
- static const u32 one[AES_BLOCK_SIZE / sizeof(u32)] = {cpu_to_le32(1), };
1811
+ static const __le32 one[AES_BLOCK_SIZE / sizeof(u32)] = {cpu_to_le32(1), };
18891812 u8 *tweak_bytes = (u8 *)tweak;
18901813 int i;
18911814
....@@ -1908,20 +1831,21 @@
19081831 atmel_aes_write_block(dd, AES_TWR(0), tweak);
19091832 atmel_aes_write_block(dd, AES_ALPHAR(0), one);
19101833 if (use_dma)
1911
- return atmel_aes_dma_start(dd, req->src, req->dst, req->nbytes,
1834
+ return atmel_aes_dma_start(dd, req->src, req->dst,
1835
+ req->cryptlen,
19121836 atmel_aes_transfer_complete);
19131837
1914
- return atmel_aes_cpu_start(dd, req->src, req->dst, req->nbytes,
1838
+ return atmel_aes_cpu_start(dd, req->src, req->dst, req->cryptlen,
19151839 atmel_aes_transfer_complete);
19161840 }
19171841
1918
-static int atmel_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
1842
+static int atmel_aes_xts_setkey(struct crypto_skcipher *tfm, const u8 *key,
19191843 unsigned int keylen)
19201844 {
1921
- struct atmel_aes_xts_ctx *ctx = crypto_ablkcipher_ctx(tfm);
1845
+ struct atmel_aes_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
19221846 int err;
19231847
1924
- err = xts_check_key(crypto_ablkcipher_tfm(tfm), key, keylen);
1848
+ err = xts_check_key(crypto_skcipher_tfm(tfm), key, keylen);
19251849 if (err)
19261850 return err;
19271851
....@@ -1932,45 +1856,39 @@
19321856 return 0;
19331857 }
19341858
1935
-static int atmel_aes_xts_encrypt(struct ablkcipher_request *req)
1859
+static int atmel_aes_xts_encrypt(struct skcipher_request *req)
19361860 {
19371861 return atmel_aes_crypt(req, AES_FLAGS_XTS | AES_FLAGS_ENCRYPT);
19381862 }
19391863
1940
-static int atmel_aes_xts_decrypt(struct ablkcipher_request *req)
1864
+static int atmel_aes_xts_decrypt(struct skcipher_request *req)
19411865 {
19421866 return atmel_aes_crypt(req, AES_FLAGS_XTS);
19431867 }
19441868
1945
-static int atmel_aes_xts_cra_init(struct crypto_tfm *tfm)
1869
+static int atmel_aes_xts_init_tfm(struct crypto_skcipher *tfm)
19461870 {
1947
- struct atmel_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm);
1871
+ struct atmel_aes_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
19481872
1949
- tfm->crt_ablkcipher.reqsize = sizeof(struct atmel_aes_reqctx);
1873
+ crypto_skcipher_set_reqsize(tfm, sizeof(struct atmel_aes_reqctx));
19501874 ctx->base.start = atmel_aes_xts_start;
19511875
19521876 return 0;
19531877 }
19541878
1955
-static struct crypto_alg aes_xts_alg = {
1956
- .cra_name = "xts(aes)",
1957
- .cra_driver_name = "atmel-xts-aes",
1958
- .cra_priority = ATMEL_AES_PRIORITY,
1959
- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1960
- .cra_blocksize = AES_BLOCK_SIZE,
1961
- .cra_ctxsize = sizeof(struct atmel_aes_xts_ctx),
1962
- .cra_alignmask = 0xf,
1963
- .cra_type = &crypto_ablkcipher_type,
1964
- .cra_module = THIS_MODULE,
1965
- .cra_init = atmel_aes_xts_cra_init,
1966
- .cra_u.ablkcipher = {
1967
- .min_keysize = 2 * AES_MIN_KEY_SIZE,
1968
- .max_keysize = 2 * AES_MAX_KEY_SIZE,
1969
- .ivsize = AES_BLOCK_SIZE,
1970
- .setkey = atmel_aes_xts_setkey,
1971
- .encrypt = atmel_aes_xts_encrypt,
1972
- .decrypt = atmel_aes_xts_decrypt,
1973
- }
1879
+static struct skcipher_alg aes_xts_alg = {
1880
+ .base.cra_name = "xts(aes)",
1881
+ .base.cra_driver_name = "atmel-xts-aes",
1882
+ .base.cra_blocksize = AES_BLOCK_SIZE,
1883
+ .base.cra_ctxsize = sizeof(struct atmel_aes_xts_ctx),
1884
+
1885
+ .min_keysize = 2 * AES_MIN_KEY_SIZE,
1886
+ .max_keysize = 2 * AES_MAX_KEY_SIZE,
1887
+ .ivsize = AES_BLOCK_SIZE,
1888
+ .setkey = atmel_aes_xts_setkey,
1889
+ .encrypt = atmel_aes_xts_encrypt,
1890
+ .decrypt = atmel_aes_xts_decrypt,
1891
+ .init = atmel_aes_xts_init_tfm,
19741892 };
19751893
19761894 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
....@@ -2041,7 +1959,7 @@
20411959 struct atmel_aes_authenc_reqctx *rctx = aead_request_ctx(req);
20421960 bool enc = atmel_aes_is_encrypt(dd);
20431961 struct scatterlist *src, *dst;
2044
- u32 iv[AES_BLOCK_SIZE / sizeof(u32)];
1962
+ __be32 iv[AES_BLOCK_SIZE / sizeof(u32)];
20451963 u32 emr;
20461964
20471965 if (is_async)
....@@ -2123,7 +2041,6 @@
21232041 {
21242042 struct atmel_aes_authenc_ctx *ctx = crypto_aead_ctx(tfm);
21252043 struct crypto_authenc_keys keys;
2126
- u32 flags;
21272044 int err;
21282045
21292046 if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
....@@ -2133,11 +2050,9 @@
21332050 goto badkey;
21342051
21352052 /* Save auth key. */
2136
- flags = crypto_aead_get_flags(tfm);
21372053 err = atmel_sha_authenc_setkey(ctx->auth,
21382054 keys.authkey, keys.authkeylen,
2139
- &flags);
2140
- crypto_aead_set_flags(tfm, flags & CRYPTO_TFM_RES_MASK);
2055
+ crypto_aead_get_flags(tfm));
21412056 if (err) {
21422057 memzero_explicit(&keys, sizeof(keys));
21432058 return err;
....@@ -2151,7 +2066,6 @@
21512066 return 0;
21522067
21532068 badkey:
2154
- crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
21552069 memzero_explicit(&keys, sizeof(keys));
21562070 return -EINVAL;
21572071 }
....@@ -2262,12 +2176,8 @@
22622176 .base = {
22632177 .cra_name = "authenc(hmac(sha1),cbc(aes))",
22642178 .cra_driver_name = "atmel-authenc-hmac-sha1-cbc-aes",
2265
- .cra_priority = ATMEL_AES_PRIORITY,
2266
- .cra_flags = CRYPTO_ALG_ASYNC,
22672179 .cra_blocksize = AES_BLOCK_SIZE,
22682180 .cra_ctxsize = sizeof(struct atmel_aes_authenc_ctx),
2269
- .cra_alignmask = 0xf,
2270
- .cra_module = THIS_MODULE,
22712181 },
22722182 },
22732183 {
....@@ -2282,12 +2192,8 @@
22822192 .base = {
22832193 .cra_name = "authenc(hmac(sha224),cbc(aes))",
22842194 .cra_driver_name = "atmel-authenc-hmac-sha224-cbc-aes",
2285
- .cra_priority = ATMEL_AES_PRIORITY,
2286
- .cra_flags = CRYPTO_ALG_ASYNC,
22872195 .cra_blocksize = AES_BLOCK_SIZE,
22882196 .cra_ctxsize = sizeof(struct atmel_aes_authenc_ctx),
2289
- .cra_alignmask = 0xf,
2290
- .cra_module = THIS_MODULE,
22912197 },
22922198 },
22932199 {
....@@ -2302,12 +2208,8 @@
23022208 .base = {
23032209 .cra_name = "authenc(hmac(sha256),cbc(aes))",
23042210 .cra_driver_name = "atmel-authenc-hmac-sha256-cbc-aes",
2305
- .cra_priority = ATMEL_AES_PRIORITY,
2306
- .cra_flags = CRYPTO_ALG_ASYNC,
23072211 .cra_blocksize = AES_BLOCK_SIZE,
23082212 .cra_ctxsize = sizeof(struct atmel_aes_authenc_ctx),
2309
- .cra_alignmask = 0xf,
2310
- .cra_module = THIS_MODULE,
23112213 },
23122214 },
23132215 {
....@@ -2322,12 +2224,8 @@
23222224 .base = {
23232225 .cra_name = "authenc(hmac(sha384),cbc(aes))",
23242226 .cra_driver_name = "atmel-authenc-hmac-sha384-cbc-aes",
2325
- .cra_priority = ATMEL_AES_PRIORITY,
2326
- .cra_flags = CRYPTO_ALG_ASYNC,
23272227 .cra_blocksize = AES_BLOCK_SIZE,
23282228 .cra_ctxsize = sizeof(struct atmel_aes_authenc_ctx),
2329
- .cra_alignmask = 0xf,
2330
- .cra_module = THIS_MODULE,
23312229 },
23322230 },
23332231 {
....@@ -2342,12 +2240,8 @@
23422240 .base = {
23432241 .cra_name = "authenc(hmac(sha512),cbc(aes))",
23442242 .cra_driver_name = "atmel-authenc-hmac-sha512-cbc-aes",
2345
- .cra_priority = ATMEL_AES_PRIORITY,
2346
- .cra_flags = CRYPTO_ALG_ASYNC,
23472243 .cra_blocksize = AES_BLOCK_SIZE,
23482244 .cra_ctxsize = sizeof(struct atmel_aes_authenc_ctx),
2349
- .cra_alignmask = 0xf,
2350
- .cra_module = THIS_MODULE,
23512245 },
23522246 },
23532247 };
....@@ -2374,47 +2268,30 @@
23742268 free_page((unsigned long)dd->buf);
23752269 }
23762270
2377
-static bool atmel_aes_filter(struct dma_chan *chan, void *slave)
2271
+static int atmel_aes_dma_init(struct atmel_aes_dev *dd)
23782272 {
2379
- struct at_dma_slave *sl = slave;
2380
-
2381
- if (sl && sl->dma_dev == chan->device->dev) {
2382
- chan->private = sl;
2383
- return true;
2384
- } else {
2385
- return false;
2386
- }
2387
-}
2388
-
2389
-static int atmel_aes_dma_init(struct atmel_aes_dev *dd,
2390
- struct crypto_platform_data *pdata)
2391
-{
2392
- struct at_dma_slave *slave;
2393
- dma_cap_mask_t mask;
2394
-
2395
- dma_cap_zero(mask);
2396
- dma_cap_set(DMA_SLAVE, mask);
2273
+ int ret;
23972274
23982275 /* Try to grab 2 DMA channels */
2399
- slave = &pdata->dma_slave->rxdata;
2400
- dd->src.chan = dma_request_slave_channel_compat(mask, atmel_aes_filter,
2401
- slave, dd->dev, "tx");
2402
- if (!dd->src.chan)
2276
+ dd->src.chan = dma_request_chan(dd->dev, "tx");
2277
+ if (IS_ERR(dd->src.chan)) {
2278
+ ret = PTR_ERR(dd->src.chan);
24032279 goto err_dma_in;
2280
+ }
24042281
2405
- slave = &pdata->dma_slave->txdata;
2406
- dd->dst.chan = dma_request_slave_channel_compat(mask, atmel_aes_filter,
2407
- slave, dd->dev, "rx");
2408
- if (!dd->dst.chan)
2282
+ dd->dst.chan = dma_request_chan(dd->dev, "rx");
2283
+ if (IS_ERR(dd->dst.chan)) {
2284
+ ret = PTR_ERR(dd->dst.chan);
24092285 goto err_dma_out;
2286
+ }
24102287
24112288 return 0;
24122289
24132290 err_dma_out:
24142291 dma_release_channel(dd->src.chan);
24152292 err_dma_in:
2416
- dev_warn(dd->dev, "no DMA channel available\n");
2417
- return -ENODEV;
2293
+ dev_err(dd->dev, "no DMA channel available\n");
2294
+ return ret;
24182295 }
24192296
24202297 static void atmel_aes_dma_cleanup(struct atmel_aes_dev *dd)
....@@ -2467,16 +2344,24 @@
24672344 #endif
24682345
24692346 if (dd->caps.has_xts)
2470
- crypto_unregister_alg(&aes_xts_alg);
2347
+ crypto_unregister_skcipher(&aes_xts_alg);
24712348
24722349 if (dd->caps.has_gcm)
24732350 crypto_unregister_aead(&aes_gcm_alg);
24742351
24752352 if (dd->caps.has_cfb64)
2476
- crypto_unregister_alg(&aes_cfb64_alg);
2353
+ crypto_unregister_skcipher(&aes_cfb64_alg);
24772354
24782355 for (i = 0; i < ARRAY_SIZE(aes_algs); i++)
2479
- crypto_unregister_alg(&aes_algs[i]);
2356
+ crypto_unregister_skcipher(&aes_algs[i]);
2357
+}
2358
+
2359
+static void atmel_aes_crypto_alg_init(struct crypto_alg *alg)
2360
+{
2361
+ alg->cra_flags = CRYPTO_ALG_ASYNC;
2362
+ alg->cra_alignmask = 0xf;
2363
+ alg->cra_priority = ATMEL_AES_PRIORITY;
2364
+ alg->cra_module = THIS_MODULE;
24802365 }
24812366
24822367 static int atmel_aes_register_algs(struct atmel_aes_dev *dd)
....@@ -2484,25 +2369,33 @@
24842369 int err, i, j;
24852370
24862371 for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
2487
- err = crypto_register_alg(&aes_algs[i]);
2372
+ atmel_aes_crypto_alg_init(&aes_algs[i].base);
2373
+
2374
+ err = crypto_register_skcipher(&aes_algs[i]);
24882375 if (err)
24892376 goto err_aes_algs;
24902377 }
24912378
24922379 if (dd->caps.has_cfb64) {
2493
- err = crypto_register_alg(&aes_cfb64_alg);
2380
+ atmel_aes_crypto_alg_init(&aes_cfb64_alg.base);
2381
+
2382
+ err = crypto_register_skcipher(&aes_cfb64_alg);
24942383 if (err)
24952384 goto err_aes_cfb64_alg;
24962385 }
24972386
24982387 if (dd->caps.has_gcm) {
2388
+ atmel_aes_crypto_alg_init(&aes_gcm_alg.base);
2389
+
24992390 err = crypto_register_aead(&aes_gcm_alg);
25002391 if (err)
25012392 goto err_aes_gcm_alg;
25022393 }
25032394
25042395 if (dd->caps.has_xts) {
2505
- err = crypto_register_alg(&aes_xts_alg);
2396
+ atmel_aes_crypto_alg_init(&aes_xts_alg.base);
2397
+
2398
+ err = crypto_register_skcipher(&aes_xts_alg);
25062399 if (err)
25072400 goto err_aes_xts_alg;
25082401 }
....@@ -2510,6 +2403,8 @@
25102403 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
25112404 if (dd->caps.has_authenc) {
25122405 for (i = 0; i < ARRAY_SIZE(aes_authenc_algs); i++) {
2406
+ atmel_aes_crypto_alg_init(&aes_authenc_algs[i].base);
2407
+
25132408 err = crypto_register_aead(&aes_authenc_algs[i]);
25142409 if (err)
25152410 goto err_aes_authenc_alg;
....@@ -2524,17 +2419,17 @@
25242419 err_aes_authenc_alg:
25252420 for (j = 0; j < i; j++)
25262421 crypto_unregister_aead(&aes_authenc_algs[j]);
2527
- crypto_unregister_alg(&aes_xts_alg);
2422
+ crypto_unregister_skcipher(&aes_xts_alg);
25282423 #endif
25292424 err_aes_xts_alg:
25302425 crypto_unregister_aead(&aes_gcm_alg);
25312426 err_aes_gcm_alg:
2532
- crypto_unregister_alg(&aes_cfb64_alg);
2427
+ crypto_unregister_skcipher(&aes_cfb64_alg);
25332428 err_aes_cfb64_alg:
25342429 i = ARRAY_SIZE(aes_algs);
25352430 err_aes_algs:
25362431 for (j = 0; j < i; j++)
2537
- crypto_unregister_alg(&aes_algs[j]);
2432
+ crypto_unregister_skcipher(&aes_algs[j]);
25382433
25392434 return err;
25402435 }
....@@ -2584,65 +2479,18 @@
25842479 { /* sentinel */ }
25852480 };
25862481 MODULE_DEVICE_TABLE(of, atmel_aes_dt_ids);
2587
-
2588
-static struct crypto_platform_data *atmel_aes_of_init(struct platform_device *pdev)
2589
-{
2590
- struct device_node *np = pdev->dev.of_node;
2591
- struct crypto_platform_data *pdata;
2592
-
2593
- if (!np) {
2594
- dev_err(&pdev->dev, "device node not found\n");
2595
- return ERR_PTR(-EINVAL);
2596
- }
2597
-
2598
- pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
2599
- if (!pdata)
2600
- return ERR_PTR(-ENOMEM);
2601
-
2602
- pdata->dma_slave = devm_kzalloc(&pdev->dev,
2603
- sizeof(*(pdata->dma_slave)),
2604
- GFP_KERNEL);
2605
- if (!pdata->dma_slave) {
2606
- devm_kfree(&pdev->dev, pdata);
2607
- return ERR_PTR(-ENOMEM);
2608
- }
2609
-
2610
- return pdata;
2611
-}
2612
-#else
2613
-static inline struct crypto_platform_data *atmel_aes_of_init(struct platform_device *pdev)
2614
-{
2615
- return ERR_PTR(-EINVAL);
2616
-}
26172482 #endif
26182483
26192484 static int atmel_aes_probe(struct platform_device *pdev)
26202485 {
26212486 struct atmel_aes_dev *aes_dd;
2622
- struct crypto_platform_data *pdata;
26232487 struct device *dev = &pdev->dev;
26242488 struct resource *aes_res;
26252489 int err;
26262490
2627
- pdata = pdev->dev.platform_data;
2628
- if (!pdata) {
2629
- pdata = atmel_aes_of_init(pdev);
2630
- if (IS_ERR(pdata)) {
2631
- err = PTR_ERR(pdata);
2632
- goto aes_dd_err;
2633
- }
2634
- }
2635
-
2636
- if (!pdata->dma_slave) {
2637
- err = -ENXIO;
2638
- goto aes_dd_err;
2639
- }
2640
-
26412491 aes_dd = devm_kzalloc(&pdev->dev, sizeof(*aes_dd), GFP_KERNEL);
2642
- if (aes_dd == NULL) {
2643
- err = -ENOMEM;
2644
- goto aes_dd_err;
2645
- }
2492
+ if (!aes_dd)
2493
+ return -ENOMEM;
26462494
26472495 aes_dd->dev = dev;
26482496
....@@ -2663,23 +2511,22 @@
26632511 if (!aes_res) {
26642512 dev_err(dev, "no MEM resource info\n");
26652513 err = -ENODEV;
2666
- goto res_err;
2514
+ goto err_tasklet_kill;
26672515 }
26682516 aes_dd->phys_base = aes_res->start;
26692517
26702518 /* Get the IRQ */
26712519 aes_dd->irq = platform_get_irq(pdev, 0);
26722520 if (aes_dd->irq < 0) {
2673
- dev_err(dev, "no IRQ resource info\n");
26742521 err = aes_dd->irq;
2675
- goto res_err;
2522
+ goto err_tasklet_kill;
26762523 }
26772524
26782525 err = devm_request_irq(&pdev->dev, aes_dd->irq, atmel_aes_irq,
26792526 IRQF_SHARED, "atmel-aes", aes_dd);
26802527 if (err) {
26812528 dev_err(dev, "unable to request aes irq.\n");
2682
- goto res_err;
2529
+ goto err_tasklet_kill;
26832530 }
26842531
26852532 /* Initializing the clock */
....@@ -2687,40 +2534,40 @@
26872534 if (IS_ERR(aes_dd->iclk)) {
26882535 dev_err(dev, "clock initialization failed.\n");
26892536 err = PTR_ERR(aes_dd->iclk);
2690
- goto res_err;
2537
+ goto err_tasklet_kill;
26912538 }
26922539
26932540 aes_dd->io_base = devm_ioremap_resource(&pdev->dev, aes_res);
26942541 if (IS_ERR(aes_dd->io_base)) {
26952542 dev_err(dev, "can't ioremap\n");
26962543 err = PTR_ERR(aes_dd->io_base);
2697
- goto res_err;
2544
+ goto err_tasklet_kill;
26982545 }
26992546
27002547 err = clk_prepare(aes_dd->iclk);
27012548 if (err)
2702
- goto res_err;
2549
+ goto err_tasklet_kill;
27032550
27042551 err = atmel_aes_hw_version_init(aes_dd);
27052552 if (err)
2706
- goto iclk_unprepare;
2553
+ goto err_iclk_unprepare;
27072554
27082555 atmel_aes_get_cap(aes_dd);
27092556
27102557 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
27112558 if (aes_dd->caps.has_authenc && !atmel_sha_authenc_is_ready()) {
27122559 err = -EPROBE_DEFER;
2713
- goto iclk_unprepare;
2560
+ goto err_iclk_unprepare;
27142561 }
27152562 #endif
27162563
27172564 err = atmel_aes_buff_init(aes_dd);
27182565 if (err)
2719
- goto err_aes_buff;
2566
+ goto err_iclk_unprepare;
27202567
2721
- err = atmel_aes_dma_init(aes_dd, pdata);
2568
+ err = atmel_aes_dma_init(aes_dd);
27222569 if (err)
2723
- goto err_aes_dma;
2570
+ goto err_buff_cleanup;
27242571
27252572 spin_lock(&atmel_aes.lock);
27262573 list_add_tail(&aes_dd->list, &atmel_aes.dev_list);
....@@ -2741,17 +2588,13 @@
27412588 list_del(&aes_dd->list);
27422589 spin_unlock(&atmel_aes.lock);
27432590 atmel_aes_dma_cleanup(aes_dd);
2744
-err_aes_dma:
2591
+err_buff_cleanup:
27452592 atmel_aes_buff_cleanup(aes_dd);
2746
-err_aes_buff:
2747
-iclk_unprepare:
2593
+err_iclk_unprepare:
27482594 clk_unprepare(aes_dd->iclk);
2749
-res_err:
2595
+err_tasklet_kill:
27502596 tasklet_kill(&aes_dd->done_task);
27512597 tasklet_kill(&aes_dd->queue_task);
2752
-aes_dd_err:
2753
- if (err != -EPROBE_DEFER)
2754
- dev_err(dev, "initialization failed.\n");
27552598
27562599 return err;
27572600 }