Skip to content

Commit 877b569

Browse files
ebiggersherbertx
authored andcommitted
crypto: shash - remove shash_desc::flags
The flags field in 'struct shash_desc' never actually does anything. The only ostensibly supported flag is CRYPTO_TFM_REQ_MAY_SLEEP. However, no shash algorithm ever sleeps, making this flag a no-op. With this being the case, inevitably some users who can't sleep wrongly pass MAY_SLEEP. These would all need to be fixed if any shash algorithm actually started sleeping. For example, the shash_ahash_*() functions, which wrap a shash algorithm with the ahash API, pass through MAY_SLEEP from the ahash API to the shash API. However, the shash functions are called under kmap_atomic(), so actually they're assumed to never sleep. Even if it turns out that some users do need preemption points while hashing large buffers, we could easily provide a helper function crypto_shash_update_large() which divides the data into smaller chunks and calls crypto_shash_update() and cond_resched() for each chunk. It's not necessary to have a flag in 'struct shash_desc', nor is it necessary to make individual shash algorithms aware of this at all. Therefore, remove shash_desc::flags, and document that the crypto_shash_*() functions can be called from any context. Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 75f2222 commit 877b569

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+8
-113
lines changed

Documentation/crypto/api-samples.rst

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ Code Example For Use of Operational State Memory With SHASH
133133
if (!sdesc)
134134
return ERR_PTR(-ENOMEM);
135135
sdesc->shash.tfm = alg;
136-
sdesc->shash.flags = 0x0;
137136
return sdesc;
138137
}
139138

arch/arm/crypto/ghash-ce-glue.c

-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ static int ghash_async_init(struct ahash_request *req)
186186
struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);
187187

188188
desc->tfm = child;
189-
desc->flags = req->base.flags;
190189
return crypto_shash_init(desc);
191190
}
192191

@@ -243,7 +242,6 @@ static int ghash_async_digest(struct ahash_request *req)
243242
struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);
244243

245244
desc->tfm = child;
246-
desc->flags = req->base.flags;
247245
return shash_ahash_digest(req, desc);
248246
}
249247
}
@@ -256,7 +254,6 @@ static int ghash_async_import(struct ahash_request *req, const void *in)
256254
struct shash_desc *desc = cryptd_shash_desc(cryptd_req);
257255

258256
desc->tfm = cryptd_ahash_child(ctx->cryptd_tfm);
259-
desc->flags = req->base.flags;
260257

261258
return crypto_shash_import(desc, in);
262259
}

arch/x86/crypto/ghash-clmulni-intel_glue.c

-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ static int ghash_async_init(struct ahash_request *req)
172172
struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);
173173

174174
desc->tfm = child;
175-
desc->flags = req->base.flags;
176175
return crypto_shash_init(desc);
177176
}
178177

@@ -252,7 +251,6 @@ static int ghash_async_digest(struct ahash_request *req)
252251
struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);
253252

254253
desc->tfm = child;
255-
desc->flags = req->base.flags;
256254
return shash_ahash_digest(req, desc);
257255
}
258256
}

arch/x86/power/hibernate.c

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ static int get_e820_md5(struct e820_table *table, void *buf)
9090
}
9191

9292
desc->tfm = tfm;
93-
desc->flags = 0;
9493

9594
size = offsetof(struct e820_table, entries) +
9695
sizeof(struct e820_entry) * table->nr_entries;

crypto/adiantum.c

-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ static int adiantum_hash_message(struct skcipher_request *req,
265265
int err;
266266

267267
hash_desc->tfm = tctx->hash;
268-
hash_desc->flags = 0;
269268

270269
err = crypto_shash_init(hash_desc);
271270
if (err)

crypto/asymmetric_keys/pkcs7_verify.c

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
5656
goto error_no_desc;
5757

5858
desc->tfm = tfm;
59-
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
6059

6160
/* Digest the message [RFC2315 9.3] */
6261
ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len,

crypto/asymmetric_keys/verify_pefile.c

-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
354354
goto error_no_desc;
355355

356356
desc->tfm = tfm;
357-
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
358357
ret = crypto_shash_init(desc);
359358
if (ret < 0)
360359
goto error;

crypto/asymmetric_keys/x509_public_key.c

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ int x509_get_sig_params(struct x509_certificate *cert)
7777
goto error;
7878

7979
desc->tfm = tfm;
80-
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
8180

8281
ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, sig->digest);
8382
if (ret < 0)

crypto/cryptd.c

-3
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ static void cryptd_hash_init(struct crypto_async_request *req_async, int err)
545545
goto out;
546546

547547
desc->tfm = child;
548-
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
549548

550549
err = crypto_shash_init(desc);
551550

@@ -637,7 +636,6 @@ static void cryptd_hash_digest(struct crypto_async_request *req_async, int err)
637636
goto out;
638637

639638
desc->tfm = child;
640-
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
641639

642640
err = shash_ahash_digest(req, desc);
643641

@@ -666,7 +664,6 @@ static int cryptd_hash_import(struct ahash_request *req, const void *in)
666664
struct shash_desc *desc = cryptd_shash_desc(req);
667665

668666
desc->tfm = ctx->child;
669-
desc->flags = req->base.flags;
670667

671668
return crypto_shash_import(desc, in);
672669
}

crypto/drbg.c

-1
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,6 @@ static int drbg_init_hash_kernel(struct drbg_state *drbg)
15871587
}
15881588

15891589
sdesc->shash.tfm = tfm;
1590-
sdesc->shash.flags = 0;
15911590
drbg->priv_data = sdesc;
15921591

15931592
return crypto_shash_alignmask(tfm);

crypto/hmac.c

-11
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ static int hmac_setkey(struct crypto_shash *parent,
5757
unsigned int i;
5858

5959
shash->tfm = hash;
60-
shash->flags = crypto_shash_get_flags(parent)
61-
& CRYPTO_TFM_REQ_MAY_SLEEP;
6260

6361
if (keylen > bs) {
6462
int err;
@@ -91,8 +89,6 @@ static int hmac_export(struct shash_desc *pdesc, void *out)
9189
{
9290
struct shash_desc *desc = shash_desc_ctx(pdesc);
9391

94-
desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
95-
9692
return crypto_shash_export(desc, out);
9793
}
9894

@@ -102,7 +98,6 @@ static int hmac_import(struct shash_desc *pdesc, const void *in)
10298
struct hmac_ctx *ctx = hmac_ctx(pdesc->tfm);
10399

104100
desc->tfm = ctx->hash;
105-
desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
106101

107102
return crypto_shash_import(desc, in);
108103
}
@@ -117,8 +112,6 @@ static int hmac_update(struct shash_desc *pdesc,
117112
{
118113
struct shash_desc *desc = shash_desc_ctx(pdesc);
119114

120-
desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
121-
122115
return crypto_shash_update(desc, data, nbytes);
123116
}
124117

@@ -130,8 +123,6 @@ static int hmac_final(struct shash_desc *pdesc, u8 *out)
130123
char *opad = crypto_shash_ctx_aligned(parent) + ss;
131124
struct shash_desc *desc = shash_desc_ctx(pdesc);
132125

133-
desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
134-
135126
return crypto_shash_final(desc, out) ?:
136127
crypto_shash_import(desc, opad) ?:
137128
crypto_shash_finup(desc, out, ds, out);
@@ -147,8 +138,6 @@ static int hmac_finup(struct shash_desc *pdesc, const u8 *data,
147138
char *opad = crypto_shash_ctx_aligned(parent) + ss;
148139
struct shash_desc *desc = shash_desc_ctx(pdesc);
149140

150-
desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
151-
152141
return crypto_shash_finup(desc, data, nbytes, out) ?:
153142
crypto_shash_import(desc, opad) ?:
154143
crypto_shash_finup(desc, out, ds, out);

crypto/shash.c

-4
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ static int shash_async_init(struct ahash_request *req)
238238
struct shash_desc *desc = ahash_request_ctx(req);
239239

240240
desc->tfm = *ctx;
241-
desc->flags = req->base.flags;
242241

243242
return crypto_shash_init(desc);
244243
}
@@ -293,7 +292,6 @@ static int shash_async_finup(struct ahash_request *req)
293292
struct shash_desc *desc = ahash_request_ctx(req);
294293

295294
desc->tfm = *ctx;
296-
desc->flags = req->base.flags;
297295

298296
return shash_ahash_finup(req, desc);
299297
}
@@ -328,7 +326,6 @@ static int shash_async_digest(struct ahash_request *req)
328326
struct shash_desc *desc = ahash_request_ctx(req);
329327

330328
desc->tfm = *ctx;
331-
desc->flags = req->base.flags;
332329

333330
return shash_ahash_digest(req, desc);
334331
}
@@ -344,7 +341,6 @@ static int shash_async_import(struct ahash_request *req, const void *in)
344341
struct shash_desc *desc = ahash_request_ctx(req);
345342

346343
desc->tfm = *ctx;
347-
desc->flags = req->base.flags;
348344

349345
return crypto_shash_import(desc, in);
350346
}

crypto/testmgr.c

-2
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,6 @@ static void generate_random_hash_testvec(struct crypto_shash *tfm,
13281328

13291329
/* Digest */
13301330
desc->tfm = tfm;
1331-
desc->flags = 0;
13321331
vec->digest_error = crypto_shash_digest(desc, vec->plaintext,
13331332
vec->psize, (u8 *)vec->digest);
13341333
done:
@@ -3027,7 +3026,6 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
30273026
u32 *ctx = (u32 *)shash_desc_ctx(shash);
30283027

30293028
shash->tfm = tfm;
3030-
shash->flags = 0;
30313029

30323030
*ctx = 420553207;
30333031
err = crypto_shash_final(shash, (u8 *)&val);

drivers/block/drbd/drbd_receiver.c

-1
Original file line numberDiff line numberDiff line change
@@ -5443,7 +5443,6 @@ static int drbd_do_auth(struct drbd_connection *connection)
54435443
rcu_read_unlock();
54445444

54455445
desc->tfm = connection->cram_hmac_tfm;
5446-
desc->flags = 0;
54475446

54485447
rv = crypto_shash_setkey(connection->cram_hmac_tfm, (u8 *)secret, key_len);
54495448
if (rv) {

drivers/block/drbd/drbd_worker.c

-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ void drbd_csum_ee(struct crypto_shash *tfm, struct drbd_peer_request *peer_req,
304304
void *src;
305305

306306
desc->tfm = tfm;
307-
desc->flags = 0;
308307

309308
crypto_shash_init(desc);
310309

@@ -332,7 +331,6 @@ void drbd_csum_bio(struct crypto_shash *tfm, struct bio *bio, void *digest)
332331
struct bvec_iter iter;
333332

334333
desc->tfm = tfm;
335-
desc->flags = 0;
336334

337335
crypto_shash_init(desc);
338336

drivers/crypto/axis/artpec6_crypto.c

-2
Original file line numberDiff line numberDiff line change
@@ -2247,8 +2247,6 @@ artpec6_crypto_hash_set_key(struct crypto_ahash *tfm,
22472247
SHASH_DESC_ON_STACK(hdesc, tfm_ctx->child_hash);
22482248

22492249
hdesc->tfm = tfm_ctx->child_hash;
2250-
hdesc->flags = crypto_ahash_get_flags(tfm) &
2251-
CRYPTO_TFM_REQ_MAY_SLEEP;
22522250

22532251
tfm_ctx->hmac_key_length = blocksize;
22542252
ret = crypto_shash_digest(hdesc, key, keylen,

drivers/crypto/bcm/cipher.c

-1
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,6 @@ static int ahash_init(struct ahash_request *req)
21402140
goto err_hash;
21412141
}
21422142
ctx->shash->tfm = hash;
2143-
ctx->shash->flags = 0;
21442143

21452144
/* Set the key using data we already have from setkey */
21462145
if (ctx->authkeylen > 0) {

drivers/crypto/bcm/util.c

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ int do_shash(unsigned char *name, unsigned char *result,
242242
goto do_shash_err;
243243
}
244244
sdesc->shash.tfm = hash;
245-
sdesc->shash.flags = 0x0;
246245

247246
if (key_len > 0) {
248247
rc = crypto_shash_setkey(hash, key, key_len);

drivers/crypto/ccp/ccp-crypto-sha.c

-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
293293
if (key_len > block_size) {
294294
/* Must hash the input key */
295295
sdesc->tfm = shash;
296-
sdesc->flags = crypto_ahash_get_flags(tfm) &
297-
CRYPTO_TFM_REQ_MAY_SLEEP;
298296

299297
ret = crypto_shash_digest(sdesc, key, key_len,
300298
ctx->u.sha.key);

drivers/crypto/chelsio/chcr_algo.c

-2
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,6 @@ static int chcr_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
21302130
* ipad in hmacctx->ipad and opad in hmacctx->opad location
21312131
*/
21322132
shash->tfm = hmacctx->base_hash;
2133-
shash->flags = crypto_shash_get_flags(hmacctx->base_hash);
21342133
if (keylen > bs) {
21352134
err = crypto_shash_digest(shash, key, keylen,
21362135
hmacctx->ipad);
@@ -3517,7 +3516,6 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
35173516
SHASH_DESC_ON_STACK(shash, base_hash);
35183517

35193518
shash->tfm = base_hash;
3520-
shash->flags = crypto_shash_get_flags(base_hash);
35213519
bs = crypto_shash_blocksize(base_hash);
35223520
align = KEYCTX_ALIGN_PAD(max_authsize);
35233521
o_ptr = actx->h_iopad + param.result_size + align;

drivers/crypto/mediatek/mtk-sha.c

-3
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ static int mtk_sha_finish_hmac(struct ahash_request *req)
365365
SHASH_DESC_ON_STACK(shash, bctx->shash);
366366

367367
shash->tfm = bctx->shash;
368-
shash->flags = 0; /* not CRYPTO_TFM_REQ_MAY_SLEEP */
369368

370369
return crypto_shash_init(shash) ?:
371370
crypto_shash_update(shash, bctx->opad, ctx->bs) ?:
@@ -810,8 +809,6 @@ static int mtk_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
810809
SHASH_DESC_ON_STACK(shash, bctx->shash);
811810

812811
shash->tfm = bctx->shash;
813-
shash->flags = crypto_shash_get_flags(bctx->shash) &
814-
CRYPTO_TFM_REQ_MAY_SLEEP;
815812

816813
if (keylen > bs) {
817814
err = crypto_shash_digest(shash, key, keylen, bctx->ipad);

drivers/crypto/n2_core.c

-2
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,6 @@ static int n2_hmac_async_setkey(struct crypto_ahash *tfm, const u8 *key,
469469
return err;
470470

471471
shash->tfm = child_shash;
472-
shash->flags = crypto_ahash_get_flags(tfm) &
473-
CRYPTO_TFM_REQ_MAY_SLEEP;
474472

475473
bs = crypto_shash_blocksize(child_shash);
476474
ds = crypto_shash_digestsize(child_shash);

drivers/crypto/omap-sham.c

-2
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,6 @@ static int omap_sham_finish_hmac(struct ahash_request *req)
10551055
SHASH_DESC_ON_STACK(shash, bctx->shash);
10561056

10571057
shash->tfm = bctx->shash;
1058-
shash->flags = 0; /* not CRYPTO_TFM_REQ_MAY_SLEEP */
10591058

10601059
return crypto_shash_init(shash) ?:
10611060
crypto_shash_update(shash, bctx->opad, bs) ?:
@@ -1226,7 +1225,6 @@ static int omap_sham_shash_digest(struct crypto_shash *tfm, u32 flags,
12261225
SHASH_DESC_ON_STACK(shash, tfm);
12271226

12281227
shash->tfm = tfm;
1229-
shash->flags = flags & CRYPTO_TFM_REQ_MAY_SLEEP;
12301228

12311229
return crypto_shash_digest(shash, data, len, out);
12321230
}

drivers/crypto/padlock-sha.c

-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static int padlock_sha_init(struct shash_desc *desc)
3939
struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm);
4040

4141
dctx->fallback.tfm = ctx->fallback;
42-
dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
4342
return crypto_shash_init(&dctx->fallback);
4443
}
4544

@@ -48,7 +47,6 @@ static int padlock_sha_update(struct shash_desc *desc,
4847
{
4948
struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
5049

51-
dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
5250
return crypto_shash_update(&dctx->fallback, data, length);
5351
}
5452

@@ -65,7 +63,6 @@ static int padlock_sha_import(struct shash_desc *desc, const void *in)
6563
struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm);
6664

6765
dctx->fallback.tfm = ctx->fallback;
68-
dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
6966
return crypto_shash_import(&dctx->fallback, in);
7067
}
7168

@@ -91,7 +88,6 @@ static int padlock_sha1_finup(struct shash_desc *desc, const u8 *in,
9188
unsigned int leftover;
9289
int err;
9390

94-
dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
9591
err = crypto_shash_export(&dctx->fallback, &state);
9692
if (err)
9793
goto out;
@@ -153,7 +149,6 @@ static int padlock_sha256_finup(struct shash_desc *desc, const u8 *in,
153149
unsigned int leftover;
154150
int err;
155151

156-
dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
157152
err = crypto_shash_export(&dctx->fallback, &state);
158153
if (err)
159154
goto out;

drivers/crypto/qat/qat_common/qat_algs.c

-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash,
164164
memset(ctx->ipad, 0, block_size);
165165
memset(ctx->opad, 0, block_size);
166166
shash->tfm = ctx->hash_tfm;
167-
shash->flags = 0x0;
168167

169168
if (auth_keylen > block_size) {
170169
int ret = crypto_shash_digest(shash, auth_key,

drivers/crypto/s5p-sss.c

-1
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,6 @@ static int s5p_hash_shash_digest(struct crypto_shash *tfm, u32 flags,
15341534
SHASH_DESC_ON_STACK(shash, tfm);
15351535

15361536
shash->tfm = tfm;
1537-
shash->flags = flags & ~CRYPTO_TFM_REQ_MAY_SLEEP;
15381537

15391538
return crypto_shash_digest(shash, data, len, out);
15401539
}

0 commit comments

Comments
 (0)