| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/t1_hash.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* $OpenBSD: t1_hash.c,v 1.3 2018/09/05 16:58:59 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 "ssl_locl.h" | - | ||||||
| 19 | - | |||||||
| 20 | #include <openssl/ssl.h> | - | ||||||
| 21 | - | |||||||
| 22 | int | - | ||||||
| 23 | tls1_handshake_hash_init(SSL *s) | - | ||||||
| 24 | { | - | ||||||
| 25 | const EVP_MD *md; | - | ||||||
| 26 | long dlen; | - | ||||||
| 27 | void *data; | - | ||||||
| 28 | - | |||||||
| 29 | tls1_handshake_hash_free(s); | - | ||||||
| 30 | - | |||||||
| 31 | if (!ssl_get_handshake_evp_md(s, &md)) {
| 0-128 | ||||||
| 32 | SSLerrorx(ERR_R_INTERNAL_ERROR); | - | ||||||
| 33 | goto err; never executed: goto err; | 0 | ||||||
| 34 | } | - | ||||||
| 35 | - | |||||||
| 36 | if ((S3I(s)->handshake_hash = EVP_MD_CTX_new()) == NULL) {
| 0-128 | ||||||
| 37 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||
| 38 | goto err; never executed: goto err; | 0 | ||||||
| 39 | } | - | ||||||
| 40 | if (!EVP_DigestInit_ex(S3I(s)->handshake_hash, md, NULL)) {
| 0-128 | ||||||
| 41 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||
| 42 | goto err; never executed: goto err; | 0 | ||||||
| 43 | } | - | ||||||
| 44 | - | |||||||
| 45 | dlen = BIO_get_mem_data(S3I(s)->handshake_buffer, &data); | - | ||||||
| 46 | if (dlen <= 0) {
| 0-128 | ||||||
| 47 | SSLerror(s, SSL_R_BAD_HANDSHAKE_LENGTH); | - | ||||||
| 48 | goto err; never executed: goto err; | 0 | ||||||
| 49 | } | - | ||||||
| 50 | if (!tls1_handshake_hash_update(s, data, dlen)) {
| 0-128 | ||||||
| 51 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||
| 52 | goto err; never executed: goto err; | 0 | ||||||
| 53 | } | - | ||||||
| 54 | - | |||||||
| 55 | return 1; executed 128 times by 3 tests: return 1;Executed by:
| 128 | ||||||
| 56 | - | |||||||
| 57 | err: | - | ||||||
| 58 | tls1_handshake_hash_free(s); | - | ||||||
| 59 | - | |||||||
| 60 | return 0; never executed: return 0; | 0 | ||||||
| 61 | } | - | ||||||
| 62 | - | |||||||
| 63 | int | - | ||||||
| 64 | tls1_handshake_hash_update(SSL *s, const unsigned char *buf, size_t len) | - | ||||||
| 65 | { | - | ||||||
| 66 | if (S3I(s)->handshake_hash == NULL)
| 202-1078 | ||||||
| 67 | return 1; executed 202 times by 4 tests: return 1;Executed by:
| 202 | ||||||
| 68 | - | |||||||
| 69 | return EVP_DigestUpdate(S3I(s)->handshake_hash, buf, len); executed 1078 times by 3 tests: return EVP_DigestUpdate((s->s3->internal)->handshake_hash, buf, len);Executed by:
| 1078 | ||||||
| 70 | } | - | ||||||
| 71 | - | |||||||
| 72 | int | - | ||||||
| 73 | tls1_handshake_hash_value(SSL *s, const unsigned char *out, size_t len, | - | ||||||
| 74 | size_t *outlen) | - | ||||||
| 75 | { | - | ||||||
| 76 | EVP_MD_CTX *mdctx = NULL; | - | ||||||
| 77 | unsigned int mdlen; | - | ||||||
| 78 | int ret = 0; | - | ||||||
| 79 | - | |||||||
| 80 | if (EVP_MD_CTX_size(S3I(s)->handshake_hash) > len)
| 0-387 | ||||||
| 81 | goto err; never executed: goto err; | 0 | ||||||
| 82 | - | |||||||
| 83 | if ((mdctx = EVP_MD_CTX_new()) == NULL) {
| 0-387 | ||||||
| 84 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||
| 85 | goto err; never executed: goto err; | 0 | ||||||
| 86 | } | - | ||||||
| 87 | if (!EVP_MD_CTX_copy_ex(mdctx, S3I(s)->handshake_hash)) {
| 0-387 | ||||||
| 88 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||
| 89 | goto err; never executed: goto err; | 0 | ||||||
| 90 | } | - | ||||||
| 91 | if (!EVP_DigestFinal_ex(mdctx, (unsigned char *)out, &mdlen)) {
| 0-387 | ||||||
| 92 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||
| 93 | goto err; never executed: goto err; | 0 | ||||||
| 94 | } | - | ||||||
| 95 | if (outlen != NULL)
| 31-356 | ||||||
| 96 | *outlen = mdlen; executed 356 times by 2 tests: *outlen = mdlen;Executed by:
| 356 | ||||||
| 97 | - | |||||||
| 98 | ret = 1; | - | ||||||
| 99 | - | |||||||
| 100 | err: code before this statement executed 387 times by 2 tests: err:Executed by:
| 387 | ||||||
| 101 | EVP_MD_CTX_free(mdctx); | - | ||||||
| 102 | - | |||||||
| 103 | return (ret); executed 387 times by 2 tests: return (ret);Executed by:
| 387 | ||||||
| 104 | } | - | ||||||
| 105 | - | |||||||
| 106 | void | - | ||||||
| 107 | tls1_handshake_hash_free(SSL *s) | - | ||||||
| 108 | { | - | ||||||
| 109 | EVP_MD_CTX_free(S3I(s)->handshake_hash); | - | ||||||
| 110 | S3I(s)->handshake_hash = NULL; | - | ||||||
| 111 | } executed 1068 times by 11 tests: end of blockExecuted by:
| 1068 | ||||||
| Source code | Switch to Preprocessed file |