* [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
@ 2020-05-02 5:31 Eric Biggers
2020-05-02 5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Eric Biggers @ 2020-05-02 5:31 UTC (permalink / raw)
To: linux-crypto
Cc: Cheng-Yi Chiang, ecryptfs, Enric Balletbo i Serra,
Gilad Ben-Yossef, Guenter Roeck, Jesper Nilsson, Kamil Konieczny,
keyrings, Krzysztof Kozlowski, Krzysztof Opasiak, Lars Persson,
linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
Robert Baldyga, Tom Lendacky, Vladimir Zapolskiy, Zaibo Xu
This series introduces a helper function crypto_shash_tfm_digest() which
replaces the following common pattern:
{
SHASH_DESC_ON_STACK(desc, tfm);
int err;
desc->tfm = tfm;
err = crypto_shash_digest(desc, data, len, out);
shash_desc_zero(desc);
}
with:
err = crypto_shash_tfm_digest(tfm, data, len, out);
Patch 1 introduces this helper function, and patches 2-20 convert all
relevant users to use it.
IMO, it would be easiest to take all these patches through the crypto
tree. But taking just the "crypto:" ones and then me trying to get the
rest merged later via subsystem trees is also an option.
Eric Biggers (20):
crypto: hash - introduce crypto_shash_tfm_digest()
crypto: arm64/aes-glue - use crypto_shash_tfm_digest()
crypto: essiv - use crypto_shash_tfm_digest()
crypto: artpec6 - use crypto_shash_tfm_digest()
crypto: ccp - use crypto_shash_tfm_digest()
crypto: ccree - use crypto_shash_tfm_digest()
crypto: hisilicon/sec2 - use crypto_shash_tfm_digest()
crypto: mediatek - use crypto_shash_tfm_digest()
crypto: n2 - use crypto_shash_tfm_digest()
crypto: omap-sham - use crypto_shash_tfm_digest()
crypto: s5p-sss - use crypto_shash_tfm_digest()
nfc: s3fwrn5: use crypto_shash_tfm_digest()
fscrypt: use crypto_shash_tfm_digest()
ecryptfs: use crypto_shash_tfm_digest()
nfsd: use crypto_shash_tfm_digest()
ubifs: use crypto_shash_tfm_digest()
Bluetooth: use crypto_shash_tfm_digest()
sctp: use crypto_shash_tfm_digest()
KEYS: encrypted: use crypto_shash_tfm_digest()
ASoC: cros_ec_codec: use crypto_shash_tfm_digest()
arch/arm64/crypto/aes-glue.c | 4 +--
crypto/essiv.c | 4 +--
crypto/shash.c | 16 +++++++++
drivers/crypto/axis/artpec6_crypto.c | 10 ++----
drivers/crypto/ccp/ccp-crypto-sha.c | 9 ++---
drivers/crypto/ccree/cc_cipher.c | 9 ++---
drivers/crypto/hisilicon/sec2/sec_crypto.c | 5 ++-
drivers/crypto/mediatek/mtk-sha.c | 7 ++--
drivers/crypto/n2_core.c | 7 ++--
drivers/crypto/omap-sham.c | 20 +++--------
drivers/crypto/s5p-sss.c | 39 ++++------------------
drivers/nfc/s3fwrn5/firmware.c | 10 +-----
fs/crypto/fname.c | 7 +---
fs/crypto/hkdf.c | 6 +---
fs/ecryptfs/crypto.c | 17 +---------
fs/nfsd/nfs4recover.c | 26 ++++-----------
fs/ubifs/auth.c | 20 ++---------
fs/ubifs/master.c | 9 ++---
fs/ubifs/replay.c | 14 ++------
include/crypto/hash.h | 19 +++++++++++
net/bluetooth/smp.c | 6 +---
net/sctp/auth.c | 10 ++----
net/sctp/sm_make_chunk.c | 23 +++++--------
security/keys/encrypted-keys/encrypted.c | 18 ++--------
sound/soc/codecs/cros_ec_codec.c | 9 +----
25 files changed, 95 insertions(+), 229 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 01/20] crypto: hash - introduce crypto_shash_tfm_digest()
2020-05-02 5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
@ 2020-05-02 5:31 ` Eric Biggers
2020-05-02 5:31 ` [PATCH 17/20] Bluetooth: use crypto_shash_tfm_digest() Eric Biggers
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Eric Biggers @ 2020-05-02 5:31 UTC (permalink / raw)
To: linux-crypto
Cc: Cheng-Yi Chiang, ecryptfs, Enric Balletbo i Serra,
Gilad Ben-Yossef, Guenter Roeck, Jesper Nilsson, Kamil Konieczny,
keyrings, Krzysztof Kozlowski, Krzysztof Opasiak, Lars Persson,
linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
Robert Baldyga, Tom Lendacky, Vladimir Zapolskiy, Zaibo Xu
From: Eric Biggers <ebiggers@google.com>
Currently the simplest use of the shash API is to use
crypto_shash_digest() to digest a whole buffer. However, this still
requires allocating a hash descriptor (struct shash_desc). Many users
don't really want to preallocate one and instead just use a one-off
descriptor on the stack like the following:
{
SHASH_DESC_ON_STACK(desc, tfm);
int err;
desc->tfm = tfm;
err = crypto_shash_digest(desc, data, len, out);
shash_desc_zero(desc);
}
Wrap this in a new helper function crypto_shash_tfm_digest() that can be
used instead of the above.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/shash.c | 16 ++++++++++++++++
include/crypto/hash.h | 19 +++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/crypto/shash.c b/crypto/shash.c
index c075b26c2a1d9f..e6a4b5f39b8c64 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -206,6 +206,22 @@ int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
}
EXPORT_SYMBOL_GPL(crypto_shash_digest);
+int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
+ unsigned int len, u8 *out)
+{
+ SHASH_DESC_ON_STACK(desc, tfm);
+ int err;
+
+ desc->tfm = tfm;
+
+ err = crypto_shash_digest(desc, data, len, out);
+
+ shash_desc_zero(desc);
+
+ return err;
+}
+EXPORT_SYMBOL_GPL(crypto_shash_tfm_digest);
+
static int shash_default_export(struct shash_desc *desc, void *out)
{
memcpy(out, shash_desc_ctx(desc), crypto_shash_descsize(desc->tfm));
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index cee446c59497c6..4829d2367eda87 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -855,6 +855,25 @@ int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key,
int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out);
+/**
+ * crypto_shash_tfm_digest() - calculate message digest for buffer
+ * @tfm: hash transformation object
+ * @data: see crypto_shash_update()
+ * @len: see crypto_shash_update()
+ * @out: see crypto_shash_final()
+ *
+ * This is a simplified version of crypto_shash_digest() for users who don't
+ * want to allocate their own hash descriptor (shash_desc). Instead,
+ * crypto_shash_tfm_digest() takes a hash transformation object (crypto_shash)
+ * directly, and it allocates a hash descriptor on the stack internally.
+ * Note that this stack allocation may be fairly large.
+ *
+ * Context: Any context.
+ * Return: 0 on success; < 0 if an error occurred.
+ */
+int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
+ unsigned int len, u8 *out);
+
/**
* crypto_shash_export() - extract operational state for message digest
* @desc: reference to the operational state handle whose state is exported
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 17/20] Bluetooth: use crypto_shash_tfm_digest()
2020-05-02 5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
2020-05-02 5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
@ 2020-05-02 5:31 ` Eric Biggers
2020-05-02 6:44 ` [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Marcel Holtmann
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Eric Biggers @ 2020-05-02 5:31 UTC (permalink / raw)
To: linux-crypto; +Cc: linux-bluetooth
From: Eric Biggers <ebiggers@google.com>
Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.
Cc: linux-bluetooth@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
net/bluetooth/smp.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 1476a91ce93572..d022f126eb026b 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -170,7 +170,6 @@ static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m,
size_t len, u8 mac[16])
{
uint8_t tmp[16], mac_msb[16], msg_msb[CMAC_MSG_MAX];
- SHASH_DESC_ON_STACK(desc, tfm);
int err;
if (len > CMAC_MSG_MAX)
@@ -181,8 +180,6 @@ static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m,
return -EINVAL;
}
- desc->tfm = tfm;
-
/* Swap key and message from LSB to MSB */
swap_buf(k, tmp, 16);
swap_buf(m, msg_msb, len);
@@ -196,8 +193,7 @@ static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m,
return err;
}
- err = crypto_shash_digest(desc, msg_msb, len, mac_msb);
- shash_desc_zero(desc);
+ err = crypto_shash_tfm_digest(tfm, msg_msb, len, mac_msb);
if (err) {
BT_ERR("Hash computation error %d", err);
return err;
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
2020-05-02 5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
2020-05-02 5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
2020-05-02 5:31 ` [PATCH 17/20] Bluetooth: use crypto_shash_tfm_digest() Eric Biggers
@ 2020-05-02 6:44 ` Marcel Holtmann
2020-05-03 16:13 ` Ard Biesheuvel
2020-05-08 6:07 ` Herbert Xu
4 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2020-05-02 6:44 UTC (permalink / raw)
To: Eric Biggers
Cc: linux-crypto, Cheng-Yi Chiang, ecryptfs, Enric Balletbo i Serra,
Gilad Ben-Yossef, Guenter Roeck, Jesper Nilsson, Kamil Konieczny,
keyrings, Krzysztof Kozlowski, Krzysztof Opasiak, Lars Persson,
linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
Robert Baldyga, Tom Lendacky, Vladimir Zapolskiy, Zaibo Xu
Hi Eric,
> This series introduces a helper function crypto_shash_tfm_digest() which
> replaces the following common pattern:
>
> {
> SHASH_DESC_ON_STACK(desc, tfm);
> int err;
>
> desc->tfm = tfm;
>
> err = crypto_shash_digest(desc, data, len, out);
>
> shash_desc_zero(desc);
> }
>
> with:
>
> err = crypto_shash_tfm_digest(tfm, data, len, out);
>
> Patch 1 introduces this helper function, and patches 2-20 convert all
> relevant users to use it.
>
> IMO, it would be easiest to take all these patches through the crypto
> tree. But taking just the "crypto:" ones and then me trying to get the
> rest merged later via subsystem trees is also an option.
I am fine if you take the net/bluetooth/smp.c change through the crypto tree.
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
2020-05-02 5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
` (2 preceding siblings ...)
2020-05-02 6:44 ` [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Marcel Holtmann
@ 2020-05-03 16:13 ` Ard Biesheuvel
2020-05-08 6:07 ` Herbert Xu
4 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2020-05-03 16:13 UTC (permalink / raw)
To: Eric Biggers
Cc: Linux Crypto Mailing List, Cheng-Yi Chiang, ecryptfs,
Enric Balletbo i Serra, Gilad Ben-Yossef, Guenter Roeck,
Jesper Nilsson, Kamil Konieczny, keyrings, Krzysztof Kozlowski,
Krzysztof Opasiak, Lars Persson, linux-bluetooth, linux-mtd,
linux-nfs, linux-sctp, Robert Baldyga, Tom Lendacky,
Vladimir Zapolskiy, Zaibo Xu
On Sat, 2 May 2020 at 07:33, Eric Biggers <ebiggers@kernel.org> wrote:
>
> This series introduces a helper function crypto_shash_tfm_digest() which
> replaces the following common pattern:
>
> {
> SHASH_DESC_ON_STACK(desc, tfm);
> int err;
>
> desc->tfm = tfm;
>
> err = crypto_shash_digest(desc, data, len, out);
>
> shash_desc_zero(desc);
> }
>
> with:
>
> err = crypto_shash_tfm_digest(tfm, data, len, out);
>
> Patch 1 introduces this helper function, and patches 2-20 convert all
> relevant users to use it.
>
> IMO, it would be easiest to take all these patches through the crypto
> tree. But taking just the "crypto:" ones and then me trying to get the
> rest merged later via subsystem trees is also an option.
>
> Eric Biggers (20):
> crypto: hash - introduce crypto_shash_tfm_digest()
> crypto: arm64/aes-glue - use crypto_shash_tfm_digest()
> crypto: essiv - use crypto_shash_tfm_digest()
> crypto: artpec6 - use crypto_shash_tfm_digest()
> crypto: ccp - use crypto_shash_tfm_digest()
> crypto: ccree - use crypto_shash_tfm_digest()
> crypto: hisilicon/sec2 - use crypto_shash_tfm_digest()
> crypto: mediatek - use crypto_shash_tfm_digest()
> crypto: n2 - use crypto_shash_tfm_digest()
> crypto: omap-sham - use crypto_shash_tfm_digest()
> crypto: s5p-sss - use crypto_shash_tfm_digest()
> nfc: s3fwrn5: use crypto_shash_tfm_digest()
> fscrypt: use crypto_shash_tfm_digest()
> ecryptfs: use crypto_shash_tfm_digest()
> nfsd: use crypto_shash_tfm_digest()
> ubifs: use crypto_shash_tfm_digest()
> Bluetooth: use crypto_shash_tfm_digest()
> sctp: use crypto_shash_tfm_digest()
> KEYS: encrypted: use crypto_shash_tfm_digest()
> ASoC: cros_ec_codec: use crypto_shash_tfm_digest()
>
For the series,
Acked-by: Ard Biesheuvel <ardb@kernel.org>
> arch/arm64/crypto/aes-glue.c | 4 +--
> crypto/essiv.c | 4 +--
> crypto/shash.c | 16 +++++++++
> drivers/crypto/axis/artpec6_crypto.c | 10 ++----
> drivers/crypto/ccp/ccp-crypto-sha.c | 9 ++---
> drivers/crypto/ccree/cc_cipher.c | 9 ++---
> drivers/crypto/hisilicon/sec2/sec_crypto.c | 5 ++-
> drivers/crypto/mediatek/mtk-sha.c | 7 ++--
> drivers/crypto/n2_core.c | 7 ++--
> drivers/crypto/omap-sham.c | 20 +++--------
> drivers/crypto/s5p-sss.c | 39 ++++------------------
> drivers/nfc/s3fwrn5/firmware.c | 10 +-----
> fs/crypto/fname.c | 7 +---
> fs/crypto/hkdf.c | 6 +---
> fs/ecryptfs/crypto.c | 17 +---------
> fs/nfsd/nfs4recover.c | 26 ++++-----------
> fs/ubifs/auth.c | 20 ++---------
> fs/ubifs/master.c | 9 ++---
> fs/ubifs/replay.c | 14 ++------
> include/crypto/hash.h | 19 +++++++++++
> net/bluetooth/smp.c | 6 +---
> net/sctp/auth.c | 10 ++----
> net/sctp/sm_make_chunk.c | 23 +++++--------
> security/keys/encrypted-keys/encrypted.c | 18 ++--------
> sound/soc/codecs/cros_ec_codec.c | 9 +----
> 25 files changed, 95 insertions(+), 229 deletions(-)
>
> --
> 2.26.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
2020-05-02 5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
` (3 preceding siblings ...)
2020-05-03 16:13 ` Ard Biesheuvel
@ 2020-05-08 6:07 ` Herbert Xu
4 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2020-05-08 6:07 UTC (permalink / raw)
To: Eric Biggers
Cc: linux-crypto, cychiang, ecryptfs, enric.balletbo, gilad, groeck,
jesper.nilsson, k.konieczny, keyrings, krzk, k.opasiak,
lars.persson, linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
r.baldyga, thomas.lendacky, vz, xuzaibo
Eric Biggers <ebiggers@kernel.org> wrote:
> This series introduces a helper function crypto_shash_tfm_digest() which
> replaces the following common pattern:
>
> {
> SHASH_DESC_ON_STACK(desc, tfm);
> int err;
>
> desc->tfm = tfm;
>
> err = crypto_shash_digest(desc, data, len, out);
>
> shash_desc_zero(desc);
> }
>
> with:
>
> err = crypto_shash_tfm_digest(tfm, data, len, out);
>
> Patch 1 introduces this helper function, and patches 2-20 convert all
> relevant users to use it.
>
> IMO, it would be easiest to take all these patches through the crypto
> tree. But taking just the "crypto:" ones and then me trying to get the
> rest merged later via subsystem trees is also an option.
>
> Eric Biggers (20):
> crypto: hash - introduce crypto_shash_tfm_digest()
> crypto: arm64/aes-glue - use crypto_shash_tfm_digest()
> crypto: essiv - use crypto_shash_tfm_digest()
> crypto: artpec6 - use crypto_shash_tfm_digest()
> crypto: ccp - use crypto_shash_tfm_digest()
> crypto: ccree - use crypto_shash_tfm_digest()
> crypto: hisilicon/sec2 - use crypto_shash_tfm_digest()
> crypto: mediatek - use crypto_shash_tfm_digest()
> crypto: n2 - use crypto_shash_tfm_digest()
> crypto: omap-sham - use crypto_shash_tfm_digest()
> crypto: s5p-sss - use crypto_shash_tfm_digest()
> nfc: s3fwrn5: use crypto_shash_tfm_digest()
> fscrypt: use crypto_shash_tfm_digest()
> ecryptfs: use crypto_shash_tfm_digest()
> nfsd: use crypto_shash_tfm_digest()
> ubifs: use crypto_shash_tfm_digest()
> Bluetooth: use crypto_shash_tfm_digest()
> sctp: use crypto_shash_tfm_digest()
> KEYS: encrypted: use crypto_shash_tfm_digest()
> ASoC: cros_ec_codec: use crypto_shash_tfm_digest()
>
> arch/arm64/crypto/aes-glue.c | 4 +--
> crypto/essiv.c | 4 +--
> crypto/shash.c | 16 +++++++++
> drivers/crypto/axis/artpec6_crypto.c | 10 ++----
> drivers/crypto/ccp/ccp-crypto-sha.c | 9 ++---
> drivers/crypto/ccree/cc_cipher.c | 9 ++---
> drivers/crypto/hisilicon/sec2/sec_crypto.c | 5 ++-
> drivers/crypto/mediatek/mtk-sha.c | 7 ++--
> drivers/crypto/n2_core.c | 7 ++--
> drivers/crypto/omap-sham.c | 20 +++--------
> drivers/crypto/s5p-sss.c | 39 ++++------------------
> drivers/nfc/s3fwrn5/firmware.c | 10 +-----
> fs/crypto/fname.c | 7 +---
> fs/crypto/hkdf.c | 6 +---
> fs/ecryptfs/crypto.c | 17 +---------
> fs/nfsd/nfs4recover.c | 26 ++++-----------
> fs/ubifs/auth.c | 20 ++---------
> fs/ubifs/master.c | 9 ++---
> fs/ubifs/replay.c | 14 ++------
> include/crypto/hash.h | 19 +++++++++++
> net/bluetooth/smp.c | 6 +---
> net/sctp/auth.c | 10 ++----
> net/sctp/sm_make_chunk.c | 23 +++++--------
> security/keys/encrypted-keys/encrypted.c | 18 ++--------
> sound/soc/codecs/cros_ec_codec.c | 9 +----
> 25 files changed, 95 insertions(+), 229 deletions(-)
All applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-05-08 6:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02 5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
2020-05-02 5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
2020-05-02 5:31 ` [PATCH 17/20] Bluetooth: use crypto_shash_tfm_digest() Eric Biggers
2020-05-02 6:44 ` [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Marcel Holtmann
2020-05-03 16:13 ` Ard Biesheuvel
2020-05-08 6:07 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).