Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/modes/wrap128.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||||||||
3 | static const unsigned char default_iv[] = { | - | ||||||||||||||||||||||||||||||||||||
4 | 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, | - | ||||||||||||||||||||||||||||||||||||
5 | }; | - | ||||||||||||||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||||||||||||||
8 | static const unsigned char default_aiv[] = { | - | ||||||||||||||||||||||||||||||||||||
9 | 0xA6, 0x59, 0x59, 0xA6 | - | ||||||||||||||||||||||||||||||||||||
10 | }; | - | ||||||||||||||||||||||||||||||||||||
11 | size_t CRYPTO_128_wrap(void *key, const unsigned char *iv, | - | ||||||||||||||||||||||||||||||||||||
12 | unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||
13 | const unsigned char *in, size_t inlen, | - | ||||||||||||||||||||||||||||||||||||
14 | block128_f block) | - | ||||||||||||||||||||||||||||||||||||
15 | { | - | ||||||||||||||||||||||||||||||||||||
16 | unsigned char *A, B[16], *R; | - | ||||||||||||||||||||||||||||||||||||
17 | size_t i, j, t; | - | ||||||||||||||||||||||||||||||||||||
18 | if ((
| 0-47 | ||||||||||||||||||||||||||||||||||||
19 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
20 | A = B; | - | ||||||||||||||||||||||||||||||||||||
21 | t = 1; | - | ||||||||||||||||||||||||||||||||||||
22 | memmove(out + 8, in, inlen); | - | ||||||||||||||||||||||||||||||||||||
23 | if (!iv
| 6-41 | ||||||||||||||||||||||||||||||||||||
24 | iv = default_iv; executed 41 times by 1 test: iv = default_iv; Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||||||||||||||
26 | memcpy(A, iv, 8); | - | ||||||||||||||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||||||||||||||
28 | for (j = 0; j < 6
| 47-282 | ||||||||||||||||||||||||||||||||||||
29 | R = out + 8; | - | ||||||||||||||||||||||||||||||||||||
30 | for (i = 0; i < inlen
| 282-744 | ||||||||||||||||||||||||||||||||||||
31 | memcpy(B + 8, R, 8); | - | ||||||||||||||||||||||||||||||||||||
32 | block(B, B, key); | - | ||||||||||||||||||||||||||||||||||||
33 | A[7] ^= (unsigned char)(t & 0xff); | - | ||||||||||||||||||||||||||||||||||||
34 | if (t > 0xff
| 0-744 | ||||||||||||||||||||||||||||||||||||
35 | A[6] ^= (unsigned char)((t >> 8) & 0xff); | - | ||||||||||||||||||||||||||||||||||||
36 | A[5] ^= (unsigned char)((t >> 16) & 0xff); | - | ||||||||||||||||||||||||||||||||||||
37 | A[4] ^= (unsigned char)((t >> 24) & 0xff); | - | ||||||||||||||||||||||||||||||||||||
38 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
39 | memcpy(R, B + 8, 8); | - | ||||||||||||||||||||||||||||||||||||
40 | } executed 744 times by 1 test: end of block Executed by:
| 744 | ||||||||||||||||||||||||||||||||||||
41 | } executed 282 times by 1 test: end of block Executed by:
| 282 | ||||||||||||||||||||||||||||||||||||
42 | memcpy(out, A, 8); | - | ||||||||||||||||||||||||||||||||||||
43 | return executed 47 times by 1 test: inlen + 8;return inlen + 8; Executed by:
executed 47 times by 1 test: return inlen + 8; Executed by:
| 47 | ||||||||||||||||||||||||||||||||||||
44 | } | - | ||||||||||||||||||||||||||||||||||||
45 | static size_t crypto_128_unwrap_raw(void *key, unsigned char *iv, | - | ||||||||||||||||||||||||||||||||||||
46 | unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||
47 | const unsigned char *in, size_t inlen, | - | ||||||||||||||||||||||||||||||||||||
48 | block128_f block) | - | ||||||||||||||||||||||||||||||||||||
49 | { | - | ||||||||||||||||||||||||||||||||||||
50 | unsigned char *A, B[16], *R; | - | ||||||||||||||||||||||||||||||||||||
51 | size_t i, j, t; | - | ||||||||||||||||||||||||||||||||||||
52 | inlen -= 8; | - | ||||||||||||||||||||||||||||||||||||
53 | if ((
| 0-48 | ||||||||||||||||||||||||||||||||||||
54 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
55 | A = B; | - | ||||||||||||||||||||||||||||||||||||
56 | t = 6 * (inlen >> 3); | - | ||||||||||||||||||||||||||||||||||||
57 | memcpy(A, in, 8); | - | ||||||||||||||||||||||||||||||||||||
58 | memmove(out, in + 8, inlen); | - | ||||||||||||||||||||||||||||||||||||
59 | for (j = 0; j < 6
| 48-288 | ||||||||||||||||||||||||||||||||||||
60 | R = out + inlen - 8; | - | ||||||||||||||||||||||||||||||||||||
61 | for (i = 0; i < inlen
| 288-768 | ||||||||||||||||||||||||||||||||||||
62 | A[7] ^= (unsigned char)(t & 0xff); | - | ||||||||||||||||||||||||||||||||||||
63 | if (t > 0xff
| 0-768 | ||||||||||||||||||||||||||||||||||||
64 | A[6] ^= (unsigned char)((t >> 8) & 0xff); | - | ||||||||||||||||||||||||||||||||||||
65 | A[5] ^= (unsigned char)((t >> 16) & 0xff); | - | ||||||||||||||||||||||||||||||||||||
66 | A[4] ^= (unsigned char)((t >> 24) & 0xff); | - | ||||||||||||||||||||||||||||||||||||
67 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
68 | memcpy(B + 8, R, 8); | - | ||||||||||||||||||||||||||||||||||||
69 | block(B, B, key); | - | ||||||||||||||||||||||||||||||||||||
70 | memcpy(R, B + 8, 8); | - | ||||||||||||||||||||||||||||||||||||
71 | } executed 768 times by 1 test: end of block Executed by:
| 768 | ||||||||||||||||||||||||||||||||||||
72 | } executed 288 times by 1 test: end of block Executed by:
| 288 | ||||||||||||||||||||||||||||||||||||
73 | memcpy(iv, A, 8); | - | ||||||||||||||||||||||||||||||||||||
74 | return executed 48 times by 1 test: inlen;return inlen; Executed by:
executed 48 times by 1 test: return inlen; Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||
75 | } | - | ||||||||||||||||||||||||||||||||||||
76 | size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv, | - | ||||||||||||||||||||||||||||||||||||
77 | unsigned char *out, const unsigned char *in, | - | ||||||||||||||||||||||||||||||||||||
78 | size_t inlen, block128_f block) | - | ||||||||||||||||||||||||||||||||||||
79 | { | - | ||||||||||||||||||||||||||||||||||||
80 | size_t ret; | - | ||||||||||||||||||||||||||||||||||||
81 | unsigned char got_iv[8]; | - | ||||||||||||||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||||||||||||||
83 | ret = crypto_128_unwrap_raw(key, got_iv, out, in, inlen, block); | - | ||||||||||||||||||||||||||||||||||||
84 | if (ret == 0
| 0-42 | ||||||||||||||||||||||||||||||||||||
85 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||||||||||||||
87 | if (!iv
| 0-42 | ||||||||||||||||||||||||||||||||||||
88 | iv = default_iv; executed 42 times by 1 test: iv = default_iv; Executed by:
| 42 | ||||||||||||||||||||||||||||||||||||
89 | if (CRYPTO_memcmp(got_iv, iv, 8)
| 1-41 | ||||||||||||||||||||||||||||||||||||
90 | OPENSSL_cleanse(out, ret); | - | ||||||||||||||||||||||||||||||||||||
91 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
92 | } | - | ||||||||||||||||||||||||||||||||||||
93 | return executed 41 times by 1 test: ret;return ret; Executed by:
executed 41 times by 1 test: return ret; Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||
94 | } | - | ||||||||||||||||||||||||||||||||||||
95 | size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv, | - | ||||||||||||||||||||||||||||||||||||
96 | unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||
97 | const unsigned char *in, size_t inlen, | - | ||||||||||||||||||||||||||||||||||||
98 | block128_f block) | - | ||||||||||||||||||||||||||||||||||||
99 | { | - | ||||||||||||||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||||||||||||||
103 | - | |||||||||||||||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||||||||||||||
106 | const size_t blocks_padded = (inlen + 7) / 8; | - | ||||||||||||||||||||||||||||||||||||
107 | const size_t padded_len = blocks_padded * 8; | - | ||||||||||||||||||||||||||||||||||||
108 | const size_t padding_len = padded_len - inlen; | - | ||||||||||||||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||||||||||||||
110 | unsigned char aiv[8]; | - | ||||||||||||||||||||||||||||||||||||
111 | int ret; | - | ||||||||||||||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||||||||||||||
114 | if (inlen == 0
| 0-12 | ||||||||||||||||||||||||||||||||||||
115 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||||||||||||||
118 | if (!icv
| 0-12 | ||||||||||||||||||||||||||||||||||||
119 | memcpy(aiv, default_aiv, 4); executed 12 times by 1 test: memcpy(aiv, default_aiv, 4); Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||
120 | else | - | ||||||||||||||||||||||||||||||||||||
121 | memcpy(aiv, icv, 4); never executed: memcpy(aiv, icv, 4); | 0 | ||||||||||||||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||||||||||||||
123 | aiv[4] = (inlen >> 24) & 0xFF; | - | ||||||||||||||||||||||||||||||||||||
124 | aiv[5] = (inlen >> 16) & 0xFF; | - | ||||||||||||||||||||||||||||||||||||
125 | aiv[6] = (inlen >> 8) & 0xFF; | - | ||||||||||||||||||||||||||||||||||||
126 | aiv[7] = inlen & 0xFF; | - | ||||||||||||||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||||||||||||||
128 | if (padded_len == 8
| 6 | ||||||||||||||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||||||||||||||
131 | - | |||||||||||||||||||||||||||||||||||||
132 | - | |||||||||||||||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||||||||||||||
134 | memmove(out + 8, in, inlen); | - | ||||||||||||||||||||||||||||||||||||
135 | memcpy(out, aiv, 8); | - | ||||||||||||||||||||||||||||||||||||
136 | memset(out + 8 + inlen, 0, padding_len); | - | ||||||||||||||||||||||||||||||||||||
137 | block(out, out, key); | - | ||||||||||||||||||||||||||||||||||||
138 | ret = 16; | - | ||||||||||||||||||||||||||||||||||||
139 | } executed 6 times by 1 test: else {end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
140 | memmove(out, in, inlen); | - | ||||||||||||||||||||||||||||||||||||
141 | memset(out + inlen, 0, padding_len); | - | ||||||||||||||||||||||||||||||||||||
142 | ret = CRYPTO_128_wrap(key, aiv, out, out, padded_len, block); | - | ||||||||||||||||||||||||||||||||||||
143 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||||||||||||||
145 | return executed 12 times by 1 test: ret;return ret; Executed by:
executed 12 times by 1 test: return ret; Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||
146 | } | - | ||||||||||||||||||||||||||||||||||||
147 | size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv, | - | ||||||||||||||||||||||||||||||||||||
148 | unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||
149 | const unsigned char *in, size_t inlen, | - | ||||||||||||||||||||||||||||||||||||
150 | block128_f block) | - | ||||||||||||||||||||||||||||||||||||
151 | { | - | ||||||||||||||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||||||||||||||
153 | size_t n = inlen / 8 - 1; | - | ||||||||||||||||||||||||||||||||||||
154 | size_t padded_len; | - | ||||||||||||||||||||||||||||||||||||
155 | size_t padding_len; | - | ||||||||||||||||||||||||||||||||||||
156 | size_t ptext_len; | - | ||||||||||||||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||||||||||||||
158 | unsigned char aiv[8]; | - | ||||||||||||||||||||||||||||||||||||
159 | static unsigned char zeros[8] = { 0x0 }; | - | ||||||||||||||||||||||||||||||||||||
160 | size_t ret; | - | ||||||||||||||||||||||||||||||||||||
161 | - | |||||||||||||||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||||||||||||||
163 | if ((
| 0-12 | ||||||||||||||||||||||||||||||||||||
164 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||||||||||||||
166 | if (inlen == 16
| 6 | ||||||||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||||||||||||||
173 | unsigned char buff[16]; | - | ||||||||||||||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||||||||||||||
175 | block(in, buff, key); | - | ||||||||||||||||||||||||||||||||||||
176 | memcpy(aiv, buff, 8); | - | ||||||||||||||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||||||||||||||
178 | memcpy(out, buff + 8, 8); | - | ||||||||||||||||||||||||||||||||||||
179 | padded_len = 8; | - | ||||||||||||||||||||||||||||||||||||
180 | OPENSSL_cleanse(buff, inlen); | - | ||||||||||||||||||||||||||||||||||||
181 | } executed 6 times by 1 test: else {end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
182 | padded_len = inlen - 8; | - | ||||||||||||||||||||||||||||||||||||
183 | ret = crypto_128_unwrap_raw(key, aiv, out, in, inlen, block); | - | ||||||||||||||||||||||||||||||||||||
184 | if (padded_len != ret
| 0-6 | ||||||||||||||||||||||||||||||||||||
185 | OPENSSL_cleanse(out, inlen); | - | ||||||||||||||||||||||||||||||||||||
186 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
187 | } | - | ||||||||||||||||||||||||||||||||||||
188 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||||||||
195 | if ((!icv
| 0-12 | ||||||||||||||||||||||||||||||||||||
196 | || (icv
| 0-12 | ||||||||||||||||||||||||||||||||||||
197 | OPENSSL_cleanse(out, inlen); | - | ||||||||||||||||||||||||||||||||||||
198 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
199 | } | - | ||||||||||||||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||||||||||||||
206 | ptext_len = ((unsigned int)aiv[4] << 24) | - | ||||||||||||||||||||||||||||||||||||
207 | | ((unsigned int)aiv[5] << 16) | - | ||||||||||||||||||||||||||||||||||||
208 | | ((unsigned int)aiv[6] << 8) | - | ||||||||||||||||||||||||||||||||||||
209 | | (unsigned int)aiv[7]; | - | ||||||||||||||||||||||||||||||||||||
210 | if (8 * (n - 1) >= ptext_len
| 0-12 | ||||||||||||||||||||||||||||||||||||
211 | OPENSSL_cleanse(out, inlen); | - | ||||||||||||||||||||||||||||||||||||
212 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
213 | } | - | ||||||||||||||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||||||||||||||
215 | - | |||||||||||||||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||||||||||||||
218 | - | |||||||||||||||||||||||||||||||||||||
219 | padding_len = padded_len - ptext_len; | - | ||||||||||||||||||||||||||||||||||||
220 | if (CRYPTO_memcmp(out + ptext_len, zeros, padding_len) != 0
| 0-12 | ||||||||||||||||||||||||||||||||||||
221 | OPENSSL_cleanse(out, inlen); | - | ||||||||||||||||||||||||||||||||||||
222 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
223 | } | - | ||||||||||||||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||||||||||||||
225 | - | |||||||||||||||||||||||||||||||||||||
226 | return executed 12 times by 1 test: ptext_len;return ptext_len; Executed by:
executed 12 times by 1 test: return ptext_len; Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||
227 | } | - | ||||||||||||||||||||||||||||||||||||
Switch to Source code | Preprocessed file |