linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/9] crypto: add hmac IPAD/OPAD constant
@ 2017-04-24 14:16 Corentin Labbe
  2017-04-24 14:16 ` [PATCH 2/9] crypto: brcm - Use " Corentin Labbe
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

Many HMAC users directly use directly 0x36/0x5c values.
It's better with crypto to use a name instead of directly some crypto
constant.

This patch simply add HMAC_IPAD_VALUE/HMAC_OPAD_VALUE defines.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 crypto/hmac.c         | 4 ++--
 include/crypto/hash.h | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/crypto/hmac.c b/crypto/hmac.c
index 72e38c0..4a997ce 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -74,8 +74,8 @@ static int hmac_setkey(struct crypto_shash *parent,
 	memcpy(opad, ipad, bs);
 
 	for (i = 0; i < bs; i++) {
-		ipad[i] ^= 0x36;
-		opad[i] ^= 0x5c;
+		ipad[i] ^= HMAC_IPAD_VALUE;
+		opad[i] ^= HMAC_OPAD_VALUE;
 	}
 
 	return crypto_shash_init(shash) ?:
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index b5727bc..0f51ff1 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -922,4 +922,7 @@ static inline void shash_desc_zero(struct shash_desc *desc)
 			 sizeof(*desc) + crypto_shash_descsize(desc->tfm));
 }
 
+#define HMAC_IPAD_VALUE 0x36
+#define HMAC_OPAD_VALUE 0x5c
+
 #endif	/* _CRYPTO_HASH_H */
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/9] crypto: brcm - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-04-24 14:16 ` [PATCH 3/9] crypto: ixp4xx " Corentin Labbe
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/bcm/cipher.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/bcm/cipher.c b/drivers/crypto/bcm/cipher.c
index cc0d5b9..304c7ed 100644
--- a/drivers/crypto/bcm/cipher.c
+++ b/drivers/crypto/bcm/cipher.c
@@ -2510,8 +2510,8 @@ static int ahash_hmac_setkey(struct crypto_ahash *ahash, const u8 *key,
 		memcpy(ctx->opad, ctx->ipad, blocksize);
 
 		for (index = 0; index < blocksize; index++) {
-			ctx->ipad[index] ^= 0x36;
-			ctx->opad[index] ^= 0x5c;
+			ctx->ipad[index] ^= HMAC_IPAD_VALUE;
+			ctx->opad[index] ^= HMAC_OPAD_VALUE;
 		}
 
 		flow_dump("  ipad: ", ctx->ipad, blocksize);
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/9] crypto: ixp4xx - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
  2017-04-24 14:16 ` [PATCH 2/9] crypto: brcm - Use " Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-04-24 14:16 ` [PATCH 4/9] crypto: marvell " Corentin Labbe
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/ixp4xx_crypto.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 771dd26..3b7680c 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -90,8 +90,6 @@
 #define CTL_FLAG_PERFORM_AEAD	0x0008
 #define CTL_FLAG_MASK		0x000f
 
-#define HMAC_IPAD_VALUE   0x36
-#define HMAC_OPAD_VALUE   0x5C
 #define HMAC_PAD_BLOCKLEN SHA1_BLOCK_SIZE
 
 #define MD5_DIGEST_SIZE   16
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/9] crypto: marvell - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
  2017-04-24 14:16 ` [PATCH 2/9] crypto: brcm - Use " Corentin Labbe
  2017-04-24 14:16 ` [PATCH 3/9] crypto: ixp4xx " Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-04-24 14:16 ` [PATCH 5/9] crypto: mv_cesa " Corentin Labbe
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/marvell/hash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/marvell/hash.c b/drivers/crypto/marvell/hash.c
index 77c0fb9..a6df61f 100644
--- a/drivers/crypto/marvell/hash.c
+++ b/drivers/crypto/marvell/hash.c
@@ -1164,8 +1164,8 @@ static int mv_cesa_ahmac_pad_init(struct ahash_request *req,
 	memcpy(opad, ipad, blocksize);
 
 	for (i = 0; i < blocksize; i++) {
-		ipad[i] ^= 0x36;
-		opad[i] ^= 0x5c;
+		ipad[i] ^= HMAC_IPAD_VALUE;
+		opad[i] ^= HMAC_OPAD_VALUE;
 	}
 
 	return 0;
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/9] crypto: mv_cesa - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
                   ` (2 preceding siblings ...)
  2017-04-24 14:16 ` [PATCH 4/9] crypto: marvell " Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-04-24 14:16 ` [PATCH 6/9] crypto: omap-sham " Corentin Labbe
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/mv_cesa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c
index 451fa18..41ae190 100644
--- a/drivers/crypto/mv_cesa.c
+++ b/drivers/crypto/mv_cesa.c
@@ -822,8 +822,8 @@ static int mv_hash_setkey(struct crypto_ahash *tfm, const u8 * key,
 		memcpy(opad, ipad, bs);
 
 		for (i = 0; i < bs; i++) {
-			ipad[i] ^= 0x36;
-			opad[i] ^= 0x5c;
+			ipad[i] ^= HMAC_IPAD_VALUE;
+			opad[i] ^= HMAC_OPAD_VALUE;
 		}
 
 		rc = crypto_shash_init(shash) ? :
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/9] crypto: omap-sham - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
                   ` (3 preceding siblings ...)
  2017-04-24 14:16 ` [PATCH 5/9] crypto: mv_cesa " Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-04-24 14:16 ` [PATCH 7/9] crypto: qat " Corentin Labbe
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/omap-sham.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index d0b16e5..11e11a6 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -1326,8 +1326,8 @@ static int omap_sham_setkey(struct crypto_ahash *tfm, const u8 *key,
 		memcpy(bctx->opad, bctx->ipad, bs);
 
 		for (i = 0; i < bs; i++) {
-			bctx->ipad[i] ^= 0x36;
-			bctx->opad[i] ^= 0x5c;
+			bctx->ipad[i] ^= HMAC_IPAD_VALUE;
+			bctx->opad[i] ^= HMAC_OPAD_VALUE;
 		}
 	}
 
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/9] crypto: qat - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
                   ` (4 preceding siblings ...)
  2017-04-24 14:16 ` [PATCH 6/9] crypto: omap-sham " Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-04-24 14:16 ` [PATCH 8/9] crypto: mediatek " Corentin Labbe
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/qat/qat_common/qat_algs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/qat_common/qat_algs.c
index 20f35df..6843fe2 100644
--- a/drivers/crypto/qat/qat_common/qat_algs.c
+++ b/drivers/crypto/qat/qat_common/qat_algs.c
@@ -178,8 +178,8 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash,
 	for (i = 0; i < block_size; i++) {
 		char *ipad_ptr = ipad + i;
 		char *opad_ptr = opad + i;
-		*ipad_ptr ^= 0x36;
-		*opad_ptr ^= 0x5C;
+		*ipad_ptr ^= HMAC_IPAD_VALUE;
+		*opad_ptr ^= HMAC_OPAD_VALUE;
 	}
 
 	if (crypto_shash_init(shash))
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 8/9] crypto: mediatek - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
                   ` (5 preceding siblings ...)
  2017-04-24 14:16 ` [PATCH 7/9] crypto: qat " Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-04-24 14:16 ` [PATCH 9/9] crypto: ccp " Corentin Labbe
  2017-05-18  4:10 ` [PATCH 1/9] crypto: add hmac " Herbert Xu
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/mediatek/mtk-sha.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/mediatek/mtk-sha.c b/drivers/crypto/mediatek/mtk-sha.c
index 2226f12..cbcb522 100644
--- a/drivers/crypto/mediatek/mtk-sha.c
+++ b/drivers/crypto/mediatek/mtk-sha.c
@@ -825,8 +825,8 @@ static int mtk_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
 	memcpy(bctx->opad, bctx->ipad, bs);
 
 	for (i = 0; i < bs; i++) {
-		bctx->ipad[i] ^= 0x36;
-		bctx->opad[i] ^= 0x5c;
+		bctx->ipad[i] ^= HMAC_IPAD_VALUE;
+		bctx->opad[i] ^= HMAC_OPAD_VALUE;
 	}
 
 	return 0;
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 9/9] crypto: ccp - Use IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
                   ` (6 preceding siblings ...)
  2017-04-24 14:16 ` [PATCH 8/9] crypto: mediatek " Corentin Labbe
@ 2017-04-24 14:16 ` Corentin Labbe
  2017-05-18  4:10 ` [PATCH 1/9] crypto: add hmac " Herbert Xu
  8 siblings, 0 replies; 10+ messages in thread
From: Corentin Labbe @ 2017-04-24 14:16 UTC (permalink / raw)
  To: herbert, davem, thomas.lendacky, gary.hook, boris.brezillon,
	arno, matthias.bgg, giovanni.cabiddu, salvatore.benedetto
  Cc: linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux, Corentin Labbe

This patch simply replace all occurrence of HMAC IPAD/OPAD value by their
define.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/crypto/ccp/ccp-crypto-sha.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-crypto-sha.c b/drivers/crypto/ccp/ccp-crypto-sha.c
index 6b46eea..3834366 100644
--- a/drivers/crypto/ccp/ccp-crypto-sha.c
+++ b/drivers/crypto/ccp/ccp-crypto-sha.c
@@ -308,8 +308,8 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
 	}
 
 	for (i = 0; i < block_size; i++) {
-		ctx->u.sha.ipad[i] = ctx->u.sha.key[i] ^ 0x36;
-		ctx->u.sha.opad[i] = ctx->u.sha.key[i] ^ 0x5c;
+		ctx->u.sha.ipad[i] = ctx->u.sha.key[i] ^ HMAC_IPAD_VALUE;
+		ctx->u.sha.opad[i] = ctx->u.sha.key[i] ^ HMAC_OPAD_VALUE;
 	}
 
 	sg_init_one(&ctx->u.sha.opad_sg, ctx->u.sha.opad, block_size);
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/9] crypto: add hmac IPAD/OPAD constant
  2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
                   ` (7 preceding siblings ...)
  2017-04-24 14:16 ` [PATCH 9/9] crypto: ccp " Corentin Labbe
@ 2017-05-18  4:10 ` Herbert Xu
  8 siblings, 0 replies; 10+ messages in thread
From: Herbert Xu @ 2017-05-18  4:10 UTC (permalink / raw)
  To: Corentin Labbe
  Cc: davem, thomas.lendacky, gary.hook, boris.brezillon, arno,
	matthias.bgg, giovanni.cabiddu, salvatore.benedetto,
	linux-crypto, linux-kernel, linux-arm-kernel, linux-mediatek,
	qat-linux

On Mon, Apr 24, 2017 at 04:16:21PM +0200, Corentin Labbe wrote:
> Many HMAC users directly use directly 0x36/0x5c values.
> It's better with crypto to use a name instead of directly some crypto
> constant.
> 
> This patch simply add HMAC_IPAD_VALUE/HMAC_OPAD_VALUE defines.
> 
> Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
> ---
>  crypto/hmac.c         | 4 ++--
>  include/crypto/hash.h | 3 +++
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/crypto/hmac.c b/crypto/hmac.c
> index 72e38c0..4a997ce 100644
> --- a/crypto/hmac.c
> +++ b/crypto/hmac.c
> @@ -74,8 +74,8 @@ static int hmac_setkey(struct crypto_shash *parent,
>  	memcpy(opad, ipad, bs);
>  
>  	for (i = 0; i < bs; i++) {
> -		ipad[i] ^= 0x36;
> -		opad[i] ^= 0x5c;
> +		ipad[i] ^= HMAC_IPAD_VALUE;
> +		opad[i] ^= HMAC_OPAD_VALUE;
>  	}
>  
>  	return crypto_shash_init(shash) ?:
> diff --git a/include/crypto/hash.h b/include/crypto/hash.h
> index b5727bc..0f51ff1 100644
> --- a/include/crypto/hash.h
> +++ b/include/crypto/hash.h
> @@ -922,4 +922,7 @@ static inline void shash_desc_zero(struct shash_desc *desc)
>  			 sizeof(*desc) + crypto_shash_descsize(desc->tfm));
>  }
>  
> +#define HMAC_IPAD_VALUE 0x36
> +#define HMAC_OPAD_VALUE 0x5c
> +
>  #endif	/* _CRYPTO_HASH_H */

I think this should go into a header file specific to hmac.  Since
I don't see an existing hmac header file you should create one for it.

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] 10+ messages in thread

end of thread, other threads:[~2017-05-18  4:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-24 14:16 [PATCH 1/9] crypto: add hmac IPAD/OPAD constant Corentin Labbe
2017-04-24 14:16 ` [PATCH 2/9] crypto: brcm - Use " Corentin Labbe
2017-04-24 14:16 ` [PATCH 3/9] crypto: ixp4xx " Corentin Labbe
2017-04-24 14:16 ` [PATCH 4/9] crypto: marvell " Corentin Labbe
2017-04-24 14:16 ` [PATCH 5/9] crypto: mv_cesa " Corentin Labbe
2017-04-24 14:16 ` [PATCH 6/9] crypto: omap-sham " Corentin Labbe
2017-04-24 14:16 ` [PATCH 7/9] crypto: qat " Corentin Labbe
2017-04-24 14:16 ` [PATCH 8/9] crypto: mediatek " Corentin Labbe
2017-04-24 14:16 ` [PATCH 9/9] crypto: ccp " Corentin Labbe
2017-05-18  4:10 ` [PATCH 1/9] crypto: add hmac " 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).