OpenCoverage

wrap128.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/modes/wrap128.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3static const unsigned char default_iv[] = {-
4 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6,-
5};-
6-
7-
8static const unsigned char default_aiv[] = {-
9 0xA6, 0x59, 0x59, 0xA6-
10};-
11size_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 ((
(inlen & 0x7)Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inlen & 0x7)
(inlen & 0x7)Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| (
(inlen < 16)Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inlen < 16)
(inlen < 16)Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| (
(inlen > (1UL << 31))Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inlen > (1UL << 31))
(inlen > (1UL << 31))Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-47
19 return
never executed: return 0;
0;
never executed: return 0;
0
20 A = B;-
21 t = 1;-
22 memmove(out + 8, in, inlen);-
23 if (!iv
!ivDescription
TRUEevaluated 41 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
6-41
24 iv = default_iv;
executed 41 times by 1 test: iv = default_iv;
Executed by:
  • libcrypto.so.1.1
41
25-
26 memcpy(A, iv, 8);-
27-
28 for (j = 0; j < 6
j < 6Description
TRUEevaluated 282 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 47 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; j++) {
47-282
29 R = out + 8;-
30 for (i = 0; i < inlen
i < inlenDescription
TRUEevaluated 744 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 282 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i += 8, t++, R += 8) {
282-744
31 memcpy(B + 8, R, 8);-
32 block(B, B, key);-
33 A[7] ^= (unsigned char)(t & 0xff);-
34 if (t > 0xff
t > 0xffDescription
TRUEnever evaluated
FALSEevaluated 744 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
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:
  • libcrypto.so.1.1
744
41 }
executed 282 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
282
42 memcpy(out, A, 8);-
43 return
executed 47 times by 1 test: return inlen + 8;
Executed by:
  • libcrypto.so.1.1
inlen + 8;
executed 47 times by 1 test: return inlen + 8;
Executed by:
  • libcrypto.so.1.1
47
44}-
45static 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 ((
(inlen & 0x7)Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inlen & 0x7)
(inlen & 0x7)Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| (
(inlen < 16)Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inlen < 16)
(inlen < 16)Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| (
(inlen > (1UL << 31))Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inlen > (1UL << 31))
(inlen > (1UL << 31))Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-48
54 return
never executed: return 0;
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
j < 6Description
TRUEevaluated 288 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 48 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; j++) {
48-288
60 R = out + inlen - 8;-
61 for (i = 0; i < inlen
i < inlenDescription
TRUEevaluated 768 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 288 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i += 8, t--, R -= 8) {
288-768
62 A[7] ^= (unsigned char)(t & 0xff);-
63 if (t > 0xff
t > 0xffDescription
TRUEnever evaluated
FALSEevaluated 768 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
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:
  • libcrypto.so.1.1
768
72 }
executed 288 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
288
73 memcpy(iv, A, 8);-
74 return
executed 48 times by 1 test: return inlen;
Executed by:
  • libcrypto.so.1.1
inlen;
executed 48 times by 1 test: return inlen;
Executed by:
  • libcrypto.so.1.1
48
75}-
76size_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
ret == 0Description
TRUEnever evaluated
FALSEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-42
85 return
never executed: return 0;
0;
never executed: return 0;
0
86-
87 if (!iv
!ivDescription
TRUEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-42
88 iv = default_iv;
executed 42 times by 1 test: iv = default_iv;
Executed by:
  • libcrypto.so.1.1
42
89 if (CRYPTO_memcmp(got_iv, iv, 8)
CRYPTO_memcmp(got_iv, iv, 8)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 41 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1-41
90 OPENSSL_cleanse(out, ret);-
91 return
executed 1 time by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
0;
executed 1 time by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
1
92 }-
93 return
executed 41 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 41 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
41
94}-
95size_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
inlen == 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| inlen >= (1UL << 31)
inlen >= (1UL << 31)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-12
115 return
never executed: return 0;
0;
never executed: return 0;
0
116-
117-
118 if (!icv
!icvDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-12
119 memcpy(aiv, default_aiv, 4);
executed 12 times by 1 test: memcpy(aiv, default_aiv, 4);
Executed by:
  • libcrypto.so.1.1
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
padded_len == 8Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
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: end of block
Executed by:
  • libcrypto.so.1.1
else {
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:
  • libcrypto.so.1.1
6
144-
145 return
executed 12 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 12 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
12
146}-
147size_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 ((
(inlen & 0x7) != 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
inlen & 0x7) != 0
(inlen & 0x7) != 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| inlen < 16
inlen < 16Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| inlen >= (1UL << 31)
inlen >= (1UL << 31)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-12
164 return
never executed: return 0;
0;
never executed: return 0;
0
165-
166 if (inlen == 16
inlen == 16Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
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: end of block
Executed by:
  • libcrypto.so.1.1
else {
6
182 padded_len = inlen - 8;-
183 ret = crypto_128_unwrap_raw(key, aiv, out, in, inlen, block);-
184 if (padded_len != ret
padded_len != retDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-6
185 OPENSSL_cleanse(out, inlen);-
186 return
never executed: return 0;
0;
never executed: return 0;
0
187 }-
188 }
executed 6 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6
189-
190-
191-
192-
193-
194-
195 if ((!icv
!icvDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
&& CRYPTO_memcmp(aiv, default_aiv, 4)
CRYPTO_memcmp(...efault_aiv, 4)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-12
196 || (icv
icvDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& CRYPTO_memcmp(aiv, icv, 4)
CRYPTO_memcmp(aiv, icv, 4)Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0-12
197 OPENSSL_cleanse(out, inlen);-
198 return
never executed: return 0;
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
8 * (n - 1) >= ptext_lenDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| ptext_len > 8 * n
ptext_len > 8 * nDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-12
211 OPENSSL_cleanse(out, inlen);-
212 return
never executed: return 0;
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
CRYPTO_memcmp(...ding_len) != 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-12
221 OPENSSL_cleanse(out, inlen);-
222 return
never executed: return 0;
0;
never executed: return 0;
0
223 }-
224-
225-
226 return
executed 12 times by 1 test: return ptext_len;
Executed by:
  • libcrypto.so.1.1
ptext_len;
executed 12 times by 1 test: return ptext_len;
Executed by:
  • libcrypto.so.1.1
12
227}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2