Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_pss.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | static const unsigned char zeroes[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | - | ||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, | - | ||||||||||||||||||
9 | const EVP_MD *Hash, const unsigned char *EM, | - | ||||||||||||||||||
10 | int sLen) | - | ||||||||||||||||||
11 | { | - | ||||||||||||||||||
12 | return never executed: RSA_verify_PKCS1_PSS_mgf1(rsa, mHash, Hash, return RSA_verify_PKCS1_PSS_mgf1(rsa, mHash, Hash, ((void *)0) , EM, sLen); never executed: return RSA_verify_PKCS1_PSS_mgf1(rsa, mHash, Hash, ((void *)0) , EM, sLen); | 0 | ||||||||||||||||||
13 | ((void *)0) never executed: return RSA_verify_PKCS1_PSS_mgf1(rsa, mHash, Hash, ((void *)0) , EM, sLen); | 0 | ||||||||||||||||||
14 | , EM, sLen); never executed: return RSA_verify_PKCS1_PSS_mgf1(rsa, mHash, Hash, ((void *)0) , EM, sLen); | 0 | ||||||||||||||||||
15 | } | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, | - | ||||||||||||||||||
18 | const EVP_MD *Hash, const EVP_MD *mgf1Hash, | - | ||||||||||||||||||
19 | const unsigned char *EM, int sLen) | - | ||||||||||||||||||
20 | { | - | ||||||||||||||||||
21 | int i; | - | ||||||||||||||||||
22 | int ret = 0; | - | ||||||||||||||||||
23 | int hLen, maskedDBLen, MSBits, emLen; | - | ||||||||||||||||||
24 | const unsigned char *H; | - | ||||||||||||||||||
25 | unsigned char *DB = | - | ||||||||||||||||||
26 | ((void *)0) | - | ||||||||||||||||||
27 | ; | - | ||||||||||||||||||
28 | EVP_MD_CTX *ctx = EVP_MD_CTX_new(); | - | ||||||||||||||||||
29 | unsigned char H_[64]; | - | ||||||||||||||||||
30 | - | |||||||||||||||||||
31 | if (ctx ==
| 0-1009 | ||||||||||||||||||
32 | ((void *)0)
| 0-1009 | ||||||||||||||||||
33 | ) | - | ||||||||||||||||||
34 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | if (mgf1Hash ==
| 75-934 | ||||||||||||||||||
37 | ((void *)0)
| 75-934 | ||||||||||||||||||
38 | ) | - | ||||||||||||||||||
39 | mgf1Hash = Hash; executed 934 times by 1 test: mgf1Hash = Hash; Executed by:
| 934 | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | hLen = EVP_MD_size(Hash); | - | ||||||||||||||||||
42 | if (hLen < 0
| 0-1009 | ||||||||||||||||||
43 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | - | |||||||||||||||||||
46 | - | |||||||||||||||||||
47 | - | |||||||||||||||||||
48 | - | |||||||||||||||||||
49 | - | |||||||||||||||||||
50 | - | |||||||||||||||||||
51 | if (sLen == -1
| 77-932 | ||||||||||||||||||
52 | sLen = hLen; | - | ||||||||||||||||||
53 | } executed 932 times by 1 test: else if (sLen < -3end of block Executed by:
| 0-932 | ||||||||||||||||||
54 | ERR_put_error(4,(126),(136),__FILE__,63); | - | ||||||||||||||||||
55 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
56 | } | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | MSBits = (BN_num_bits(rsa->n) - 1) & 0x7; | - | ||||||||||||||||||
59 | emLen = RSA_size(rsa); | - | ||||||||||||||||||
60 | if (EM[0] & (0xFF << MSBits)
| 1-1008 | ||||||||||||||||||
61 | ERR_put_error(4,(126),(133),__FILE__,70); | - | ||||||||||||||||||
62 | goto executed 1 time by 1 test: err;goto err; Executed by:
executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||
63 | } | - | ||||||||||||||||||
64 | if (MSBits == 0
| 7-1001 | ||||||||||||||||||
65 | EM++; | - | ||||||||||||||||||
66 | emLen--; | - | ||||||||||||||||||
67 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
68 | if (emLen < hLen + 2
| 1-1007 | ||||||||||||||||||
69 | ERR_put_error(4,(126),(109),__FILE__,78); | - | ||||||||||||||||||
70 | goto executed 1 time by 1 test: err;goto err; Executed by:
executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||
71 | } | - | ||||||||||||||||||
72 | if (sLen == -3
| 2-1005 | ||||||||||||||||||
73 | sLen = emLen - hLen - 2; | - | ||||||||||||||||||
74 | } executed 2 times by 1 test: else if (sLen > emLen - hLen - 2end of block Executed by:
| 1-1004 | ||||||||||||||||||
75 | ERR_put_error(4,(126),(109),__FILE__,84); | - | ||||||||||||||||||
76 | goto executed 1 time by 1 test: err;goto err; Executed by:
executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||
77 | } | - | ||||||||||||||||||
78 | if (EM[emLen - 1] != 0xbc
| 6-1000 | ||||||||||||||||||
79 | ERR_put_error(4,(126),(134),__FILE__,88); | - | ||||||||||||||||||
80 | goto executed 6 times by 1 test: err;goto err; Executed by:
executed 6 times by 1 test: goto err; Executed by:
| 6 | ||||||||||||||||||
81 | } | - | ||||||||||||||||||
82 | maskedDBLen = emLen - hLen - 1; | - | ||||||||||||||||||
83 | H = EM + maskedDBLen; | - | ||||||||||||||||||
84 | DB = CRYPTO_malloc(maskedDBLen, __FILE__, 93); | - | ||||||||||||||||||
85 | if (DB ==
| 0-1000 | ||||||||||||||||||
86 | ((void *)0)
| 0-1000 | ||||||||||||||||||
87 | ) { | - | ||||||||||||||||||
88 | ERR_put_error(4,(126),((1|64)),__FILE__,95); | - | ||||||||||||||||||
89 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
90 | } | - | ||||||||||||||||||
91 | if (PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash) < 0
| 0-1000 | ||||||||||||||||||
92 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
93 | for (i = 0; i < maskedDBLen
| 1000-215712 | ||||||||||||||||||
94 | DB[i] ^= EM[i]; executed 215712 times by 1 test: DB[i] ^= EM[i]; Executed by:
| 215712 | ||||||||||||||||||
95 | if (MSBits
| 7-993 | ||||||||||||||||||
96 | DB[0] &= 0xFF >> (8 - MSBits); executed 993 times by 1 test: DB[0] &= 0xFF >> (8 - MSBits); Executed by:
| 993 | ||||||||||||||||||
97 | for (i = 0; DB[i] == 0
executed 181936 times by 1 test: ; Executed by:
| 0-181936 | ||||||||||||||||||
98 | if (DB[i++] != 0x1
| 6-994 | ||||||||||||||||||
99 | ERR_put_error(4,(126),(135),__FILE__,106); | - | ||||||||||||||||||
100 | goto executed 6 times by 1 test: err;goto err; Executed by:
executed 6 times by 1 test: goto err; Executed by:
| 6 | ||||||||||||||||||
101 | } | - | ||||||||||||||||||
102 | if (sLen != -2
| 3-933 | ||||||||||||||||||
103 | ERR_put_error(4,(126),(136),__FILE__,110); | - | ||||||||||||||||||
104 | goto executed 3 times by 1 test: err;goto err; Executed by:
executed 3 times by 1 test: goto err; Executed by:
| 3 | ||||||||||||||||||
105 | } | - | ||||||||||||||||||
106 | if (!EVP_DigestInit_ex(ctx, Hash,
| 0-991 | ||||||||||||||||||
107 | ((void *)0)
| 0-991 | ||||||||||||||||||
108 | )
| 0-991 | ||||||||||||||||||
109 | || !EVP_DigestUpdate(ctx, zeroes, sizeof(zeroes))
| 0-991 | ||||||||||||||||||
110 | || !EVP_DigestUpdate(ctx, mHash, hLen)
| 0-991 | ||||||||||||||||||
111 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
112 | if (maskedDBLen - i
| 1-990 | ||||||||||||||||||
113 | if (!EVP_DigestUpdate(ctx, DB + i, maskedDBLen - i)
| 0-990 | ||||||||||||||||||
114 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
115 | } executed 990 times by 1 test: end of block Executed by:
| 990 | ||||||||||||||||||
116 | if (!EVP_DigestFinal_ex(ctx, H_,
| 0-991 | ||||||||||||||||||
117 | ((void *)0)
| 0-991 | ||||||||||||||||||
118 | )
| 0-991 | ||||||||||||||||||
119 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
120 | if (memcmp(H_, H, hLen)
| 2-989 | ||||||||||||||||||
121 | ERR_put_error(4,(126),(104),__FILE__,124); | - | ||||||||||||||||||
122 | ret = 0; | - | ||||||||||||||||||
123 | } executed 2 times by 1 test: else {end of block Executed by:
| 2 | ||||||||||||||||||
124 | ret = 1; | - | ||||||||||||||||||
125 | } executed 989 times by 1 test: end of block Executed by:
| 989 | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | err: code before this statement executed 991 times by 1 test: err: Executed by:
| 991 | ||||||||||||||||||
128 | CRYPTO_free(DB, __FILE__, 131); | - | ||||||||||||||||||
129 | EVP_MD_CTX_free(ctx); | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | return executed 1009 times by 1 test: ret;return ret; Executed by:
executed 1009 times by 1 test: return ret; Executed by:
| 1009 | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | } | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, | - | ||||||||||||||||||
136 | const unsigned char *mHash, | - | ||||||||||||||||||
137 | const EVP_MD *Hash, int sLen) | - | ||||||||||||||||||
138 | { | - | ||||||||||||||||||
139 | return never executed: RSA_padding_add_PKCS1_PSS_mgf1(rsa, EM, mHash, Hash, return RSA_padding_add_PKCS1_PSS_mgf1(rsa, EM, mHash, Hash, ((void *)0) , sLen); never executed: return RSA_padding_add_PKCS1_PSS_mgf1(rsa, EM, mHash, Hash, ((void *)0) , sLen); | 0 | ||||||||||||||||||
140 | ((void *)0) never executed: return RSA_padding_add_PKCS1_PSS_mgf1(rsa, EM, mHash, Hash, ((void *)0) , sLen); | 0 | ||||||||||||||||||
141 | , sLen); never executed: return RSA_padding_add_PKCS1_PSS_mgf1(rsa, EM, mHash, Hash, ((void *)0) , sLen); | 0 | ||||||||||||||||||
142 | } | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, | - | ||||||||||||||||||
145 | const unsigned char *mHash, | - | ||||||||||||||||||
146 | const EVP_MD *Hash, const EVP_MD *mgf1Hash, | - | ||||||||||||||||||
147 | int sLen) | - | ||||||||||||||||||
148 | { | - | ||||||||||||||||||
149 | int i; | - | ||||||||||||||||||
150 | int ret = 0; | - | ||||||||||||||||||
151 | int hLen, maskedDBLen, MSBits, emLen; | - | ||||||||||||||||||
152 | unsigned char *H, *salt = | - | ||||||||||||||||||
153 | ((void *)0) | - | ||||||||||||||||||
154 | , *p; | - | ||||||||||||||||||
155 | EVP_MD_CTX *ctx = | - | ||||||||||||||||||
156 | ((void *)0) | - | ||||||||||||||||||
157 | ; | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | if (mgf1Hash ==
| 4-1090 | ||||||||||||||||||
160 | ((void *)0)
| 4-1090 | ||||||||||||||||||
161 | ) | - | ||||||||||||||||||
162 | mgf1Hash = Hash; executed 1090 times by 1 test: mgf1Hash = Hash; Executed by:
| 1090 | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | hLen = EVP_MD_size(Hash); | - | ||||||||||||||||||
165 | if (hLen < 0
| 0-1094 | ||||||||||||||||||
166 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | - | |||||||||||||||||||
169 | - | |||||||||||||||||||
170 | - | |||||||||||||||||||
171 | - | |||||||||||||||||||
172 | - | |||||||||||||||||||
173 | - | |||||||||||||||||||
174 | if (sLen == -1
| 8-1086 | ||||||||||||||||||
175 | sLen = hLen; | - | ||||||||||||||||||
176 | } executed 1086 times by 1 test: else if (sLen == -2end of block Executed by:
| 3-1086 | ||||||||||||||||||
177 | sLen = -3; | - | ||||||||||||||||||
178 | } executed 3 times by 1 test: else if (sLen < -3end of block Executed by:
| 0-5 | ||||||||||||||||||
179 | ERR_put_error(4,(152),(136),__FILE__,174); | - | ||||||||||||||||||
180 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | MSBits = (BN_num_bits(rsa->n) - 1) & 0x7; | - | ||||||||||||||||||
184 | emLen = RSA_size(rsa); | - | ||||||||||||||||||
185 | if (MSBits == 0
| 0-1094 | ||||||||||||||||||
186 | *EM++ = 0; | - | ||||||||||||||||||
187 | emLen--; | - | ||||||||||||||||||
188 | } never executed: end of block | 0 | ||||||||||||||||||
189 | if (emLen < hLen + 2
| 2-1092 | ||||||||||||||||||
190 | ERR_put_error(4,(152),(110),__FILE__,186) | - | ||||||||||||||||||
191 | ; | - | ||||||||||||||||||
192 | goto executed 2 times by 1 test: err;goto err; Executed by:
executed 2 times by 1 test: goto err; Executed by:
| 2 | ||||||||||||||||||
193 | } | - | ||||||||||||||||||
194 | if (sLen == -3
| 4-1088 | ||||||||||||||||||
195 | sLen = emLen - hLen - 2; | - | ||||||||||||||||||
196 | } executed 4 times by 1 test: else if (sLen > emLen - hLen - 2end of block Executed by:
| 0-1088 | ||||||||||||||||||
197 | ERR_put_error(4,(152),(110),__FILE__,193) | - | ||||||||||||||||||
198 | ; | - | ||||||||||||||||||
199 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | if (sLen > 0
| 2-1090 | ||||||||||||||||||
202 | salt = CRYPTO_malloc(sLen, __FILE__, 197); | - | ||||||||||||||||||
203 | if (salt ==
| 0-1090 | ||||||||||||||||||
204 | ((void *)0)
| 0-1090 | ||||||||||||||||||
205 | ) { | - | ||||||||||||||||||
206 | ERR_put_error(4,(152),((1|64)),__FILE__,200) | - | ||||||||||||||||||
207 | ; | - | ||||||||||||||||||
208 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
209 | } | - | ||||||||||||||||||
210 | if (RAND_bytes(salt, sLen) <= 0
| 0-1090 | ||||||||||||||||||
211 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
212 | } executed 1090 times by 1 test: end of block Executed by:
| 1090 | ||||||||||||||||||
213 | maskedDBLen = emLen - hLen - 1; | - | ||||||||||||||||||
214 | H = EM + maskedDBLen; | - | ||||||||||||||||||
215 | ctx = EVP_MD_CTX_new(); | - | ||||||||||||||||||
216 | if (ctx ==
| 0-1092 | ||||||||||||||||||
217 | ((void *)0)
| 0-1092 | ||||||||||||||||||
218 | ) | - | ||||||||||||||||||
219 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
220 | if (!EVP_DigestInit_ex(ctx, Hash,
| 0-1092 | ||||||||||||||||||
221 | ((void *)0)
| 0-1092 | ||||||||||||||||||
222 | )
| 0-1092 | ||||||||||||||||||
223 | || !EVP_DigestUpdate(ctx, zeroes, sizeof(zeroes))
| 0-1092 | ||||||||||||||||||
224 | || !EVP_DigestUpdate(ctx, mHash, hLen)
| 0-1092 | ||||||||||||||||||
225 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
226 | if (sLen
| 0-1090 | ||||||||||||||||||
227 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
228 | if (!EVP_DigestFinal_ex(ctx, H,
| 0-1092 | ||||||||||||||||||
229 | ((void *)0)
| 0-1092 | ||||||||||||||||||
230 | )
| 0-1092 | ||||||||||||||||||
231 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | - | |||||||||||||||||||
234 | if (PKCS1_MGF1(EM, maskedDBLen, H, hLen, mgf1Hash)
| 0-1092 | ||||||||||||||||||
235 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | p = EM; | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | - | |||||||||||||||||||
240 | - | |||||||||||||||||||
241 | - | |||||||||||||||||||
242 | - | |||||||||||||||||||
243 | p += emLen - sLen - hLen - 2; | - | ||||||||||||||||||
244 | *p++ ^= 0x1; | - | ||||||||||||||||||
245 | if (sLen > 0
| 2-1090 | ||||||||||||||||||
246 | for (i = 0; i < sLen
| 1090-35780 | ||||||||||||||||||
247 | * executed 35780 times by 1 test: p++ ^= salt[i];*p++ ^= salt[i]; Executed by:
executed 35780 times by 1 test: *p++ ^= salt[i]; Executed by:
| 35780 | ||||||||||||||||||
248 | } executed 1090 times by 1 test: end of block Executed by:
| 1090 | ||||||||||||||||||
249 | if (MSBits
| 0-1092 | ||||||||||||||||||
250 | EM[0] &= 0xFF >> (8 - MSBits); executed 1092 times by 1 test: EM[0] &= 0xFF >> (8 - MSBits); Executed by:
| 1092 | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | - | |||||||||||||||||||
253 | - | |||||||||||||||||||
254 | EM[emLen - 1] = 0xbc; | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | ret = 1; | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | err: code before this statement executed 1092 times by 1 test: err: Executed by:
| 1092 | ||||||||||||||||||
259 | EVP_MD_CTX_free(ctx); | - | ||||||||||||||||||
260 | CRYPTO_clear_free(salt, (size_t)sLen, __FILE__, 247); | - | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | return executed 1094 times by 1 test: ret;return ret; Executed by:
executed 1094 times by 1 test: return ret; Executed by:
| 1094 | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |