summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/hmac
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2016-07-23 19:31:36 +0000
committercvs2svn <admin@example.com>2016-07-23 19:31:36 +0000
commit86c49b31af735796dfde37aa29473a30d36367db (patch)
treee9a354a92a348338fe2b361e2eda703cae23cfab /src/lib/libcrypto/hmac
parent19d5fe348e8926bac4521c5807aa64c45b8f7a41 (diff)
downloadopenbsd-OPENBSD_6_0_BASE.tar.gz
openbsd-OPENBSD_6_0_BASE.tar.bz2
openbsd-OPENBSD_6_0_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_6_0_BASE'.OPENBSD_6_0_BASE
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/hmac/hm_ameth.c169
-rw-r--r--src/lib/libcrypto/hmac/hm_pmeth.c259
-rw-r--r--src/lib/libcrypto/hmac/hmac.c225
-rw-r--r--src/lib/libcrypto/hmac/hmac.h108
4 files changed, 0 insertions, 761 deletions
diff --git a/src/lib/libcrypto/hmac/hm_ameth.c b/src/lib/libcrypto/hmac/hm_ameth.c
deleted file mode 100644
index cfa0239705..0000000000
--- a/src/lib/libcrypto/hmac/hm_ameth.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/* $OpenBSD: hm_ameth.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007.
4 */
5/* ====================================================================
6 * Copyright (c) 2007 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61
62#include <openssl/evp.h>
63
64#include "asn1_locl.h"
65
66#define HMAC_TEST_PRIVATE_KEY_FORMAT
67
68/* HMAC "ASN1" method. This is just here to indicate the
69 * maximum HMAC output length and to free up an HMAC
70 * key.
71 */
72
73static int
74hmac_size(const EVP_PKEY *pkey)
75{
76 return EVP_MAX_MD_SIZE;
77}
78
79static void
80hmac_key_free(EVP_PKEY *pkey)
81{
82 ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr;
83
84 if (os) {
85 if (os->data)
86 explicit_bzero(os->data, os->length);
87 ASN1_OCTET_STRING_free(os);
88 }
89}
90
91static int
92hmac_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
93{
94 switch (op) {
95 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
96 *(int *)arg2 = NID_sha1;
97 return 1;
98 default:
99 return -2;
100 }
101}
102
103#ifdef HMAC_TEST_PRIVATE_KEY_FORMAT
104/* A bogus private key format for test purposes. This is simply the
105 * HMAC key with "HMAC PRIVATE KEY" in the headers. When enabled the
106 * genpkey utility can be used to "generate" HMAC keys.
107 */
108
109static int
110old_hmac_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
111{
112 ASN1_OCTET_STRING *os;
113
114 os = ASN1_OCTET_STRING_new();
115 if (os == NULL)
116 goto err;
117 if (ASN1_OCTET_STRING_set(os, *pder, derlen) == 0)
118 goto err;
119 if (EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, os) == 0)
120 goto err;
121 return 1;
122
123err:
124 ASN1_OCTET_STRING_free(os);
125 return 0;
126}
127
128static int
129old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder)
130{
131 int inc;
132 ASN1_OCTET_STRING *os = (ASN1_OCTET_STRING *)pkey->pkey.ptr;
133
134 if (pder) {
135 if (!*pder) {
136 *pder = malloc(os->length);
137 if (*pder == NULL)
138 return -1;
139 inc = 0;
140 } else
141 inc = 1;
142
143 memcpy(*pder, os->data, os->length);
144
145 if (inc)
146 *pder += os->length;
147 }
148
149 return os->length;
150}
151
152#endif
153
154const EVP_PKEY_ASN1_METHOD hmac_asn1_meth = {
155 .pkey_id = EVP_PKEY_HMAC,
156 .pkey_base_id = EVP_PKEY_HMAC,
157
158 .pem_str = "HMAC",
159 .info = "OpenSSL HMAC method",
160
161 .pkey_size = hmac_size,
162
163 .pkey_free = hmac_key_free,
164 .pkey_ctrl = hmac_pkey_ctrl,
165#ifdef HMAC_TEST_PRIVATE_KEY_FORMAT
166 .old_priv_decode = old_hmac_decode,
167 .old_priv_encode = old_hmac_encode
168#endif
169};
diff --git a/src/lib/libcrypto/hmac/hm_pmeth.c b/src/lib/libcrypto/hmac/hm_pmeth.c
deleted file mode 100644
index c5ac6c00c0..0000000000
--- a/src/lib/libcrypto/hmac/hm_pmeth.c
+++ /dev/null
@@ -1,259 +0,0 @@
1/* $OpenBSD: hm_pmeth.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007.
4 */
5/* ====================================================================
6 * Copyright (c) 2007 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61
62#include <openssl/evp.h>
63#include <openssl/hmac.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67#include "evp_locl.h"
68
69/* HMAC pkey context structure */
70
71typedef struct {
72 const EVP_MD *md; /* MD for HMAC use */
73 ASN1_OCTET_STRING ktmp; /* Temp storage for key */
74 HMAC_CTX ctx;
75} HMAC_PKEY_CTX;
76
77static int
78pkey_hmac_init(EVP_PKEY_CTX *ctx)
79{
80 HMAC_PKEY_CTX *hctx;
81
82 hctx = malloc(sizeof(HMAC_PKEY_CTX));
83 if (!hctx)
84 return 0;
85 hctx->md = NULL;
86 hctx->ktmp.data = NULL;
87 hctx->ktmp.length = 0;
88 hctx->ktmp.flags = 0;
89 hctx->ktmp.type = V_ASN1_OCTET_STRING;
90 HMAC_CTX_init(&hctx->ctx);
91
92 ctx->data = hctx;
93 ctx->keygen_info_count = 0;
94
95 return 1;
96}
97
98static int
99pkey_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
100{
101 HMAC_PKEY_CTX *sctx, *dctx;
102
103 if (!pkey_hmac_init(dst))
104 return 0;
105 sctx = src->data;
106 dctx = dst->data;
107 dctx->md = sctx->md;
108 HMAC_CTX_init(&dctx->ctx);
109 if (!HMAC_CTX_copy(&dctx->ctx, &sctx->ctx))
110 return 0;
111 if (sctx->ktmp.data) {
112 if (!ASN1_OCTET_STRING_set(&dctx->ktmp, sctx->ktmp.data,
113 sctx->ktmp.length))
114 return 0;
115 }
116 return 1;
117}
118
119static void
120pkey_hmac_cleanup(EVP_PKEY_CTX *ctx)
121{
122 HMAC_PKEY_CTX *hctx = ctx->data;
123
124 HMAC_CTX_cleanup(&hctx->ctx);
125 if (hctx->ktmp.data) {
126 if (hctx->ktmp.length)
127 explicit_bzero(hctx->ktmp.data, hctx->ktmp.length);
128 free(hctx->ktmp.data);
129 hctx->ktmp.data = NULL;
130 }
131 free(hctx);
132}
133
134static int
135pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
136{
137 ASN1_OCTET_STRING *hkey = NULL;
138 HMAC_PKEY_CTX *hctx = ctx->data;
139
140 if (!hctx->ktmp.data)
141 return 0;
142 hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp);
143 if (!hkey)
144 return 0;
145 EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey);
146
147 return 1;
148}
149
150static int
151int_update(EVP_MD_CTX *ctx, const void *data, size_t count)
152{
153 HMAC_PKEY_CTX *hctx = ctx->pctx->data;
154
155 if (!HMAC_Update(&hctx->ctx, data, count))
156 return 0;
157 return 1;
158}
159
160static int
161hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
162{
163 HMAC_PKEY_CTX *hctx = ctx->data;
164
165 HMAC_CTX_set_flags(&hctx->ctx, mctx->flags & ~EVP_MD_CTX_FLAG_NO_INIT);
166 EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);
167 mctx->update = int_update;
168 return 1;
169}
170
171static int
172hmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
173 EVP_MD_CTX *mctx)
174{
175 unsigned int hlen;
176 HMAC_PKEY_CTX *hctx = ctx->data;
177 int l = EVP_MD_CTX_size(mctx);
178
179 if (l < 0)
180 return 0;
181 *siglen = l;
182 if (!sig)
183 return 1;
184
185 if (!HMAC_Final(&hctx->ctx, sig, &hlen))
186 return 0;
187 *siglen = (size_t)hlen;
188 return 1;
189}
190
191static int
192pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
193{
194 HMAC_PKEY_CTX *hctx = ctx->data;
195 ASN1_OCTET_STRING *key;
196
197 switch (type) {
198 case EVP_PKEY_CTRL_SET_MAC_KEY:
199 if ((!p2 && p1 > 0) || (p1 < -1))
200 return 0;
201 if (!ASN1_OCTET_STRING_set(&hctx->ktmp, p2, p1))
202 return 0;
203 break;
204
205 case EVP_PKEY_CTRL_MD:
206 hctx->md = p2;
207 break;
208
209 case EVP_PKEY_CTRL_DIGESTINIT:
210 key = (ASN1_OCTET_STRING *)ctx->pkey->pkey.ptr;
211 if (!HMAC_Init_ex(&hctx->ctx, key->data, key->length, hctx->md,
212 ctx->engine))
213 return 0;
214 break;
215
216 default:
217 return -2;
218 }
219 return 1;
220}
221
222static int
223pkey_hmac_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
224{
225 if (!value)
226 return 0;
227 if (!strcmp(type, "key")) {
228 void *p = (void *)value;
229 return pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, -1, p);
230 }
231 if (!strcmp(type, "hexkey")) {
232 unsigned char *key;
233 int r;
234 long keylen;
235 key = string_to_hex(value, &keylen);
236 if (!key)
237 return 0;
238 r = pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
239 free(key);
240 return r;
241 }
242 return -2;
243}
244
245const EVP_PKEY_METHOD hmac_pkey_meth = {
246 .pkey_id = EVP_PKEY_HMAC,
247
248 .init = pkey_hmac_init,
249 .copy = pkey_hmac_copy,
250 .cleanup = pkey_hmac_cleanup,
251
252 .keygen = pkey_hmac_keygen,
253
254 .signctx_init = hmac_signctx_init,
255 .signctx = hmac_signctx,
256
257 .ctrl = pkey_hmac_ctrl,
258 .ctrl_str = pkey_hmac_ctrl_str
259};
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
deleted file mode 100644
index 155e32a540..0000000000
--- a/src/lib/libcrypto/hmac/hmac.c
+++ /dev/null
@@ -1,225 +0,0 @@
1/* $OpenBSD: hmac.c,v 1.22 2015/02/10 09:52:35 miod Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
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
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
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.
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
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:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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
51 * SUCH DAMAGE.
52 *
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
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63#include <openssl/err.h>
64#include <openssl/hmac.h>
65
66int
67HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md,
68 ENGINE *impl)
69{
70 int i, j, reset = 0;
71 unsigned char pad[HMAC_MAX_MD_CBLOCK];
72
73 if (md != NULL) {
74 reset = 1;
75 ctx->md = md;
76 } else
77 md = ctx->md;
78
79 if (key != NULL) {
80 reset = 1;
81 j = EVP_MD_block_size(md);
82 if ((size_t)j > sizeof(ctx->key)) {
83 EVPerr(EVP_F_HMAC_INIT_EX, EVP_R_BAD_BLOCK_LENGTH);
84 goto err;
85 }
86 if (j < len) {
87 if (!EVP_DigestInit_ex(&ctx->md_ctx, md, impl))
88 goto err;
89 if (!EVP_DigestUpdate(&ctx->md_ctx, key, len))
90 goto err;
91 if (!EVP_DigestFinal_ex(&(ctx->md_ctx), ctx->key,
92 &ctx->key_length))
93 goto err;
94 } else {
95 if ((size_t)len > sizeof(ctx->key)) {
96 EVPerr(EVP_F_HMAC_INIT_EX,
97 EVP_R_BAD_KEY_LENGTH);
98 goto err;
99 }
100 memcpy(ctx->key, key, len);
101 ctx->key_length = len;
102 }
103 if (ctx->key_length != HMAC_MAX_MD_CBLOCK)
104 memset(&ctx->key[ctx->key_length], 0,
105 HMAC_MAX_MD_CBLOCK - ctx->key_length);
106 }
107
108 if (reset) {
109 for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++)
110 pad[i] = 0x36 ^ ctx->key[i];
111 if (!EVP_DigestInit_ex(&ctx->i_ctx, md, impl))
112 goto err;
113 if (!EVP_DigestUpdate(&ctx->i_ctx, pad, EVP_MD_block_size(md)))
114 goto err;
115
116 for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++)
117 pad[i] = 0x5c ^ ctx->key[i];
118 if (!EVP_DigestInit_ex(&ctx->o_ctx, md, impl))
119 goto err;
120 if (!EVP_DigestUpdate(&ctx->o_ctx, pad, EVP_MD_block_size(md)))
121 goto err;
122 }
123 if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx, &ctx->i_ctx))
124 goto err;
125 return 1;
126err:
127 return 0;
128}
129
130int
131HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md)
132{
133 if (key && md)
134 HMAC_CTX_init(ctx);
135 return HMAC_Init_ex(ctx, key, len, md, NULL);
136}
137
138int
139HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len)
140{
141 return EVP_DigestUpdate(&ctx->md_ctx, data, len);
142}
143
144int
145HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
146{
147 unsigned int i;
148 unsigned char buf[EVP_MAX_MD_SIZE];
149
150 if (!EVP_DigestFinal_ex(&ctx->md_ctx, buf, &i))
151 goto err;
152 if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx, &ctx->o_ctx))
153 goto err;
154 if (!EVP_DigestUpdate(&ctx->md_ctx, buf, i))
155 goto err;
156 if (!EVP_DigestFinal_ex(&ctx->md_ctx, md, len))
157 goto err;
158 return 1;
159err:
160 return 0;
161}
162
163void
164HMAC_CTX_init(HMAC_CTX *ctx)
165{
166 EVP_MD_CTX_init(&ctx->i_ctx);
167 EVP_MD_CTX_init(&ctx->o_ctx);
168 EVP_MD_CTX_init(&ctx->md_ctx);
169}
170
171int
172HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)
173{
174 if (!EVP_MD_CTX_copy(&dctx->i_ctx, &sctx->i_ctx))
175 goto err;
176 if (!EVP_MD_CTX_copy(&dctx->o_ctx, &sctx->o_ctx))
177 goto err;
178 if (!EVP_MD_CTX_copy(&dctx->md_ctx, &sctx->md_ctx))
179 goto err;
180 memcpy(dctx->key, sctx->key, HMAC_MAX_MD_CBLOCK);
181 dctx->key_length = sctx->key_length;
182 dctx->md = sctx->md;
183 return 1;
184err:
185 return 0;
186}
187
188void
189HMAC_CTX_cleanup(HMAC_CTX *ctx)
190{
191 EVP_MD_CTX_cleanup(&ctx->i_ctx);
192 EVP_MD_CTX_cleanup(&ctx->o_ctx);
193 EVP_MD_CTX_cleanup(&ctx->md_ctx);
194 memset(ctx, 0, sizeof *ctx);
195}
196
197unsigned char *
198HMAC(const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d,
199 size_t n, unsigned char *md, unsigned int *md_len)
200{
201 HMAC_CTX c;
202 static unsigned char m[EVP_MAX_MD_SIZE];
203
204 if (md == NULL)
205 md = m;
206 HMAC_CTX_init(&c);
207 if (!HMAC_Init(&c, key, key_len, evp_md))
208 goto err;
209 if (!HMAC_Update(&c, d, n))
210 goto err;
211 if (!HMAC_Final(&c, md, md_len))
212 goto err;
213 HMAC_CTX_cleanup(&c);
214 return md;
215err:
216 return NULL;
217}
218
219void
220HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
221{
222 EVP_MD_CTX_set_flags(&ctx->i_ctx, flags);
223 EVP_MD_CTX_set_flags(&ctx->o_ctx, flags);
224 EVP_MD_CTX_set_flags(&ctx->md_ctx, flags);
225}
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
deleted file mode 100644
index f3418b3cb7..0000000000
--- a/src/lib/libcrypto/hmac/hmac.h
+++ /dev/null
@@ -1,108 +0,0 @@
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)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
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
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
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.
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
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:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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
51 * SUCH DAMAGE.
52 *
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
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#ifndef HEADER_HMAC_H
59#define HEADER_HMAC_H
60
61#include <openssl/opensslconf.h>
62
63#ifdef OPENSSL_NO_HMAC
64#error HMAC is disabled.
65#endif
66
67#include <openssl/evp.h>
68
69#define HMAC_MAX_MD_CBLOCK 128 /* largest known is SHA512 */
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75typedef struct hmac_ctx_st {
76 const EVP_MD *md;
77 EVP_MD_CTX md_ctx;
78 EVP_MD_CTX i_ctx;
79 EVP_MD_CTX o_ctx;
80 unsigned int key_length;
81 unsigned char key[HMAC_MAX_MD_CBLOCK];
82} HMAC_CTX;
83
84#define HMAC_size(e) (EVP_MD_size((e)->md))
85
86
87void HMAC_CTX_init(HMAC_CTX *ctx);
88void HMAC_CTX_cleanup(HMAC_CTX *ctx);
89
90#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */
91
92int HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
93 const EVP_MD *md); /* deprecated */
94int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md,
95 ENGINE *impl);
96int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
97int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
98unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
99 const unsigned char *d, size_t n, unsigned char *md, unsigned int *md_len);
100int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
101
102void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif