Mercurial > gnulib
annotate lib/hmac.c @ 40231:9b3c79fdfe0b
strtod: fix clash with strtold
Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817).
* lib/strtod.c (compute_minus_zero, minus_zero):
Simplify by remving the macro / external variable,
and having just a function. User changed. This avoids
the need for an external variable that might clash.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Mar 2019 16:40:29 -0700 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
39875
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
1 /* hmac.c -- hashed message authentication codes |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
39875
diff
changeset
|
2 Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. |
39875
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
3 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
4 This program is free software; you can redistribute it and/or modify |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 2, or (at your option) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
7 any later version. |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
8 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
13 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
16 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
17 #include <string.h> |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
18 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
19 #include "memxor.h" |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
20 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
21 #define IPAD 0x36 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
22 #define OPAD 0x5c |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
23 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
24 /* Concatenate two preprocessor tokens. */ |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
25 #define _GLHMAC_CONCAT_(prefix, suffix) prefix##suffix |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
26 #define _GLHMAC_CONCAT(prefix, suffix) _GLHMAC_CONCAT_ (prefix, suffix) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
27 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
28 #if GL_HMAC_NAME == 5 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
29 # define HMAC_ALG md5 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
30 #else |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
31 # define HMAC_ALG _GLHMAC_CONCAT (sha, GL_HMAC_NAME) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
32 #endif |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
33 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
34 #define GL_HMAC_CTX _GLHMAC_CONCAT (HMAC_ALG, _ctx) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
35 #define GL_HMAC_FN _GLHMAC_CONCAT (hmac_, HMAC_ALG) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
36 #define GL_HMAC_FN_INIT _GLHMAC_CONCAT (HMAC_ALG, _init_ctx) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
37 #define GL_HMAC_FN_BLOC _GLHMAC_CONCAT (HMAC_ALG, _process_block) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
38 #define GL_HMAC_FN_PROC _GLHMAC_CONCAT (HMAC_ALG, _process_bytes) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
39 #define GL_HMAC_FN_FINI _GLHMAC_CONCAT (HMAC_ALG, _finish_ctx) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
40 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
41 static void |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
42 hmac_hash (const void *key, size_t keylen, |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
43 const void *in, size_t inlen, |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
44 int pad, void *resbuf) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
45 { |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
46 struct GL_HMAC_CTX hmac_ctx; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
47 char block[GL_HMAC_BLOCKSIZE]; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
48 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
49 memset (block, pad, sizeof block); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
50 memxor (block, key, keylen); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
51 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
52 GL_HMAC_FN_INIT (&hmac_ctx); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
53 GL_HMAC_FN_BLOC (block, sizeof block, &hmac_ctx); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
54 GL_HMAC_FN_PROC (in, inlen, &hmac_ctx); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
55 GL_HMAC_FN_FINI (&hmac_ctx, resbuf); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
56 } |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
57 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
58 int |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
59 GL_HMAC_FN (const void *key, size_t keylen, |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
60 const void *in, size_t inlen, void *resbuf) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
61 { |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
62 char optkeybuf[GL_HMAC_HASHSIZE]; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
63 char innerhash[GL_HMAC_HASHSIZE]; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
64 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
65 /* Ensure key size is <= block size. */ |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
66 if (keylen > GL_HMAC_BLOCKSIZE) |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
67 { |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
68 struct GL_HMAC_CTX keyhash; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
69 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
70 GL_HMAC_FN_INIT (&keyhash); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
71 GL_HMAC_FN_PROC (key, keylen, &keyhash); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
72 GL_HMAC_FN_FINI (&keyhash, optkeybuf); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
73 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
74 key = optkeybuf; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
75 /* zero padding of the key to the block size |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
76 is implicit in the memxor. */ |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
77 keylen = sizeof optkeybuf; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
78 } |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
79 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
80 /* Compute INNERHASH from KEY and IN. */ |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
81 hmac_hash (key, keylen, in, inlen, IPAD, innerhash); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
82 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
83 /* Compute result from KEY and INNERHASH. */ |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
84 hmac_hash (key, keylen, innerhash, sizeof innerhash, OPAD, resbuf); |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
85 |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
86 return 0; |
67e1644a2382
hmac-*: refactor to remove repetitive code
Pádraig Brady <P@draigBrady.com>
parents:
diff
changeset
|
87 } |