Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_pk1.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | - | ||||||||||||||||||||||||
4 | const unsigned char *from, int flen) | - | ||||||||||||||||||||||||
5 | { | - | ||||||||||||||||||||||||
6 | int j; | - | ||||||||||||||||||||||||
7 | unsigned char *p; | - | ||||||||||||||||||||||||
8 | - | |||||||||||||||||||||||||
9 | if (flen > (tlen - 11)
| 0-559 | ||||||||||||||||||||||||
10 | ERR_put_error(4,(108),(110),__FILE__,26) | - | ||||||||||||||||||||||||
11 | ; | - | ||||||||||||||||||||||||
12 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
13 | } | - | ||||||||||||||||||||||||
14 | - | |||||||||||||||||||||||||
15 | p = (unsigned char *)to; | - | ||||||||||||||||||||||||
16 | - | |||||||||||||||||||||||||
17 | *(p++) = 0; | - | ||||||||||||||||||||||||
18 | *(p++) = 1; | - | ||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||
21 | j = tlen - 3 - flen; | - | ||||||||||||||||||||||||
22 | memset(p, 0xff, j); | - | ||||||||||||||||||||||||
23 | p += j; | - | ||||||||||||||||||||||||
24 | *(p++) = '\0'; | - | ||||||||||||||||||||||||
25 | memcpy(p, from, (unsigned int)flen); | - | ||||||||||||||||||||||||
26 | return executed 559 times by 1 test: 1;return 1; Executed by:
executed 559 times by 1 test: return 1; Executed by:
| 559 | ||||||||||||||||||||||||
27 | } | - | ||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, | - | ||||||||||||||||||||||||
30 | const unsigned char *from, int flen, | - | ||||||||||||||||||||||||
31 | int num) | - | ||||||||||||||||||||||||
32 | { | - | ||||||||||||||||||||||||
33 | int i, j; | - | ||||||||||||||||||||||||
34 | const unsigned char *p; | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | p = from; | - | ||||||||||||||||||||||||
37 | if (num < 11
| 0-1763 | ||||||||||||||||||||||||
38 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | if (num == flen
| 0-1763 | ||||||||||||||||||||||||
42 | if ((*
| 16-1747 | ||||||||||||||||||||||||
43 | ERR_put_error(4,(112),(138),__FILE__,67) | - | ||||||||||||||||||||||||
44 | ; | - | ||||||||||||||||||||||||
45 | return executed 16 times by 1 test: -1;return -1; Executed by:
executed 16 times by 1 test: return -1; Executed by:
| 16 | ||||||||||||||||||||||||
46 | } | - | ||||||||||||||||||||||||
47 | flen--; | - | ||||||||||||||||||||||||
48 | } executed 1747 times by 1 test: end of block Executed by:
| 1747 | ||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||
50 | if ((
| 0-1747 | ||||||||||||||||||||||||
51 | ERR_put_error(4,(112),(106),__FILE__,75) | - | ||||||||||||||||||||||||
52 | ; | - | ||||||||||||||||||||||||
53 | return executed 1 time by 1 test: -1;return -1; Executed by:
executed 1 time by 1 test: return -1; Executed by:
| 1 | ||||||||||||||||||||||||
54 | } | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | j = flen - 1; | - | ||||||||||||||||||||||||
58 | for (i = 0; i < j
| 1-361120 | ||||||||||||||||||||||||
59 | if (*
| 1745-359375 | ||||||||||||||||||||||||
60 | if (*
| 2-1743 | ||||||||||||||||||||||||
61 | p++; | - | ||||||||||||||||||||||||
62 | break; executed 1743 times by 1 test: break; Executed by:
| 1743 | ||||||||||||||||||||||||
63 | } else { | - | ||||||||||||||||||||||||
64 | ERR_put_error(4,(112),(102),__FILE__,88) | - | ||||||||||||||||||||||||
65 | ; | - | ||||||||||||||||||||||||
66 | return executed 2 times by 1 test: -1;return -1; Executed by:
executed 2 times by 1 test: return -1; Executed by:
| 2 | ||||||||||||||||||||||||
67 | } | - | ||||||||||||||||||||||||
68 | } | - | ||||||||||||||||||||||||
69 | p++; | - | ||||||||||||||||||||||||
70 | } executed 359375 times by 1 test: end of block Executed by:
| 359375 | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | if (i == j
| 1-1743 | ||||||||||||||||||||||||
73 | ERR_put_error(4,(112),(113),__FILE__,97) | - | ||||||||||||||||||||||||
74 | ; | - | ||||||||||||||||||||||||
75 | return executed 1 time by 1 test: -1;return -1; Executed by:
executed 1 time by 1 test: return -1; Executed by:
| 1 | ||||||||||||||||||||||||
76 | } | - | ||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||
78 | if (i < 8
| 0-1743 | ||||||||||||||||||||||||
79 | ERR_put_error(4,(112),(103),__FILE__,103) | - | ||||||||||||||||||||||||
80 | ; | - | ||||||||||||||||||||||||
81 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
82 | } | - | ||||||||||||||||||||||||
83 | i++; | - | ||||||||||||||||||||||||
84 | j -= i; | - | ||||||||||||||||||||||||
85 | if (j > tlen
| 0-1743 | ||||||||||||||||||||||||
86 | ERR_put_error(4,(112),(109),__FILE__,109); | - | ||||||||||||||||||||||||
87 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
88 | } | - | ||||||||||||||||||||||||
89 | memcpy(to, p, (unsigned int)j); | - | ||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||
91 | return executed 1743 times by 1 test: j;return j; Executed by:
executed 1743 times by 1 test: return j; Executed by:
| 1743 | ||||||||||||||||||||||||
92 | } | - | ||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||
94 | int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, | - | ||||||||||||||||||||||||
95 | const unsigned char *from, int flen) | - | ||||||||||||||||||||||||
96 | { | - | ||||||||||||||||||||||||
97 | int i, j; | - | ||||||||||||||||||||||||
98 | unsigned char *p; | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | if (flen > (tlen - 11)
| 1-492 | ||||||||||||||||||||||||
101 | ERR_put_error(4,(109),(110),__FILE__,125) | - | ||||||||||||||||||||||||
102 | ; | - | ||||||||||||||||||||||||
103 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||
104 | } | - | ||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||
106 | p = (unsigned char *)to; | - | ||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||
108 | *(p++) = 0; | - | ||||||||||||||||||||||||
109 | *(p++) = 2; | - | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||
112 | j = tlen - 3 - flen; | - | ||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | if (RAND_bytes(p, j) <= 0
| 0-492 | ||||||||||||||||||||||||
115 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
116 | for (i = 0; i < j
| 492-62886 | ||||||||||||||||||||||||
117 | if (*
| 118-62768 | ||||||||||||||||||||||||
118 | do { | - | ||||||||||||||||||||||||
119 | if (RAND_bytes(p, 1) <= 0
| 0-119 | ||||||||||||||||||||||||
120 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
121 | } executed 119 times by 1 test: while (*end of block Executed by:
| 1-119 | ||||||||||||||||||||||||
122 | p++; | - | ||||||||||||||||||||||||
123 | } executed 62886 times by 1 test: end of block Executed by:
| 62886 | ||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | *(p++) = '\0'; | - | ||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||
127 | memcpy(p, from, (unsigned int)flen); | - | ||||||||||||||||||||||||
128 | return executed 492 times by 1 test: 1;return 1; Executed by:
executed 492 times by 1 test: return 1; Executed by:
| 492 | ||||||||||||||||||||||||
129 | } | - | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, | - | ||||||||||||||||||||||||
132 | const unsigned char *from, int flen, | - | ||||||||||||||||||||||||
133 | int num) | - | ||||||||||||||||||||||||
134 | { | - | ||||||||||||||||||||||||
135 | int i; | - | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | unsigned char *em = | - | ||||||||||||||||||||||||
138 | ((void *)0) | - | ||||||||||||||||||||||||
139 | ; | - | ||||||||||||||||||||||||
140 | unsigned int good, found_zero_byte; | - | ||||||||||||||||||||||||
141 | int zero_index = 0, msg_index, mlen = -1; | - | ||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||
143 | if (tlen < 0
| 0-31 | ||||||||||||||||||||||||
144 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||
151 | if (flen > num
| 0-31 | ||||||||||||||||||||||||
152 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | if (num < 11
| 0-31 | ||||||||||||||||||||||||
155 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | if (flen != num
| 0-31 | ||||||||||||||||||||||||
158 | em = CRYPTO_zalloc(num, __FILE__, 179); | - | ||||||||||||||||||||||||
159 | if (em ==
| 0 | ||||||||||||||||||||||||
160 | ((void *)0)
| 0 | ||||||||||||||||||||||||
161 | ) { | - | ||||||||||||||||||||||||
162 | ERR_put_error(4,(113),((1|64)),__FILE__,181); | - | ||||||||||||||||||||||||
163 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
164 | } | - | ||||||||||||||||||||||||
165 | memcpy(em + num - flen, from, flen); | - | ||||||||||||||||||||||||
166 | from = em; | - | ||||||||||||||||||||||||
167 | } never executed: end of block | 0 | ||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||
169 | good = constant_time_is_zero(from[0]); | - | ||||||||||||||||||||||||
170 | good &= constant_time_eq(from[1], 2); | - | ||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||
172 | found_zero_byte = 0; | - | ||||||||||||||||||||||||
173 | for (i = 2; i < num
| 31-9268 | ||||||||||||||||||||||||
174 | unsigned int equals0 = constant_time_is_zero(from[i]); | - | ||||||||||||||||||||||||
175 | zero_index = | - | ||||||||||||||||||||||||
176 | constant_time_select_int(~found_zero_byte & equals0, i, | - | ||||||||||||||||||||||||
177 | zero_index); | - | ||||||||||||||||||||||||
178 | found_zero_byte |= equals0; | - | ||||||||||||||||||||||||
179 | } executed 9268 times by 1 test: end of block Executed by:
| 9268 | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | - | |||||||||||||||||||||||||
182 | - | |||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | - | |||||||||||||||||||||||||
186 | good &= constant_time_ge((unsigned int)(zero_index), 2 + 8); | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | - | |||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||
192 | msg_index = zero_index + 1; | - | ||||||||||||||||||||||||
193 | mlen = num - msg_index; | - | ||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||
195 | - | |||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | - | |||||||||||||||||||||||||
199 | good &= constant_time_ge((unsigned int)(tlen), (unsigned int)(mlen)); | - | ||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | if (!good
| 5-26 | ||||||||||||||||||||||||
207 | mlen = -1; | - | ||||||||||||||||||||||||
208 | goto executed 5 times by 1 test: err;goto err; Executed by:
executed 5 times by 1 test: goto err; Executed by:
| 5 | ||||||||||||||||||||||||
209 | } | - | ||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||
211 | memcpy(to, from + msg_index, mlen); | - | ||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||
213 | err: code before this statement executed 26 times by 1 test: err: Executed by:
| 26 | ||||||||||||||||||||||||
214 | CRYPTO_clear_free(em, num, __FILE__, 241); | - | ||||||||||||||||||||||||
215 | if (mlen == -1
| 5-26 | ||||||||||||||||||||||||
216 | ERR_put_error(4,(113),(159),__FILE__,244) executed 5 times by 1 test: ERR_put_error(4,(113),(159),__FILE__,244) ; Executed by:
| 5 | ||||||||||||||||||||||||
217 | ; executed 5 times by 1 test: ERR_put_error(4,(113),(159),__FILE__,244) ; Executed by:
| 5 | ||||||||||||||||||||||||
218 | return executed 31 times by 1 test: mlen;return mlen; Executed by:
executed 31 times by 1 test: return mlen; Executed by:
| 31 | ||||||||||||||||||||||||
219 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |