Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/t1_enc.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: t1_enc.c,v 1.114 2018/09/08 14:39:41 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 | /* ==================================================================== | - | ||||||||||||||||||
59 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. | - | ||||||||||||||||||
60 | * | - | ||||||||||||||||||
61 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||
62 | * modification, are permitted provided that the following conditions | - | ||||||||||||||||||
63 | * are met: | - | ||||||||||||||||||
64 | * | - | ||||||||||||||||||
65 | * 1. Redistributions of source code must retain the above copyright | - | ||||||||||||||||||
66 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||||||||
67 | * | - | ||||||||||||||||||
68 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||
69 | * notice, this list of conditions and the following disclaimer in | - | ||||||||||||||||||
70 | * the documentation and/or other materials provided with the | - | ||||||||||||||||||
71 | * distribution. | - | ||||||||||||||||||
72 | * | - | ||||||||||||||||||
73 | * 3. All advertising materials mentioning features or use of this | - | ||||||||||||||||||
74 | * software must display the following acknowledgment: | - | ||||||||||||||||||
75 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||||||||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | - | ||||||||||||||||||
77 | * | - | ||||||||||||||||||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | - | ||||||||||||||||||
79 | * endorse or promote products derived from this software without | - | ||||||||||||||||||
80 | * prior written permission. For written permission, please contact | - | ||||||||||||||||||
81 | * openssl-core@openssl.org. | - | ||||||||||||||||||
82 | * | - | ||||||||||||||||||
83 | * 5. Products derived from this software may not be called "OpenSSL" | - | ||||||||||||||||||
84 | * nor may "OpenSSL" appear in their names without prior written | - | ||||||||||||||||||
85 | * permission of the OpenSSL Project. | - | ||||||||||||||||||
86 | * | - | ||||||||||||||||||
87 | * 6. Redistributions of any form whatsoever must retain the following | - | ||||||||||||||||||
88 | * acknowledgment: | - | ||||||||||||||||||
89 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||||||||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | - | ||||||||||||||||||
91 | * | - | ||||||||||||||||||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | - | ||||||||||||||||||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||||||||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||||||||||||||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | - | ||||||||||||||||||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - | ||||||||||||||||||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | - | ||||||||||||||||||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||||||||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||||||||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | - | ||||||||||||||||||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||||||||||||||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | - | ||||||||||||||||||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||||||||
104 | * ==================================================================== | - | ||||||||||||||||||
105 | * | - | ||||||||||||||||||
106 | * This product includes cryptographic software written by Eric Young | - | ||||||||||||||||||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | - | ||||||||||||||||||
108 | * Hudson (tjh@cryptsoft.com). | - | ||||||||||||||||||
109 | * | - | ||||||||||||||||||
110 | */ | - | ||||||||||||||||||
111 | /* ==================================================================== | - | ||||||||||||||||||
112 | * Copyright 2005 Nokia. All rights reserved. | - | ||||||||||||||||||
113 | * | - | ||||||||||||||||||
114 | * The portions of the attached software ("Contribution") is developed by | - | ||||||||||||||||||
115 | * Nokia Corporation and is licensed pursuant to the OpenSSL open source | - | ||||||||||||||||||
116 | * license. | - | ||||||||||||||||||
117 | * | - | ||||||||||||||||||
118 | * The Contribution, originally written by Mika Kousa and Pasi Eronen of | - | ||||||||||||||||||
119 | * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites | - | ||||||||||||||||||
120 | * support (see RFC 4279) to OpenSSL. | - | ||||||||||||||||||
121 | * | - | ||||||||||||||||||
122 | * No patent licenses or other rights except those expressly stated in | - | ||||||||||||||||||
123 | * the OpenSSL open source license shall be deemed granted or received | - | ||||||||||||||||||
124 | * expressly, by implication, estoppel, or otherwise. | - | ||||||||||||||||||
125 | * | - | ||||||||||||||||||
126 | * No assurances are provided by Nokia that the Contribution does not | - | ||||||||||||||||||
127 | * infringe the patent or other intellectual property rights of any third | - | ||||||||||||||||||
128 | * party or that the license provides you with all the necessary rights | - | ||||||||||||||||||
129 | * to make use of the Contribution. | - | ||||||||||||||||||
130 | * | - | ||||||||||||||||||
131 | * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN | - | ||||||||||||||||||
132 | * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA | - | ||||||||||||||||||
133 | * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY | - | ||||||||||||||||||
134 | * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR | - | ||||||||||||||||||
135 | * OTHERWISE. | - | ||||||||||||||||||
136 | */ | - | ||||||||||||||||||
137 | - | |||||||||||||||||||
138 | #include <limits.h> | - | ||||||||||||||||||
139 | #include <stdio.h> | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | #include "ssl_locl.h" | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | #include <openssl/evp.h> | - | ||||||||||||||||||
144 | #include <openssl/hmac.h> | - | ||||||||||||||||||
145 | #include <openssl/md5.h> | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | int tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len, | - | ||||||||||||||||||
148 | const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len, | - | ||||||||||||||||||
149 | const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len, | - | ||||||||||||||||||
150 | const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len); | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | void | - | ||||||||||||||||||
153 | tls1_cleanup_key_block(SSL *s) | - | ||||||||||||||||||
154 | { | - | ||||||||||||||||||
155 | freezero(S3I(s)->hs.key_block, S3I(s)->hs.key_block_len); | - | ||||||||||||||||||
156 | S3I(s)->hs.key_block = NULL; | - | ||||||||||||||||||
157 | S3I(s)->hs.key_block_len = 0; | - | ||||||||||||||||||
158 | } executed 1192 times by 11 tests: end of block Executed by:
| 1192 | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | int | - | ||||||||||||||||||
161 | tls1_init_finished_mac(SSL *s) | - | ||||||||||||||||||
162 | { | - | ||||||||||||||||||
163 | BIO_free(S3I(s)->handshake_buffer); | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | S3I(s)->handshake_buffer = BIO_new(BIO_s_mem()); | - | ||||||||||||||||||
166 | if (S3I(s)->handshake_buffer == NULL)
| 0-139 | ||||||||||||||||||
167 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | (void)BIO_set_close(S3I(s)->handshake_buffer, BIO_CLOSE); | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | return (1); executed 139 times by 4 tests: return (1); Executed by:
| 139 | ||||||||||||||||||
172 | } | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | int | - | ||||||||||||||||||
175 | tls1_finish_mac(SSL *s, const unsigned char *buf, int len) | - | ||||||||||||||||||
176 | { | - | ||||||||||||||||||
177 | if (len < 0)
| 0-1152 | ||||||||||||||||||
178 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | if (!tls1_handshake_hash_update(s, buf, len))
| 0-1152 | ||||||||||||||||||
181 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | if (S3I(s)->handshake_buffer &&
| 352-800 | ||||||||||||||||||
184 | !(s->s3->flags & TLS1_FLAGS_KEEP_HANDSHAKE)) {
| 5-347 | ||||||||||||||||||
185 | BIO_write(S3I(s)->handshake_buffer, (void *)buf, len); | - | ||||||||||||||||||
186 | return 1; executed 347 times by 4 tests: return 1; Executed by:
| 347 | ||||||||||||||||||
187 | } | - | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | return 1; executed 805 times by 3 tests: return 1; Executed by:
| 805 | ||||||||||||||||||
190 | } | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | int | - | ||||||||||||||||||
193 | tls1_digest_cached_records(SSL *s) | - | ||||||||||||||||||
194 | { | - | ||||||||||||||||||
195 | long hdatalen; | - | ||||||||||||||||||
196 | void *hdata; | - | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | hdatalen = BIO_get_mem_data(S3I(s)->handshake_buffer, &hdata); | - | ||||||||||||||||||
199 | if (hdatalen <= 0) {
| 0-128 | ||||||||||||||||||
200 | SSLerror(s, SSL_R_BAD_HANDSHAKE_LENGTH); | - | ||||||||||||||||||
201 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
202 | } | - | ||||||||||||||||||
203 | - | |||||||||||||||||||
204 | if (!(s->s3->flags & TLS1_FLAGS_KEEP_HANDSHAKE)) {
| 5-123 | ||||||||||||||||||
205 | BIO_free(S3I(s)->handshake_buffer); | - | ||||||||||||||||||
206 | S3I(s)->handshake_buffer = NULL; | - | ||||||||||||||||||
207 | } executed 123 times by 3 tests: end of block Executed by:
| 123 | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | return 1; executed 128 times by 3 tests: return 1; Executed by:
| 128 | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | err: | - | ||||||||||||||||||
212 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
213 | } | - | ||||||||||||||||||
214 | - | |||||||||||||||||||
215 | void | - | ||||||||||||||||||
216 | tls1_record_sequence_increment(unsigned char *seq) | - | ||||||||||||||||||
217 | { | - | ||||||||||||||||||
218 | int i; | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | for (i = SSL3_SEQUENCE_SIZE - 1; i >= 0; i--) {
| 0-752 | ||||||||||||||||||
221 | if (++seq[i] != 0)
| 0-752 | ||||||||||||||||||
222 | break; executed 752 times by 3 tests: break; Executed by:
| 752 | ||||||||||||||||||
223 | } never executed: end of block | 0 | ||||||||||||||||||
224 | } executed 752 times by 3 tests: end of block Executed by:
| 752 | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | /* | - | ||||||||||||||||||
227 | * TLS P_hash() data expansion function - see RFC 5246, section 5. | - | ||||||||||||||||||
228 | */ | - | ||||||||||||||||||
229 | static int | - | ||||||||||||||||||
230 | tls1_P_hash(const EVP_MD *md, const unsigned char *secret, size_t secret_len, | - | ||||||||||||||||||
231 | const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len, | - | ||||||||||||||||||
232 | const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len, | - | ||||||||||||||||||
233 | const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len) | - | ||||||||||||||||||
234 | { | - | ||||||||||||||||||
235 | unsigned char A1[EVP_MAX_MD_SIZE], hmac[EVP_MAX_MD_SIZE]; | - | ||||||||||||||||||
236 | size_t A1_len, hmac_len; | - | ||||||||||||||||||
237 | EVP_MD_CTX ctx; | - | ||||||||||||||||||
238 | EVP_PKEY *mac_key; | - | ||||||||||||||||||
239 | int ret = 0; | - | ||||||||||||||||||
240 | int chunk; | - | ||||||||||||||||||
241 | size_t i; | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | chunk = EVP_MD_size(md); | - | ||||||||||||||||||
244 | OPENSSL_assert(chunk >= 0); | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | EVP_MD_CTX_init(&ctx); | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, secret, secret_len); | - | ||||||||||||||||||
249 | if (!mac_key)
| 0-1644 | ||||||||||||||||||
250 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
251 | if (!EVP_DigestSignInit(&ctx, NULL, md, NULL, mac_key))
| 0-1644 | ||||||||||||||||||
252 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
253 | if (seed1 && !EVP_DigestSignUpdate(&ctx, seed1, seed1_len))
| 0-1644 | ||||||||||||||||||
254 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
255 | if (seed2 && !EVP_DigestSignUpdate(&ctx, seed2, seed2_len))
| 0-1644 | ||||||||||||||||||
256 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
257 | if (seed3 && !EVP_DigestSignUpdate(&ctx, seed3, seed3_len))
| 0-952 | ||||||||||||||||||
258 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
259 | if (seed4 && !EVP_DigestSignUpdate(&ctx, seed4, seed4_len))
| 0-952 | ||||||||||||||||||
260 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
261 | if (seed5 && !EVP_DigestSignUpdate(&ctx, seed5, seed5_len))
| 0-876 | ||||||||||||||||||
262 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
263 | if (!EVP_DigestSignFinal(&ctx, A1, &A1_len))
| 0-1644 | ||||||||||||||||||
264 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
265 | - | |||||||||||||||||||
266 | for (;;) { | - | ||||||||||||||||||
267 | if (!EVP_DigestSignInit(&ctx, NULL, md, NULL, mac_key))
| 0-4318 | ||||||||||||||||||
268 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
269 | if (!EVP_DigestSignUpdate(&ctx, A1, A1_len))
| 0-4318 | ||||||||||||||||||
270 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
271 | if (seed1 && !EVP_DigestSignUpdate(&ctx, seed1, seed1_len))
| 0-4318 | ||||||||||||||||||
272 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
273 | if (seed2 && !EVP_DigestSignUpdate(&ctx, seed2, seed2_len))
| 0-4318 | ||||||||||||||||||
274 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
275 | if (seed3 && !EVP_DigestSignUpdate(&ctx, seed3, seed3_len))
| 0-3334 | ||||||||||||||||||
276 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
277 | if (seed4 && !EVP_DigestSignUpdate(&ctx, seed4, seed4_len))
| 0-2728 | ||||||||||||||||||
278 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
279 | if (seed5 && !EVP_DigestSignUpdate(&ctx, seed5, seed5_len))
| 0-2252 | ||||||||||||||||||
280 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
281 | if (!EVP_DigestSignFinal(&ctx, hmac, &hmac_len))
| 0-4318 | ||||||||||||||||||
282 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
283 | - | |||||||||||||||||||
284 | if (hmac_len > out_len)
| 1524-2794 | ||||||||||||||||||
285 | hmac_len = out_len; executed 1524 times by 3 tests: hmac_len = out_len; Executed by:
| 1524 | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | for (i = 0; i < hmac_len; i++)
| 4318-85792 | ||||||||||||||||||
288 | out[i] ^= hmac[i]; executed 85792 times by 3 tests: out[i] ^= hmac[i]; Executed by:
| 85792 | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | out += hmac_len; | - | ||||||||||||||||||
291 | out_len -= hmac_len; | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | if (out_len == 0)
| 1644-2674 | ||||||||||||||||||
294 | break; executed 1644 times by 3 tests: break; Executed by:
| 1644 | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | if (!EVP_DigestSignInit(&ctx, NULL, md, NULL, mac_key))
| 0-2674 | ||||||||||||||||||
297 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
298 | if (!EVP_DigestSignUpdate(&ctx, A1, A1_len))
| 0-2674 | ||||||||||||||||||
299 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
300 | if (!EVP_DigestSignFinal(&ctx, A1, &A1_len))
| 0-2674 | ||||||||||||||||||
301 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
302 | } executed 2674 times by 3 tests: end of block Executed by:
| 2674 | ||||||||||||||||||
303 | ret = 1; | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | err: code before this statement executed 1644 times by 3 tests: err: Executed by:
| 1644 | ||||||||||||||||||
306 | EVP_PKEY_free(mac_key); | - | ||||||||||||||||||
307 | EVP_MD_CTX_cleanup(&ctx); | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | explicit_bzero(A1, sizeof(A1)); | - | ||||||||||||||||||
310 | explicit_bzero(hmac, sizeof(hmac)); | - | ||||||||||||||||||
311 | - | |||||||||||||||||||
312 | return ret; executed 1644 times by 3 tests: return ret; Executed by:
| 1644 | ||||||||||||||||||
313 | } | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | int | - | ||||||||||||||||||
316 | tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len, | - | ||||||||||||||||||
317 | const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len, | - | ||||||||||||||||||
318 | const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len, | - | ||||||||||||||||||
319 | const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len) | - | ||||||||||||||||||
320 | { | - | ||||||||||||||||||
321 | const EVP_MD *md; | - | ||||||||||||||||||
322 | size_t half_len; | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | memset(out, 0, out_len); | - | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | if (!ssl_get_handshake_evp_md(s, &md))
| 0-1248 | ||||||||||||||||||
327 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | if (md->type == NID_md5_sha1) {
| 396-852 | ||||||||||||||||||
330 | /* | - | ||||||||||||||||||
331 | * Partition secret between MD5 and SHA1, then XOR result. | - | ||||||||||||||||||
332 | * If the secret length is odd, a one byte overlap is used. | - | ||||||||||||||||||
333 | */ | - | ||||||||||||||||||
334 | half_len = secret_len - (secret_len / 2); | - | ||||||||||||||||||
335 | if (!tls1_P_hash(EVP_md5(), secret, half_len, seed1, seed1_len,
| 0-396 | ||||||||||||||||||
336 | seed2, seed2_len, seed3, seed3_len, seed4, seed4_len,
| 0-396 | ||||||||||||||||||
337 | seed5, seed5_len, out, out_len))
| 0-396 | ||||||||||||||||||
338 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | secret += secret_len - half_len; | - | ||||||||||||||||||
341 | if (!tls1_P_hash(EVP_sha1(), secret, half_len, seed1, seed1_len,
| 0-396 | ||||||||||||||||||
342 | seed2, seed2_len, seed3, seed3_len, seed4, seed4_len,
| 0-396 | ||||||||||||||||||
343 | seed5, seed5_len, out, out_len))
| 0-396 | ||||||||||||||||||
344 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | return (1); executed 396 times by 2 tests: return (1); Executed by:
| 396 | ||||||||||||||||||
347 | } | - | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | if (!tls1_P_hash(md, secret, secret_len, seed1, seed1_len,
| 0-852 | ||||||||||||||||||
350 | seed2, seed2_len, seed3, seed3_len, seed4, seed4_len,
| 0-852 | ||||||||||||||||||
351 | seed5, seed5_len, out, out_len))
| 0-852 | ||||||||||||||||||
352 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | return (1); executed 852 times by 3 tests: return (1); Executed by:
| 852 | ||||||||||||||||||
355 | } | - | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | static int | - | ||||||||||||||||||
358 | tls1_generate_key_block(SSL *s, unsigned char *km, int num) | - | ||||||||||||||||||
359 | { | - | ||||||||||||||||||
360 | if (num < 0)
| 0-126 | ||||||||||||||||||
361 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | return tls1_PRF(s, executed 126 times by 2 tests: return tls1_PRF(s, s->session->master_key, s->session->master_key_length, "key expansion", 13, s->s3->server_random, 32, s->s3->client_random, 32, ((void *)0) , 0, ((void *)0) , 0, km, num); Executed by:
| 126 | ||||||||||||||||||
364 | s->session->master_key, s->session->master_key_length, executed 126 times by 2 tests: return tls1_PRF(s, s->session->master_key, s->session->master_key_length, "key expansion", 13, s->s3->server_random, 32, s->s3->client_random, 32, ((void *)0) , 0, ((void *)0) , 0, km, num); Executed by:
| 126 | ||||||||||||||||||
365 | TLS_MD_KEY_EXPANSION_CONST, TLS_MD_KEY_EXPANSION_CONST_SIZE, executed 126 times by 2 tests: return tls1_PRF(s, s->session->master_key, s->session->master_key_length, "key expansion", 13, s->s3->server_random, 32, s->s3->client_random, 32, ((void *)0) , 0, ((void *)0) , 0, km, num); Executed by:
| 126 | ||||||||||||||||||
366 | s->s3->server_random, SSL3_RANDOM_SIZE, executed 126 times by 2 tests: return tls1_PRF(s, s->session->master_key, s->session->master_key_length, "key expansion", 13, s->s3->server_random, 32, s->s3->client_random, 32, ((void *)0) , 0, ((void *)0) , 0, km, num); Executed by:
| 126 | ||||||||||||||||||
367 | s->s3->client_random, SSL3_RANDOM_SIZE, executed 126 times by 2 tests: return tls1_PRF(s, s->session->master_key, s->session->master_key_length, "key expansion", 13, s->s3->server_random, 32, s->s3->client_random, 32, ((void *)0) , 0, ((void *)0) , 0, km, num); Executed by:
| 126 | ||||||||||||||||||
368 | NULL, 0, NULL, 0, km, num); executed 126 times by 2 tests: return tls1_PRF(s, s->session->master_key, s->session->master_key_length, "key expansion", 13, s->s3->server_random, 32, s->s3->client_random, 32, ((void *)0) , 0, ((void *)0) , 0, km, num); Executed by:
| 126 | ||||||||||||||||||
369 | } | - | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | /* | - | ||||||||||||||||||
372 | * tls1_aead_ctx_init allocates aead_ctx, if needed. It returns 1 on success | - | ||||||||||||||||||
373 | * and 0 on failure. | - | ||||||||||||||||||
374 | */ | - | ||||||||||||||||||
375 | static int | - | ||||||||||||||||||
376 | tls1_aead_ctx_init(SSL_AEAD_CTX **aead_ctx) | - | ||||||||||||||||||
377 | { | - | ||||||||||||||||||
378 | if (*aead_ctx != NULL) {
| 0-92 | ||||||||||||||||||
379 | EVP_AEAD_CTX_cleanup(&(*aead_ctx)->ctx); | - | ||||||||||||||||||
380 | return (1); never executed: return (1); | 0 | ||||||||||||||||||
381 | } | - | ||||||||||||||||||
382 | - | |||||||||||||||||||
383 | *aead_ctx = malloc(sizeof(SSL_AEAD_CTX)); | - | ||||||||||||||||||
384 | if (*aead_ctx == NULL) {
| 0-92 | ||||||||||||||||||
385 | SSLerrorx(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
386 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
387 | } | - | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | return (1); executed 92 times by 2 tests: return (1); Executed by:
| 92 | ||||||||||||||||||
390 | } | - | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | static int | - | ||||||||||||||||||
393 | tls1_change_cipher_state_aead(SSL *s, char is_read, const unsigned char *key, | - | ||||||||||||||||||
394 | unsigned key_len, const unsigned char *iv, unsigned iv_len) | - | ||||||||||||||||||
395 | { | - | ||||||||||||||||||
396 | const EVP_AEAD *aead = S3I(s)->tmp.new_aead; | - | ||||||||||||||||||
397 | SSL_AEAD_CTX *aead_ctx; | - | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | if (is_read) {
| 46 | ||||||||||||||||||
400 | ssl_clear_cipher_read_state(s); | - | ||||||||||||||||||
401 | if (!tls1_aead_ctx_init(&s->internal->aead_read_ctx))
| 0-46 | ||||||||||||||||||
402 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
403 | aead_ctx = s->internal->aead_read_ctx; | - | ||||||||||||||||||
404 | } else { executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
405 | /* XXX - Need to correctly handle DTLS. */ | - | ||||||||||||||||||
406 | ssl_clear_cipher_write_state(s); | - | ||||||||||||||||||
407 | if (!tls1_aead_ctx_init(&s->internal->aead_write_ctx))
| 0-46 | ||||||||||||||||||
408 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
409 | aead_ctx = s->internal->aead_write_ctx; | - | ||||||||||||||||||
410 | } executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | if (!EVP_AEAD_CTX_init(&aead_ctx->ctx, aead, key, key_len,
| 0-92 | ||||||||||||||||||
413 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL))
| 0-92 | ||||||||||||||||||
414 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
415 | if (iv_len > sizeof(aead_ctx->fixed_nonce)) {
| 0-92 | ||||||||||||||||||
416 | SSLerrorx(ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
417 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
418 | } | - | ||||||||||||||||||
419 | memcpy(aead_ctx->fixed_nonce, iv, iv_len); | - | ||||||||||||||||||
420 | aead_ctx->fixed_nonce_len = iv_len; | - | ||||||||||||||||||
421 | aead_ctx->variable_nonce_len = 8; /* always the case, currently. */ | - | ||||||||||||||||||
422 | aead_ctx->variable_nonce_in_record = | - | ||||||||||||||||||
423 | (S3I(s)->hs.new_cipher->algorithm2 & | - | ||||||||||||||||||
424 | SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD) != 0; | - | ||||||||||||||||||
425 | aead_ctx->xor_fixed_nonce = | - | ||||||||||||||||||
426 | S3I(s)->hs.new_cipher->algorithm_enc == SSL_CHACHA20POLY1305; | - | ||||||||||||||||||
427 | aead_ctx->tag_len = EVP_AEAD_max_overhead(aead); | - | ||||||||||||||||||
428 | - | |||||||||||||||||||
429 | if (aead_ctx->xor_fixed_nonce) {
| 24-68 | ||||||||||||||||||
430 | if (aead_ctx->fixed_nonce_len != EVP_AEAD_nonce_length(aead) ||
| 0-68 | ||||||||||||||||||
431 | aead_ctx->variable_nonce_len > EVP_AEAD_nonce_length(aead)) {
| 0-68 | ||||||||||||||||||
432 | SSLerrorx(ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
433 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
434 | } | - | ||||||||||||||||||
435 | } else { executed 68 times by 2 tests: end of block Executed by:
| 68 | ||||||||||||||||||
436 | if (aead_ctx->variable_nonce_len + aead_ctx->fixed_nonce_len !=
| 0-24 | ||||||||||||||||||
437 | EVP_AEAD_nonce_length(aead)) {
| 0-24 | ||||||||||||||||||
438 | SSLerrorx(ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
439 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
440 | } | - | ||||||||||||||||||
441 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | return (1); executed 92 times by 2 tests: return (1); Executed by:
| 92 | ||||||||||||||||||
444 | } | - | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | /* | - | ||||||||||||||||||
447 | * tls1_change_cipher_state_cipher performs the work needed to switch cipher | - | ||||||||||||||||||
448 | * states when using EVP_CIPHER. The argument is_read is true iff this function | - | ||||||||||||||||||
449 | * is being called due to reading, as opposed to writing, a ChangeCipherSpec | - | ||||||||||||||||||
450 | * message. | - | ||||||||||||||||||
451 | */ | - | ||||||||||||||||||
452 | static int | - | ||||||||||||||||||
453 | tls1_change_cipher_state_cipher(SSL *s, char is_read, | - | ||||||||||||||||||
454 | const unsigned char *mac_secret, unsigned int mac_secret_size, | - | ||||||||||||||||||
455 | const unsigned char *key, unsigned int key_len, const unsigned char *iv, | - | ||||||||||||||||||
456 | unsigned int iv_len) | - | ||||||||||||||||||
457 | { | - | ||||||||||||||||||
458 | EVP_CIPHER_CTX *cipher_ctx; | - | ||||||||||||||||||
459 | const EVP_CIPHER *cipher; | - | ||||||||||||||||||
460 | EVP_MD_CTX *mac_ctx; | - | ||||||||||||||||||
461 | EVP_PKEY *mac_key; | - | ||||||||||||||||||
462 | const EVP_MD *mac; | - | ||||||||||||||||||
463 | int mac_type; | - | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | cipher = S3I(s)->tmp.new_sym_enc; | - | ||||||||||||||||||
466 | mac = S3I(s)->tmp.new_hash; | - | ||||||||||||||||||
467 | mac_type = S3I(s)->tmp.new_mac_pkey_type; | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | if (is_read) {
| 80 | ||||||||||||||||||
470 | if (S3I(s)->hs.new_cipher->algorithm2 & TLS1_STREAM_MAC)
| 0-80 | ||||||||||||||||||
471 | s->internal->mac_flags |= SSL_MAC_FLAG_READ_MAC_STREAM; never executed: s->internal->mac_flags |= 1; | 0 | ||||||||||||||||||
472 | else | - | ||||||||||||||||||
473 | s->internal->mac_flags &= ~SSL_MAC_FLAG_READ_MAC_STREAM; executed 80 times by 1 test: s->internal->mac_flags &= ~1; Executed by:
| 80 | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | ssl_clear_cipher_read_state(s); | - | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | if ((cipher_ctx = EVP_CIPHER_CTX_new()) == NULL)
| 0-80 | ||||||||||||||||||
478 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
479 | s->enc_read_ctx = cipher_ctx; | - | ||||||||||||||||||
480 | if ((mac_ctx = EVP_MD_CTX_new()) == NULL)
| 0-80 | ||||||||||||||||||
481 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
482 | s->read_hash = mac_ctx; | - | ||||||||||||||||||
483 | } else { executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||||||||
484 | if (S3I(s)->hs.new_cipher->algorithm2 & TLS1_STREAM_MAC)
| 0-80 | ||||||||||||||||||
485 | s->internal->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; never executed: s->internal->mac_flags |= 2; | 0 | ||||||||||||||||||
486 | else | - | ||||||||||||||||||
487 | s->internal->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; executed 80 times by 1 test: s->internal->mac_flags &= ~2; Executed by:
| 80 | ||||||||||||||||||
488 | - | |||||||||||||||||||
489 | /* | - | ||||||||||||||||||
490 | * DTLS fragments retain a pointer to the compression, cipher | - | ||||||||||||||||||
491 | * and hash contexts, so that it can restore state in order | - | ||||||||||||||||||
492 | * to perform retransmissions. As such, we cannot free write | - | ||||||||||||||||||
493 | * contexts that are used for DTLS - these are instead freed | - | ||||||||||||||||||
494 | * by DTLS when its frees a ChangeCipherSpec fragment. | - | ||||||||||||||||||
495 | */ | - | ||||||||||||||||||
496 | if (!SSL_IS_DTLS(s))
| 22-58 | ||||||||||||||||||
497 | ssl_clear_cipher_write_state(s); executed 58 times by 1 test: ssl_clear_cipher_write_state(s); Executed by:
| 58 | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | if ((cipher_ctx = EVP_CIPHER_CTX_new()) == NULL)
| 0-80 | ||||||||||||||||||
500 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
501 | s->internal->enc_write_ctx = cipher_ctx; | - | ||||||||||||||||||
502 | if ((mac_ctx = EVP_MD_CTX_new()) == NULL)
| 0-80 | ||||||||||||||||||
503 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
504 | s->internal->write_hash = mac_ctx; | - | ||||||||||||||||||
505 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | EVP_CipherInit_ex(cipher_ctx, cipher, NULL, key, iv, !is_read); | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | if ((mac_key = EVP_PKEY_new_mac_key(mac_type, NULL, mac_secret,
| 0-160 | ||||||||||||||||||
510 | mac_secret_size)) == NULL)
| 0-160 | ||||||||||||||||||
511 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
512 | EVP_DigestSignInit(mac_ctx, NULL, mac, NULL, mac_key); | - | ||||||||||||||||||
513 | EVP_PKEY_free(mac_key); | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | if (S3I(s)->hs.new_cipher->algorithm_enc == SSL_eGOST2814789CNT) {
| 0-160 | ||||||||||||||||||
516 | int nid; | - | ||||||||||||||||||
517 | if (S3I(s)->hs.new_cipher->algorithm2 & SSL_HANDSHAKE_MAC_GOST94)
| 0 | ||||||||||||||||||
518 | nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet; never executed: nid = 824; | 0 | ||||||||||||||||||
519 | else | - | ||||||||||||||||||
520 | nid = NID_id_tc26_gost_28147_param_Z; never executed: nid = 945; | 0 | ||||||||||||||||||
521 | - | |||||||||||||||||||
522 | EVP_CIPHER_CTX_ctrl(cipher_ctx, EVP_CTRL_GOST_SET_SBOX, nid, 0); | - | ||||||||||||||||||
523 | if (S3I(s)->hs.new_cipher->algorithm_mac == SSL_GOST89MAC)
| 0 | ||||||||||||||||||
524 | EVP_MD_CTX_ctrl(mac_ctx, EVP_MD_CTRL_GOST_SET_SBOX, nid, 0); never executed: EVP_MD_CTX_ctrl(mac_ctx, 0x4, nid, 0); | 0 | ||||||||||||||||||
525 | } never executed: end of block | 0 | ||||||||||||||||||
526 | - | |||||||||||||||||||
527 | return (1); executed 160 times by 1 test: return (1); Executed by:
| 160 | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | err: | - | ||||||||||||||||||
530 | SSLerrorx(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
531 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
532 | } | - | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | int | - | ||||||||||||||||||
535 | tls1_change_cipher_state(SSL *s, int which) | - | ||||||||||||||||||
536 | { | - | ||||||||||||||||||
537 | const unsigned char *client_write_mac_secret, *server_write_mac_secret; | - | ||||||||||||||||||
538 | const unsigned char *client_write_key, *server_write_key; | - | ||||||||||||||||||
539 | const unsigned char *client_write_iv, *server_write_iv; | - | ||||||||||||||||||
540 | const unsigned char *mac_secret, *key, *iv; | - | ||||||||||||||||||
541 | int mac_secret_size, key_len, iv_len; | - | ||||||||||||||||||
542 | unsigned char *key_block, *seq; | - | ||||||||||||||||||
543 | const EVP_CIPHER *cipher; | - | ||||||||||||||||||
544 | const EVP_AEAD *aead; | - | ||||||||||||||||||
545 | char is_read, use_client_keys; | - | ||||||||||||||||||
546 | - | |||||||||||||||||||
547 | cipher = S3I(s)->tmp.new_sym_enc; | - | ||||||||||||||||||
548 | aead = S3I(s)->tmp.new_aead; | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | /* | - | ||||||||||||||||||
551 | * is_read is true if we have just read a ChangeCipherSpec message, | - | ||||||||||||||||||
552 | * that is we need to update the read cipherspec. Otherwise we have | - | ||||||||||||||||||
553 | * just written one. | - | ||||||||||||||||||
554 | */ | - | ||||||||||||||||||
555 | is_read = (which & SSL3_CC_READ) != 0; | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | /* | - | ||||||||||||||||||
558 | * use_client_keys is true if we wish to use the keys for the "client | - | ||||||||||||||||||
559 | * write" direction. This is the case if we're a client sending a | - | ||||||||||||||||||
560 | * ChangeCipherSpec, or a server reading a client's ChangeCipherSpec. | - | ||||||||||||||||||
561 | */ | - | ||||||||||||||||||
562 | use_client_keys = ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
| 63-189 | ||||||||||||||||||
563 | (which == SSL3_CHANGE_CIPHER_SERVER_READ));
| 63-126 | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | /* | - | ||||||||||||||||||
566 | * Reset sequence number to zero - for DTLS this is handled in | - | ||||||||||||||||||
567 | * dtls1_reset_seq_numbers(). | - | ||||||||||||||||||
568 | */ | - | ||||||||||||||||||
569 | if (!SSL_IS_DTLS(s)) {
| 44-208 | ||||||||||||||||||
570 | seq = is_read ? S3I(s)->read_sequence : S3I(s)->write_sequence;
| 104 | ||||||||||||||||||
571 | memset(seq, 0, SSL3_SEQUENCE_SIZE); | - | ||||||||||||||||||
572 | } executed 208 times by 2 tests: end of block Executed by:
| 208 | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | if (aead != NULL) {
| 92-160 | ||||||||||||||||||
575 | key_len = EVP_AEAD_key_length(aead); | - | ||||||||||||||||||
576 | iv_len = SSL_CIPHER_AEAD_FIXED_NONCE_LEN(S3I(s)->hs.new_cipher); | - | ||||||||||||||||||
577 | } else { executed 92 times by 2 tests: end of block Executed by:
| 92 | ||||||||||||||||||
578 | key_len = EVP_CIPHER_key_length(cipher); | - | ||||||||||||||||||
579 | iv_len = EVP_CIPHER_iv_length(cipher); | - | ||||||||||||||||||
580 | } executed 160 times by 1 test: end of block Executed by:
| 160 | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | mac_secret_size = s->s3->tmp.new_mac_secret_size; | - | ||||||||||||||||||
583 | - | |||||||||||||||||||
584 | key_block = S3I(s)->hs.key_block; | - | ||||||||||||||||||
585 | client_write_mac_secret = key_block; | - | ||||||||||||||||||
586 | key_block += mac_secret_size; | - | ||||||||||||||||||
587 | server_write_mac_secret = key_block; | - | ||||||||||||||||||
588 | key_block += mac_secret_size; | - | ||||||||||||||||||
589 | client_write_key = key_block; | - | ||||||||||||||||||
590 | key_block += key_len; | - | ||||||||||||||||||
591 | server_write_key = key_block; | - | ||||||||||||||||||
592 | key_block += key_len; | - | ||||||||||||||||||
593 | client_write_iv = key_block; | - | ||||||||||||||||||
594 | key_block += iv_len; | - | ||||||||||||||||||
595 | server_write_iv = key_block; | - | ||||||||||||||||||
596 | key_block += iv_len; | - | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | if (use_client_keys) {
| 126 | ||||||||||||||||||
599 | mac_secret = client_write_mac_secret; | - | ||||||||||||||||||
600 | key = client_write_key; | - | ||||||||||||||||||
601 | iv = client_write_iv; | - | ||||||||||||||||||
602 | } else { executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
603 | mac_secret = server_write_mac_secret; | - | ||||||||||||||||||
604 | key = server_write_key; | - | ||||||||||||||||||
605 | iv = server_write_iv; | - | ||||||||||||||||||
606 | } executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
607 | - | |||||||||||||||||||
608 | if (key_block - S3I(s)->hs.key_block != S3I(s)->hs.key_block_len) {
| 0-252 | ||||||||||||||||||
609 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||
610 | goto err2; never executed: goto err2; | 0 | ||||||||||||||||||
611 | } | - | ||||||||||||||||||
612 | - | |||||||||||||||||||
613 | if (is_read) {
| 126 | ||||||||||||||||||
614 | memcpy(S3I(s)->read_mac_secret, mac_secret, mac_secret_size); | - | ||||||||||||||||||
615 | S3I(s)->read_mac_secret_size = mac_secret_size; | - | ||||||||||||||||||
616 | } else { executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
617 | memcpy(S3I(s)->write_mac_secret, mac_secret, mac_secret_size); | - | ||||||||||||||||||
618 | S3I(s)->write_mac_secret_size = mac_secret_size; | - | ||||||||||||||||||
619 | } executed 126 times by 2 tests: end of block Executed by:
| 126 | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | if (aead != NULL) {
| 92-160 | ||||||||||||||||||
622 | return tls1_change_cipher_state_aead(s, is_read, key, key_len, executed 92 times by 2 tests: return tls1_change_cipher_state_aead(s, is_read, key, key_len, iv, iv_len); Executed by:
| 92 | ||||||||||||||||||
623 | iv, iv_len); executed 92 times by 2 tests: return tls1_change_cipher_state_aead(s, is_read, key, key_len, iv, iv_len); Executed by:
| 92 | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | return tls1_change_cipher_state_cipher(s, is_read, executed 160 times by 1 test: return tls1_change_cipher_state_cipher(s, is_read, mac_secret, mac_secret_size, key, key_len, iv, iv_len); Executed by:
| 160 | ||||||||||||||||||
627 | mac_secret, mac_secret_size, key, key_len, iv, iv_len); executed 160 times by 1 test: return tls1_change_cipher_state_cipher(s, is_read, mac_secret, mac_secret_size, key, key_len, iv, iv_len); Executed by:
| 160 | ||||||||||||||||||
628 | - | |||||||||||||||||||
629 | err2: | - | ||||||||||||||||||
630 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
631 | } | - | ||||||||||||||||||
632 | - | |||||||||||||||||||
633 | int | - | ||||||||||||||||||
634 | tls1_setup_key_block(SSL *s) | - | ||||||||||||||||||
635 | { | - | ||||||||||||||||||
636 | unsigned char *key_block; | - | ||||||||||||||||||
637 | int mac_type = NID_undef, mac_secret_size = 0; | - | ||||||||||||||||||
638 | int key_block_len, key_len, iv_len; | - | ||||||||||||||||||
639 | const EVP_CIPHER *cipher = NULL; | - | ||||||||||||||||||
640 | const EVP_AEAD *aead = NULL; | - | ||||||||||||||||||
641 | const EVP_MD *mac = NULL; | - | ||||||||||||||||||
642 | int ret = 0; | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | if (S3I(s)->hs.key_block_len != 0)
| 63-126 | ||||||||||||||||||
645 | return (1); executed 63 times by 2 tests: return (1); Executed by:
| 63 | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | if (s->session->cipher &&
| 0-126 | ||||||||||||||||||
648 | (s->session->cipher->algorithm_mac & SSL_AEAD)) {
| 46-80 | ||||||||||||||||||
649 | if (!ssl_cipher_get_evp_aead(s->session, &aead)) {
| 0-46 | ||||||||||||||||||
650 | SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | - | ||||||||||||||||||
651 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
652 | } | - | ||||||||||||||||||
653 | key_len = EVP_AEAD_key_length(aead); | - | ||||||||||||||||||
654 | iv_len = SSL_CIPHER_AEAD_FIXED_NONCE_LEN(s->session->cipher); | - | ||||||||||||||||||
655 | } else { executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
656 | if (!ssl_cipher_get_evp(s->session, &cipher, &mac, &mac_type,
| 0-80 | ||||||||||||||||||
657 | &mac_secret_size)) {
| 0-80 | ||||||||||||||||||
658 | SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | - | ||||||||||||||||||
659 | return (0); never executed: return (0); | 0 | ||||||||||||||||||
660 | } | - | ||||||||||||||||||
661 | key_len = EVP_CIPHER_key_length(cipher); | - | ||||||||||||||||||
662 | iv_len = EVP_CIPHER_iv_length(cipher); | - | ||||||||||||||||||
663 | } executed 80 times by 1 test: end of block Executed by:
| 80 | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | S3I(s)->tmp.new_aead = aead; | - | ||||||||||||||||||
666 | S3I(s)->tmp.new_sym_enc = cipher; | - | ||||||||||||||||||
667 | S3I(s)->tmp.new_hash = mac; | - | ||||||||||||||||||
668 | S3I(s)->tmp.new_mac_pkey_type = mac_type; | - | ||||||||||||||||||
669 | s->s3->tmp.new_mac_secret_size = mac_secret_size; | - | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | tls1_cleanup_key_block(s); | - | ||||||||||||||||||
672 | - | |||||||||||||||||||
673 | if ((key_block = reallocarray(NULL, mac_secret_size + key_len + iv_len,
| 0-126 | ||||||||||||||||||
674 | 2)) == NULL) {
| 0-126 | ||||||||||||||||||
675 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
676 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
677 | } | - | ||||||||||||||||||
678 | key_block_len = (mac_secret_size + key_len + iv_len) * 2; | - | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | S3I(s)->hs.key_block_len = key_block_len; | - | ||||||||||||||||||
681 | S3I(s)->hs.key_block = key_block; | - | ||||||||||||||||||
682 | - | |||||||||||||||||||
683 | if (!tls1_generate_key_block(s, key_block, key_block_len))
| 0-126 | ||||||||||||||||||
684 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | if (!(s->internal->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) &&
| 0-126 | ||||||||||||||||||
687 | s->method->internal->version <= TLS1_VERSION) {
| 36-90 | ||||||||||||||||||
688 | /* | - | ||||||||||||||||||
689 | * Enable vulnerability countermeasure for CBC ciphers with | - | ||||||||||||||||||
690 | * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt) | - | ||||||||||||||||||
691 | */ | - | ||||||||||||||||||
692 | S3I(s)->need_empty_fragments = 1; | - | ||||||||||||||||||
693 | - | |||||||||||||||||||
694 | if (s->session->cipher != NULL) {
| 0-36 | ||||||||||||||||||
695 | if (s->session->cipher->algorithm_enc == SSL_eNULL)
| 0-36 | ||||||||||||||||||
696 | S3I(s)->need_empty_fragments = 0; never executed: (s->s3->internal)->need_empty_fragments = 0; | 0 | ||||||||||||||||||
697 | - | |||||||||||||||||||
698 | #ifndef OPENSSL_NO_RC4 | - | ||||||||||||||||||
699 | if (s->session->cipher->algorithm_enc == SSL_RC4)
| 0-36 | ||||||||||||||||||
700 | S3I(s)->need_empty_fragments = 0; never executed: (s->s3->internal)->need_empty_fragments = 0; | 0 | ||||||||||||||||||
701 | #endif | - | ||||||||||||||||||
702 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
703 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
704 | - | |||||||||||||||||||
705 | ret = 1; | - | ||||||||||||||||||
706 | - | |||||||||||||||||||
707 | err: code before this statement executed 126 times by 2 tests: err: Executed by:
| 126 | ||||||||||||||||||
708 | return (ret); executed 126 times by 2 tests: return (ret); Executed by:
| 126 | ||||||||||||||||||
709 | } | - | ||||||||||||||||||
710 | - | |||||||||||||||||||
711 | /* tls1_enc encrypts/decrypts the record in |s->wrec| / |s->rrec|, respectively. | - | ||||||||||||||||||
712 | * | - | ||||||||||||||||||
713 | * Returns: | - | ||||||||||||||||||
714 | * 0: (in non-constant time) if the record is publically invalid (i.e. too | - | ||||||||||||||||||
715 | * short etc). | - | ||||||||||||||||||
716 | * 1: if the record's padding is valid / the encryption was successful. | - | ||||||||||||||||||
717 | * -1: if the record's padding/AEAD-authenticator is invalid or, if sending, | - | ||||||||||||||||||
718 | * an internal error occured. | - | ||||||||||||||||||
719 | */ | - | ||||||||||||||||||
720 | int | - | ||||||||||||||||||
721 | tls1_enc(SSL *s, int send) | - | ||||||||||||||||||
722 | { | - | ||||||||||||||||||
723 | const SSL_AEAD_CTX *aead; | - | ||||||||||||||||||
724 | const EVP_CIPHER *enc; | - | ||||||||||||||||||
725 | EVP_CIPHER_CTX *ds; | - | ||||||||||||||||||
726 | SSL3_RECORD *rec; | - | ||||||||||||||||||
727 | unsigned char *seq; | - | ||||||||||||||||||
728 | unsigned long l; | - | ||||||||||||||||||
729 | int bs, i, j, k, pad = 0, ret, mac_size = 0; | - | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | if (send) {
| 700-820 | ||||||||||||||||||
732 | aead = s->internal->aead_write_ctx; | - | ||||||||||||||||||
733 | rec = &S3I(s)->wrec; | - | ||||||||||||||||||
734 | seq = S3I(s)->write_sequence; | - | ||||||||||||||||||
735 | } else { executed 820 times by 4 tests: end of block Executed by:
| 820 | ||||||||||||||||||
736 | aead = s->internal->aead_read_ctx; | - | ||||||||||||||||||
737 | rec = &S3I(s)->rrec; | - | ||||||||||||||||||
738 | seq = S3I(s)->read_sequence; | - | ||||||||||||||||||
739 | } executed 700 times by 3 tests: end of block Executed by:
| 700 | ||||||||||||||||||
740 | - | |||||||||||||||||||
741 | if (aead) {
| 214-1306 | ||||||||||||||||||
742 | unsigned char ad[13], *in, *out, nonce[16]; | - | ||||||||||||||||||
743 | size_t out_len, pad_len = 0; | - | ||||||||||||||||||
744 | unsigned int nonce_used; | - | ||||||||||||||||||
745 | - | |||||||||||||||||||
746 | if (SSL_IS_DTLS(s)) {
| 0-214 | ||||||||||||||||||
747 | dtls1_build_sequence_number(ad, seq, | - | ||||||||||||||||||
748 | send ? D1I(s)->w_epoch : D1I(s)->r_epoch); | - | ||||||||||||||||||
749 | } else { never executed: end of block | 0 | ||||||||||||||||||
750 | memcpy(ad, seq, SSL3_SEQUENCE_SIZE); | - | ||||||||||||||||||
751 | tls1_record_sequence_increment(seq); | - | ||||||||||||||||||
752 | } executed 214 times by 2 tests: end of block Executed by:
| 214 | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | ad[8] = rec->type; | - | ||||||||||||||||||
755 | ad[9] = (unsigned char)(s->version >> 8); | - | ||||||||||||||||||
756 | ad[10] = (unsigned char)(s->version); | - | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | if (aead->variable_nonce_len > 8 ||
| 0-214 | ||||||||||||||||||
759 | aead->variable_nonce_len > sizeof(nonce))
| 0-214 | ||||||||||||||||||
760 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | if (aead->xor_fixed_nonce) {
| 60-154 | ||||||||||||||||||
763 | if (aead->fixed_nonce_len > sizeof(nonce) ||
| 0-154 | ||||||||||||||||||
764 | aead->variable_nonce_len > aead->fixed_nonce_len)
| 0-154 | ||||||||||||||||||
765 | return -1; /* Should never happen. */ never executed: return -1; | 0 | ||||||||||||||||||
766 | pad_len = aead->fixed_nonce_len - aead->variable_nonce_len; | - | ||||||||||||||||||
767 | } else { executed 154 times by 2 tests: end of block Executed by:
| 154 | ||||||||||||||||||
768 | if (aead->fixed_nonce_len +
| 0-60 | ||||||||||||||||||
769 | aead->variable_nonce_len > sizeof(nonce))
| 0-60 | ||||||||||||||||||
770 | return -1; /* Should never happen. */ never executed: return -1; | 0 | ||||||||||||||||||
771 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | if (send) {
| 84-130 | ||||||||||||||||||
774 | size_t len = rec->length; | - | ||||||||||||||||||
775 | size_t eivlen = 0; | - | ||||||||||||||||||
776 | in = rec->input; | - | ||||||||||||||||||
777 | out = rec->data; | - | ||||||||||||||||||
778 | - | |||||||||||||||||||
779 | if (aead->xor_fixed_nonce) {
| 36-94 | ||||||||||||||||||
780 | /* | - | ||||||||||||||||||
781 | * The sequence number is left zero | - | ||||||||||||||||||
782 | * padded, then xored with the fixed | - | ||||||||||||||||||
783 | * nonce. | - | ||||||||||||||||||
784 | */ | - | ||||||||||||||||||
785 | memset(nonce, 0, pad_len); | - | ||||||||||||||||||
786 | memcpy(nonce + pad_len, ad, | - | ||||||||||||||||||
787 | aead->variable_nonce_len); | - | ||||||||||||||||||
788 | for (i = 0; i < aead->fixed_nonce_len; i++)
| 94-1128 | ||||||||||||||||||
789 | nonce[i] ^= aead->fixed_nonce[i]; executed 1128 times by 2 tests: nonce[i] ^= aead->fixed_nonce[i]; Executed by:
| 1128 | ||||||||||||||||||
790 | nonce_used = aead->fixed_nonce_len; | - | ||||||||||||||||||
791 | } else { executed 94 times by 2 tests: end of block Executed by:
| 94 | ||||||||||||||||||
792 | /* | - | ||||||||||||||||||
793 | * When sending we use the sequence number as | - | ||||||||||||||||||
794 | * the variable part of the nonce. | - | ||||||||||||||||||
795 | */ | - | ||||||||||||||||||
796 | memcpy(nonce, aead->fixed_nonce, | - | ||||||||||||||||||
797 | aead->fixed_nonce_len); | - | ||||||||||||||||||
798 | nonce_used = aead->fixed_nonce_len; | - | ||||||||||||||||||
799 | memcpy(nonce + nonce_used, ad, | - | ||||||||||||||||||
800 | aead->variable_nonce_len); | - | ||||||||||||||||||
801 | nonce_used += aead->variable_nonce_len; | - | ||||||||||||||||||
802 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
803 | - | |||||||||||||||||||
804 | /* | - | ||||||||||||||||||
805 | * In do_ssl3_write, rec->input is moved forward by | - | ||||||||||||||||||
806 | * variable_nonce_len in order to leave space for the | - | ||||||||||||||||||
807 | * variable nonce. Thus we can copy the sequence number | - | ||||||||||||||||||
808 | * bytes into place without overwriting any of the | - | ||||||||||||||||||
809 | * plaintext. | - | ||||||||||||||||||
810 | */ | - | ||||||||||||||||||
811 | if (aead->variable_nonce_in_record) {
| 36-94 | ||||||||||||||||||
812 | memcpy(out, ad, aead->variable_nonce_len); | - | ||||||||||||||||||
813 | len -= aead->variable_nonce_len; | - | ||||||||||||||||||
814 | eivlen = aead->variable_nonce_len; | - | ||||||||||||||||||
815 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
816 | - | |||||||||||||||||||
817 | ad[11] = len >> 8; | - | ||||||||||||||||||
818 | ad[12] = len & 0xff; | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | if (!EVP_AEAD_CTX_seal(&aead->ctx,
| 0-130 | ||||||||||||||||||
821 | out + eivlen, &out_len, len + aead->tag_len, nonce,
| 0-130 | ||||||||||||||||||
822 | nonce_used, in + eivlen, len, ad, sizeof(ad)))
| 0-130 | ||||||||||||||||||
823 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
824 | if (aead->variable_nonce_in_record)
| 36-94 | ||||||||||||||||||
825 | out_len += aead->variable_nonce_len; executed 36 times by 1 test: out_len += aead->variable_nonce_len; Executed by:
| 36 | ||||||||||||||||||
826 | } else { executed 130 times by 2 tests: end of block Executed by:
| 130 | ||||||||||||||||||
827 | /* receive */ | - | ||||||||||||||||||
828 | size_t len = rec->length; | - | ||||||||||||||||||
829 | - | |||||||||||||||||||
830 | if (rec->data != rec->input)
| 0-84 | ||||||||||||||||||
831 | return -1; /* internal error - should never happen. */ never executed: return -1; | 0 | ||||||||||||||||||
832 | out = in = rec->input; | - | ||||||||||||||||||
833 | - | |||||||||||||||||||
834 | if (len < aead->variable_nonce_len)
| 0-84 | ||||||||||||||||||
835 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | if (aead->xor_fixed_nonce) {
| 24-60 | ||||||||||||||||||
838 | /* | - | ||||||||||||||||||
839 | * The sequence number is left zero | - | ||||||||||||||||||
840 | * padded, then xored with the fixed | - | ||||||||||||||||||
841 | * nonce. | - | ||||||||||||||||||
842 | */ | - | ||||||||||||||||||
843 | memset(nonce, 0, pad_len); | - | ||||||||||||||||||
844 | memcpy(nonce + pad_len, ad, | - | ||||||||||||||||||
845 | aead->variable_nonce_len); | - | ||||||||||||||||||
846 | for (i = 0; i < aead->fixed_nonce_len; i++)
| 60-720 | ||||||||||||||||||
847 | nonce[i] ^= aead->fixed_nonce[i]; executed 720 times by 2 tests: nonce[i] ^= aead->fixed_nonce[i]; Executed by:
| 720 | ||||||||||||||||||
848 | nonce_used = aead->fixed_nonce_len; | - | ||||||||||||||||||
849 | } else { executed 60 times by 2 tests: end of block Executed by:
| 60 | ||||||||||||||||||
850 | memcpy(nonce, aead->fixed_nonce, | - | ||||||||||||||||||
851 | aead->fixed_nonce_len); | - | ||||||||||||||||||
852 | nonce_used = aead->fixed_nonce_len; | - | ||||||||||||||||||
853 | - | |||||||||||||||||||
854 | memcpy(nonce + nonce_used, | - | ||||||||||||||||||
855 | aead->variable_nonce_in_record ? in : ad, | - | ||||||||||||||||||
856 | aead->variable_nonce_len); | - | ||||||||||||||||||
857 | nonce_used += aead->variable_nonce_len; | - | ||||||||||||||||||
858 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
859 | - | |||||||||||||||||||
860 | if (aead->variable_nonce_in_record) {
| 24-60 | ||||||||||||||||||
861 | in += aead->variable_nonce_len; | - | ||||||||||||||||||
862 | len -= aead->variable_nonce_len; | - | ||||||||||||||||||
863 | out += aead->variable_nonce_len; | - | ||||||||||||||||||
864 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
865 | - | |||||||||||||||||||
866 | if (len < aead->tag_len)
| 0-84 | ||||||||||||||||||
867 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
868 | len -= aead->tag_len; | - | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | ad[11] = len >> 8; | - | ||||||||||||||||||
871 | ad[12] = len & 0xff; | - | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | if (!EVP_AEAD_CTX_open(&aead->ctx, out, &out_len, len,
| 0-84 | ||||||||||||||||||
874 | nonce, nonce_used, in, len + aead->tag_len, ad,
| 0-84 | ||||||||||||||||||
875 | sizeof(ad)))
| 0-84 | ||||||||||||||||||
876 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
877 | - | |||||||||||||||||||
878 | rec->data = rec->input = out; | - | ||||||||||||||||||
879 | } executed 84 times by 2 tests: end of block Executed by:
| 84 | ||||||||||||||||||
880 | - | |||||||||||||||||||
881 | rec->length = out_len; | - | ||||||||||||||||||
882 | - | |||||||||||||||||||
883 | return 1; executed 214 times by 2 tests: return 1; Executed by:
| 214 | ||||||||||||||||||
884 | } | - | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | if (send) {
| 616-690 | ||||||||||||||||||
887 | if (EVP_MD_CTX_md(s->internal->write_hash)) {
| 210-480 | ||||||||||||||||||
888 | int n = EVP_MD_CTX_size(s->internal->write_hash); | - | ||||||||||||||||||
889 | OPENSSL_assert(n >= 0); | - | ||||||||||||||||||
890 | } executed 210 times by 1 test: end of block Executed by:
| 210 | ||||||||||||||||||
891 | ds = s->internal->enc_write_ctx; | - | ||||||||||||||||||
892 | if (s->internal->enc_write_ctx == NULL)
| 210-480 | ||||||||||||||||||
893 | enc = NULL; executed 480 times by 4 tests: enc = ((void *)0) ; Executed by:
| 480 | ||||||||||||||||||
894 | else { | - | ||||||||||||||||||
895 | int ivlen = 0; | - | ||||||||||||||||||
896 | enc = EVP_CIPHER_CTX_cipher(s->internal->enc_write_ctx); | - | ||||||||||||||||||
897 | if (SSL_USE_EXPLICIT_IV(s) &&
| 66-144 | ||||||||||||||||||
898 | EVP_CIPHER_mode(enc) == EVP_CIPH_CBC_MODE)
| 6-60 | ||||||||||||||||||
899 | ivlen = EVP_CIPHER_iv_length(enc); executed 60 times by 1 test: ivlen = EVP_CIPHER_iv_length(enc); Executed by:
| 60 | ||||||||||||||||||
900 | if (ivlen > 1) {
| 60-150 | ||||||||||||||||||
901 | if (rec->data != rec->input) {
| 0-60 | ||||||||||||||||||
902 | #ifdef DEBUG | - | ||||||||||||||||||
903 | /* we can't write into the input stream: | - | ||||||||||||||||||
904 | * Can this ever happen?? (steve) | - | ||||||||||||||||||
905 | */ | - | ||||||||||||||||||
906 | fprintf(stderr, | - | ||||||||||||||||||
907 | "%s:%d: rec->data != rec->input\n", | - | ||||||||||||||||||
908 | __FILE__, __LINE__); | - | ||||||||||||||||||
909 | #endif | - | ||||||||||||||||||
910 | } else never executed: end of block | 0 | ||||||||||||||||||
911 | arc4random_buf(rec->input, ivlen); executed 60 times by 1 test: arc4random_buf(rec->input, ivlen); Executed by:
| 60 | ||||||||||||||||||
912 | } | - | ||||||||||||||||||
913 | } executed 210 times by 1 test: end of block Executed by:
| 210 | ||||||||||||||||||
914 | } else { | - | ||||||||||||||||||
915 | if (EVP_MD_CTX_md(s->read_hash)) {
| 152-464 | ||||||||||||||||||
916 | int n = EVP_MD_CTX_size(s->read_hash); | - | ||||||||||||||||||
917 | OPENSSL_assert(n >= 0); | - | ||||||||||||||||||
918 | } executed 152 times by 1 test: end of block Executed by:
| 152 | ||||||||||||||||||
919 | ds = s->enc_read_ctx; | - | ||||||||||||||||||
920 | if (s->enc_read_ctx == NULL)
| 152-464 | ||||||||||||||||||
921 | enc = NULL; executed 464 times by 3 tests: enc = ((void *)0) ; Executed by:
| 464 | ||||||||||||||||||
922 | else | - | ||||||||||||||||||
923 | enc = EVP_CIPHER_CTX_cipher(s->enc_read_ctx); executed 152 times by 1 test: enc = EVP_CIPHER_CTX_cipher(s->enc_read_ctx); Executed by:
| 152 | ||||||||||||||||||
924 | } | - | ||||||||||||||||||
925 | - | |||||||||||||||||||
926 | if ((s->session == NULL) || (ds == NULL) || (enc == NULL)) {
| 0-1261 | ||||||||||||||||||
927 | memmove(rec->data, rec->input, rec->length); | - | ||||||||||||||||||
928 | rec->input = rec->data; | - | ||||||||||||||||||
929 | ret = 1; | - | ||||||||||||||||||
930 | } else { executed 944 times by 4 tests: end of block Executed by:
| 944 | ||||||||||||||||||
931 | l = rec->length; | - | ||||||||||||||||||
932 | bs = EVP_CIPHER_block_size(ds->cipher); | - | ||||||||||||||||||
933 | - | |||||||||||||||||||
934 | if (bs != 1 && send) {
| 10-352 | ||||||||||||||||||
935 | i = bs - ((int)l % bs); | - | ||||||||||||||||||
936 | - | |||||||||||||||||||
937 | /* Add weird padding of upto 256 bytes */ | - | ||||||||||||||||||
938 | - | |||||||||||||||||||
939 | /* we need to add 'i' padding bytes of value j */ | - | ||||||||||||||||||
940 | j = i - 1; | - | ||||||||||||||||||
941 | for (k = (int)l; k < (int)(l + i); k++)
| 204-2576 | ||||||||||||||||||
942 | rec->input[k] = j; executed 2576 times by 1 test: rec->input[k] = j; Executed by:
| 2576 | ||||||||||||||||||
943 | l += i; | - | ||||||||||||||||||
944 | rec->length += i; | - | ||||||||||||||||||
945 | } executed 204 times by 1 test: end of block Executed by:
| 204 | ||||||||||||||||||
946 | - | |||||||||||||||||||
947 | if (!send) {
| 152-210 | ||||||||||||||||||
948 | if (l == 0 || l % bs != 0)
| 0-152 | ||||||||||||||||||
949 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
950 | } executed 152 times by 1 test: end of block Executed by:
| 152 | ||||||||||||||||||
951 | - | |||||||||||||||||||
952 | i = EVP_Cipher(ds, rec->data, rec->input, l); | - | ||||||||||||||||||
953 | if ((EVP_CIPHER_flags(ds->cipher) &
| 0-362 | ||||||||||||||||||
954 | EVP_CIPH_FLAG_CUSTOM_CIPHER) ? (i < 0) : (i == 0))
| 0-362 | ||||||||||||||||||
955 | return -1; /* AEAD can fail to verify MAC */ never executed: return -1; | 0 | ||||||||||||||||||
956 | - | |||||||||||||||||||
957 | ret = 1; | - | ||||||||||||||||||
958 | if (EVP_MD_CTX_md(s->read_hash) != NULL)
| 29-333 | ||||||||||||||||||
959 | mac_size = EVP_MD_CTX_size(s->read_hash); executed 333 times by 1 test: mac_size = EVP_MD_size(EVP_MD_CTX_md(s->read_hash)); Executed by:
| 333 | ||||||||||||||||||
960 | if ((bs != 1) && !send)
| 10-352 | ||||||||||||||||||
961 | ret = tls1_cbc_remove_padding(s, rec, bs, mac_size); executed 148 times by 1 test: ret = tls1_cbc_remove_padding(s, rec, bs, mac_size); Executed by:
| 148 | ||||||||||||||||||
962 | if (pad && !send)
| 0-362 | ||||||||||||||||||
963 | rec->length -= pad; never executed: rec->length -= pad; | 0 | ||||||||||||||||||
964 | } executed 362 times by 1 test: end of block Executed by:
| 362 | ||||||||||||||||||
965 | return ret; executed 1306 times by 4 tests: return ret; Executed by:
| 1306 | ||||||||||||||||||
966 | } | - | ||||||||||||||||||
967 | - | |||||||||||||||||||
968 | int | - | ||||||||||||||||||
969 | tls1_final_finish_mac(SSL *s, const char *str, int str_len, unsigned char *out) | - | ||||||||||||||||||
970 | { | - | ||||||||||||||||||
971 | unsigned char buf[EVP_MAX_MD_SIZE]; | - | ||||||||||||||||||
972 | size_t hash_len; | - | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | if (str_len < 0)
| 0-356 | ||||||||||||||||||
975 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | if (!tls1_handshake_hash_value(s, buf, sizeof(buf), &hash_len))
| 0-356 | ||||||||||||||||||
978 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
979 | - | |||||||||||||||||||
980 | if (!tls1_PRF(s, s->session->master_key, s->session->master_key_length,
| 0-356 | ||||||||||||||||||
981 | str, str_len, buf, hash_len, NULL, 0, NULL, 0, NULL, 0,
| 0-356 | ||||||||||||||||||
982 | out, TLS1_FINISH_MAC_LENGTH))
| 0-356 | ||||||||||||||||||
983 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
984 | - | |||||||||||||||||||
985 | return TLS1_FINISH_MAC_LENGTH; executed 356 times by 2 tests: return 12; Executed by:
| 356 | ||||||||||||||||||
986 | } | - | ||||||||||||||||||
987 | - | |||||||||||||||||||
988 | int | - | ||||||||||||||||||
989 | tls1_mac(SSL *ssl, unsigned char *md, int send) | - | ||||||||||||||||||
990 | { | - | ||||||||||||||||||
991 | SSL3_RECORD *rec; | - | ||||||||||||||||||
992 | unsigned char *seq; | - | ||||||||||||||||||
993 | EVP_MD_CTX *hash; | - | ||||||||||||||||||
994 | size_t md_size, orig_len; | - | ||||||||||||||||||
995 | EVP_MD_CTX hmac, *mac_ctx; | - | ||||||||||||||||||
996 | unsigned char header[13]; | - | ||||||||||||||||||
997 | int stream_mac = (send ?
| 196-276 | ||||||||||||||||||
998 | (ssl->internal->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM) : | - | ||||||||||||||||||
999 | (ssl->internal->mac_flags & SSL_MAC_FLAG_READ_MAC_STREAM)); | - | ||||||||||||||||||
1000 | int t; | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | if (send) {
| 196-276 | ||||||||||||||||||
1003 | rec = &(ssl->s3->internal->wrec); | - | ||||||||||||||||||
1004 | seq = &(ssl->s3->internal->write_sequence[0]); | - | ||||||||||||||||||
1005 | hash = ssl->internal->write_hash; | - | ||||||||||||||||||
1006 | } else { executed 276 times by 1 test: end of block Executed by:
| 276 | ||||||||||||||||||
1007 | rec = &(ssl->s3->internal->rrec); | - | ||||||||||||||||||
1008 | seq = &(ssl->s3->internal->read_sequence[0]); | - | ||||||||||||||||||
1009 | hash = ssl->read_hash; | - | ||||||||||||||||||
1010 | } executed 196 times by 1 test: end of block Executed by:
| 196 | ||||||||||||||||||
1011 | - | |||||||||||||||||||
1012 | t = EVP_MD_CTX_size(hash); | - | ||||||||||||||||||
1013 | OPENSSL_assert(t >= 0); | - | ||||||||||||||||||
1014 | md_size = t; | - | ||||||||||||||||||
1015 | - | |||||||||||||||||||
1016 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ | - | ||||||||||||||||||
1017 | if (stream_mac) {
| 0-472 | ||||||||||||||||||
1018 | mac_ctx = hash; | - | ||||||||||||||||||
1019 | } else { never executed: end of block | 0 | ||||||||||||||||||
1020 | if (!EVP_MD_CTX_copy(&hmac, hash))
| 0-472 | ||||||||||||||||||
1021 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
1022 | mac_ctx = &hmac; | - | ||||||||||||||||||
1023 | } executed 472 times by 1 test: end of block Executed by:
| 472 | ||||||||||||||||||
1024 | - | |||||||||||||||||||
1025 | if (SSL_IS_DTLS(ssl))
| 110-362 | ||||||||||||||||||
1026 | dtls1_build_sequence_number(header, seq, executed 110 times by 1 test: dtls1_build_sequence_number(header, seq, send ? (ssl->d1->internal)->w_epoch : (ssl->d1->internal)->r_epoch); Executed by:
| 110 | ||||||||||||||||||
1027 | send ? D1I(ssl)->w_epoch : D1I(ssl)->r_epoch); executed 110 times by 1 test: dtls1_build_sequence_number(header, seq, send ? (ssl->d1->internal)->w_epoch : (ssl->d1->internal)->r_epoch); Executed by:
| 110 | ||||||||||||||||||
1028 | else | - | ||||||||||||||||||
1029 | memcpy(header, seq, SSL3_SEQUENCE_SIZE); executed 362 times by 1 test: memcpy(header, seq, 8); Executed by:
| 362 | ||||||||||||||||||
1030 | - | |||||||||||||||||||
1031 | /* kludge: tls1_cbc_remove_padding passes padding length in rec->type */ | - | ||||||||||||||||||
1032 | orig_len = rec->length + md_size + ((unsigned int)rec->type >> 8); | - | ||||||||||||||||||
1033 | rec->type &= 0xff; | - | ||||||||||||||||||
1034 | - | |||||||||||||||||||
1035 | header[8] = rec->type; | - | ||||||||||||||||||
1036 | header[9] = (unsigned char)(ssl->version >> 8); | - | ||||||||||||||||||
1037 | header[10] = (unsigned char)(ssl->version); | - | ||||||||||||||||||
1038 | header[11] = (rec->length) >> 8; | - | ||||||||||||||||||
1039 | header[12] = (rec->length) & 0xff; | - | ||||||||||||||||||
1040 | - | |||||||||||||||||||
1041 | if (!send &&
| 196-276 | ||||||||||||||||||
1042 | EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&
| 12-184 | ||||||||||||||||||
1043 | ssl3_cbc_record_digest_supported(mac_ctx)) {
| 0-184 | ||||||||||||||||||
1044 | /* This is a CBC-encrypted record. We must avoid leaking any | - | ||||||||||||||||||
1045 | * timing-side channel information about how many blocks of | - | ||||||||||||||||||
1046 | * data we are hashing because that gives an attacker a | - | ||||||||||||||||||
1047 | * timing-oracle. */ | - | ||||||||||||||||||
1048 | if (!ssl3_cbc_digest_record(mac_ctx,
| 0-184 | ||||||||||||||||||
1049 | md, &md_size, header, rec->input,
| 0-184 | ||||||||||||||||||
1050 | rec->length + md_size, orig_len,
| 0-184 | ||||||||||||||||||
1051 | ssl->s3->internal->read_mac_secret,
| 0-184 | ||||||||||||||||||
1052 | ssl->s3->internal->read_mac_secret_size))
| 0-184 | ||||||||||||||||||
1053 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
1054 | } else { executed 184 times by 1 test: end of block Executed by:
| 184 | ||||||||||||||||||
1055 | EVP_DigestSignUpdate(mac_ctx, header, sizeof(header)); | - | ||||||||||||||||||
1056 | EVP_DigestSignUpdate(mac_ctx, rec->input, rec->length); | - | ||||||||||||||||||
1057 | t = EVP_DigestSignFinal(mac_ctx, md, &md_size); | - | ||||||||||||||||||
1058 | OPENSSL_assert(t > 0); | - | ||||||||||||||||||
1059 | } executed 288 times by 1 test: end of block Executed by:
| 288 | ||||||||||||||||||
1060 | - | |||||||||||||||||||
1061 | if (!stream_mac)
| 0-472 | ||||||||||||||||||
1062 | EVP_MD_CTX_cleanup(&hmac); executed 472 times by 1 test: EVP_MD_CTX_cleanup(&hmac); Executed by:
| 472 | ||||||||||||||||||
1063 | - | |||||||||||||||||||
1064 | if (!SSL_IS_DTLS(ssl))
| 110-362 | ||||||||||||||||||
1065 | tls1_record_sequence_increment(seq); executed 362 times by 1 test: tls1_record_sequence_increment(seq); Executed by:
| 362 | ||||||||||||||||||
1066 | - | |||||||||||||||||||
1067 | return (md_size); executed 472 times by 1 test: return (md_size); Executed by:
| 472 | ||||||||||||||||||
1068 | } | - | ||||||||||||||||||
1069 | - | |||||||||||||||||||
1070 | int | - | ||||||||||||||||||
1071 | tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, | - | ||||||||||||||||||
1072 | int len) | - | ||||||||||||||||||
1073 | { | - | ||||||||||||||||||
1074 | if (len < 0)
| 0-126 | ||||||||||||||||||
1075 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1076 | - | |||||||||||||||||||
1077 | if (!tls1_PRF(s, p, len,
| 0-126 | ||||||||||||||||||
1078 | TLS_MD_MASTER_SECRET_CONST, TLS_MD_MASTER_SECRET_CONST_SIZE,
| 0-126 | ||||||||||||||||||
1079 | s->s3->client_random, SSL3_RANDOM_SIZE, NULL, 0,
| 0-126 | ||||||||||||||||||
1080 | s->s3->server_random, SSL3_RANDOM_SIZE, NULL, 0,
| 0-126 | ||||||||||||||||||
1081 | s->session->master_key, SSL_MAX_MASTER_KEY_LENGTH))
| 0-126 | ||||||||||||||||||
1082 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | return (SSL_MAX_MASTER_KEY_LENGTH); executed 126 times by 2 tests: return (48); Executed by:
| 126 | ||||||||||||||||||
1085 | } | - | ||||||||||||||||||
1086 | - | |||||||||||||||||||
1087 | int | - | ||||||||||||||||||
1088 | tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen, | - | ||||||||||||||||||
1089 | const char *label, size_t llen, const unsigned char *context, | - | ||||||||||||||||||
1090 | size_t contextlen, int use_context) | - | ||||||||||||||||||
1091 | { | - | ||||||||||||||||||
1092 | unsigned char *val = NULL; | - | ||||||||||||||||||
1093 | size_t vallen, currentvalpos; | - | ||||||||||||||||||
1094 | int rv; | - | ||||||||||||||||||
1095 | - | |||||||||||||||||||
1096 | /* construct PRF arguments | - | ||||||||||||||||||
1097 | * we construct the PRF argument ourself rather than passing separate | - | ||||||||||||||||||
1098 | * values into the TLS PRF to ensure that the concatenation of values | - | ||||||||||||||||||
1099 | * does not create a prohibited label. | - | ||||||||||||||||||
1100 | */ | - | ||||||||||||||||||
1101 | vallen = llen + SSL3_RANDOM_SIZE * 2; | - | ||||||||||||||||||
1102 | if (use_context) {
| 0 | ||||||||||||||||||
1103 | vallen += 2 + contextlen; | - | ||||||||||||||||||
1104 | } never executed: end of block | 0 | ||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | val = malloc(vallen); | - | ||||||||||||||||||
1107 | if (val == NULL)
| 0 | ||||||||||||||||||
1108 | goto err2; never executed: goto err2; | 0 | ||||||||||||||||||
1109 | currentvalpos = 0; | - | ||||||||||||||||||
1110 | memcpy(val + currentvalpos, (unsigned char *) label, llen); | - | ||||||||||||||||||
1111 | currentvalpos += llen; | - | ||||||||||||||||||
1112 | memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE); | - | ||||||||||||||||||
1113 | currentvalpos += SSL3_RANDOM_SIZE; | - | ||||||||||||||||||
1114 | memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE); | - | ||||||||||||||||||
1115 | currentvalpos += SSL3_RANDOM_SIZE; | - | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | if (use_context) {
| 0 | ||||||||||||||||||
1118 | val[currentvalpos] = (contextlen >> 8) & 0xff; | - | ||||||||||||||||||
1119 | currentvalpos++; | - | ||||||||||||||||||
1120 | val[currentvalpos] = contextlen & 0xff; | - | ||||||||||||||||||
1121 | currentvalpos++; | - | ||||||||||||||||||
1122 | if ((contextlen > 0) || (context != NULL)) {
| 0 | ||||||||||||||||||
1123 | memcpy(val + currentvalpos, context, contextlen); | - | ||||||||||||||||||
1124 | } never executed: end of block | 0 | ||||||||||||||||||
1125 | } never executed: end of block | 0 | ||||||||||||||||||
1126 | - | |||||||||||||||||||
1127 | /* disallow prohibited labels | - | ||||||||||||||||||
1128 | * note that SSL3_RANDOM_SIZE > max(prohibited label len) = | - | ||||||||||||||||||
1129 | * 15, so size of val > max(prohibited label len) = 15 and the | - | ||||||||||||||||||
1130 | * comparisons won't have buffer overflow | - | ||||||||||||||||||
1131 | */ | - | ||||||||||||||||||
1132 | if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
| 0 | ||||||||||||||||||
1133 | TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)
| 0 | ||||||||||||||||||
1134 | goto err1; never executed: goto err1; | 0 | ||||||||||||||||||
1135 | if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
| 0 | ||||||||||||||||||
1136 | TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)
| 0 | ||||||||||||||||||
1137 | goto err1; never executed: goto err1; | 0 | ||||||||||||||||||
1138 | if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
| 0 | ||||||||||||||||||
1139 | TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)
| 0 | ||||||||||||||||||
1140 | goto err1; never executed: goto err1; | 0 | ||||||||||||||||||
1141 | if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
| 0 | ||||||||||||||||||
1142 | TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)
| 0 | ||||||||||||||||||
1143 | goto err1; never executed: goto err1; | 0 | ||||||||||||||||||
1144 | - | |||||||||||||||||||
1145 | rv = tls1_PRF(s, s->session->master_key, s->session->master_key_length, | - | ||||||||||||||||||
1146 | val, vallen, NULL, 0, NULL, 0, NULL, 0, NULL, 0, out, olen); | - | ||||||||||||||||||
1147 | - | |||||||||||||||||||
1148 | goto ret; never executed: goto ret; | 0 | ||||||||||||||||||
1149 | err1: | - | ||||||||||||||||||
1150 | SSLerror(s, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL); | - | ||||||||||||||||||
1151 | rv = 0; | - | ||||||||||||||||||
1152 | goto ret; never executed: goto ret; | 0 | ||||||||||||||||||
1153 | err2: | - | ||||||||||||||||||
1154 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
1155 | rv = 0; | - | ||||||||||||||||||
1156 | ret: code before this statement never executed: ret: | 0 | ||||||||||||||||||
1157 | free(val); | - | ||||||||||||||||||
1158 | - | |||||||||||||||||||
1159 | return (rv); never executed: return (rv); | 0 | ||||||||||||||||||
1160 | } | - | ||||||||||||||||||
1161 | - | |||||||||||||||||||
1162 | int | - | ||||||||||||||||||
1163 | tls1_alert_code(int code) | - | ||||||||||||||||||
1164 | { | - | ||||||||||||||||||
1165 | switch (code) { | - | ||||||||||||||||||
1166 | case SSL_AD_CLOSE_NOTIFY: executed 126 times by 2 tests: case 0: Executed by:
| 126 | ||||||||||||||||||
1167 | return (SSL3_AD_CLOSE_NOTIFY); executed 126 times by 2 tests: return (0); Executed by:
| 126 | ||||||||||||||||||
1168 | case SSL_AD_UNEXPECTED_MESSAGE: never executed: case 10: | 0 | ||||||||||||||||||
1169 | return (SSL3_AD_UNEXPECTED_MESSAGE); never executed: return (10); | 0 | ||||||||||||||||||
1170 | case SSL_AD_BAD_RECORD_MAC: never executed: case 20: | 0 | ||||||||||||||||||
1171 | return (SSL3_AD_BAD_RECORD_MAC); never executed: return (20); | 0 | ||||||||||||||||||
1172 | case SSL_AD_DECRYPTION_FAILED: never executed: case 21: | 0 | ||||||||||||||||||
1173 | return (TLS1_AD_DECRYPTION_FAILED); never executed: return (21); | 0 | ||||||||||||||||||
1174 | case SSL_AD_RECORD_OVERFLOW: never executed: case 22: | 0 | ||||||||||||||||||
1175 | return (TLS1_AD_RECORD_OVERFLOW); never executed: return (22); | 0 | ||||||||||||||||||
1176 | case SSL_AD_DECOMPRESSION_FAILURE: never executed: case 30: | 0 | ||||||||||||||||||
1177 | return (SSL3_AD_DECOMPRESSION_FAILURE); never executed: return (30); | 0 | ||||||||||||||||||
1178 | case SSL_AD_HANDSHAKE_FAILURE: never executed: case 40: | 0 | ||||||||||||||||||
1179 | return (SSL3_AD_HANDSHAKE_FAILURE); never executed: return (40); | 0 | ||||||||||||||||||
1180 | case SSL_AD_NO_CERTIFICATE: never executed: case 41: | 0 | ||||||||||||||||||
1181 | return (-1); never executed: return (-1); | 0 | ||||||||||||||||||
1182 | case SSL_AD_BAD_CERTIFICATE: never executed: case 42: | 0 | ||||||||||||||||||
1183 | return (SSL3_AD_BAD_CERTIFICATE); never executed: return (42); | 0 | ||||||||||||||||||
1184 | case SSL_AD_UNSUPPORTED_CERTIFICATE: never executed: case 43: | 0 | ||||||||||||||||||
1185 | return (SSL3_AD_UNSUPPORTED_CERTIFICATE); never executed: return (43); | 0 | ||||||||||||||||||
1186 | case SSL_AD_CERTIFICATE_REVOKED: never executed: case 44: | 0 | ||||||||||||||||||
1187 | return (SSL3_AD_CERTIFICATE_REVOKED); never executed: return (44); | 0 | ||||||||||||||||||
1188 | case SSL_AD_CERTIFICATE_EXPIRED: never executed: case 45: | 0 | ||||||||||||||||||
1189 | return (SSL3_AD_CERTIFICATE_EXPIRED); never executed: return (45); | 0 | ||||||||||||||||||
1190 | case SSL_AD_CERTIFICATE_UNKNOWN: never executed: case 46: | 0 | ||||||||||||||||||
1191 | return (SSL3_AD_CERTIFICATE_UNKNOWN); never executed: return (46); | 0 | ||||||||||||||||||
1192 | case SSL_AD_ILLEGAL_PARAMETER: never executed: case 47: | 0 | ||||||||||||||||||
1193 | return (SSL3_AD_ILLEGAL_PARAMETER); never executed: return (47); | 0 | ||||||||||||||||||
1194 | case SSL_AD_UNKNOWN_CA: never executed: case 48: | 0 | ||||||||||||||||||
1195 | return (TLS1_AD_UNKNOWN_CA); never executed: return (48); | 0 | ||||||||||||||||||
1196 | case SSL_AD_ACCESS_DENIED: never executed: case 49: | 0 | ||||||||||||||||||
1197 | return (TLS1_AD_ACCESS_DENIED); never executed: return (49); | 0 | ||||||||||||||||||
1198 | case SSL_AD_DECODE_ERROR: never executed: case 50: | 0 | ||||||||||||||||||
1199 | return (TLS1_AD_DECODE_ERROR); never executed: return (50); | 0 | ||||||||||||||||||
1200 | case SSL_AD_DECRYPT_ERROR: never executed: case 51: | 0 | ||||||||||||||||||
1201 | return (TLS1_AD_DECRYPT_ERROR); never executed: return (51); | 0 | ||||||||||||||||||
1202 | case SSL_AD_EXPORT_RESTRICTION: never executed: case 60: | 0 | ||||||||||||||||||
1203 | return (TLS1_AD_EXPORT_RESTRICTION); never executed: return (60); | 0 | ||||||||||||||||||
1204 | case SSL_AD_PROTOCOL_VERSION: never executed: case 70: | 0 | ||||||||||||||||||
1205 | return (TLS1_AD_PROTOCOL_VERSION); never executed: return (70); | 0 | ||||||||||||||||||
1206 | case SSL_AD_INSUFFICIENT_SECURITY: never executed: case 71: | 0 | ||||||||||||||||||
1207 | return (TLS1_AD_INSUFFICIENT_SECURITY); never executed: return (71); | 0 | ||||||||||||||||||
1208 | case SSL_AD_INTERNAL_ERROR: never executed: case 80: | 0 | ||||||||||||||||||
1209 | return (TLS1_AD_INTERNAL_ERROR); never executed: return (80); | 0 | ||||||||||||||||||
1210 | case SSL_AD_INAPPROPRIATE_FALLBACK: never executed: case 86: | 0 | ||||||||||||||||||
1211 | return(TLS1_AD_INAPPROPRIATE_FALLBACK); never executed: return(86); | 0 | ||||||||||||||||||
1212 | case SSL_AD_USER_CANCELLED: never executed: case 90: | 0 | ||||||||||||||||||
1213 | return (TLS1_AD_USER_CANCELLED); never executed: return (90); | 0 | ||||||||||||||||||
1214 | case SSL_AD_NO_RENEGOTIATION: never executed: case 100: | 0 | ||||||||||||||||||
1215 | return (TLS1_AD_NO_RENEGOTIATION); never executed: return (100); | 0 | ||||||||||||||||||
1216 | case SSL_AD_UNSUPPORTED_EXTENSION: never executed: case 110: | 0 | ||||||||||||||||||
1217 | return (TLS1_AD_UNSUPPORTED_EXTENSION); never executed: return (110); | 0 | ||||||||||||||||||
1218 | case SSL_AD_CERTIFICATE_UNOBTAINABLE: never executed: case 111: | 0 | ||||||||||||||||||
1219 | return (TLS1_AD_CERTIFICATE_UNOBTAINABLE); never executed: return (111); | 0 | ||||||||||||||||||
1220 | case SSL_AD_UNRECOGNIZED_NAME: never executed: case 112: | 0 | ||||||||||||||||||
1221 | return (TLS1_AD_UNRECOGNIZED_NAME); never executed: return (112); | 0 | ||||||||||||||||||
1222 | case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE: never executed: case 113: | 0 | ||||||||||||||||||
1223 | return (TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE); never executed: return (113); | 0 | ||||||||||||||||||
1224 | case SSL_AD_BAD_CERTIFICATE_HASH_VALUE: never executed: case 114: | 0 | ||||||||||||||||||
1225 | return (TLS1_AD_BAD_CERTIFICATE_HASH_VALUE); never executed: return (114); | 0 | ||||||||||||||||||
1226 | case SSL_AD_UNKNOWN_PSK_IDENTITY: never executed: case 115: | 0 | ||||||||||||||||||
1227 | return (TLS1_AD_UNKNOWN_PSK_IDENTITY); never executed: return (115); | 0 | ||||||||||||||||||
1228 | default: never executed: default: | 0 | ||||||||||||||||||
1229 | return (-1); never executed: return (-1); | 0 | ||||||||||||||||||
1230 | } | - | ||||||||||||||||||
1231 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |