| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/e_rc4_hmac_md5.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | typedef struct { | - | ||||||||||||
| 11 | RC4_KEY ks; | - | ||||||||||||
| 12 | MD5_CTX head, tail, md; | - | ||||||||||||
| 13 | size_t payload_length; | - | ||||||||||||
| 14 | } EVP_RC4_HMAC_MD5; | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | - | |||||||||||||
| 17 | - | |||||||||||||
| 18 | void rc4_md5_enc (RC4_KEY *key, const void *in0, void *out, | - | ||||||||||||
| 19 | MD5_CTX *ctx, const void *inp, size_t blocks); | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | - | |||||||||||||
| 22 | - | |||||||||||||
| 23 | static int | - | ||||||||||||
| 24 | rc4_hmac_md5_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *inkey, | - | ||||||||||||
| 25 | const unsigned char *iv, int enc) | - | ||||||||||||
| 26 | { | - | ||||||||||||
| 27 | EVP_RC4_HMAC_MD5 *key = ((EVP_RC4_HMAC_MD5 *)(ctx)->cipher_data); | - | ||||||||||||
| 28 | - | |||||||||||||
| 29 | RC4_set_key(&key->ks, EVP_CIPHER_CTX_key_length(ctx), inkey); | - | ||||||||||||
| 30 | - | |||||||||||||
| 31 | MD5_Init(&key->head); | - | ||||||||||||
| 32 | key->tail = key->head; | - | ||||||||||||
| 33 | key->md = key->head; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | key->payload_length = ((size_t)-1); | - | ||||||||||||
| 36 | - | |||||||||||||
| 37 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||
| 38 | } | - | ||||||||||||
| 39 | static int | - | ||||||||||||
| 40 | rc4_hmac_md5_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
| 41 | const unsigned char *in, size_t len) | - | ||||||||||||
| 42 | { | - | ||||||||||||
| 43 | EVP_RC4_HMAC_MD5 *key = ((EVP_RC4_HMAC_MD5 *)(ctx)->cipher_data); | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | - | |||||||||||||
| 46 | - | |||||||||||||
| 47 | - | |||||||||||||
| 48 | - | |||||||||||||
| 49 | - | |||||||||||||
| 50 | size_t plen = key->payload_length; | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | if (plen != ((size_t)-1)
| 0 | ||||||||||||
| 53 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 54 | - | |||||||||||||
| 55 | if (ctx->encrypt
| 0 | ||||||||||||
| 56 | if (plen == ((size_t)-1)
| 0 | ||||||||||||
| 57 | plen = len; never executed: plen = len; | 0 | ||||||||||||
| 58 | MD5_Update(&key->md, in + 0, plen - 0); | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | if (plen!=len
| 0 | ||||||||||||
| 61 | if (in != out
| 0 | ||||||||||||
| 62 | memcpy(out + 0, in + 0, never executed: memcpy(out + 0, in + 0, plen - 0); | 0 | ||||||||||||
| 63 | plen - 0); never executed: memcpy(out + 0, in + 0, plen - 0); | 0 | ||||||||||||
| 64 | - | |||||||||||||
| 65 | - | |||||||||||||
| 66 | MD5_Final(out + plen, &key->md); | - | ||||||||||||
| 67 | key->md = key->tail; | - | ||||||||||||
| 68 | MD5_Update(&key->md, out + plen, 16); | - | ||||||||||||
| 69 | MD5_Final(out + plen, &key->md); | - | ||||||||||||
| 70 | - | |||||||||||||
| 71 | - | |||||||||||||
| 72 | RC4(&key->ks, len - 0, out + 0, | - | ||||||||||||
| 73 | out + 0); | - | ||||||||||||
| 74 | } never executed: else {end of block | 0 | ||||||||||||
| 75 | RC4(&key->ks, len - 0, in + 0, | - | ||||||||||||
| 76 | out + 0); | - | ||||||||||||
| 77 | } never executed: end of block | 0 | ||||||||||||
| 78 | } else { | - | ||||||||||||
| 79 | unsigned char mac[16]; | - | ||||||||||||
| 80 | RC4(&key->ks, len - 0, in + 0, out + 0); | - | ||||||||||||
| 81 | if (plen!=((size_t)-1)
| 0 | ||||||||||||
| 82 | MD5_Update(&key->md, out + 0, plen - 0); | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | - | |||||||||||||
| 85 | MD5_Final(mac, &key->md); | - | ||||||||||||
| 86 | key->md = key->tail; | - | ||||||||||||
| 87 | MD5_Update(&key->md, mac, 16); | - | ||||||||||||
| 88 | MD5_Final(mac, &key->md); | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | if (memcmp(out + plen, mac, 16)
| 0 | ||||||||||||
| 91 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 92 | } never executed: else {end of block | 0 | ||||||||||||
| 93 | MD5_Update(&key->md, out + 0, len - 0); | - | ||||||||||||
| 94 | } never executed: end of block | 0 | ||||||||||||
| 95 | } | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | key->payload_length = ((size_t)-1); | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||
| 100 | } | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | static int | - | ||||||||||||
| 103 | rc4_hmac_md5_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | EVP_RC4_HMAC_MD5 *key = ((EVP_RC4_HMAC_MD5 *)(ctx)->cipher_data); | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | switch (type) { | - | ||||||||||||
| 108 | case never executed: 0x17:case 0x17:never executed: case 0x17: | 0 | ||||||||||||
| 109 | { | - | ||||||||||||
| 110 | unsigned int i; | - | ||||||||||||
| 111 | unsigned char hmac_key[64]; | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | memset (hmac_key, 0, sizeof(hmac_key)); | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | if (arg > (int)sizeof(hmac_key)
| 0 | ||||||||||||
| 116 | MD5_Init(&key->head); | - | ||||||||||||
| 117 | MD5_Update(&key->head, ptr, arg); | - | ||||||||||||
| 118 | MD5_Final(hmac_key, &key->head); | - | ||||||||||||
| 119 | } never executed: else {end of block | 0 | ||||||||||||
| 120 | memcpy(hmac_key, ptr, arg); | - | ||||||||||||
| 121 | } never executed: end of block | 0 | ||||||||||||
| 122 | - | |||||||||||||
| 123 | for (i = 0; i < sizeof(hmac_key)
| 0 | ||||||||||||
| 124 | hmac_key[i] ^= 0x36; never executed: hmac_key[i] ^= 0x36; | 0 | ||||||||||||
| 125 | MD5_Init(&key->head); | - | ||||||||||||
| 126 | MD5_Update(&key->head, hmac_key, sizeof(hmac_key)); | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | for (i = 0; i < sizeof(hmac_key)
| 0 | ||||||||||||
| 129 | hmac_key[i] ^= 0x36 ^ 0x5c; never executed: hmac_key[i] ^= 0x36 ^ 0x5c; | 0 | ||||||||||||
| 130 | MD5_Init(&key->tail); | - | ||||||||||||
| 131 | MD5_Update(&key->tail, hmac_key, sizeof(hmac_key)); | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||
| 134 | } | - | ||||||||||||
| 135 | case never executed: 0x16:case 0x16:never executed: case 0x16: | 0 | ||||||||||||
| 136 | { | - | ||||||||||||
| 137 | unsigned char *p = ptr; | - | ||||||||||||
| 138 | unsigned int len = p[arg - 2] << 8 | p[arg - 1]; | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | if (!ctx->encrypt
| 0 | ||||||||||||
| 141 | if (len < 16
| 0 | ||||||||||||
| 142 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 143 | len -= 16; | - | ||||||||||||
| 144 | p[arg - 2] = len >> 8; | - | ||||||||||||
| 145 | p[arg - 1] = len; | - | ||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||
| 147 | key->payload_length = len; | - | ||||||||||||
| 148 | key->md = key->head; | - | ||||||||||||
| 149 | MD5_Update(&key->md, p, arg); | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | return never executed: 16;return 16;never executed: return 16; | 0 | ||||||||||||
| 152 | } | - | ||||||||||||
| 153 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 154 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | } | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | static EVP_CIPHER r4_hmac_md5_cipher = { | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | 915, | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | - | |||||||||||||
| 163 | - | |||||||||||||
| 164 | 1, 16, 0, | - | ||||||||||||
| 165 | 0x0|0x8|0x200000, | - | ||||||||||||
| 166 | rc4_hmac_md5_init_key, | - | ||||||||||||
| 167 | rc4_hmac_md5_cipher, | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | ((void *)0) | - | ||||||||||||
| 170 | , | - | ||||||||||||
| 171 | sizeof(EVP_RC4_HMAC_MD5), | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | ((void *)0) | - | ||||||||||||
| 174 | , | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | ((void *)0) | - | ||||||||||||
| 177 | , | - | ||||||||||||
| 178 | rc4_hmac_md5_ctrl, | - | ||||||||||||
| 179 | - | |||||||||||||
| 180 | ((void *)0) | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | }; | - | ||||||||||||
| 183 | - | |||||||||||||
| 184 | const EVP_CIPHER * | - | ||||||||||||
| 185 | EVP_rc4_hmac_md5(void) | - | ||||||||||||
| 186 | { | - | ||||||||||||
| 187 | return executed 625 times by 33 tests: (&r4_hmac_md5_cipher);return (&r4_hmac_md5_cipher);Executed by:
executed 625 times by 33 tests: return (&r4_hmac_md5_cipher);Executed by:
| 625 | ||||||||||||
| 188 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |