Skip to content

Commit 03d7db5

Browse files
montjoieherbertx
authored andcommitted
crypto: hmac - add hmac IPAD/OPAD constant
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 in a new include file "crypto/hmac.h" and use them in crypto/hmac.c Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9417cd1 commit 03d7db5

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎crypto/hmac.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818

19+
#include <crypto/hmac.h>
1920
#include <crypto/internal/hash.h>
2021
#include <crypto/scatterwalk.h>
2122
#include <linux/err.h>
@@ -74,8 +75,8 @@ static int hmac_setkey(struct crypto_shash *parent,
7475
memcpy(opad, ipad, bs);
7576

7677
for (i = 0; i < bs; i++) {
77-
ipad[i] ^= 0x36;
78-
opad[i] ^= 0x5c;
78+
ipad[i] ^= HMAC_IPAD_VALUE;
79+
opad[i] ^= HMAC_OPAD_VALUE;
7980
}
8081

8182
return crypto_shash_init(shash) ?:

‎include/crypto/hmac.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef _CRYPTO_HMAC_H
2+
#define _CRYPTO_HMAC_H
3+
4+
#define HMAC_IPAD_VALUE 0x36
5+
#define HMAC_OPAD_VALUE 0x5c
6+
7+
#endif /* _CRYPTO_HMAC_H */

0 commit comments

Comments
 (0)