Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/hmac/hmac.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | - | ||||||||||||
3 | const EVP_MD *md, ENGINE *impl) | - | ||||||||||||
4 | { | - | ||||||||||||
5 | int rv = 0; | - | ||||||||||||
6 | int i, j, reset = 0; | - | ||||||||||||
7 | unsigned char pad[144]; | - | ||||||||||||
8 | - | |||||||||||||
9 | - | |||||||||||||
10 | if (md !=
| 55-53523 | ||||||||||||
11 | ((void *)0)
| 55-53523 | ||||||||||||
12 | && md != ctx->md
| 0-53523 | ||||||||||||
13 | ((void *)0)
| 2-53521 | ||||||||||||
14 | || len < 0
| 1-53520 | ||||||||||||
15 | return executed 3 times by 1 test: 0;return 0; Executed by:
executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||
16 | - | |||||||||||||
17 | if (md !=
| 55-53520 | ||||||||||||
18 | ((void *)0)
| 55-53520 | ||||||||||||
19 | ) { | - | ||||||||||||
20 | reset = 1; | - | ||||||||||||
21 | ctx->md = md; | - | ||||||||||||
22 | } executed 53520 times by 1 test: else if (ctx->mdend of block Executed by:
| 2-53520 | ||||||||||||
23 | md = ctx->md; | - | ||||||||||||
24 | } executed 53 times by 1 test: else {end of block Executed by:
| 53 | ||||||||||||
25 | return executed 2 times by 1 test: 0;return 0; Executed by:
executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
26 | } | - | ||||||||||||
27 | - | |||||||||||||
28 | if (key !=
| 52-53521 | ||||||||||||
29 | ((void *)0)
| 52-53521 | ||||||||||||
30 | ) { | - | ||||||||||||
31 | reset = 1; | - | ||||||||||||
32 | j = EVP_MD_block_size(md); | - | ||||||||||||
33 | if (!((j <= (int)sizeof(ctx->key)) != 0)
| 0-53521 | ||||||||||||
34 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
35 | if (j < len
| 206-53315 | ||||||||||||
36 | if (!EVP_DigestInit_ex(ctx->md_ctx, md, impl)
| 0-206 | ||||||||||||
37 | || !EVP_DigestUpdate(ctx->md_ctx, key, len)
| 0-206 | ||||||||||||
38 | || !EVP_DigestFinal_ex(ctx->md_ctx, ctx->key,
| 0-206 | ||||||||||||
39 | &ctx->key_length)
| 0-206 | ||||||||||||
40 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
41 | } executed 206 times by 1 test: else {end of block Executed by:
| 206 | ||||||||||||
42 | if (len < 0
| 0-53315 | ||||||||||||
43 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
44 | memcpy(ctx->key, key, len); | - | ||||||||||||
45 | ctx->key_length = len; | - | ||||||||||||
46 | } executed 53315 times by 1 test: end of block Executed by:
| 53315 | ||||||||||||
47 | if (ctx->key_length != 144
| 1-53520 | ||||||||||||
48 | memset(&ctx->key[ctx->key_length], 0, executed 53520 times by 1 test: memset(&ctx->key[ctx->key_length], 0, 144 - ctx->key_length); Executed by:
| 53520 | ||||||||||||
49 | 144 - ctx->key_length); executed 53520 times by 1 test: memset(&ctx->key[ctx->key_length], 0, 144 - ctx->key_length); Executed by:
| 53520 | ||||||||||||
50 | } executed 53521 times by 1 test: end of block Executed by:
| 53521 | ||||||||||||
51 | - | |||||||||||||
52 | if (reset
| 52-53521 | ||||||||||||
53 | for (i = 0; i < 144
| 53521-7707024 | ||||||||||||
54 | pad[i] = 0x36 ^ ctx->key[i]; executed 7707024 times by 1 test: pad[i] = 0x36 ^ ctx->key[i]; Executed by:
| 7707024 | ||||||||||||
55 | if (!EVP_DigestInit_ex(ctx->i_ctx, md, impl)
| 0-53521 | ||||||||||||
56 | || !EVP_DigestUpdate(ctx->i_ctx, pad, EVP_MD_block_size(md))
| 0-53521 | ||||||||||||
57 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
58 | - | |||||||||||||
59 | for (i = 0; i < 144
| 53521-7707024 | ||||||||||||
60 | pad[i] = 0x5c ^ ctx->key[i]; executed 7707024 times by 1 test: pad[i] = 0x5c ^ ctx->key[i]; Executed by:
| 7707024 | ||||||||||||
61 | if (!EVP_DigestInit_ex(ctx->o_ctx, md, impl)
| 0-53521 | ||||||||||||
62 | || !EVP_DigestUpdate(ctx->o_ctx, pad, EVP_MD_block_size(md))
| 0-53521 | ||||||||||||
63 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
64 | } executed 53521 times by 1 test: end of block Executed by:
| 53521 | ||||||||||||
65 | if (!EVP_MD_CTX_copy_ex(ctx->md_ctx, ctx->i_ctx)
| 0-53573 | ||||||||||||
66 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
67 | rv = 1; | - | ||||||||||||
68 | err: code before this statement executed 53573 times by 1 test: err: Executed by:
| 53573 | ||||||||||||
69 | if (reset
| 52-53521 | ||||||||||||
70 | OPENSSL_cleanse(pad, sizeof(pad)); executed 53521 times by 1 test: OPENSSL_cleanse(pad, sizeof(pad)); Executed by:
| 53521 | ||||||||||||
71 | return executed 53573 times by 1 test: rv;return rv; Executed by:
executed 53573 times by 1 test: return rv; Executed by:
| 53573 | ||||||||||||
72 | } | - | ||||||||||||
73 | - | |||||||||||||
74 | - | |||||||||||||
75 | int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md) | - | ||||||||||||
76 | { | - | ||||||||||||
77 | if (key
| 0 | ||||||||||||
78 | HMAC_CTX_reset(ctx); never executed: HMAC_CTX_reset(ctx); | 0 | ||||||||||||
79 | return never executed: HMAC_Init_ex(ctx, key, len, md, return HMAC_Init_ex(ctx, key, len, md, ((void *)0) ); never executed: return HMAC_Init_ex(ctx, key, len, md, ((void *)0) ); | 0 | ||||||||||||
80 | ((void *)0) never executed: return HMAC_Init_ex(ctx, key, len, md, ((void *)0) ); | 0 | ||||||||||||
81 | ); never executed: return HMAC_Init_ex(ctx, key, len, md, ((void *)0) ); | 0 | ||||||||||||
82 | } | - | ||||||||||||
83 | - | |||||||||||||
84 | - | |||||||||||||
85 | int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | if (!ctx->md
| 3-218860 | ||||||||||||
88 | return executed 3 times by 1 test: 0;return 0; Executed by:
executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||
89 | return executed 218860 times by 1 test: EVP_DigestUpdate(ctx->md_ctx, data, len);return EVP_DigestUpdate(ctx->md_ctx, data, len); Executed by:
executed 218860 times by 1 test: return EVP_DigestUpdate(ctx->md_ctx, data, len); Executed by:
| 218860 | ||||||||||||
90 | } | - | ||||||||||||
91 | - | |||||||||||||
92 | int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) | - | ||||||||||||
93 | { | - | ||||||||||||
94 | unsigned int i; | - | ||||||||||||
95 | unsigned char buf[64]; | - | ||||||||||||
96 | - | |||||||||||||
97 | if (!ctx->md
| 0-163219 | ||||||||||||
98 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
99 | - | |||||||||||||
100 | if (!EVP_DigestFinal_ex(ctx->md_ctx, buf, &i)
| 0-163219 | ||||||||||||
101 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
102 | if (!EVP_MD_CTX_copy_ex(ctx->md_ctx, ctx->o_ctx)
| 0-163219 | ||||||||||||
103 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
104 | if (!EVP_DigestUpdate(ctx->md_ctx, buf, i)
| 0-163219 | ||||||||||||
105 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
106 | if (!EVP_DigestFinal_ex(ctx->md_ctx, md, len)
| 0-163219 | ||||||||||||
107 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
108 | return executed 163219 times by 1 test: 1;return 1; Executed by:
executed 163219 times by 1 test: return 1; Executed by:
| 163219 | ||||||||||||
109 | err: | - | ||||||||||||
110 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
111 | } | - | ||||||||||||
112 | - | |||||||||||||
113 | size_t HMAC_size(const HMAC_CTX *ctx) | - | ||||||||||||
114 | { | - | ||||||||||||
115 | int size = EVP_MD_size((ctx)->md); | - | ||||||||||||
116 | - | |||||||||||||
117 | return executed 221 times by 1 test: (return (size < 0) ? 0 : size; Executed by:
executed 221 times by 1 test: return (size < 0) ? 0 : size; Executed by:
| 0-221 | ||||||||||||
118 | } | - | ||||||||||||
119 | - | |||||||||||||
120 | HMAC_CTX *HMAC_CTX_new(void) | - | ||||||||||||
121 | { | - | ||||||||||||
122 | HMAC_CTX *ctx = CRYPTO_zalloc(sizeof(HMAC_CTX), __FILE__, 128); | - | ||||||||||||
123 | - | |||||||||||||
124 | if (ctx !=
| 0-215927 | ||||||||||||
125 | ((void *)0)
| 0-215927 | ||||||||||||
126 | ) { | - | ||||||||||||
127 | if (!HMAC_CTX_reset(ctx)
| 0-215927 | ||||||||||||
128 | HMAC_CTX_free(ctx); | - | ||||||||||||
129 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
130 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
131 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
132 | } | - | ||||||||||||
133 | } executed 215927 times by 1 test: end of block Executed by:
| 215927 | ||||||||||||
134 | return executed 215927 times by 1 test: ctx;return ctx; Executed by:
executed 215927 times by 1 test: return ctx; Executed by:
| 215927 | ||||||||||||
135 | } | - | ||||||||||||
136 | - | |||||||||||||
137 | static void hmac_ctx_cleanup(HMAC_CTX *ctx) | - | ||||||||||||
138 | { | - | ||||||||||||
139 | EVP_MD_CTX_reset(ctx->i_ctx); | - | ||||||||||||
140 | EVP_MD_CTX_reset(ctx->o_ctx); | - | ||||||||||||
141 | EVP_MD_CTX_reset(ctx->md_ctx); | - | ||||||||||||
142 | ctx->md = | - | ||||||||||||
143 | ((void *)0) | - | ||||||||||||
144 | ; | - | ||||||||||||
145 | ctx->key_length = 0; | - | ||||||||||||
146 | OPENSSL_cleanse(ctx->key, sizeof(ctx->key)); | - | ||||||||||||
147 | } executed 431855 times by 1 test: end of block Executed by:
| 431855 | ||||||||||||
148 | - | |||||||||||||
149 | void HMAC_CTX_free(HMAC_CTX *ctx) | - | ||||||||||||
150 | { | - | ||||||||||||
151 | if (ctx !=
| 1191-215927 | ||||||||||||
152 | ((void *)0)
| 1191-215927 | ||||||||||||
153 | ) { | - | ||||||||||||
154 | hmac_ctx_cleanup(ctx); | - | ||||||||||||
155 | EVP_MD_CTX_free(ctx->i_ctx); | - | ||||||||||||
156 | EVP_MD_CTX_free(ctx->o_ctx); | - | ||||||||||||
157 | EVP_MD_CTX_free(ctx->md_ctx); | - | ||||||||||||
158 | CRYPTO_free(ctx, __FILE__, 156); | - | ||||||||||||
159 | } executed 215927 times by 1 test: end of block Executed by:
| 215927 | ||||||||||||
160 | } executed 217118 times by 1 test: end of block Executed by:
| 217118 | ||||||||||||
161 | - | |||||||||||||
162 | static int hmac_ctx_alloc_mds(HMAC_CTX *ctx) | - | ||||||||||||
163 | { | - | ||||||||||||
164 | if (ctx->i_ctx ==
| 207331-215927 | ||||||||||||
165 | ((void *)0)
| 207331-215927 | ||||||||||||
166 | ) | - | ||||||||||||
167 | ctx->i_ctx = EVP_MD_CTX_new(); executed 215927 times by 1 test: ctx->i_ctx = EVP_MD_CTX_new(); Executed by:
| 215927 | ||||||||||||
168 | if (ctx->i_ctx ==
| 0-423258 | ||||||||||||
169 | ((void *)0)
| 0-423258 | ||||||||||||
170 | ) | - | ||||||||||||
171 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
172 | if (ctx->o_ctx ==
| 207331-215927 | ||||||||||||
173 | ((void *)0)
| 207331-215927 | ||||||||||||
174 | ) | - | ||||||||||||
175 | ctx->o_ctx = EVP_MD_CTX_new(); executed 215927 times by 1 test: ctx->o_ctx = EVP_MD_CTX_new(); Executed by:
| 215927 | ||||||||||||
176 | if (ctx->o_ctx ==
| 0-423258 | ||||||||||||
177 | ((void *)0)
| 0-423258 | ||||||||||||
178 | ) | - | ||||||||||||
179 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
180 | if (ctx->md_ctx ==
| 207331-215927 | ||||||||||||
181 | ((void *)0)
| 207331-215927 | ||||||||||||
182 | ) | - | ||||||||||||
183 | ctx->md_ctx = EVP_MD_CTX_new(); executed 215927 times by 1 test: ctx->md_ctx = EVP_MD_CTX_new(); Executed by:
| 215927 | ||||||||||||
184 | if (ctx->md_ctx ==
| 0-423258 | ||||||||||||
185 | ((void *)0)
| 0-423258 | ||||||||||||
186 | ) | - | ||||||||||||
187 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
188 | return executed 423258 times by 1 test: 1;return 1; Executed by:
executed 423258 times by 1 test: return 1; Executed by:
| 423258 | ||||||||||||
189 | } | - | ||||||||||||
190 | - | |||||||||||||
191 | int HMAC_CTX_reset(HMAC_CTX *ctx) | - | ||||||||||||
192 | { | - | ||||||||||||
193 | hmac_ctx_cleanup(ctx); | - | ||||||||||||
194 | if (!hmac_ctx_alloc_mds(ctx)
| 0-215928 | ||||||||||||
195 | hmac_ctx_cleanup(ctx); | - | ||||||||||||
196 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
197 | } | - | ||||||||||||
198 | return executed 215928 times by 1 test: 1;return 1; Executed by:
executed 215928 times by 1 test: return 1; Executed by:
| 215928 | ||||||||||||
199 | } | - | ||||||||||||
200 | - | |||||||||||||
201 | int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx) | - | ||||||||||||
202 | { | - | ||||||||||||
203 | if (!hmac_ctx_alloc_mds(dctx)
| 0-207330 | ||||||||||||
204 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
205 | if (!EVP_MD_CTX_copy_ex(dctx->i_ctx, sctx->i_ctx)
| 0-207330 | ||||||||||||
206 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
207 | if (!EVP_MD_CTX_copy_ex(dctx->o_ctx, sctx->o_ctx)
| 0-207330 | ||||||||||||
208 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
209 | if (!EVP_MD_CTX_copy_ex(dctx->md_ctx, sctx->md_ctx)
| 0-207330 | ||||||||||||
210 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
211 | memcpy(dctx->key, sctx->key, 144); | - | ||||||||||||
212 | dctx->key_length = sctx->key_length; | - | ||||||||||||
213 | dctx->md = sctx->md; | - | ||||||||||||
214 | return executed 207330 times by 1 test: 1;return 1; Executed by:
executed 207330 times by 1 test: return 1; Executed by:
| 207330 | ||||||||||||
215 | err: | - | ||||||||||||
216 | hmac_ctx_cleanup(dctx); | - | ||||||||||||
217 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
218 | } | - | ||||||||||||
219 | - | |||||||||||||
220 | unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, | - | ||||||||||||
221 | const unsigned char *d, size_t n, unsigned char *md, | - | ||||||||||||
222 | unsigned int *md_len) | - | ||||||||||||
223 | { | - | ||||||||||||
224 | HMAC_CTX *c = | - | ||||||||||||
225 | ((void *)0) | - | ||||||||||||
226 | ; | - | ||||||||||||
227 | static unsigned char m[64]; | - | ||||||||||||
228 | static const unsigned char dummy_key[1] = {'\0'}; | - | ||||||||||||
229 | - | |||||||||||||
230 | if (md ==
| 5-4480 | ||||||||||||
231 | ((void *)0)
| 5-4480 | ||||||||||||
232 | ) | - | ||||||||||||
233 | md = m; executed 5 times by 1 test: md = m; Executed by:
| 5 | ||||||||||||
234 | if ((
| 0-4485 | ||||||||||||
235 | ((void *)0)
| 0-4485 | ||||||||||||
236 | ) | - | ||||||||||||
237 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
238 | - | |||||||||||||
239 | - | |||||||||||||
240 | if (key ==
| 1571-2914 | ||||||||||||
241 | ((void *)0)
| 1571-2914 | ||||||||||||
242 | && key_len == 0
| 0-1571 | ||||||||||||
243 | key = dummy_key; | - | ||||||||||||
244 | } executed 1571 times by 1 test: end of block Executed by:
| 1571 | ||||||||||||
245 | - | |||||||||||||
246 | if (!HMAC_Init_ex(c, key, key_len, evp_md,
| 0-4485 | ||||||||||||
247 | ((void *)0)
| 0-4485 | ||||||||||||
248 | )
| 0-4485 | ||||||||||||
249 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
250 | if (!HMAC_Update(c, d, n)
| 0-4485 | ||||||||||||
251 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
252 | if (!HMAC_Final(c, md, md_len)
| 0-4485 | ||||||||||||
253 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
254 | HMAC_CTX_free(c); | - | ||||||||||||
255 | return executed 4485 times by 1 test: md;return md; Executed by:
executed 4485 times by 1 test: return md; Executed by:
| 4485 | ||||||||||||
256 | err: | - | ||||||||||||
257 | HMAC_CTX_free(c); | - | ||||||||||||
258 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
259 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
260 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
261 | } | - | ||||||||||||
262 | - | |||||||||||||
263 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags) | - | ||||||||||||
264 | { | - | ||||||||||||
265 | EVP_MD_CTX_set_flags(ctx->i_ctx, flags); | - | ||||||||||||
266 | EVP_MD_CTX_set_flags(ctx->o_ctx, flags); | - | ||||||||||||
267 | EVP_MD_CTX_set_flags(ctx->md_ctx, flags); | - | ||||||||||||
268 | } executed 19206 times by 1 test: end of block Executed by:
| 19206 | ||||||||||||
269 | - | |||||||||||||
270 | const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx) | - | ||||||||||||
271 | { | - | ||||||||||||
272 | return executed 3 times by 1 test: ctx->md;return ctx->md; Executed by:
executed 3 times by 1 test: return ctx->md; Executed by:
| 3 | ||||||||||||
273 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |