crypto: hmac - add hmac IPAD/OPAD constant
authorCorentin LABBE <clabbe.montjoie@gmail.com>
Fri, 19 May 2017 06:53:23 +0000 (08:53 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 23 May 2017 04:52:05 +0000 (12:52 +0800)
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>
crypto/hmac.c
include/crypto/hmac.h [new file with mode: 0644]

index 72e38c098bb3184d3886ac4054f123dca3bb49ac..92871dc2a63ec66ca628df3a44b025b7ef6f247e 100644 (file)
@@ -16,6 +16,7 @@
  *
  */
 
+#include <crypto/hmac.h>
 #include <crypto/internal/hash.h>
 #include <crypto/scatterwalk.h>
 #include <linux/err.h>
@@ -74,8 +75,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/hmac.h b/include/crypto/hmac.h
new file mode 100644 (file)
index 0000000..ef09f79
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _CRYPTO_HMAC_H
+#define _CRYPTO_HMAC_H
+
+#define HMAC_IPAD_VALUE 0x36
+#define HMAC_OPAD_VALUE 0x5c
+
+#endif /* _CRYPTO_HMAC_H */