Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/pbe_scrypt.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||||||||
5 | static void salsa208_word_specification(uint32_t inout[16]) | - | ||||||||||||||||||||||||||||||
6 | { | - | ||||||||||||||||||||||||||||||
7 | int i; | - | ||||||||||||||||||||||||||||||
8 | uint32_t x[16]; | - | ||||||||||||||||||||||||||||||
9 | memcpy(x, inout, sizeof(x)); | - | ||||||||||||||||||||||||||||||
10 | for (i = 8; i > 0
| 3670144-14680576 | ||||||||||||||||||||||||||||||
11 | x[4] ^= (((x[0] + x[12]) << (7)) | ((x[0] + x[12]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
12 | x[8] ^= (((x[4] + x[0]) << (9)) | ((x[4] + x[0]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
13 | x[12] ^= (((x[8] + x[4]) << (13)) | ((x[8] + x[4]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
14 | x[0] ^= (((x[12] + x[8]) << (18)) | ((x[12] + x[8]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
15 | x[9] ^= (((x[5] + x[1]) << (7)) | ((x[5] + x[1]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
16 | x[13] ^= (((x[9] + x[5]) << (9)) | ((x[9] + x[5]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
17 | x[1] ^= (((x[13] + x[9]) << (13)) | ((x[13] + x[9]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
18 | x[5] ^= (((x[1] + x[13]) << (18)) | ((x[1] + x[13]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
19 | x[14] ^= (((x[10] + x[6]) << (7)) | ((x[10] + x[6]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
20 | x[2] ^= (((x[14] + x[10]) << (9)) | ((x[14] + x[10]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
21 | x[6] ^= (((x[2] + x[14]) << (13)) | ((x[2] + x[14]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
22 | x[10] ^= (((x[6] + x[2]) << (18)) | ((x[6] + x[2]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
23 | x[3] ^= (((x[15] + x[11]) << (7)) | ((x[15] + x[11]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
24 | x[7] ^= (((x[3] + x[15]) << (9)) | ((x[3] + x[15]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
25 | x[11] ^= (((x[7] + x[3]) << (13)) | ((x[7] + x[3]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
26 | x[15] ^= (((x[11] + x[7]) << (18)) | ((x[11] + x[7]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
27 | x[1] ^= (((x[0] + x[3]) << (7)) | ((x[0] + x[3]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
28 | x[2] ^= (((x[1] + x[0]) << (9)) | ((x[1] + x[0]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
29 | x[3] ^= (((x[2] + x[1]) << (13)) | ((x[2] + x[1]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
30 | x[0] ^= (((x[3] + x[2]) << (18)) | ((x[3] + x[2]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
31 | x[6] ^= (((x[5] + x[4]) << (7)) | ((x[5] + x[4]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
32 | x[7] ^= (((x[6] + x[5]) << (9)) | ((x[6] + x[5]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
33 | x[4] ^= (((x[7] + x[6]) << (13)) | ((x[7] + x[6]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
34 | x[5] ^= (((x[4] + x[7]) << (18)) | ((x[4] + x[7]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
35 | x[11] ^= (((x[10] + x[9]) << (7)) | ((x[10] + x[9]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
36 | x[8] ^= (((x[11] + x[10]) << (9)) | ((x[11] + x[10]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
37 | x[9] ^= (((x[8] + x[11]) << (13)) | ((x[8] + x[11]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
38 | x[10] ^= (((x[9] + x[8]) << (18)) | ((x[9] + x[8]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
39 | x[12] ^= (((x[15] + x[14]) << (7)) | ((x[15] + x[14]) >> (32 - (7)))); | - | ||||||||||||||||||||||||||||||
40 | x[13] ^= (((x[12] + x[15]) << (9)) | ((x[12] + x[15]) >> (32 - (9)))); | - | ||||||||||||||||||||||||||||||
41 | x[14] ^= (((x[13] + x[12]) << (13)) | ((x[13] + x[12]) >> (32 - (13)))); | - | ||||||||||||||||||||||||||||||
42 | x[15] ^= (((x[14] + x[13]) << (18)) | ((x[14] + x[13]) >> (32 - (18)))); | - | ||||||||||||||||||||||||||||||
43 | } executed 14680576 times by 1 test: end of block Executed by:
| 14680576 | ||||||||||||||||||||||||||||||
44 | for (i = 0; i < 16
| 3670144-58722304 | ||||||||||||||||||||||||||||||
45 | inout[i] += x[i]; executed 58722304 times by 1 test: inout[i] += x[i]; Executed by:
| 58722304 | ||||||||||||||||||||||||||||||
46 | OPENSSL_cleanse(x, sizeof(x)); | - | ||||||||||||||||||||||||||||||
47 | } executed 3670144 times by 1 test: end of block Executed by:
| 3670144 | ||||||||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||||||||
49 | static void scryptBlockMix(uint32_t *B_, uint32_t *B, uint64_t r) | - | ||||||||||||||||||||||||||||||
50 | { | - | ||||||||||||||||||||||||||||||
51 | uint64_t i, j; | - | ||||||||||||||||||||||||||||||
52 | uint32_t X[16], *pB; | - | ||||||||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||||||||
54 | memcpy(X, B + (r * 2 - 1) * 16, sizeof(X)); | - | ||||||||||||||||||||||||||||||
55 | pB = B; | - | ||||||||||||||||||||||||||||||
56 | for (i = 0; i < r * 2
| 229440-3670144 | ||||||||||||||||||||||||||||||
57 | for (j = 0; j < 16
| 3670144-58722304 | ||||||||||||||||||||||||||||||
58 | X[j] ^= *pB++; executed 58722304 times by 1 test: X[j] ^= *pB++; Executed by:
| 58722304 | ||||||||||||||||||||||||||||||
59 | salsa208_word_specification(X); | - | ||||||||||||||||||||||||||||||
60 | memcpy(B_ + (i / 2 + (i & 1) * r) * 16, X, sizeof(X)); | - | ||||||||||||||||||||||||||||||
61 | } executed 3670144 times by 1 test: end of block Executed by:
| 3670144 | ||||||||||||||||||||||||||||||
62 | OPENSSL_cleanse(X, sizeof(X)); | - | ||||||||||||||||||||||||||||||
63 | } executed 229440 times by 1 test: end of block Executed by:
| 229440 | ||||||||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||||||||
65 | static void scryptROMix(unsigned char *B, uint64_t r, uint64_t N, | - | ||||||||||||||||||||||||||||||
66 | uint32_t *X, uint32_t *T, uint32_t *V) | - | ||||||||||||||||||||||||||||||
67 | { | - | ||||||||||||||||||||||||||||||
68 | unsigned char *pB; | - | ||||||||||||||||||||||||||||||
69 | uint32_t *pV; | - | ||||||||||||||||||||||||||||||
70 | uint64_t i, k; | - | ||||||||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||||||||
73 | for (pV = V, i = 0, pB = B; i < 32 * r
| 84-21056 | ||||||||||||||||||||||||||||||
74 | *pV = *pB++; | - | ||||||||||||||||||||||||||||||
75 | *pV |= *pB++ << 8; | - | ||||||||||||||||||||||||||||||
76 | *pV |= *pB++ << 16; | - | ||||||||||||||||||||||||||||||
77 | *pV |= (uint32_t)*pB++ << 24; | - | ||||||||||||||||||||||||||||||
78 | } executed 21056 times by 1 test: end of block Executed by:
| 21056 | ||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||
80 | for (i = 1; i < N
| 84-114636 | ||||||||||||||||||||||||||||||
81 | scryptBlockMix(pV, pV - 32 * r, r); executed 114636 times by 1 test: scryptBlockMix(pV, pV - 32 * r, r); Executed by:
| 114636 | ||||||||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||||||||
83 | scryptBlockMix(X, V + (N - 1) * 32 * r, r); | - | ||||||||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||||||||
85 | for (i = 0; i < N
| 84-114720 | ||||||||||||||||||||||||||||||
86 | uint32_t j; | - | ||||||||||||||||||||||||||||||
87 | j = X[16 * (2 * r - 1)] % N; | - | ||||||||||||||||||||||||||||||
88 | pV = V + 32 * r * j; | - | ||||||||||||||||||||||||||||||
89 | for (k = 0; k < 32 * r
| 114720-29361152 | ||||||||||||||||||||||||||||||
90 | T[k] = X[k] ^ *pV++; executed 29361152 times by 1 test: T[k] = X[k] ^ *pV++; Executed by:
| 29361152 | ||||||||||||||||||||||||||||||
91 | scryptBlockMix(X, T, r); | - | ||||||||||||||||||||||||||||||
92 | } executed 114720 times by 1 test: end of block Executed by:
| 114720 | ||||||||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||||||||
94 | for (i = 0, pB = B; i < 32 * r
| 84-21056 | ||||||||||||||||||||||||||||||
95 | uint32_t xtmp = X[i]; | - | ||||||||||||||||||||||||||||||
96 | *pB++ = xtmp & 0xff; | - | ||||||||||||||||||||||||||||||
97 | *pB++ = (xtmp >> 8) & 0xff; | - | ||||||||||||||||||||||||||||||
98 | *pB++ = (xtmp >> 16) & 0xff; | - | ||||||||||||||||||||||||||||||
99 | *pB++ = (xtmp >> 24) & 0xff; | - | ||||||||||||||||||||||||||||||
100 | } executed 21056 times by 1 test: end of block Executed by:
| 21056 | ||||||||||||||||||||||||||||||
101 | } executed 84 times by 1 test: end of block Executed by:
| 84 | ||||||||||||||||||||||||||||||
102 | int EVP_PBE_scrypt(const char *pass, size_t passlen, | - | ||||||||||||||||||||||||||||||
103 | const unsigned char *salt, size_t saltlen, | - | ||||||||||||||||||||||||||||||
104 | uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, | - | ||||||||||||||||||||||||||||||
105 | unsigned char *key, size_t keylen) | - | ||||||||||||||||||||||||||||||
106 | { | - | ||||||||||||||||||||||||||||||
107 | int rv = 0; | - | ||||||||||||||||||||||||||||||
108 | unsigned char *B; | - | ||||||||||||||||||||||||||||||
109 | uint32_t *X, *V, *T; | - | ||||||||||||||||||||||||||||||
110 | uint64_t i, Blen, Vlen; | - | ||||||||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||||||||
114 | if (r == 0
| 0-11 | ||||||||||||||||||||||||||||||
115 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||||||||
117 | if (p > ((1 << 30) - 1) / r
| 0-11 | ||||||||||||||||||||||||||||||
118 | ERR_put_error(6,(181),(172),__FILE__,174); | - | ||||||||||||||||||||||||||||||
119 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
120 | } | - | ||||||||||||||||||||||||||||||
121 | - | |||||||||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||||||||
123 | - | |||||||||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||||||||
127 | if (16 * r <= (sizeof(uint64_t) * 8 - 1)
| 2-9 | ||||||||||||||||||||||||||||||
128 | if (N >= (((uint64_t)1) << (16 * r))
| 0-2 | ||||||||||||||||||||||||||||||
129 | ERR_put_error(6,(181),(172),__FILE__,185); | - | ||||||||||||||||||||||||||||||
130 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
131 | } | - | ||||||||||||||||||||||||||||||
132 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
133 | Blen = p * 128 * r; | - | ||||||||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||||||||
138 | if (Blen > 0x7fffffff
| 0-11 | ||||||||||||||||||||||||||||||
139 | ERR_put_error(6,(181),(172),__FILE__,203); | - | ||||||||||||||||||||||||||||||
140 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
141 | } | - | ||||||||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||||||||
147 | i = | - | ||||||||||||||||||||||||||||||
148 | (18446744073709551615UL) | - | ||||||||||||||||||||||||||||||
149 | / (32 * sizeof(uint32_t)); | - | ||||||||||||||||||||||||||||||
150 | if (N + 2 > i / r
| 0-11 | ||||||||||||||||||||||||||||||
151 | ERR_put_error(6,(181),(172),__FILE__,213); | - | ||||||||||||||||||||||||||||||
152 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
153 | } | - | ||||||||||||||||||||||||||||||
154 | Vlen = 32 * r * (N + 2) * sizeof(uint32_t); | - | ||||||||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||||||||
157 | if (Blen >
| 0-11 | ||||||||||||||||||||||||||||||
158 | (18446744073709551615UL)
| 0-11 | ||||||||||||||||||||||||||||||
159 | - Vlen
| 0-11 | ||||||||||||||||||||||||||||||
160 | ERR_put_error(6,(181),(172),__FILE__,220); | - | ||||||||||||||||||||||||||||||
161 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
162 | } | - | ||||||||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||||||||
164 | if (maxmem == 0
| 4-7 | ||||||||||||||||||||||||||||||
165 | maxmem = (1024 * 1024 * 32); executed 4 times by 1 test: maxmem = (1024 * 1024 * 32); Executed by:
| 4 | ||||||||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||
168 | if (maxmem >
| 0-11 | ||||||||||||||||||||||||||||||
169 | (18446744073709551615UL)
| 0-11 | ||||||||||||||||||||||||||||||
170 | ) | - | ||||||||||||||||||||||||||||||
171 | maxmem = never executed: maxmem = (18446744073709551615UL) ; | 0 | ||||||||||||||||||||||||||||||
172 | (18446744073709551615UL) never executed: maxmem = (18446744073709551615UL) ; | 0 | ||||||||||||||||||||||||||||||
173 | ; never executed: maxmem = (18446744073709551615UL) ; | 0 | ||||||||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||||||||
175 | if (Blen + Vlen > maxmem
| 2-9 | ||||||||||||||||||||||||||||||
176 | ERR_put_error(6,(181),(172),__FILE__,232); | - | ||||||||||||||||||||||||||||||
177 | return executed 2 times by 1 test: 0;return 0; Executed by:
executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||||||||
178 | } | - | ||||||||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||||||||
181 | if (key ==
| 0-9 | ||||||||||||||||||||||||||||||
182 | ((void *)0)
| 0-9 | ||||||||||||||||||||||||||||||
183 | ) | - | ||||||||||||||||||||||||||||||
184 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
185 | - | |||||||||||||||||||||||||||||||
186 | B = CRYPTO_malloc((size_t)(Blen + Vlen), __FILE__, 240); | - | ||||||||||||||||||||||||||||||
187 | if (B ==
| 0-9 | ||||||||||||||||||||||||||||||
188 | ((void *)0)
| 0-9 | ||||||||||||||||||||||||||||||
189 | ) { | - | ||||||||||||||||||||||||||||||
190 | ERR_put_error(6,(181),((1|64)),__FILE__,242); | - | ||||||||||||||||||||||||||||||
191 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
192 | } | - | ||||||||||||||||||||||||||||||
193 | X = (uint32_t *)(B + Blen); | - | ||||||||||||||||||||||||||||||
194 | T = X + 32 * r; | - | ||||||||||||||||||||||||||||||
195 | V = T + 32 * r; | - | ||||||||||||||||||||||||||||||
196 | if (PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, 1, EVP_sha256(),
| 0-9 | ||||||||||||||||||||||||||||||
197 | (int)Blen, B) == 0
| 0-9 | ||||||||||||||||||||||||||||||
198 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
199 | - | |||||||||||||||||||||||||||||||
200 | for (i = 0; i < p
| 9-84 | ||||||||||||||||||||||||||||||
201 | scryptROMix(B + 128 * r * i, r, N, X, T, V); executed 84 times by 1 test: scryptROMix(B + 128 * r * i, r, N, X, T, V); Executed by:
| 84 | ||||||||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||||||||
203 | if (PKCS5_PBKDF2_HMAC(pass, passlen, B, (int)Blen, 1, EVP_sha256(),
| 0-9 | ||||||||||||||||||||||||||||||
204 | keylen, key) == 0
| 0-9 | ||||||||||||||||||||||||||||||
205 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
206 | rv = 1; | - | ||||||||||||||||||||||||||||||
207 | err: code before this statement executed 9 times by 1 test: err: Executed by:
| 9 | ||||||||||||||||||||||||||||||
208 | if (rv == 0
| 0-9 | ||||||||||||||||||||||||||||||
209 | ERR_put_error(6,(181),(181),__FILE__,261); never executed: ERR_put_error(6,(181),(181),__FILE__,261); | 0 | ||||||||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||||||||
211 | CRYPTO_clear_free(B, (size_t)(Blen + Vlen), __FILE__, 263); | - | ||||||||||||||||||||||||||||||
212 | return executed 9 times by 1 test: rv;return rv; Executed by:
executed 9 times by 1 test: return rv; Executed by:
| 9 | ||||||||||||||||||||||||||||||
213 | } | - | ||||||||||||||||||||||||||||||
Switch to Source code | Preprocessed file |