| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/s3_cbc.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | static unsigned | - | ||||||||||||
| 3 | constant_time_lt(unsigned a, unsigned b) | - | ||||||||||||
| 4 | { | - | ||||||||||||
| 5 | a -= b; | - | ||||||||||||
| 6 | return executed 29976 times by 1 test: ((unsigned)((int)(a) >> (sizeof(int) * 8 - 1)));return ((unsigned)((int)(a) >> (sizeof(int) * 8 - 1)));Executed by:
executed 29976 times by 1 test: return ((unsigned)((int)(a) >> (sizeof(int) * 8 - 1)));Executed by:
| 29976 | ||||||||||||
| 7 | } | - | ||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | static unsigned | - | ||||||||||||
| 11 | constant_time_ge(unsigned a, unsigned b) | - | ||||||||||||
| 12 | { | - | ||||||||||||
| 13 | a -= b; | - | ||||||||||||
| 14 | return executed 243952 times by 1 test: ((unsigned)((int)(~a) >> (sizeof(int) * 8 - 1)));return ((unsigned)((int)(~a) >> (sizeof(int) * 8 - 1)));Executed by:
executed 243952 times by 1 test: return ((unsigned)((int)(~a) >> (sizeof(int) * 8 - 1)));Executed by:
| 243952 | ||||||||||||
| 15 | } | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | - | |||||||||||||
| 18 | static unsigned char | - | ||||||||||||
| 19 | constant_time_eq_8(unsigned a, unsigned b) | - | ||||||||||||
| 20 | { | - | ||||||||||||
| 21 | unsigned c = a ^ b; | - | ||||||||||||
| 22 | c--; | - | ||||||||||||
| 23 | return executed 2576 times by 1 test: ((unsigned char)(((unsigned)((int)(c) >> (sizeof(int) * 8 - 1)))));return ((unsigned char)(((unsigned)((int)(c) >> (sizeof(int) * 8 - 1)))));Executed by:
executed 2576 times by 1 test: return ((unsigned char)(((unsigned)((int)(c) >> (sizeof(int) * 8 - 1)))));Executed by:
| 2576 | ||||||||||||
| 24 | } | - | ||||||||||||
| 25 | int | - | ||||||||||||
| 26 | tls1_cbc_remove_padding(const SSL* s, SSL3_RECORD *rec, unsigned block_size, | - | ||||||||||||
| 27 | unsigned mac_size) | - | ||||||||||||
| 28 | { | - | ||||||||||||
| 29 | unsigned padding_length, good, to_check, i; | - | ||||||||||||
| 30 | const unsigned overhead = 1 + mac_size; | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | - | |||||||||||||
| 33 | if ((
| 76-108 | ||||||||||||
| 34 | - | |||||||||||||
| 35 | - | |||||||||||||
| 36 | - | |||||||||||||
| 37 | if (overhead + block_size > rec->length
| 0-76 | ||||||||||||
| 38 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 39 | - | |||||||||||||
| 40 | rec->data += block_size; | - | ||||||||||||
| 41 | rec->input += block_size; | - | ||||||||||||
| 42 | rec->length -= block_size; | - | ||||||||||||
| 43 | } executed 76 times by 1 test: else if (overhead > rec->lengthend of blockExecuted by:
| 0-108 | ||||||||||||
| 44 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 45 | - | |||||||||||||
| 46 | padding_length = rec->data[rec->length - 1]; | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | good = constant_time_ge(rec->length, overhead + padding_length); | - | ||||||||||||
| 49 | to_check = 255; | - | ||||||||||||
| 50 | if (to_check > rec->length - 1
| 74-110 | ||||||||||||
| 51 | to_check = rec->length - 1; executed 110 times by 1 test: to_check = rec->length - 1;Executed by:
| 110 | ||||||||||||
| 52 | - | |||||||||||||
| 53 | for (i = 0; i < to_check
| 184-23816 | ||||||||||||
| 54 | unsigned char mask = constant_time_ge(padding_length, i); | - | ||||||||||||
| 55 | unsigned char b = rec->data[rec->length - 1 - i]; | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | - | |||||||||||||
| 58 | good &= ~(mask&(padding_length ^ b)); | - | ||||||||||||
| 59 | } executed 23816 times by 1 test: end of blockExecuted by:
| 23816 | ||||||||||||
| 60 | - | |||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | - | |||||||||||||
| 64 | - | |||||||||||||
| 65 | good &= good >> 4; | - | ||||||||||||
| 66 | good &= good >> 2; | - | ||||||||||||
| 67 | good &= good >> 1; | - | ||||||||||||
| 68 | good <<= sizeof(good)*8 - 1; | - | ||||||||||||
| 69 | good = ((unsigned)((int)(good) >> (sizeof(int) * 8 - 1))); | - | ||||||||||||
| 70 | - | |||||||||||||
| 71 | padding_length = good & (padding_length + 1); | - | ||||||||||||
| 72 | rec->length -= padding_length; | - | ||||||||||||
| 73 | rec->type |= padding_length<<8; | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | return executed 184 times by 1 test: (int)((good & 1) | (~good & -1));return (int)((good & 1) | (~good & -1));Executed by:
executed 184 times by 1 test: return (int)((good & 1) | (~good & -1));Executed by:
| 184 | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | void | - | ||||||||||||
| 78 | ssl3_cbc_copy_mac(unsigned char* out, const SSL3_RECORD *rec, | - | ||||||||||||
| 79 | unsigned md_size, unsigned orig_len) | - | ||||||||||||
| 80 | { | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | unsigned char rotated_mac_buf[64 + 64]; | - | ||||||||||||
| 83 | unsigned char *rotated_mac; | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | - | |||||||||||||
| 86 | - | |||||||||||||
| 87 | - | |||||||||||||
| 88 | - | |||||||||||||
| 89 | unsigned mac_end = rec->length; | - | ||||||||||||
| 90 | unsigned mac_start = mac_end - md_size; | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | - | |||||||||||||
| 93 | unsigned scan_start = 0; | - | ||||||||||||
| 94 | unsigned i, j; | - | ||||||||||||
| 95 | unsigned div_spoiler; | - | ||||||||||||
| 96 | unsigned rotate_offset; | - | ||||||||||||
| 97 | - | |||||||||||||
| 98 | (void)((orig_len >= md_size) ? 0 : (OpenSSLDie(__FILE__, 217, "orig_len >= md_size"),1)); | - | ||||||||||||
| 99 | (void)((md_size <= 64) ? 0 : (OpenSSLDie(__FILE__, 218, "md_size <= EVP_MAX_MD_SIZE"),1)); | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | - | |||||||||||||
| 102 | rotated_mac = rotated_mac_buf + ((0 - (size_t)rotated_mac_buf)&63); | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | - | |||||||||||||
| 105 | - | |||||||||||||
| 106 | if (orig_len > md_size + 255 + 1
| 74-110 | ||||||||||||
| 107 | scan_start = orig_len - (md_size + 255 + 1); executed 74 times by 1 test: scan_start = orig_len - (md_size + 255 + 1);Executed by:
| 74 | ||||||||||||
| 108 | - | |||||||||||||
| 109 | - | |||||||||||||
| 110 | - | |||||||||||||
| 111 | - | |||||||||||||
| 112 | - | |||||||||||||
| 113 | - | |||||||||||||
| 114 | - | |||||||||||||
| 115 | div_spoiler = md_size >> 1; | - | ||||||||||||
| 116 | div_spoiler <<= (sizeof(div_spoiler) - 1) * 8; | - | ||||||||||||
| 117 | rotate_offset = (div_spoiler + mac_start - scan_start) % md_size; | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | memset(rotated_mac, 0, md_size); | - | ||||||||||||
| 120 | for (i = scan_start, j = 0; i < orig_len
| 184-25752 | ||||||||||||
| 121 | unsigned char mac_started = constant_time_ge(i, mac_start); | - | ||||||||||||
| 122 | unsigned char mac_ended = constant_time_ge(i, mac_end); | - | ||||||||||||
| 123 | unsigned char b = rec->data[i]; | - | ||||||||||||
| 124 | rotated_mac[j++] |= b & mac_started & ~mac_ended; | - | ||||||||||||
| 125 | j &= constant_time_lt(j, md_size); | - | ||||||||||||
| 126 | } executed 25752 times by 1 test: end of blockExecuted by:
| 25752 | ||||||||||||
| 127 | - | |||||||||||||
| 128 | - | |||||||||||||
| 129 | - | |||||||||||||
| 130 | j = 0; | - | ||||||||||||
| 131 | for (i = 0; i < md_size
| 184-4224 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | ((volatile unsigned char *)rotated_mac)[rotate_offset^32]; | - | ||||||||||||
| 134 | out[j++] = rotated_mac[rotate_offset++]; | - | ||||||||||||
| 135 | rotate_offset &= constant_time_lt(rotate_offset, md_size); | - | ||||||||||||
| 136 | } executed 4224 times by 1 test: end of blockExecuted by:
| 4224 | ||||||||||||
| 137 | } executed 184 times by 1 test: end of blockExecuted by:
| 184 | ||||||||||||
| 138 | static void | - | ||||||||||||
| 139 | tls1_md5_final_raw(void* ctx, unsigned char *md_out) | - | ||||||||||||
| 140 | { | - | ||||||||||||
| 141 | MD5_CTX *md5 = ctx; | - | ||||||||||||
| 142 | (*((md_out)++)=(unsigned char)(md5->A), *((md_out)++)=(unsigned char)(md5->A>>8), *((md_out)++)=(unsigned char)(md5->A>>16), *((md_out)++)=(unsigned char)(md5->A>>24)); | - | ||||||||||||
| 143 | (*((md_out)++)=(unsigned char)(md5->B), *((md_out)++)=(unsigned char)(md5->B>>8), *((md_out)++)=(unsigned char)(md5->B>>16), *((md_out)++)=(unsigned char)(md5->B>>24)); | - | ||||||||||||
| 144 | (*((md_out)++)=(unsigned char)(md5->C), *((md_out)++)=(unsigned char)(md5->C>>8), *((md_out)++)=(unsigned char)(md5->C>>16), *((md_out)++)=(unsigned char)(md5->C>>24)); | - | ||||||||||||
| 145 | (*((md_out)++)=(unsigned char)(md5->D), *((md_out)++)=(unsigned char)(md5->D>>8), *((md_out)++)=(unsigned char)(md5->D>>16), *((md_out)++)=(unsigned char)(md5->D>>24)); | - | ||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||
| 147 | - | |||||||||||||
| 148 | static void | - | ||||||||||||
| 149 | tls1_sha1_final_raw(void* ctx, unsigned char *md_out) | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | SHA_CTX *sha1 = ctx; | - | ||||||||||||
| 152 | (*((md_out)++)=(unsigned char)(((sha1->h0)>>24)&0xff), *((md_out)++)=(unsigned char)(((sha1->h0)>>16)&0xff), *((md_out)++)=(unsigned char)(((sha1->h0)>> 8)&0xff), *((md_out)++)=(unsigned char)(((sha1->h0) )&0xff)); | - | ||||||||||||
| 153 | (*((md_out)++)=(unsigned char)(((sha1->h1)>>24)&0xff), *((md_out)++)=(unsigned char)(((sha1->h1)>>16)&0xff), *((md_out)++)=(unsigned char)(((sha1->h1)>> 8)&0xff), *((md_out)++)=(unsigned char)(((sha1->h1) )&0xff)); | - | ||||||||||||
| 154 | (*((md_out)++)=(unsigned char)(((sha1->h2)>>24)&0xff), *((md_out)++)=(unsigned char)(((sha1->h2)>>16)&0xff), *((md_out)++)=(unsigned char)(((sha1->h2)>> 8)&0xff), *((md_out)++)=(unsigned char)(((sha1->h2) )&0xff)); | - | ||||||||||||
| 155 | (*((md_out)++)=(unsigned char)(((sha1->h3)>>24)&0xff), *((md_out)++)=(unsigned char)(((sha1->h3)>>16)&0xff), *((md_out)++)=(unsigned char)(((sha1->h3)>> 8)&0xff), *((md_out)++)=(unsigned char)(((sha1->h3) )&0xff)); | - | ||||||||||||
| 156 | (*((md_out)++)=(unsigned char)(((sha1->h4)>>24)&0xff), *((md_out)++)=(unsigned char)(((sha1->h4)>>16)&0xff), *((md_out)++)=(unsigned char)(((sha1->h4)>> 8)&0xff), *((md_out)++)=(unsigned char)(((sha1->h4) )&0xff)); | - | ||||||||||||
| 157 | } executed 1008 times by 1 test: end of blockExecuted by:
| 1008 | ||||||||||||
| 158 | - | |||||||||||||
| 159 | static void | - | ||||||||||||
| 160 | tls1_sha256_final_raw(void* ctx, unsigned char *md_out) | - | ||||||||||||
| 161 | { | - | ||||||||||||
| 162 | SHA256_CTX *sha256 = ctx; | - | ||||||||||||
| 163 | unsigned i; | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | for (i = 0; i < 8
| 252-2016 | ||||||||||||
| 166 | (*((md_out)++)=(unsigned char)(((sha256->h[i])>>24)&0xff), *((md_out)++)=(unsigned char)(((sha256->h[i])>>16)&0xff), *((md_out)++)=(unsigned char)(((sha256->h[i])>> 8)&0xff), *((md_out)++)=(unsigned char)(((sha256->h[i]) )&0xff)); | - | ||||||||||||
| 167 | } executed 2016 times by 1 test: end of blockExecuted by:
| 2016 | ||||||||||||
| 168 | } executed 252 times by 1 test: end of blockExecuted by:
| 252 | ||||||||||||
| 169 | - | |||||||||||||
| 170 | static void | - | ||||||||||||
| 171 | tls1_sha512_final_raw(void* ctx, unsigned char *md_out) | - | ||||||||||||
| 172 | { | - | ||||||||||||
| 173 | SHA512_CTX *sha512 = ctx; | - | ||||||||||||
| 174 | unsigned i; | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | for (i = 0; i < 8
| 28-224 | ||||||||||||
| 177 | (*((md_out)++)=(unsigned char)(((sha512->h[i])>>56)&0xff), *((md_out)++)=(unsigned char)(((sha512->h[i])>>48)&0xff), *((md_out)++)=(unsigned char)(((sha512->h[i])>>40)&0xff), *((md_out)++)=(unsigned char)(((sha512->h[i])>>32)&0xff), *((md_out)++)=(unsigned char)(((sha512->h[i])>>24)&0xff), *((md_out)++)=(unsigned char)(((sha512->h[i])>>16)&0xff), *((md_out)++)=(unsigned char)(((sha512->h[i])>> 8)&0xff), *((md_out)++)=(unsigned char)(((sha512->h[i]) )&0xff)); | - | ||||||||||||
| 178 | } executed 224 times by 1 test: end of blockExecuted by:
| 224 | ||||||||||||
| 179 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||
| 180 | char | - | ||||||||||||
| 181 | ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx) | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | switch (EVP_MD_type(EVP_MD_CTX_md(ctx))) { | - | ||||||||||||
| 184 | case never executed: 4:case 4:never executed: case 4: | 0 | ||||||||||||
| 185 | case executed 144 times by 1 test: 64:case 64:Executed by:
executed 144 times by 1 test: case 64:Executed by:
| 144 | ||||||||||||
| 186 | case never executed: 675:case 675:never executed: case 675: | 0 | ||||||||||||
| 187 | case executed 36 times by 1 test: 672:case 672:Executed by:
executed 36 times by 1 test: case 672:Executed by:
| 36 | ||||||||||||
| 188 | case executed 4 times by 1 test: 673:case 673:Executed by:
executed 4 times by 1 test: case 673:Executed by:
| 4 | ||||||||||||
| 189 | case never executed: 674:case 674:never executed: case 674: | 0 | ||||||||||||
| 190 | return executed 184 times by 1 test: 1;return 1;Executed by:
executed 184 times by 1 test: return 1;Executed by:
| 184 | ||||||||||||
| 191 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 192 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 193 | } | - | ||||||||||||
| 194 | } | - | ||||||||||||
| 195 | int | - | ||||||||||||
| 196 | ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char* md_out, | - | ||||||||||||
| 197 | size_t* md_out_size, const unsigned char header[13], | - | ||||||||||||
| 198 | const unsigned char *data, size_t data_plus_mac_size, | - | ||||||||||||
| 199 | size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret, | - | ||||||||||||
| 200 | unsigned mac_secret_length) | - | ||||||||||||
| 201 | { | - | ||||||||||||
| 202 | union { | - | ||||||||||||
| 203 | - | |||||||||||||
| 204 | - | |||||||||||||
| 205 | - | |||||||||||||
| 206 | - | |||||||||||||
| 207 | - | |||||||||||||
| 208 | unsigned long align; | - | ||||||||||||
| 209 | unsigned char c[sizeof(SHA512_CTX)]; | - | ||||||||||||
| 210 | } md_state; | - | ||||||||||||
| 211 | void (*md_final_raw)(void *ctx, unsigned char *md_out); | - | ||||||||||||
| 212 | void (*md_transform)(void *ctx, const unsigned char *block); | - | ||||||||||||
| 213 | unsigned md_size, md_block_size = 64; | - | ||||||||||||
| 214 | unsigned header_length, variance_blocks, | - | ||||||||||||
| 215 | len, max_mac_bytes, num_blocks, | - | ||||||||||||
| 216 | num_starting_blocks, k, mac_end_offset, c, index_a, index_b; | - | ||||||||||||
| 217 | unsigned int bits; | - | ||||||||||||
| 218 | unsigned char length_bytes[16]; | - | ||||||||||||
| 219 | - | |||||||||||||
| 220 | unsigned char hmac_pad[128]; | - | ||||||||||||
| 221 | unsigned char first_block[128]; | - | ||||||||||||
| 222 | unsigned char mac_out[64]; | - | ||||||||||||
| 223 | unsigned i, j, md_out_size_u; | - | ||||||||||||
| 224 | EVP_MD_CTX md_ctx; | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | - | |||||||||||||
| 227 | unsigned md_length_size = 8; | - | ||||||||||||
| 228 | char length_is_big_endian = 1; | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | - | |||||||||||||
| 231 | - | |||||||||||||
| 232 | (void)((data_plus_mac_plus_padding_size < 1024*1024) ? 0 : (OpenSSLDie(__FILE__, 403, "data_plus_mac_plus_padding_size < 1024*1024"),1)); | - | ||||||||||||
| 233 | - | |||||||||||||
| 234 | switch (EVP_MD_type(EVP_MD_CTX_md(ctx))) { | - | ||||||||||||
| 235 | case never executed: 4:case 4:never executed: case 4: | 0 | ||||||||||||
| 236 | MD5_Init((MD5_CTX*)md_state.c); | - | ||||||||||||
| 237 | md_final_raw = tls1_md5_final_raw; | - | ||||||||||||
| 238 | md_transform = (void(*)(void *ctx, const unsigned char *block)) MD5_Transform; | - | ||||||||||||
| 239 | md_size = 16; | - | ||||||||||||
| 240 | length_is_big_endian = 0; | - | ||||||||||||
| 241 | break; never executed: break; | 0 | ||||||||||||
| 242 | case executed 144 times by 1 test: 64:case 64:Executed by:
executed 144 times by 1 test: case 64:Executed by:
| 144 | ||||||||||||
| 243 | SHA1_Init((SHA_CTX*)md_state.c); | - | ||||||||||||
| 244 | md_final_raw = tls1_sha1_final_raw; | - | ||||||||||||
| 245 | md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA1_Transform; | - | ||||||||||||
| 246 | md_size = 20; | - | ||||||||||||
| 247 | break; executed 144 times by 1 test: break;Executed by:
| 144 | ||||||||||||
| 248 | case never executed: 675:case 675:never executed: case 675: | 0 | ||||||||||||
| 249 | SHA224_Init((SHA256_CTX*)md_state.c); | - | ||||||||||||
| 250 | md_final_raw = tls1_sha256_final_raw; | - | ||||||||||||
| 251 | md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform; | - | ||||||||||||
| 252 | md_size = 224/8; | - | ||||||||||||
| 253 | break; never executed: break; | 0 | ||||||||||||
| 254 | case executed 36 times by 1 test: 672:case 672:Executed by:
executed 36 times by 1 test: case 672:Executed by:
| 36 | ||||||||||||
| 255 | SHA256_Init((SHA256_CTX*)md_state.c); | - | ||||||||||||
| 256 | md_final_raw = tls1_sha256_final_raw; | - | ||||||||||||
| 257 | md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform; | - | ||||||||||||
| 258 | md_size = 32; | - | ||||||||||||
| 259 | break; executed 36 times by 1 test: break;Executed by:
| 36 | ||||||||||||
| 260 | case executed 4 times by 1 test: 673:case 673:Executed by:
executed 4 times by 1 test: case 673:Executed by:
| 4 | ||||||||||||
| 261 | SHA384_Init((SHA512_CTX*)md_state.c); | - | ||||||||||||
| 262 | md_final_raw = tls1_sha512_final_raw; | - | ||||||||||||
| 263 | md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform; | - | ||||||||||||
| 264 | md_size = 384/8; | - | ||||||||||||
| 265 | md_block_size = 128; | - | ||||||||||||
| 266 | md_length_size = 16; | - | ||||||||||||
| 267 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||
| 268 | case never executed: 674:case 674:never executed: case 674: | 0 | ||||||||||||
| 269 | SHA512_Init((SHA512_CTX*)md_state.c); | - | ||||||||||||
| 270 | md_final_raw = tls1_sha512_final_raw; | - | ||||||||||||
| 271 | md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform; | - | ||||||||||||
| 272 | md_size = 64; | - | ||||||||||||
| 273 | md_block_size = 128; | - | ||||||||||||
| 274 | md_length_size = 16; | - | ||||||||||||
| 275 | break; never executed: break; | 0 | ||||||||||||
| 276 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 277 | - | |||||||||||||
| 278 | - | |||||||||||||
| 279 | - | |||||||||||||
| 280 | (void)((0) ? 0 : (OpenSSLDie(__FILE__, 451, "0"),1)); | - | ||||||||||||
| 281 | if (md_out_size
| 0 | ||||||||||||
| 282 | * never executed: md_out_size = 0;*md_out_size = 0;never executed: *md_out_size = 0; | 0 | ||||||||||||
| 283 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 284 | } | - | ||||||||||||
| 285 | - | |||||||||||||
| 286 | (void)((md_length_size <= 16) ? 0 : (OpenSSLDie(__FILE__, 457, "md_length_size <= MAX_HASH_BIT_COUNT_BYTES"),1)); | - | ||||||||||||
| 287 | (void)((md_block_size <= 128) ? 0 : (OpenSSLDie(__FILE__, 458, "md_block_size <= MAX_HASH_BLOCK_SIZE"),1)); | - | ||||||||||||
| 288 | (void)((md_size <= 64) ? 0 : (OpenSSLDie(__FILE__, 459, "md_size <= EVP_MAX_MD_SIZE"),1)); | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | header_length = 13; | - | ||||||||||||
| 291 | variance_blocks = 6; | - | ||||||||||||
| 292 | - | |||||||||||||
| 293 | - | |||||||||||||
| 294 | len = data_plus_mac_plus_padding_size + header_length; | - | ||||||||||||
| 295 | - | |||||||||||||
| 296 | - | |||||||||||||
| 297 | max_mac_bytes = len - md_size - 1; | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | num_blocks = (max_mac_bytes + 1 + md_length_size + md_block_size - 1) / md_block_size; | - | ||||||||||||
| 300 | - | |||||||||||||
| 301 | - | |||||||||||||
| 302 | - | |||||||||||||
| 303 | - | |||||||||||||
| 304 | - | |||||||||||||
| 305 | - | |||||||||||||
| 306 | num_starting_blocks = 0; | - | ||||||||||||
| 307 | - | |||||||||||||
| 308 | - | |||||||||||||
| 309 | k = 0; | - | ||||||||||||
| 310 | - | |||||||||||||
| 311 | - | |||||||||||||
| 312 | mac_end_offset = data_plus_mac_size + header_length - md_size; | - | ||||||||||||
| 313 | - | |||||||||||||
| 314 | - | |||||||||||||
| 315 | c = mac_end_offset % md_block_size; | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | - | |||||||||||||
| 318 | index_a = mac_end_offset / md_block_size; | - | ||||||||||||
| 319 | - | |||||||||||||
| 320 | - | |||||||||||||
| 321 | index_b = (mac_end_offset + md_length_size) / md_block_size; | - | ||||||||||||
| 322 | - | |||||||||||||
| 323 | - | |||||||||||||
| 324 | - | |||||||||||||
| 325 | if (num_blocks > variance_blocks
| 0-184 | ||||||||||||
| 326 | num_starting_blocks = num_blocks - variance_blocks; | - | ||||||||||||
| 327 | k = md_block_size*num_starting_blocks; | - | ||||||||||||
| 328 | } never executed: end of block | 0 | ||||||||||||
| 329 | - | |||||||||||||
| 330 | bits = 8*mac_end_offset; | - | ||||||||||||
| 331 | - | |||||||||||||
| 332 | bits += 8*md_block_size; | - | ||||||||||||
| 333 | memset(hmac_pad, 0, md_block_size); | - | ||||||||||||
| 334 | (void)((mac_secret_length <= sizeof(hmac_pad)) ? 0 : (OpenSSLDie(__FILE__, 516, "mac_secret_length <= sizeof(hmac_pad)"),1)); | - | ||||||||||||
| 335 | memcpy(hmac_pad, mac_secret, mac_secret_length); | - | ||||||||||||
| 336 | for (i = 0; i < md_block_size
| 184-12032 | ||||||||||||
| 337 | hmac_pad[i] ^= 0x36; executed 12032 times by 1 test: hmac_pad[i] ^= 0x36;Executed by:
| 12032 | ||||||||||||
| 338 | - | |||||||||||||
| 339 | md_transform(md_state.c, hmac_pad); | - | ||||||||||||
| 340 | - | |||||||||||||
| 341 | if (length_is_big_endian
| 0-184 | ||||||||||||
| 342 | memset(length_bytes, 0, md_length_size - 4); | - | ||||||||||||
| 343 | length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24); | - | ||||||||||||
| 344 | length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16); | - | ||||||||||||
| 345 | length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8); | - | ||||||||||||
| 346 | length_bytes[md_length_size - 1] = (unsigned char)bits; | - | ||||||||||||
| 347 | } executed 184 times by 1 test: else {end of blockExecuted by:
| 184 | ||||||||||||
| 348 | memset(length_bytes, 0, md_length_size); | - | ||||||||||||
| 349 | length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24); | - | ||||||||||||
| 350 | length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16); | - | ||||||||||||
| 351 | length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8); | - | ||||||||||||
| 352 | length_bytes[md_length_size - 8] = (unsigned char)bits; | - | ||||||||||||
| 353 | } never executed: end of block | 0 | ||||||||||||
| 354 | - | |||||||||||||
| 355 | if (k > 0
| 0-184 | ||||||||||||
| 356 | - | |||||||||||||
| 357 | memcpy(first_block, header, 13); | - | ||||||||||||
| 358 | memcpy(first_block + 13, data, md_block_size - 13); | - | ||||||||||||
| 359 | md_transform(md_state.c, first_block); | - | ||||||||||||
| 360 | for (i = 1; i < k/md_block_size
| 0 | ||||||||||||
| 361 | md_transform(md_state.c, data + md_block_size*i - 13); never executed: md_transform(md_state.c, data + md_block_size*i - 13); | 0 | ||||||||||||
| 362 | } never executed: end of block | 0 | ||||||||||||
| 363 | - | |||||||||||||
| 364 | memset(mac_out, 0, sizeof(mac_out)); | - | ||||||||||||
| 365 | - | |||||||||||||
| 366 | - | |||||||||||||
| 367 | - | |||||||||||||
| 368 | - | |||||||||||||
| 369 | - | |||||||||||||
| 370 | for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks
| 184-1288 | ||||||||||||
| 371 | unsigned char block[128]; | - | ||||||||||||
| 372 | unsigned char is_block_a = constant_time_eq_8(i, index_a); | - | ||||||||||||
| 373 | unsigned char is_block_b = constant_time_eq_8(i, index_b); | - | ||||||||||||
| 374 | for (j = 0; j < md_block_size
| 1288-84224 | ||||||||||||
| 375 | unsigned char b = 0, is_past_c, is_past_cp1; | - | ||||||||||||
| 376 | if (k < header_length
| 2392-81832 | ||||||||||||
| 377 | b = header[k]; executed 2392 times by 1 test: b = header[k];Executed by:
| 2392 | ||||||||||||
| 378 | else if (k < data_plus_mac_plus_padding_size + header_length
| 26704-55128 | ||||||||||||
| 379 | b = data[k - header_length]; executed 26704 times by 1 test: b = data[k - header_length];Executed by:
| 26704 | ||||||||||||
| 380 | k++; | - | ||||||||||||
| 381 | - | |||||||||||||
| 382 | is_past_c = is_block_a & constant_time_ge(j, c); | - | ||||||||||||
| 383 | is_past_cp1 = is_block_a & constant_time_ge(j, c + 1); | - | ||||||||||||
| 384 | - | |||||||||||||
| 385 | - | |||||||||||||
| 386 | - | |||||||||||||
| 387 | b = (b&~is_past_c) | (0x80&is_past_c); | - | ||||||||||||
| 388 | - | |||||||||||||
| 389 | - | |||||||||||||
| 390 | - | |||||||||||||
| 391 | b = b&~is_past_cp1; | - | ||||||||||||
| 392 | - | |||||||||||||
| 393 | - | |||||||||||||
| 394 | - | |||||||||||||
| 395 | - | |||||||||||||
| 396 | b &= ~is_block_b | is_block_a; | - | ||||||||||||
| 397 | - | |||||||||||||
| 398 | - | |||||||||||||
| 399 | - | |||||||||||||
| 400 | if (j >= md_block_size - md_length_size
| 10528-73696 | ||||||||||||
| 401 | - | |||||||||||||
| 402 | b = (b&~is_block_b) | (is_block_b&length_bytes[j - (md_block_size - md_length_size)]); | - | ||||||||||||
| 403 | } executed 10528 times by 1 test: end of blockExecuted by:
| 10528 | ||||||||||||
| 404 | block[j] = b; | - | ||||||||||||
| 405 | } executed 84224 times by 1 test: end of blockExecuted by:
| 84224 | ||||||||||||
| 406 | - | |||||||||||||
| 407 | md_transform(md_state.c, block); | - | ||||||||||||
| 408 | md_final_raw(md_state.c, block); | - | ||||||||||||
| 409 | - | |||||||||||||
| 410 | for (j = 0; j < md_size
| 1288-29568 | ||||||||||||
| 411 | mac_out[j] |= block[j]&is_block_b; executed 29568 times by 1 test: mac_out[j] |= block[j]&is_block_b;Executed by:
| 29568 | ||||||||||||
| 412 | } executed 1288 times by 1 test: end of blockExecuted by:
| 1288 | ||||||||||||
| 413 | - | |||||||||||||
| 414 | EVP_MD_CTX_init(&md_ctx); | - | ||||||||||||
| 415 | if (!EVP_DigestInit_ex(&md_ctx, ctx->digest,
| 0-184 | ||||||||||||
| 416 | ((void *)0)
| 0-184 | ||||||||||||
| 417 | )
| 0-184 | ||||||||||||
| 418 | EVP_MD_CTX_cleanup(&md_ctx); | - | ||||||||||||
| 419 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 420 | } | - | ||||||||||||
| 421 | - | |||||||||||||
| 422 | - | |||||||||||||
| 423 | for (i = 0; i < md_block_size
| 184-12032 | ||||||||||||
| 424 | hmac_pad[i] ^= 0x6a; executed 12032 times by 1 test: hmac_pad[i] ^= 0x6a;Executed by:
| 12032 | ||||||||||||
| 425 | - | |||||||||||||
| 426 | EVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size); | - | ||||||||||||
| 427 | EVP_DigestUpdate(&md_ctx, mac_out, md_size); | - | ||||||||||||
| 428 | - | |||||||||||||
| 429 | EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u); | - | ||||||||||||
| 430 | if (md_out_size
| 0-184 | ||||||||||||
| 431 | * executed 184 times by 1 test: md_out_size = md_out_size_u;*md_out_size = md_out_size_u;Executed by:
executed 184 times by 1 test: *md_out_size = md_out_size_u;Executed by:
| 184 | ||||||||||||
| 432 | EVP_MD_CTX_cleanup(&md_ctx); | - | ||||||||||||
| 433 | - | |||||||||||||
| 434 | return executed 184 times by 1 test: 1;return 1;Executed by:
executed 184 times by 1 test: return 1;Executed by:
| 184 | ||||||||||||
| 435 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |