Skip to content

Commit 54c7d29

Browse files
ebiggersopsiff
authored andcommitted
crypto: authenc - use memcpy_sglist() instead of null skcipher
mainline inclusion from mainline-v6.16-rc1 category: bugfix For copying data between two scatterlists, just use memcpy_sglist() instead of the so-called "null skcipher". This is much simpler. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> (cherry picked from commit dbc4b14) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 204e293 commit 54c7d29

3 files changed

Lines changed: 4 additions & 67 deletions

File tree

crypto/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ config CRYPTO_AUTHENC
221221
select CRYPTO_SKCIPHER
222222
select CRYPTO_MANAGER
223223
select CRYPTO_HASH
224-
select CRYPTO_NULL
225224
help
226225
Authenc: Combined mode wrapper for IPsec.
227226

crypto/authenc.c

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <crypto/internal/hash.h>
1010
#include <crypto/internal/skcipher.h>
1111
#include <crypto/authenc.h>
12-
#include <crypto/null.h>
1312
#include <crypto/scatterwalk.h>
1413
#include <linux/err.h>
1514
#include <linux/init.h>
@@ -28,7 +27,6 @@ struct authenc_instance_ctx {
2827
struct crypto_authenc_ctx {
2928
struct crypto_ahash *auth;
3029
struct crypto_skcipher *enc;
31-
struct crypto_sync_skcipher *null;
3230
};
3331

3432
struct authenc_request_ctx {
@@ -189,21 +187,6 @@ static void crypto_authenc_encrypt_done(void *data, int err)
189187
authenc_request_complete(areq, err);
190188
}
191189

192-
static int crypto_authenc_copy_assoc(struct aead_request *req)
193-
{
194-
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
195-
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
196-
SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
197-
198-
skcipher_request_set_sync_tfm(skreq, ctx->null);
199-
skcipher_request_set_callback(skreq, aead_request_flags(req),
200-
NULL, NULL);
201-
skcipher_request_set_crypt(skreq, req->src, req->dst, req->assoclen,
202-
NULL);
203-
204-
return crypto_skcipher_encrypt(skreq);
205-
}
206-
207190
static int crypto_authenc_encrypt(struct aead_request *req)
208191
{
209192
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
@@ -222,10 +205,7 @@ static int crypto_authenc_encrypt(struct aead_request *req)
222205
dst = src;
223206

224207
if (req->src != req->dst) {
225-
err = crypto_authenc_copy_assoc(req);
226-
if (err)
227-
return err;
228-
208+
memcpy_sglist(req->dst, req->src, req->assoclen);
229209
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen);
230210
}
231211

@@ -334,7 +314,6 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
334314
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(tfm);
335315
struct crypto_ahash *auth;
336316
struct crypto_skcipher *enc;
337-
struct crypto_sync_skcipher *null;
338317
int err;
339318

340319
auth = crypto_spawn_ahash(&ictx->auth);
@@ -346,14 +325,8 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
346325
if (IS_ERR(enc))
347326
goto err_free_ahash;
348327

349-
null = crypto_get_default_null_skcipher();
350-
err = PTR_ERR(null);
351-
if (IS_ERR(null))
352-
goto err_free_skcipher;
353-
354328
ctx->auth = auth;
355329
ctx->enc = enc;
356-
ctx->null = null;
357330

358331
crypto_aead_set_reqsize(
359332
tfm,
@@ -367,8 +340,6 @@ static int crypto_authenc_init_tfm(struct crypto_aead *tfm)
367340

368341
return 0;
369342

370-
err_free_skcipher:
371-
crypto_free_skcipher(enc);
372343
err_free_ahash:
373344
crypto_free_ahash(auth);
374345
return err;
@@ -380,7 +351,6 @@ static void crypto_authenc_exit_tfm(struct crypto_aead *tfm)
380351

381352
crypto_free_ahash(ctx->auth);
382353
crypto_free_skcipher(ctx->enc);
383-
crypto_put_default_null_skcipher();
384354
}
385355

386356
static void crypto_authenc_free(struct aead_instance *inst)

crypto/authencesn.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <crypto/internal/hash.h>
1313
#include <crypto/internal/skcipher.h>
1414
#include <crypto/authenc.h>
15-
#include <crypto/null.h>
1615
#include <crypto/scatterwalk.h>
1716
#include <linux/err.h>
1817
#include <linux/init.h>
@@ -31,7 +30,6 @@ struct crypto_authenc_esn_ctx {
3130
unsigned int reqoff;
3231
struct crypto_ahash *auth;
3332
struct crypto_skcipher *enc;
34-
struct crypto_sync_skcipher *null;
3533
};
3634

3735
struct authenc_esn_request_ctx {
@@ -162,20 +160,6 @@ static void crypto_authenc_esn_encrypt_done(void *data, int err)
162160
authenc_esn_request_complete(areq, err);
163161
}
164162

165-
static int crypto_authenc_esn_copy(struct aead_request *req, unsigned int len)
166-
{
167-
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
168-
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
169-
SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null);
170-
171-
skcipher_request_set_sync_tfm(skreq, ctx->null);
172-
skcipher_request_set_callback(skreq, aead_request_flags(req),
173-
NULL, NULL);
174-
skcipher_request_set_crypt(skreq, req->src, req->dst, len, NULL);
175-
176-
return crypto_skcipher_encrypt(skreq);
177-
}
178-
179163
static int crypto_authenc_esn_encrypt(struct aead_request *req)
180164
{
181165
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req);
@@ -197,10 +181,7 @@ static int crypto_authenc_esn_encrypt(struct aead_request *req)
197181
dst = src;
198182

199183
if (req->src != req->dst) {
200-
err = crypto_authenc_esn_copy(req, assoclen);
201-
if (err)
202-
return err;
203-
184+
memcpy_sglist(req->dst, req->src, assoclen);
204185
sg_init_table(areq_ctx->dst, 2);
205186
dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, assoclen);
206187
}
@@ -289,11 +270,8 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req)
289270

290271
cryptlen -= authsize;
291272

292-
if (req->src != dst) {
293-
err = crypto_authenc_esn_copy(req, assoclen + cryptlen);
294-
if (err)
295-
return err;
296-
}
273+
if (req->src != dst)
274+
memcpy_sglist(dst, req->src, assoclen + cryptlen);
297275

298276
scatterwalk_map_and_copy(ihash, req->src, assoclen + cryptlen,
299277
authsize, 0);
@@ -329,7 +307,6 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
329307
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm);
330308
struct crypto_ahash *auth;
331309
struct crypto_skcipher *enc;
332-
struct crypto_sync_skcipher *null;
333310
int err;
334311

335312
auth = crypto_spawn_ahash(&ictx->auth);
@@ -341,14 +318,8 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
341318
if (IS_ERR(enc))
342319
goto err_free_ahash;
343320

344-
null = crypto_get_default_null_skcipher();
345-
err = PTR_ERR(null);
346-
if (IS_ERR(null))
347-
goto err_free_skcipher;
348-
349321
ctx->auth = auth;
350322
ctx->enc = enc;
351-
ctx->null = null;
352323

353324
ctx->reqoff = ALIGN(2 * crypto_ahash_digestsize(auth),
354325
crypto_ahash_alignmask(auth) + 1);
@@ -365,8 +336,6 @@ static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm)
365336

366337
return 0;
367338

368-
err_free_skcipher:
369-
crypto_free_skcipher(enc);
370339
err_free_ahash:
371340
crypto_free_ahash(auth);
372341
return err;
@@ -378,7 +347,6 @@ static void crypto_authenc_esn_exit_tfm(struct crypto_aead *tfm)
378347

379348
crypto_free_ahash(ctx->auth);
380349
crypto_free_skcipher(ctx->enc);
381-
crypto_put_default_null_skcipher();
382350
}
383351

384352
static void crypto_authenc_esn_free(struct aead_instance *inst)

0 commit comments

Comments
 (0)