Skip to content

Commit

Permalink
crypto: shash - remove shash_desc::flags
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ebiggers authored and herbertx committed Apr 25, 2019
1 parent 75f2222 commit 877b569
Show file tree
Hide file tree
Showing 66 changed files with 8 additions and 113 deletions.
1 change: 0 additions & 1 deletion Documentation/crypto/api-samples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ Code Example For Use of Operational State Memory With SHASH
if (!sdesc)
return ERR_PTR(-ENOMEM);
sdesc->shash.tfm = alg;
sdesc->shash.flags = 0x0;
return sdesc;
}

Expand Down
3 changes: 0 additions & 3 deletions arch/arm/crypto/ghash-ce-glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ static int ghash_async_init(struct ahash_request *req)
struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);

desc->tfm = child;
desc->flags = req->base.flags;
return crypto_shash_init(desc);
}

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

desc->tfm = child;
desc->flags = req->base.flags;
return shash_ahash_digest(req, desc);
}
}
Expand All @@ -256,7 +254,6 @@ static int ghash_async_import(struct ahash_request *req, const void *in)
struct shash_desc *desc = cryptd_shash_desc(cryptd_req);

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

return crypto_shash_import(desc, in);
}
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/crypto/ghash-clmulni-intel_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ static int ghash_async_init(struct ahash_request *req)
struct crypto_shash *child = cryptd_ahash_child(cryptd_tfm);

desc->tfm = child;
desc->flags = req->base.flags;
return crypto_shash_init(desc);
}

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

desc->tfm = child;
desc->flags = req->base.flags;
return shash_ahash_digest(req, desc);
}
}
Expand Down
1 change: 0 additions & 1 deletion arch/x86/power/hibernate.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ static int get_e820_md5(struct e820_table *table, void *buf)
}

desc->tfm = tfm;
desc->flags = 0;

size = offsetof(struct e820_table, entries) +
sizeof(struct e820_entry) * table->nr_entries;
Expand Down
1 change: 0 additions & 1 deletion crypto/adiantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ static int adiantum_hash_message(struct skcipher_request *req,
int err;

hash_desc->tfm = tctx->hash;
hash_desc->flags = 0;

err = crypto_shash_init(hash_desc);
if (err)
Expand Down
1 change: 0 additions & 1 deletion crypto/asymmetric_keys/pkcs7_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
goto error_no_desc;

desc->tfm = tfm;
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;

/* Digest the message [RFC2315 9.3] */
ret = crypto_shash_digest(desc, pkcs7->data, pkcs7->data_len,
Expand Down
1 change: 0 additions & 1 deletion crypto/asymmetric_keys/verify_pefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
goto error_no_desc;

desc->tfm = tfm;
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
ret = crypto_shash_init(desc);
if (ret < 0)
goto error;
Expand Down
1 change: 0 additions & 1 deletion crypto/asymmetric_keys/x509_public_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ int x509_get_sig_params(struct x509_certificate *cert)
goto error;

desc->tfm = tfm;
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;

ret = crypto_shash_digest(desc, cert->tbs, cert->tbs_size, sig->digest);
if (ret < 0)
Expand Down
3 changes: 0 additions & 3 deletions crypto/cryptd.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ static void cryptd_hash_init(struct crypto_async_request *req_async, int err)
goto out;

desc->tfm = child;
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;

err = crypto_shash_init(desc);

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

desc->tfm = child;
desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;

err = shash_ahash_digest(req, desc);

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

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

return crypto_shash_import(desc, in);
}
Expand Down
1 change: 0 additions & 1 deletion crypto/drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,6 @@ static int drbg_init_hash_kernel(struct drbg_state *drbg)
}

sdesc->shash.tfm = tfm;
sdesc->shash.flags = 0;
drbg->priv_data = sdesc;

return crypto_shash_alignmask(tfm);
Expand Down
11 changes: 0 additions & 11 deletions crypto/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ static int hmac_setkey(struct crypto_shash *parent,
unsigned int i;

shash->tfm = hash;
shash->flags = crypto_shash_get_flags(parent)
& CRYPTO_TFM_REQ_MAY_SLEEP;

if (keylen > bs) {
int err;
Expand Down Expand Up @@ -91,8 +89,6 @@ static int hmac_export(struct shash_desc *pdesc, void *out)
{
struct shash_desc *desc = shash_desc_ctx(pdesc);

desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;

return crypto_shash_export(desc, out);
}

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

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

return crypto_shash_import(desc, in);
}
Expand All @@ -117,8 +112,6 @@ static int hmac_update(struct shash_desc *pdesc,
{
struct shash_desc *desc = shash_desc_ctx(pdesc);

desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;

return crypto_shash_update(desc, data, nbytes);
}

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

desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;

return crypto_shash_final(desc, out) ?:
crypto_shash_import(desc, opad) ?:
crypto_shash_finup(desc, out, ds, out);
Expand All @@ -147,8 +138,6 @@ static int hmac_finup(struct shash_desc *pdesc, const u8 *data,
char *opad = crypto_shash_ctx_aligned(parent) + ss;
struct shash_desc *desc = shash_desc_ctx(pdesc);

desc->flags = pdesc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;

return crypto_shash_finup(desc, data, nbytes, out) ?:
crypto_shash_import(desc, opad) ?:
crypto_shash_finup(desc, out, ds, out);
Expand Down
4 changes: 0 additions & 4 deletions crypto/shash.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ static int shash_async_init(struct ahash_request *req)
struct shash_desc *desc = ahash_request_ctx(req);

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

return crypto_shash_init(desc);
}
Expand Down Expand Up @@ -293,7 +292,6 @@ static int shash_async_finup(struct ahash_request *req)
struct shash_desc *desc = ahash_request_ctx(req);

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

return shash_ahash_finup(req, desc);
}
Expand Down Expand Up @@ -328,7 +326,6 @@ static int shash_async_digest(struct ahash_request *req)
struct shash_desc *desc = ahash_request_ctx(req);

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

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

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

return crypto_shash_import(desc, in);
}
Expand Down
2 changes: 0 additions & 2 deletions crypto/testmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,6 @@ static void generate_random_hash_testvec(struct crypto_shash *tfm,

/* Digest */
desc->tfm = tfm;
desc->flags = 0;
vec->digest_error = crypto_shash_digest(desc, vec->plaintext,
vec->psize, (u8 *)vec->digest);
done:
Expand Down Expand Up @@ -3027,7 +3026,6 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
u32 *ctx = (u32 *)shash_desc_ctx(shash);

shash->tfm = tfm;
shash->flags = 0;

*ctx = 420553207;
err = crypto_shash_final(shash, (u8 *)&val);
Expand Down
1 change: 0 additions & 1 deletion drivers/block/drbd/drbd_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -5443,7 +5443,6 @@ static int drbd_do_auth(struct drbd_connection *connection)
rcu_read_unlock();

desc->tfm = connection->cram_hmac_tfm;
desc->flags = 0;

rv = crypto_shash_setkey(connection->cram_hmac_tfm, (u8 *)secret, key_len);
if (rv) {
Expand Down
2 changes: 0 additions & 2 deletions drivers/block/drbd/drbd_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ void drbd_csum_ee(struct crypto_shash *tfm, struct drbd_peer_request *peer_req,
void *src;

desc->tfm = tfm;
desc->flags = 0;

crypto_shash_init(desc);

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

desc->tfm = tfm;
desc->flags = 0;

crypto_shash_init(desc);

Expand Down
2 changes: 0 additions & 2 deletions drivers/crypto/axis/artpec6_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -2247,8 +2247,6 @@ artpec6_crypto_hash_set_key(struct crypto_ahash *tfm,
SHASH_DESC_ON_STACK(hdesc, tfm_ctx->child_hash);

hdesc->tfm = tfm_ctx->child_hash;
hdesc->flags = crypto_ahash_get_flags(tfm) &
CRYPTO_TFM_REQ_MAY_SLEEP;

tfm_ctx->hmac_key_length = blocksize;
ret = crypto_shash_digest(hdesc, key, keylen,
Expand Down
1 change: 0 additions & 1 deletion drivers/crypto/bcm/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,6 @@ static int ahash_init(struct ahash_request *req)
goto err_hash;
}
ctx->shash->tfm = hash;
ctx->shash->flags = 0;

/* Set the key using data we already have from setkey */
if (ctx->authkeylen > 0) {
Expand Down
1 change: 0 additions & 1 deletion drivers/crypto/bcm/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ int do_shash(unsigned char *name, unsigned char *result,
goto do_shash_err;
}
sdesc->shash.tfm = hash;
sdesc->shash.flags = 0x0;

if (key_len > 0) {
rc = crypto_shash_setkey(hash, key, key_len);
Expand Down
2 changes: 0 additions & 2 deletions drivers/crypto/ccp/ccp-crypto-sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
if (key_len > block_size) {
/* Must hash the input key */
sdesc->tfm = shash;
sdesc->flags = crypto_ahash_get_flags(tfm) &
CRYPTO_TFM_REQ_MAY_SLEEP;

ret = crypto_shash_digest(sdesc, key, key_len,
ctx->u.sha.key);
Expand Down
2 changes: 0 additions & 2 deletions drivers/crypto/chelsio/chcr_algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,6 @@ static int chcr_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
* ipad in hmacctx->ipad and opad in hmacctx->opad location
*/
shash->tfm = hmacctx->base_hash;
shash->flags = crypto_shash_get_flags(hmacctx->base_hash);
if (keylen > bs) {
err = crypto_shash_digest(shash, key, keylen,
hmacctx->ipad);
Expand Down Expand Up @@ -3517,7 +3516,6 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
SHASH_DESC_ON_STACK(shash, base_hash);

shash->tfm = base_hash;
shash->flags = crypto_shash_get_flags(base_hash);
bs = crypto_shash_blocksize(base_hash);
align = KEYCTX_ALIGN_PAD(max_authsize);
o_ptr = actx->h_iopad + param.result_size + align;
Expand Down
3 changes: 0 additions & 3 deletions drivers/crypto/mediatek/mtk-sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ static int mtk_sha_finish_hmac(struct ahash_request *req)
SHASH_DESC_ON_STACK(shash, bctx->shash);

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

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

shash->tfm = bctx->shash;
shash->flags = crypto_shash_get_flags(bctx->shash) &
CRYPTO_TFM_REQ_MAY_SLEEP;

if (keylen > bs) {
err = crypto_shash_digest(shash, key, keylen, bctx->ipad);
Expand Down
2 changes: 0 additions & 2 deletions drivers/crypto/n2_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,6 @@ static int n2_hmac_async_setkey(struct crypto_ahash *tfm, const u8 *key,
return err;

shash->tfm = child_shash;
shash->flags = crypto_ahash_get_flags(tfm) &
CRYPTO_TFM_REQ_MAY_SLEEP;

bs = crypto_shash_blocksize(child_shash);
ds = crypto_shash_digestsize(child_shash);
Expand Down
2 changes: 0 additions & 2 deletions drivers/crypto/omap-sham.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,6 @@ static int omap_sham_finish_hmac(struct ahash_request *req)
SHASH_DESC_ON_STACK(shash, bctx->shash);

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

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

shash->tfm = tfm;
shash->flags = flags & CRYPTO_TFM_REQ_MAY_SLEEP;

return crypto_shash_digest(shash, data, len, out);
}
Expand Down
5 changes: 0 additions & 5 deletions drivers/crypto/padlock-sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ static int padlock_sha_init(struct shash_desc *desc)
struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm);

dctx->fallback.tfm = ctx->fallback;
dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
return crypto_shash_init(&dctx->fallback);
}

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

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

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

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

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

dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
err = crypto_shash_export(&dctx->fallback, &state);
if (err)
goto out;
Expand Down Expand Up @@ -153,7 +149,6 @@ static int padlock_sha256_finup(struct shash_desc *desc, const u8 *in,
unsigned int leftover;
int err;

dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
err = crypto_shash_export(&dctx->fallback, &state);
if (err)
goto out;
Expand Down
1 change: 0 additions & 1 deletion drivers/crypto/qat/qat_common/qat_algs.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash,
memset(ctx->ipad, 0, block_size);
memset(ctx->opad, 0, block_size);
shash->tfm = ctx->hash_tfm;
shash->flags = 0x0;

if (auth_keylen > block_size) {
int ret = crypto_shash_digest(shash, auth_key,
Expand Down
1 change: 0 additions & 1 deletion drivers/crypto/s5p-sss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,6 @@ static int s5p_hash_shash_digest(struct crypto_shash *tfm, u32 flags,
SHASH_DESC_ON_STACK(shash, tfm);

shash->tfm = tfm;
shash->flags = flags & ~CRYPTO_TFM_REQ_MAY_SLEEP;

return crypto_shash_digest(shash, data, len, out);
}
Expand Down
Loading

0 comments on commit 877b569

Please sign in to comment.