summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/hmac
diff options
context:
space:
mode:
authorjsing <>2014-06-21 13:42:14 +0000
committerjsing <>2014-06-21 13:42:14 +0000
commit13487d6ff5ba78e217edd743efcdd9a1be05aa21 (patch)
tree630b9b1b9589f6fa12e705f2da2d35788b2dcbb7 /src/lib/libcrypto/hmac
parent08ade2d2f3bc84d98839ae9064475c6fca84a29f (diff)
downloadopenbsd-13487d6ff5ba78e217edd743efcdd9a1be05aa21.tar.gz
openbsd-13487d6ff5ba78e217edd743efcdd9a1be05aa21.tar.bz2
openbsd-13487d6ff5ba78e217edd743efcdd9a1be05aa21.zip
More KNF.
Diffstat (limited to 'src/lib/libcrypto/hmac')
-rw-r--r--src/lib/libcrypto/hmac/hm_ameth.c9
-rw-r--r--src/lib/libcrypto/hmac/hm_pmeth.c15
-rw-r--r--src/lib/libcrypto/hmac/hmac.c29
-rw-r--r--src/lib/libcrypto/hmac/hmac.h28
4 files changed, 39 insertions, 42 deletions
diff --git a/src/lib/libcrypto/hmac/hm_ameth.c b/src/lib/libcrypto/hmac/hm_ameth.c
index ef97918472..c3e9038c0c 100644
--- a/src/lib/libcrypto/hmac/hm_ameth.c
+++ b/src/lib/libcrypto/hmac/hm_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_ameth.c,v 1.5 2014/06/21 12:00:01 miod Exp $ */ 1/* $OpenBSD: hm_ameth.c,v 1.6 2014/06/21 13:39:46 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007. 3 * project 2007.
4 */ 4 */
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -134,14 +134,13 @@ old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder)
134 if (inc) 134 if (inc)
135 *pder += os->length; 135 *pder += os->length;
136 } 136 }
137 137
138 return os->length; 138 return os->length;
139} 139}
140 140
141#endif 141#endif
142 142
143const EVP_PKEY_ASN1_METHOD 143const EVP_PKEY_ASN1_METHOD hmac_asn1_meth = {
144hmac_asn1_meth = {
145 .pkey_id = EVP_PKEY_HMAC, 144 .pkey_id = EVP_PKEY_HMAC,
146 .pkey_base_id = EVP_PKEY_HMAC, 145 .pkey_base_id = EVP_PKEY_HMAC,
147 146
diff --git a/src/lib/libcrypto/hmac/hm_pmeth.c b/src/lib/libcrypto/hmac/hm_pmeth.c
index c1ada08a48..75b5ad469d 100644
--- a/src/lib/libcrypto/hmac/hm_pmeth.c
+++ b/src/lib/libcrypto/hmac/hm_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_pmeth.c,v 1.5 2014/06/21 12:00:01 miod Exp $ */ 1/* $OpenBSD: hm_pmeth.c,v 1.6 2014/06/21 13:39:46 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007. 3 * project 2007.
4 */ 4 */
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -100,7 +100,7 @@ pkey_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
100 100
101 if (!pkey_hmac_init(dst)) 101 if (!pkey_hmac_init(dst))
102 return 0; 102 return 0;
103 sctx = src->data; 103 sctx = src->data;
104 dctx = dst->data; 104 dctx = dst->data;
105 dctx->md = sctx->md; 105 dctx->md = sctx->md;
106 HMAC_CTX_init(&dctx->ctx); 106 HMAC_CTX_init(&dctx->ctx);
@@ -141,12 +141,12 @@ pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
141 if (!hkey) 141 if (!hkey)
142 return 0; 142 return 0;
143 EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey); 143 EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey);
144 144
145 return 1; 145 return 1;
146} 146}
147 147
148static int 148static int
149int_update(EVP_MD_CTX *ctx,const void *data,size_t count) 149int_update(EVP_MD_CTX *ctx, const void *data, size_t count)
150{ 150{
151 HMAC_PKEY_CTX *hctx = ctx->pctx->data; 151 HMAC_PKEY_CTX *hctx = ctx->pctx->data;
152 152
@@ -186,7 +186,7 @@ hmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
186 return 1; 186 return 1;
187} 187}
188 188
189static int 189static int
190pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) 190pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
191{ 191{
192 HMAC_PKEY_CTX *hctx = ctx->data; 192 HMAC_PKEY_CTX *hctx = ctx->data;
@@ -240,8 +240,7 @@ pkey_hmac_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
240 return -2; 240 return -2;
241} 241}
242 242
243const EVP_PKEY_METHOD 243const EVP_PKEY_METHOD hmac_pkey_meth = {
244hmac_pkey_meth = {
245 .pkey_id = EVP_PKEY_HMAC, 244 .pkey_id = EVP_PKEY_HMAC,
246 245
247 .init = pkey_hmac_init, 246 .init = pkey_hmac_init,
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
index 0c29156d80..975fc4d1ec 100644
--- a/src/lib/libcrypto/hmac/hmac.c
+++ b/src/lib/libcrypto/hmac/hmac.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: hmac.c,v 1.19 2014/06/21 12:00:01 miod Exp $ */ 1/* $OpenBSD: hmac.c,v 1.20 2014/06/21 13:39:46 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -84,17 +84,18 @@ HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md,
84 if (!EVP_DigestUpdate(&ctx->md_ctx, key, len)) 84 if (!EVP_DigestUpdate(&ctx->md_ctx, key, len))
85 goto err; 85 goto err;
86 if (!EVP_DigestFinal_ex(&(ctx->md_ctx), ctx->key, 86 if (!EVP_DigestFinal_ex(&(ctx->md_ctx), ctx->key,
87 &ctx->key_length)) 87 &ctx->key_length))
88 goto err; 88 goto err;
89 } else { 89 } else {
90 OPENSSL_assert(len>=0 && len<=(int)sizeof(ctx->key)); 90 OPENSSL_assert(len >= 0 &&
91 memcpy(ctx->key,key,len); 91 len <= (int)sizeof(ctx->key));
92 memcpy(ctx->key, key, len);
92 ctx->key_length = len; 93 ctx->key_length = len;
93 } 94 }
94 if (ctx->key_length != HMAC_MAX_MD_CBLOCK) 95 if (ctx->key_length != HMAC_MAX_MD_CBLOCK)
95 memset(&ctx->key[ctx->key_length], 0, 96 memset(&ctx->key[ctx->key_length], 0,
96 HMAC_MAX_MD_CBLOCK - ctx->key_length); 97 HMAC_MAX_MD_CBLOCK - ctx->key_length);
97 } 98 }
98 99
99 if (reset) { 100 if (reset) {
100 for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++) 101 for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++)
@@ -122,14 +123,14 @@ int
122HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md) 123HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md)
123{ 124{
124 if (key && md) 125 if (key && md)
125 HMAC_CTX_init(ctx); 126 HMAC_CTX_init(ctx);
126 return HMAC_Init_ex(ctx,key,len,md, NULL); 127 return HMAC_Init_ex(ctx, key, len, md, NULL);
127} 128}
128 129
129int 130int
130HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len) 131HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len)
131{ 132{
132 return EVP_DigestUpdate(&ctx->md_ctx,data,len); 133 return EVP_DigestUpdate(&ctx->md_ctx, data, len);
133} 134}
134 135
135int 136int
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
index 5631d465e9..f3418b3cb7 100644
--- a/src/lib/libcrypto/hmac/hmac.h
+++ b/src/lib/libcrypto/hmac/hmac.h
@@ -1,25 +1,25 @@
1/* $OpenBSD: hmac.h,v 1.11 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: hmac.h,v 1.12 2014/06/21 13:39:46 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -72,15 +72,14 @@
72extern "C" { 72extern "C" {
73#endif 73#endif
74 74
75typedef struct hmac_ctx_st 75typedef struct hmac_ctx_st {
76 {
77 const EVP_MD *md; 76 const EVP_MD *md;
78 EVP_MD_CTX md_ctx; 77 EVP_MD_CTX md_ctx;
79 EVP_MD_CTX i_ctx; 78 EVP_MD_CTX i_ctx;
80 EVP_MD_CTX o_ctx; 79 EVP_MD_CTX o_ctx;
81 unsigned int key_length; 80 unsigned int key_length;
82 unsigned char key[HMAC_MAX_MD_CBLOCK]; 81 unsigned char key[HMAC_MAX_MD_CBLOCK];
83 } HMAC_CTX; 82} HMAC_CTX;
84 83
85#define HMAC_size(e) (EVP_MD_size((e)->md)) 84#define HMAC_size(e) (EVP_MD_size((e)->md))
86 85
@@ -91,14 +90,13 @@ void HMAC_CTX_cleanup(HMAC_CTX *ctx);
91#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */ 90#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */
92 91
93int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, 92int HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
94 const EVP_MD *md); /* deprecated */ 93 const EVP_MD *md); /* deprecated */
95int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, 94int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md,
96 const EVP_MD *md, ENGINE *impl); 95 ENGINE *impl);
97int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 96int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
98int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 97int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
99unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 98unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
100 const unsigned char *d, size_t n, unsigned char *md, 99 const unsigned char *d, size_t n, unsigned char *md, unsigned int *md_len);
101 unsigned int *md_len);
102int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); 100int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
103 101
104void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); 102void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);