summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2017-02-28 14:15:37 +0000
committerjsing <>2017-02-28 14:15:37 +0000
commitca28e541c86936857a23a70090980a8bb952e842 (patch)
tree2539caf54ac751f30ddb7c36d52b988a41e9b202 /src/lib
parent38da1a984b117a519fe2a498ead2bd71e9597591 (diff)
downloadopenbsd-ca28e541c86936857a23a70090980a8bb952e842.tar.gz
openbsd-ca28e541c86936857a23a70090980a8bb952e842.tar.bz2
openbsd-ca28e541c86936857a23a70090980a8bb952e842.zip
Add an EVP interface that provides concatenated MD5+SHA1 hashes, which are
used in various parts of TLS 1.0/1.1. This will allow for code simplification in libssl. The same interface exists in OpenSSL 1.1. ok beck@ deraadt@ inoguchi@ millert@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/Makefile3
-rw-r--r--src/lib/libcrypto/Symbols.list1
-rw-r--r--src/lib/libcrypto/evp/evp.h3
-rw-r--r--src/lib/libcrypto/evp/m_md5_sha1.c83
4 files changed, 88 insertions, 2 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile
index 3fb904b470..9ab1e0349d 100644
--- a/src/lib/libcrypto/Makefile
+++ b/src/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.14 2017/01/21 09:38:58 beck Exp $ 1# $OpenBSD: Makefile,v 1.15 2017/02/28 14:15:37 jsing Exp $
2 2
3LIB= crypto 3LIB= crypto
4 4
@@ -158,6 +158,7 @@ SRCS+= e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c
158SRCS+= e_aes_cbc_hmac_sha1.c e_rc4_hmac_md5.c 158SRCS+= e_aes_cbc_hmac_sha1.c e_rc4_hmac_md5.c
159SRCS+= e_chacha.c evp_aead.c e_chacha20poly1305.c 159SRCS+= e_chacha.c evp_aead.c e_chacha20poly1305.c
160SRCS+= e_gost2814789.c m_gost2814789.c m_gostr341194.c m_streebog.c 160SRCS+= e_gost2814789.c m_gost2814789.c m_gostr341194.c m_streebog.c
161SRCS+= m_md5_sha1.c
161 162
162# gost/ 163# gost/
163SRCS+= gost2814789.c gost89_keywrap.c gost89_params.c gost89imit_ameth.c 164SRCS+= gost2814789.c gost89_keywrap.c gost89_params.c gost89imit_ameth.c
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index ae14b1a607..16dd18f920 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -1505,6 +1505,7 @@ EVP_idea_ecb
1505EVP_idea_ofb 1505EVP_idea_ofb
1506EVP_md4 1506EVP_md4
1507EVP_md5 1507EVP_md5
1508EVP_md5_sha1
1508EVP_md_null 1509EVP_md_null
1509EVP_rc2_40_cbc 1510EVP_rc2_40_cbc
1510EVP_rc2_64_cbc 1511EVP_rc2_64_cbc
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index 75798dae8c..68e1049587 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp.h,v 1.51 2016/05/30 13:42:54 beck Exp $ */ 1/* $OpenBSD: evp.h,v 1.52 2017/02/28 14:15:37 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 *
@@ -659,6 +659,7 @@ const EVP_MD *EVP_md4(void);
659#endif 659#endif
660#ifndef OPENSSL_NO_MD5 660#ifndef OPENSSL_NO_MD5
661const EVP_MD *EVP_md5(void); 661const EVP_MD *EVP_md5(void);
662const EVP_MD *EVP_md5_sha1(void);
662#endif 663#endif
663#ifndef OPENSSL_NO_SHA 664#ifndef OPENSSL_NO_SHA
664const EVP_MD *EVP_sha1(void); 665const EVP_MD *EVP_sha1(void);
diff --git a/src/lib/libcrypto/evp/m_md5_sha1.c b/src/lib/libcrypto/evp/m_md5_sha1.c
new file mode 100644
index 0000000000..272cdee9dd
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md5_sha1.c
@@ -0,0 +1,83 @@
1/* $OpenBSD: m_md5_sha1.c,v 1.1 2017/02/28 14:15:37 jsing Exp $ */
2/*
3 * Copyright (c) 2017 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <openssl/evp.h>
19#include <openssl/md5.h>
20#include <openssl/objects.h>
21#include <openssl/sha.h>
22
23struct md5_sha1_ctx {
24 MD5_CTX md5;
25 SHA_CTX sha1;
26};
27
28static int
29md5_sha1_init(EVP_MD_CTX *ctx)
30{
31 struct md5_sha1_ctx *mdctx = ctx->md_data;
32
33 if (!MD5_Init(&mdctx->md5))
34 return 0;
35 if (!SHA1_Init(&mdctx->sha1))
36 return 0;
37
38 return 1;
39}
40
41static int
42md5_sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count)
43{
44 struct md5_sha1_ctx *mdctx = ctx->md_data;
45
46 if (!MD5_Update(&mdctx->md5, data, count))
47 return 0;
48 if (!SHA1_Update(&mdctx->sha1, data, count))
49 return 0;
50
51 return 1;
52}
53
54static int
55md5_sha1_final(EVP_MD_CTX *ctx, unsigned char *out)
56{
57 struct md5_sha1_ctx *mdctx = ctx->md_data;
58
59 if (!MD5_Final(out, &mdctx->md5))
60 return 0;
61 if (!SHA1_Final(out + MD5_DIGEST_LENGTH, &mdctx->sha1))
62 return 0;
63
64 return 1;
65}
66
67static const EVP_MD md5_sha1_md = {
68 .type = NID_md5_sha1,
69 .pkey_type = NID_md5_sha1,
70 .md_size = MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH,
71 .flags = 0,
72 .init = md5_sha1_init,
73 .update = md5_sha1_update,
74 .final = md5_sha1_final,
75 .block_size = MD5_CBLOCK, /* MD5_CBLOCK == SHA_CBLOCK */
76 .ctx_size = sizeof(EVP_MD *) + sizeof(struct md5_sha1_ctx),
77};
78
79const EVP_MD *
80EVP_md5_sha1(void)
81{
82 return &md5_sha1_md;
83}