summaryrefslogtreecommitdiff
path: root/lib/hmac-sha1.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2018-09-29 22:20:17 -0700
committerPádraig Brady <P@draigBrady.com>2018-10-01 01:08:31 -0700
commit7d0bb7b0e50dbd631f7b0f3cf2718bcdf06e0506 (patch)
tree810ab111d375bb9693ace4cd84c152a536d10e86 /lib/hmac-sha1.c
parentcfc433962ce15e5f45c00d938f1ca6af3f4a29b9 (diff)
downloadgnulib-7d0bb7b0e50dbd631f7b0f3cf2718bcdf06e0506.tar.gz
hmac-*: refactor to remove repetitive code
A net removal of 240 lines. * lib/hmac.c: A new parameterized single implementation. * lib/hmac-md5.c: Define parameters and include implementation. * lib/hmac-sha1.c: Likewise. * lib/hmac-sha256.c: Likewise. * lib/hmac-sha512.c: Likewise. * modules/crypto/hmac-md5: Reference the new implementation file. * modules/crypto/hmac-sha1: Likewise. * modules/crypto/hmac-sha256: Likewise. * modules/crypto/hmac-sha512: Likewise. * tests/test-hmac-md5.c: Refactor common code to a single function. * tests/test-hmac-sha1.c: Likewise. * tests/test-hmac-sha256.c: Likewise. * tests/test-hmac-sha512.c: Likewise.
Diffstat (limited to 'lib/hmac-sha1.c')
-rw-r--r--lib/hmac-sha1.c64
1 files changed, 5 insertions, 59 deletions
diff --git a/lib/hmac-sha1.c b/lib/hmac-sha1.c
index fd82e3eeb3..6f28bdc5b0 100644
--- a/lib/hmac-sha1.c
+++ b/lib/hmac-sha1.c
@@ -1,5 +1,5 @@
/* hmac-sha1.c -- hashed message authentication codes
- Copyright (C) 2005-2006, 2009-2018 Free Software Foundation, Inc.
+ Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -14,67 +14,13 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
-/* Written by Simon Josefsson. */
-
#include <config.h>
#include "hmac.h"
-#include "memxor.h"
#include "sha1.h"
-#include <string.h>
-
-#define IPAD 0x36
-#define OPAD 0x5c
-
-int
-hmac_sha1 (const void *key, size_t keylen,
- const void *in, size_t inlen, void *resbuf)
-{
- struct sha1_ctx inner;
- struct sha1_ctx outer;
- char optkeybuf[20];
- char block[64];
- char innerhash[20];
-
- /* Reduce the key's size, so that it becomes <= 64 bytes large. */
-
- if (keylen > 64)
- {
- struct sha1_ctx keyhash;
-
- sha1_init_ctx (&keyhash);
- sha1_process_bytes (key, keylen, &keyhash);
- sha1_finish_ctx (&keyhash, optkeybuf);
-
- key = optkeybuf;
- keylen = 20;
- }
-
- /* Compute INNERHASH from KEY and IN. */
-
- sha1_init_ctx (&inner);
-
- memset (block, IPAD, sizeof (block));
- memxor (block, key, keylen);
-
- sha1_process_block (block, 64, &inner);
- sha1_process_bytes (in, inlen, &inner);
-
- sha1_finish_ctx (&inner, innerhash);
-
- /* Compute result from KEY and INNERHASH. */
-
- sha1_init_ctx (&outer);
-
- memset (block, OPAD, sizeof (block));
- memxor (block, key, keylen);
-
- sha1_process_block (block, 64, &outer);
- sha1_process_bytes (innerhash, 20, &outer);
-
- sha1_finish_ctx (&outer, resbuf);
-
- return 0;
-}
+#define GL_HMAC_NAME 1
+#define GL_HMAC_BLOCKSIZE 64
+#define GL_HMAC_HASHSIZE 20
+#include "hmac.c"