Skip to content

Commit

Permalink
crypto: shash - fold shash_digest_unaligned() into crypto_shash_digest()
Browse files Browse the repository at this point in the history
Fold shash_digest_unaligned() into its only remaining caller.  Also,
avoid a redundant check of CRYPTO_TFM_NEED_KEY by replacing the call to
crypto_shash_init() with shash->init(desc).  Finally, replace
shash_update_unaligned() + shash_final_unaligned() with
shash_finup_unaligned() which does exactly that.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Eric Biggers authored and Herbert Xu committed Oct 20, 2023
1 parent 313a407 commit 2e02c25
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions crypto/shash.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,6 @@ int crypto_shash_finup(struct shash_desc *desc, const u8 *data,
}
EXPORT_SYMBOL_GPL(crypto_shash_finup);

static int shash_digest_unaligned(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out)
{
return crypto_shash_init(desc) ?:
shash_update_unaligned(desc, data, len) ?:
shash_final_unaligned(desc, out);
}

static int shash_default_digest(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out)
{
Expand Down Expand Up @@ -260,7 +252,8 @@ int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
err = -ENOKEY;
else if (((unsigned long)data | (unsigned long)out) & alignmask)
err = shash_digest_unaligned(desc, data, len, out);
err = shash->init(desc) ?:
shash_finup_unaligned(desc, data, len, out);
else
err = shash->digest(desc, data, len, out);

Expand Down

0 comments on commit 2e02c25

Please sign in to comment.