diff options
author | jsing <> | 2017-03-05 14:39:53 +0000 |
---|---|---|
committer | jsing <> | 2017-03-05 14:39:53 +0000 |
commit | e04ca894aa08b4b01dbc7ead7524d8026ce8f3be (patch) | |
tree | 4868a41992758cf1a7f9ffdaf1b940ee7bcceb4c /src/lib/libssl/t1_hash.c | |
parent | b7e97f3829f43765f12691c1665b5e6017d75d28 (diff) | |
download | openbsd-e04ca894aa08b4b01dbc7ead7524d8026ce8f3be.tar.gz openbsd-e04ca894aa08b4b01dbc7ead7524d8026ce8f3be.tar.bz2 openbsd-e04ca894aa08b4b01dbc7ead7524d8026ce8f3be.zip |
Provide a rolling handshake hash that commences as soon as the cipher
suite has been selected, and convert the final finish MAC to use this
handshake hash.
This is a first step towards cleaning up the current handshake
buffer/digest code.
ok beck@ inoguchi@
Diffstat (limited to 'src/lib/libssl/t1_hash.c')
-rw-r--r-- | src/lib/libssl/t1_hash.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/lib/libssl/t1_hash.c b/src/lib/libssl/t1_hash.c new file mode 100644 index 0000000000..94410e4127 --- /dev/null +++ b/src/lib/libssl/t1_hash.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "ssl_locl.h" | ||
18 | |||
19 | #include <openssl/ssl.h> | ||
20 | |||
21 | int | ||
22 | tls1_handshake_hash_init(SSL *s) | ||
23 | { | ||
24 | const EVP_MD *md; | ||
25 | long dlen; | ||
26 | void *data; | ||
27 | |||
28 | tls1_handshake_hash_free(s); | ||
29 | |||
30 | if (!ssl_get_handshake_evp_md(s, &md)) { | ||
31 | SSLerrorx(ERR_R_INTERNAL_ERROR); | ||
32 | goto err; | ||
33 | } | ||
34 | |||
35 | if ((S3I(s)->handshake_hash = EVP_MD_CTX_create()) == NULL) { | ||
36 | SSLerror(s, ERR_R_MALLOC_FAILURE); | ||
37 | goto err; | ||
38 | } | ||
39 | if (!EVP_DigestInit_ex(S3I(s)->handshake_hash, md, NULL)) { | ||
40 | SSLerror(s, ERR_R_EVP_LIB); | ||
41 | goto err; | ||
42 | } | ||
43 | |||
44 | dlen = BIO_get_mem_data(S3I(s)->handshake_buffer, &data); | ||
45 | if (dlen <= 0) { | ||
46 | SSLerror(s, SSL_R_BAD_HANDSHAKE_LENGTH); | ||
47 | goto err; | ||
48 | } | ||
49 | if (!tls1_handshake_hash_update(s, data, dlen)) { | ||
50 | SSLerror(s, ERR_R_EVP_LIB); | ||
51 | goto err; | ||
52 | } | ||
53 | |||
54 | return 1; | ||
55 | |||
56 | err: | ||
57 | tls1_handshake_hash_free(s); | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | int | ||
63 | tls1_handshake_hash_update(SSL *s, const unsigned char *buf, size_t len) | ||
64 | { | ||
65 | if (S3I(s)->handshake_hash == NULL) | ||
66 | return 1; | ||
67 | |||
68 | return EVP_DigestUpdate(S3I(s)->handshake_hash, buf, len); | ||
69 | } | ||
70 | |||
71 | int | ||
72 | tls1_handshake_hash_value(SSL *s, const unsigned char *out, size_t len, | ||
73 | size_t *outlen) | ||
74 | { | ||
75 | EVP_MD_CTX *mdctx = NULL; | ||
76 | unsigned int mdlen; | ||
77 | int ret = 0; | ||
78 | |||
79 | if (EVP_MD_CTX_size(S3I(s)->handshake_hash) > len) | ||
80 | goto err; | ||
81 | |||
82 | if ((mdctx = EVP_MD_CTX_create()) == NULL) { | ||
83 | SSLerror(s, ERR_R_MALLOC_FAILURE); | ||
84 | goto err; | ||
85 | } | ||
86 | if (!EVP_MD_CTX_copy_ex(mdctx, S3I(s)->handshake_hash)) { | ||
87 | SSLerror(s, ERR_R_EVP_LIB); | ||
88 | goto err; | ||
89 | } | ||
90 | if (!EVP_DigestFinal_ex(mdctx, (unsigned char *)out, &mdlen)) { | ||
91 | SSLerror(s, ERR_R_EVP_LIB); | ||
92 | goto err; | ||
93 | } | ||
94 | if (outlen != NULL) | ||
95 | *outlen = mdlen; | ||
96 | |||
97 | ret = 1; | ||
98 | |||
99 | err: | ||
100 | EVP_MD_CTX_destroy(mdctx); | ||
101 | |||
102 | return (ret); | ||
103 | } | ||
104 | |||
105 | void | ||
106 | tls1_handshake_hash_free(SSL *s) | ||
107 | { | ||
108 | EVP_MD_CTX_destroy(S3I(s)->handshake_hash); | ||
109 | S3I(s)->handshake_hash = NULL; | ||
110 | } | ||