diff options
author | Eric Biggers <ebiggers@google.com> | 2019-04-14 20:37:09 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2019-04-25 03:38:12 -0400 |
commit | 877b5691f27a1aec0d9b53095a323e45c30069e2 (patch) | |
tree | 59eba93e8d253fb0e12a0a2040de99e96e873933 /crypto | |
parent | 75f2222832e0fecba7a45ca6ac07ea895ea1e046 (diff) |
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 <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/adiantum.c | 1 | ||||
-rw-r--r-- | crypto/asymmetric_keys/pkcs7_verify.c | 1 | ||||
-rw-r--r-- | crypto/asymmetric_keys/verify_pefile.c | 1 | ||||
-rw-r--r-- | crypto/asymmetric_keys/x509_public_key.c | 1 | ||||
-rw-r--r-- | crypto/cryptd.c | 3 | ||||
-rw-r--r-- | crypto/drbg.c | 1 | ||||
-rw-r--r-- | crypto/hmac.c | 11 | ||||
-rw-r--r-- | crypto/shash.c | 4 | ||||
-rw-r--r-- | crypto/testmgr.c | 2 |
9 files changed, 0 insertions, 25 deletions
diff --git a/crypto/adiantum.c b/crypto/adiantum.c index e6de50f669aa..395a3ddd3707 100644 --- a/crypto/adiantum.c +++ b/crypto/adiantum.c | |||
@@ -265,7 +265,6 @@ static int adiantum_hash_message(struct skcipher_request *req, | |||
265 | int err; | 265 | int err; |
266 | 266 | ||
267 | hash_desc->tfm = tctx->hash; | 267 | hash_desc->tfm = tctx->hash; |
268 | hash_desc->flags = 0; | ||
269 | 268 | ||
270 | err = crypto_shash_init(hash_desc); | 269 | err = crypto_shash_init(hash_desc); |
271 | if (err) | 270 | if (err) |
diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c index 97c77f66b20d..f7b0980bf02d 100644 --- a/crypto/asymmetric_keys/pkcs7_verify.c +++ b/crypto/asymmetric_keys/pkcs7_verify.c | |||
@@ -56,7 +56,6 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7, | |||
56 | goto error_no_desc; | 56 | goto error_no_desc; |
57 | 57 | ||
58 | desc->tfm = tfm; | 58 | desc->tfm = tfm; |
59 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; | ||
60 | 59 | ||
61 | /* Digest the message [RFC2315 9.3] */ | 60 | /* Digest the message [RFC2315 9.3] */ |
62 | ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len, | 61 | ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len, |
diff --git a/crypto/asymmetric_keys/verify_pefile.c b/crypto/asymmetric_keys/verify_pefile.c index d178650fd524..f8e4a932bcfb 100644 --- a/crypto/asymmetric_keys/verify_pefile.c +++ b/crypto/asymmetric_keys/verify_pefile.c | |||
@@ -354,7 +354,6 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen, | |||
354 | goto error_no_desc; | 354 | goto error_no_desc; |
355 | 355 | ||
356 | desc->tfm = tfm; | 356 | desc->tfm = tfm; |
357 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; | ||
358 | ret = crypto_shash_init(desc); | 357 | ret = crypto_shash_init(desc); |
359 | if (ret < 0) | 358 | if (ret < 0) |
360 | goto error; | 359 | goto error; |
diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index 9338b4558cdc..bd96683d8cde 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c | |||
@@ -77,7 +77,6 @@ int x509_get_sig_params(struct x509_certificate *cert) | |||
77 | goto error; | 77 | goto error; |
78 | 78 | ||
79 | desc->tfm = tfm; | 79 | desc->tfm = tfm; |
80 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; | ||
81 | 80 | ||
82 | ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, sig->digest); | 81 | ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, sig->digest); |
83 | if (ret < 0) | 82 | if (ret < 0) |
diff --git a/crypto/cryptd.c b/crypto/cryptd.c index 42533cf80acc..b3bb99390ae7 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c | |||
@@ -545,7 +545,6 @@ static void cryptd_hash_init(struct crypto_async_request *req_async, int err) | |||
545 | goto out; | 545 | goto out; |
546 | 546 | ||
547 | desc->tfm = child; | 547 | desc->tfm = child; |
548 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; | ||
549 | 548 | ||
550 | err = crypto_shash_init(desc); | 549 | err = crypto_shash_init(desc); |
551 | 550 | ||
@@ -637,7 +636,6 @@ static void cryptd_hash_digest(struct crypto_async_request *req_async, int err) | |||
637 | goto out; | 636 | goto out; |
638 | 637 | ||
639 | desc->tfm = child; | 638 | desc->tfm = child; |
640 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; | ||
641 | 639 | ||
642 | err = shash_ahash_digest(req, desc); | 640 | err = shash_ahash_digest(req, desc); |
643 | 641 | ||
@@ -666,7 +664,6 @@ static int cryptd_hash_import(struct ahash_request *req, const void *in) | |||
666 | struct shash_desc *desc = cryptd_shash_desc(req); | 664 | struct shash_desc *desc = cryptd_shash_desc(req); |
667 | 665 | ||
668 | desc->tfm = ctx->child; | 666 | desc->tfm = ctx->child; |
669 | desc->flags = req->base.flags; | ||
670 | 667 | ||
671 | return crypto_shash_import(desc, in); | 668 | return crypto_shash_import(desc, in); |
672 | } | 669 | } |
diff --git a/crypto/drbg.c b/crypto/drbg.c index 710b3046a4df..2a5b16bb000c 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c | |||
@@ -1587,7 +1587,6 @@ static int drbg_init_hash_kernel(struct drbg_state *drbg) | |||
1587 | } | 1587 | } |
1588 | 1588 | ||
1589 | sdesc->shash.tfm = tfm; | 1589 | sdesc->shash.tfm = tfm; |
1590 | sdesc->shash.flags = 0; | ||
1591 | drbg->priv_data = sdesc; | 1590 | drbg->priv_data = sdesc; |
1592 | 1591 | ||
1593 | return crypto_shash_alignmask(tfm); | 1592 | return crypto_shash_alignmask(tfm); |
diff --git a/crypto/hmac.c b/crypto/hmac.c index 4ceb3f1f0eb8..a68c1266121f 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c | |||
@@ -57,8 +57,6 @@ static int hmac_setkey(struct crypto_shash *parent, | |||
57 | unsigned int i; | 57 | unsigned int i; |
58 | 58 | ||
59 | shash->tfm = hash; | 59 | shash->tfm = hash; |
60 | shash->flags = crypto_shash_get_flags(parent) | ||
61 | & CRYPTO_TFM_REQ_MAY_SLEEP; | ||
62 | 60 | ||
63 | if (keylen > bs) { | 61 | if (keylen > bs) { |
64 | int err; | 62 | int err; |
@@ -91,8 +89,6 @@ static int hmac_export(struct shash_desc *pdesc, void *out) | |||
91 | { | 89 | { |
92 | struct shash_desc *desc = shash_desc_ctx(pdesc); | 90 | struct shash_desc *desc = shash_desc_ctx(pdesc); |
93 | 91 | ||
94 | desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; | ||
95 | |||
96 | return crypto_shash_export(desc, out); | 92 | return crypto_shash_export(desc, out); |
97 | } | 93 | } |
98 | 94 | ||
@@ -102,7 +98,6 @@ static int hmac_import(struct shash_desc *pdesc, const void *in) | |||
102 | struct hmac_ctx *ctx = hmac_ctx(pdesc->tfm); | 98 | struct hmac_ctx *ctx = hmac_ctx(pdesc->tfm); |
103 | 99 | ||
104 | desc->tfm = ctx->hash; | 100 | desc->tfm = ctx->hash; |
105 | desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; | ||
106 | 101 | ||
107 | return crypto_shash_import(desc, in); | 102 | return crypto_shash_import(desc, in); |
108 | } | 103 | } |
@@ -117,8 +112,6 @@ static int hmac_update(struct shash_desc *pdesc, | |||
117 | { | 112 | { |
118 | struct shash_desc *desc = shash_desc_ctx(pdesc); | 113 | struct shash_desc *desc = shash_desc_ctx(pdesc); |
119 | 114 | ||
120 | desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; | ||
121 | |||
122 | return crypto_shash_update(desc, data, nbytes); | 115 | return crypto_shash_update(desc, data, nbytes); |
123 | } | 116 | } |
124 | 117 | ||
@@ -130,8 +123,6 @@ static int hmac_final(struct shash_desc *pdesc, u8 *out) | |||
130 | char *opad = crypto_shash_ctx_aligned(parent) + ss; | 123 | char *opad = crypto_shash_ctx_aligned(parent) + ss; |
131 | struct shash_desc *desc = shash_desc_ctx(pdesc); | 124 | struct shash_desc *desc = shash_desc_ctx(pdesc); |
132 | 125 | ||
133 | desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; | ||
134 | |||
135 | return crypto_shash_final(desc, out) ?: | 126 | return crypto_shash_final(desc, out) ?: |
136 | crypto_shash_import(desc, opad) ?: | 127 | crypto_shash_import(desc, opad) ?: |
137 | crypto_shash_finup(desc, out, ds, out); | 128 | crypto_shash_finup(desc, out, ds, out); |
@@ -147,8 +138,6 @@ static int hmac_finup(struct shash_desc *pdesc, const u8 *data, | |||
147 | char *opad = crypto_shash_ctx_aligned(parent) + ss; | 138 | char *opad = crypto_shash_ctx_aligned(parent) + ss; |
148 | struct shash_desc *desc = shash_desc_ctx(pdesc); | 139 | struct shash_desc *desc = shash_desc_ctx(pdesc); |
149 | 140 | ||
150 | desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; | ||
151 | |||
152 | return crypto_shash_finup(desc, data, nbytes, out) ?: | 141 | return crypto_shash_finup(desc, data, nbytes, out) ?: |
153 | crypto_shash_import(desc, opad) ?: | 142 | crypto_shash_import(desc, opad) ?: |
154 | crypto_shash_finup(desc, out, ds, out); | 143 | crypto_shash_finup(desc, out, ds, out); |
diff --git a/crypto/shash.c b/crypto/shash.c index 599468478f7b..e55c1f558bc3 100644 --- a/crypto/shash.c +++ b/crypto/shash.c | |||
@@ -238,7 +238,6 @@ static int shash_async_init(struct ahash_request *req) | |||
238 | struct shash_desc *desc = ahash_request_ctx(req); | 238 | struct shash_desc *desc = ahash_request_ctx(req); |
239 | 239 | ||
240 | desc->tfm = *ctx; | 240 | desc->tfm = *ctx; |
241 | desc->flags = req->base.flags; | ||
242 | 241 | ||
243 | return crypto_shash_init(desc); | 242 | return crypto_shash_init(desc); |
244 | } | 243 | } |
@@ -293,7 +292,6 @@ static int shash_async_finup(struct ahash_request *req) | |||
293 | struct shash_desc *desc = ahash_request_ctx(req); | 292 | struct shash_desc *desc = ahash_request_ctx(req); |
294 | 293 | ||
295 | desc->tfm = *ctx; | 294 | desc->tfm = *ctx; |
296 | desc->flags = req->base.flags; | ||
297 | 295 | ||
298 | return shash_ahash_finup(req, desc); | 296 | return shash_ahash_finup(req, desc); |
299 | } | 297 | } |
@@ -328,7 +326,6 @@ static int shash_async_digest(struct ahash_request *req) | |||
328 | struct shash_desc *desc = ahash_request_ctx(req); | 326 | struct shash_desc *desc = ahash_request_ctx(req); |
329 | 327 | ||
330 | desc->tfm = *ctx; | 328 | desc->tfm = *ctx; |
331 | desc->flags = req->base.flags; | ||
332 | 329 | ||
333 | return shash_ahash_digest(req, desc); | 330 | return shash_ahash_digest(req, desc); |
334 | } | 331 | } |
@@ -344,7 +341,6 @@ static int shash_async_import(struct ahash_request *req, const void *in) | |||
344 | struct shash_desc *desc = ahash_request_ctx(req); | 341 | struct shash_desc *desc = ahash_request_ctx(req); |
345 | 342 | ||
346 | desc->tfm = *ctx; | 343 | desc->tfm = *ctx; |
347 | desc->flags = req->base.flags; | ||
348 | 344 | ||
349 | return crypto_shash_import(desc, in); | 345 | return crypto_shash_import(desc, in); |
350 | } | 346 | } |
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 87abfd1ce232..2bd89a65e9e7 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -1328,7 +1328,6 @@ static void generate_random_hash_testvec(struct crypto_shash *tfm, | |||
1328 | 1328 | ||
1329 | /* Digest */ | 1329 | /* Digest */ |
1330 | desc->tfm = tfm; | 1330 | desc->tfm = tfm; |
1331 | desc->flags = 0; | ||
1332 | vec->digest_error = crypto_shash_digest(desc, vec->plaintext, | 1331 | vec->digest_error = crypto_shash_digest(desc, vec->plaintext, |
1333 | vec->psize, (u8 *)vec->digest); | 1332 | vec->psize, (u8 *)vec->digest); |
1334 | done: | 1333 | done: |
@@ -3027,7 +3026,6 @@ static int alg_test_crc32c(const struct alg_test_desc *desc, | |||
3027 | u32 *ctx = (u32 *)shash_desc_ctx(shash); | 3026 | u32 *ctx = (u32 *)shash_desc_ctx(shash); |
3028 | 3027 | ||
3029 | shash->tfm = tfm; | 3028 | shash->tfm = tfm; |
3030 | shash->flags = 0; | ||
3031 | 3029 | ||
3032 | *ctx = 420553207; | 3030 | *ctx = 420553207; |
3033 | err = crypto_shash_final(shash, (u8 *)&val); | 3031 | err = crypto_shash_final(shash, (u8 *)&val); |