New s390 specific protected key hmac
Subsystems (3)
Harald Freudenberger
maintainerv2 cover New s390 specific protected key hmac
Add support for protected key hmac ("phmac") for s390 arch.
With the latest machine generation there is now support for protected key (that is a key wrapped by a master key stored in firmware) hmac for sha2 (sha224, sha256, sha384 and sha512) for the s390 specific CPACF instruction kmac.
This patch adds support via 4 new shashes registered as phmac(sha224), phmac(sha256), phmac(sha384) and phmac(sha512).
Please note that as of now, there is no selftest enabled for these shashes, but the implementation has been tested with testcases via AF_ALG interface. However, there may come an improvement soon to use the available clear key hmac selftests.
Changelog:
v1: Initial version
v2: Increase HASH_MAX_DESCSIZE generic (not just for arch s390).
Fix one finding to use kmemdup instead of kmalloc/memcpy from test robot. Remove unneeded cpacf subfunctions checks. Simplify clone_tfm() function.
Rebased to s390/features.
Holger Dengler (3):
crypto: api - Adjust HASH_MAX_DESCSIZE for s390-phmac context s390/crypto: Add protected key hmac subfunctions for KMAC s390/crypto: New s390 specific shash phmac
arch/s390/configs/debug_defconfig | 1 + arch/s390/configs/defconfig | 1 + arch/s390/crypto/Makefile | 1 + arch/s390/crypto/phmac_s390.c | 468 ++++++++++++++++++++++++++++++ arch/s390/include/asm/cpacf.h | 4 + drivers/crypto/Kconfig | 12 + include/crypto/hash.h | 5 +- 7 files changed, 489 insertions(+), 3 deletions(-) create mode 100644 arch/s390/crypto/phmac_s390.c
base-commit: 8cf0b93919e13d1e8d4466eb4080a4c4d9d66d7b
Signature · 1 line
2.43.0
Harald Freudenberger
maintainerPATCH v2 1/3 crypto: api - Adjust HASH_MAX_DESCSIZE for s390-phmac context
From: Holger Dengler <[email protected]>
The phmac context exceeds the generic "worst case". Change this define to cover the s390 specific 'phmac(sha512)' which is a "protected" key hmac-sha2 implementation.
--- include/crypto/hash.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
include/crypto/hash.h +2 -3
@@ -159,10 +159,9 @@ struct shash_desc {#define HASH_MAX_DIGESTSIZE 64/* -* Worst case is hmac(sha3-224-generic). Its context is a nested 'shash_desc' -* containing a 'struct sha3_state'. +* The max case is currently the s390 specific shash 'phmac(sha512)'. */ -#define HASH_MAX_DESCSIZE (sizeof(struct shash_desc) + 360) +#define HASH_MAX_DESCSIZE (sizeof(struct shash_desc) + 376)#define SHASH_DESC_ON_STACK (shash, ctx) \ char __##shash##_desc[sizeof(struct shash_desc) + HASH_MAX_DESCSIZE] \
Signature · 1 line
2.43.0
Harald Freudenberger
maintainerPATCH v2 2/3 s390/crypto: Add protected key hmac subfunctions for KMAC
In reply to Harald FreudenbergerFrom: Holger Dengler <[email protected]>
The CPACF KMAC instruction supports new subfunctions for protected key hmac. Add defines for these 4 new subfuctions.
--- arch/s390/include/asm/cpacf.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/s390/include/asm/cpacf.h +4 -0
@@ -127,6 +127,10 @@#define CPACF_KMAC_HMAC_SHA_256 0x71#define CPACF_KMAC_HMAC_SHA_384 0x72#define CPACF_KMAC_HMAC_SHA_512 0x73 +#define CPACF_KMAC_PHMAC_SHA_224 0x78 +#define CPACF_KMAC_PHMAC_SHA_256 0x79 +#define CPACF_KMAC_PHMAC_SHA_384 0x7a +#define CPACF_KMAC_PHMAC_SHA_512 0x7b/* * Function codes for the PCKMO (PERFORM CRYPTOGRAPHIC KEY MANAGEMENT)
Signature · 1 line
2.43.0
Harald Freudenberger
maintainerPATCH v2 3/3 s390/crypto: New s390 specific shash phmac
In reply to Harald FreudenbergerFrom: Holger Dengler <[email protected]>
Add support for protected key hmac ("phmac") for s390 arch.
With the latest machine generation there is now support for protected key (that is a key wrapped by a master key stored in firmware) hmac for sha2 (sha224, sha256, sha384 and sha512) for the s390 specific CPACF instruction kmac.
This patch adds support via 4 new shashes registered as phmac(sha224), phmac(sha256), phmac(sha384) and phmac(sha512).
Please note that as of now, there is no selftest enabled for these shashes, but the implementation has been tested with testcases via AF_ALG interface.
--- arch/s390/configs/debug_defconfig | 1 + arch/s390/configs/defconfig | 1 + arch/s390/crypto/Makefile | 1 + arch/s390/crypto/phmac_s390.c | 468 ++++++++++++++++++++++++++++++ drivers/crypto/Kconfig | 12 + 5 files changed, 483 insertions(+) create mode 100644 arch/s390/crypto/phmac_s390.c
arch/s390/configs/debug_defconfig +1 -0
@@ -802,6 +802,7 @@ CONFIG_PKEY_CCA=m CONFIG_PKEY_EP11=m CONFIG_PKEY_PCKMO=m CONFIG_CRYPTO_PAES_S390=m +CONFIG_CRYPTO_PHMAC_S390=m CONFIG_CRYPTO_DEV_VIRTIO=m CONFIG_SYSTEM_BLACKLIST_KEYRING=y CONFIG_CORDIC=m
arch/s390/configs/defconfig +1 -0
@@ -788,6 +788,7 @@ CONFIG_PKEY_CCA=m CONFIG_PKEY_EP11=m CONFIG_PKEY_PCKMO=m CONFIG_CRYPTO_PAES_S390=m +CONFIG_CRYPTO_PHMAC_S390=m CONFIG_CRYPTO_DEV_VIRTIO=m CONFIG_SYSTEM_BLACKLIST_KEYRING=y CONFIG_CORDIC=m
arch/s390/crypto/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_S390_PRNG) += prng.o obj-$(CONFIG_CRYPTO_GHASH_S390) += ghash_s390.o obj-$(CONFIG_CRYPTO_CRC32_S390) += crc32-vx_s390.o obj-$(CONFIG_CRYPTO_HMAC_S390) += hmac_s390.o +obj-$(CONFIG_CRYPTO_PHMAC_S390) += phmac_s390.o obj-y += arch_random.o crc32-vx_s390-y := crc32-vx.o crc32le-vx.o crc32be-vx.o
arch/s390/crypto/phmac_s390.c new file +468 -0
468 lines not on this page · raw message
drivers/crypto/Kconfig +12 -0
@@ -166,6 +166,18 @@ config CRYPTO_PAES_S390 Select this option if you want to use the paes cipher for example to use protected key encrypted devices. +config CRYPTO_PHMAC_S390 + tristate "PHMAC cipher algorithms" + depends on S390 + depends on PKEY + select CRYPTO_HASH + help + This is the s390 hardware accelerated implementation of the + protected key HMAC support for SHA224, SHA256, SHA384 and SHA512. + + Select this option if you want to use the phmac digests + for example to use dm-integrity with secure/protected keys. + config S390_PRNG tristate "Pseudo random number generator device driver" depends on S390
Signature · 1 line
2.43.0
Holger Dengler
maintainerRe: [PATCH v2 3/3] s390/crypto: New s390 specific shash phmac
Quoted 27 lines · Harald Freudenberger
From: Holger Dengler <[email protected]>
Add support for protected key hmac ("phmac") for s390 arch.
With the latest machine generation there is now support for protected key (that is a key wrapped by a master key stored in firmware) hmac for sha2 (sha224, sha256, sha384 and sha512) for the s390 specific CPACF instruction kmac.
This patch adds support via 4 new shashes registered as phmac(sha224), phmac(sha256), phmac(sha384) and phmac(sha512).
Please note that as of now, there is no selftest enabled for these shashes, but the implementation has been tested with testcases via
AF_ALGinterface.Signed-off-by Holger Dengler <[email protected]>Signed-off-by Harald Freudenberger <[email protected]>--- arch/s390/configs/debug_defconfig | 1 + arch/s390/configs/defconfig | 1 + arch/s390/crypto/Makefile | 1 + arch/s390/crypto/phmac_s390.c | 468 ++++++++++++++++++++++++++++++ drivers/crypto/Kconfig | 12 + 5 files changed, 483 insertions(+) create mode 100644 arch/s390/crypto/phmac_s390.c
[...]
Quoted 6 lines
arch/s390/crypto/phmac_s390.c new file +0
-0@@ -0,0 +1,468 @@
[...]
arch/s390/crypto/phmac_s390.c line 381
Quoted 11 lines
arch/s390/crypto/phmac_s390.c new file +11
-0+static int s390_phmac_sha2_clone_tfm (struct crypto_shash *dst, +struct crypto_shash *src) +{ +struct s390_phmac_ctx *src_ctx =crypto_shash_ctx (src); +int rc; + + rc =s390_phmac_sha2_init_tfm (dst); +if (rc) +return rc; + +return s390_phmac_sha2_setkey (dst, src_ctx->key, src_ctx->keylen);
You should call setkey() only if the key in src_ctx has been set.
return src_ctx->key ? s390_phmac_sha2_setkey(dst, src_ctx->key, src_ctx->keylen) : 0;
Quoted 1 line
+}
Signature · 5 lines
Mit freundlichen Grüßen / Kind regards Holger Dengler -- IBM Systems, Linux on IBM Z Development [email protected]
Herbert Xu
maintainerRe: [PATCH v2 3/3] s390/crypto: New s390 specific shash phmac
In reply to Harald FreudenbergerQuoted 4 lines · Harald Freudenberger
arch/s390/crypto/phmac_s390.c new file +3
-0+static inline int s390_phmac_sha2_setkey (struct crypto_shash *tfm, +const u8 *key,unsigned int keylen) +{
arch/s390/crypto/phmac_s390.c line 165
Quoted 10 lines
arch/s390/crypto/phmac_s390.c new file +10
-0+struct s390_phmac_ctx *tfm_ctx =crypto_shash_ctx (tfm); +int rc = -ENOMEM ; + +if (tfm_ctx->keylen) { +kfree_sensitive (tfm_ctx->key); + tfm_ctx->key =NULL ; + tfm_ctx->keylen =0 ; + } + + tfm_ctx->key =kmemdup (key, keylen,GFP_KERNEL );
Please use GFP_ATOMIC. GFP_KERNEL allocations are not allowed in setkey.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt