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