Skip to content

Commit cf2c0fe

Browse files
committed
crypto: aes-ce-ccm - Use skcipher walk interface
This patch makes use of the new skcipher walk interface instead of the obsolete blkcipher walk interface. Signed-off-by: Herbert Xu <[email protected]>
1 parent b286d8b commit cf2c0fe

File tree

1 file changed

+13
-37
lines changed

1 file changed

+13
-37
lines changed

arch/arm64/crypto/aes-ce-ccm-glue.c

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <asm/neon.h>
1212
#include <asm/unaligned.h>
1313
#include <crypto/aes.h>
14-
#include <crypto/algapi.h>
1514
#include <crypto/scatterwalk.h>
1615
#include <crypto/internal/aead.h>
16+
#include <crypto/internal/skcipher.h>
1717
#include <linux/module.h>
1818

1919
#include "aes-ce-setkey.h"
@@ -149,12 +149,7 @@ static int ccm_encrypt(struct aead_request *req)
149149
{
150150
struct crypto_aead *aead = crypto_aead_reqtfm(req);
151151
struct crypto_aes_ctx *ctx = crypto_aead_ctx(aead);
152-
struct blkcipher_desc desc = { .info = req->iv };
153-
struct blkcipher_walk walk;
154-
struct scatterlist srcbuf[2];
155-
struct scatterlist dstbuf[2];
156-
struct scatterlist *src;
157-
struct scatterlist *dst;
152+
struct skcipher_walk walk;
158153
u8 __aligned(8) mac[AES_BLOCK_SIZE];
159154
u8 buf[AES_BLOCK_SIZE];
160155
u32 len = req->cryptlen;
@@ -172,27 +167,19 @@ static int ccm_encrypt(struct aead_request *req)
172167
/* preserve the original iv for the final round */
173168
memcpy(buf, req->iv, AES_BLOCK_SIZE);
174169

175-
src = scatterwalk_ffwd(srcbuf, req->src, req->assoclen);
176-
dst = src;
177-
if (req->src != req->dst)
178-
dst = scatterwalk_ffwd(dstbuf, req->dst, req->assoclen);
179-
180-
blkcipher_walk_init(&walk, dst, src, len);
181-
err = blkcipher_aead_walk_virt_block(&desc, &walk, aead,
182-
AES_BLOCK_SIZE);
170+
err = skcipher_walk_aead(&walk, req, true);
183171

184172
while (walk.nbytes) {
185173
u32 tail = walk.nbytes % AES_BLOCK_SIZE;
186174

187-
if (walk.nbytes == len)
175+
if (walk.nbytes == walk.total)
188176
tail = 0;
189177

190178
ce_aes_ccm_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
191179
walk.nbytes - tail, ctx->key_enc,
192180
num_rounds(ctx), mac, walk.iv);
193181

194-
len -= walk.nbytes - tail;
195-
err = blkcipher_walk_done(&desc, &walk, tail);
182+
err = skcipher_walk_done(&walk, tail);
196183
}
197184
if (!err)
198185
ce_aes_ccm_final(mac, buf, ctx->key_enc, num_rounds(ctx));
@@ -203,7 +190,7 @@ static int ccm_encrypt(struct aead_request *req)
203190
return err;
204191

205192
/* copy authtag to end of dst */
206-
scatterwalk_map_and_copy(mac, dst, req->cryptlen,
193+
scatterwalk_map_and_copy(mac, req->dst, req->assoclen + req->cryptlen,
207194
crypto_aead_authsize(aead), 1);
208195

209196
return 0;
@@ -214,12 +201,7 @@ static int ccm_decrypt(struct aead_request *req)
214201
struct crypto_aead *aead = crypto_aead_reqtfm(req);
215202
struct crypto_aes_ctx *ctx = crypto_aead_ctx(aead);
216203
unsigned int authsize = crypto_aead_authsize(aead);
217-
struct blkcipher_desc desc = { .info = req->iv };
218-
struct blkcipher_walk walk;
219-
struct scatterlist srcbuf[2];
220-
struct scatterlist dstbuf[2];
221-
struct scatterlist *src;
222-
struct scatterlist *dst;
204+
struct skcipher_walk walk;
223205
u8 __aligned(8) mac[AES_BLOCK_SIZE];
224206
u8 buf[AES_BLOCK_SIZE];
225207
u32 len = req->cryptlen - authsize;
@@ -237,27 +219,19 @@ static int ccm_decrypt(struct aead_request *req)
237219
/* preserve the original iv for the final round */
238220
memcpy(buf, req->iv, AES_BLOCK_SIZE);
239221

240-
src = scatterwalk_ffwd(srcbuf, req->src, req->assoclen);
241-
dst = src;
242-
if (req->src != req->dst)
243-
dst = scatterwalk_ffwd(dstbuf, req->dst, req->assoclen);
244-
245-
blkcipher_walk_init(&walk, dst, src, len);
246-
err = blkcipher_aead_walk_virt_block(&desc, &walk, aead,
247-
AES_BLOCK_SIZE);
222+
err = skcipher_walk_aead(&walk, req, true);
248223

249224
while (walk.nbytes) {
250225
u32 tail = walk.nbytes % AES_BLOCK_SIZE;
251226

252-
if (walk.nbytes == len)
227+
if (walk.nbytes == walk.total)
253228
tail = 0;
254229

255230
ce_aes_ccm_decrypt(walk.dst.virt.addr, walk.src.virt.addr,
256231
walk.nbytes - tail, ctx->key_enc,
257232
num_rounds(ctx), mac, walk.iv);
258233

259-
len -= walk.nbytes - tail;
260-
err = blkcipher_walk_done(&desc, &walk, tail);
234+
err = skcipher_walk_done(&walk, tail);
261235
}
262236
if (!err)
263237
ce_aes_ccm_final(mac, buf, ctx->key_enc, num_rounds(ctx));
@@ -268,7 +242,8 @@ static int ccm_decrypt(struct aead_request *req)
268242
return err;
269243

270244
/* compare calculated auth tag with the stored one */
271-
scatterwalk_map_and_copy(buf, src, req->cryptlen - authsize,
245+
scatterwalk_map_and_copy(buf, req->src,
246+
req->assoclen + req->cryptlen - authsize,
272247
authsize, 0);
273248

274249
if (crypto_memneq(mac, buf, authsize))
@@ -287,6 +262,7 @@ static struct aead_alg ccm_aes_alg = {
287262
.cra_module = THIS_MODULE,
288263
},
289264
.ivsize = AES_BLOCK_SIZE,
265+
.chunksize = AES_BLOCK_SIZE,
290266
.maxauthsize = AES_BLOCK_SIZE,
291267
.setkey = ccm_setkey,
292268
.setauthsize = ccm_setauthsize,

0 commit comments

Comments
 (0)