OpenCoverage

rsa_pk1.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_pk1.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3int 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)
flen > (tlen - 11)Description
TRUEnever evaluated
FALSEevaluated 559 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-559
10 ERR_put_error(4,(108),(110),__FILE__,26)-
11 ;-
12 return
never executed: return 0;
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: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 559 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
559
27}-
28-
29int 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
num < 11Description
TRUEnever evaluated
FALSEevaluated 1763 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-1763
38 return
never executed: return -1;
-1;
never executed: return -1;
0
39-
40-
41 if (num == flen
num == flenDescription
TRUEevaluated 1763 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-1763
42 if ((*
(*p++) != 0x00Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1747 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p++) != 0x00
(*p++) != 0x00Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1747 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
16-1747
43 ERR_put_error(4,(112),(138),__FILE__,67)-
44 ;-
45 return
executed 16 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
-1;
executed 16 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
16
46 }-
47 flen--;-
48 }
executed 1747 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1747
49-
50 if ((
(num != (flen + 1))Description
TRUEnever evaluated
FALSEevaluated 1747 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
num != (flen + 1))
(num != (flen + 1))Description
TRUEnever evaluated
FALSEevaluated 1747 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| (*(
(*(p++) != 0x01)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p++) != 0x01)
(*(p++) != 0x01)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1746 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-1747
51 ERR_put_error(4,(112),(106),__FILE__,75)-
52 ;-
53 return
executed 1 time by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
-1;
executed 1 time by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
1
54 }-
55-
56-
57 j = flen - 1;-
58 for (i = 0; i < j
i < jDescription
TRUEevaluated 361120 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++) {
1-361120
59 if (*
*p != 0xffDescription
TRUEevaluated 1745 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 359375 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p != 0xff
*p != 0xffDescription
TRUEevaluated 1745 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 359375 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1745-359375
60 if (*
*p == 0Description
TRUEevaluated 1743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p == 0
*p == 0Description
TRUEevaluated 1743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
2-1743
61 p++;-
62 break;
executed 1743 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
1743
63 } else {-
64 ERR_put_error(4,(112),(102),__FILE__,88)-
65 ;-
66 return
executed 2 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
-1;
executed 2 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
2
67 }-
68 }-
69 p++;-
70 }
executed 359375 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
359375
71-
72 if (i == j
i == jDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1-1743
73 ERR_put_error(4,(112),(113),__FILE__,97)-
74 ;-
75 return
executed 1 time by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
-1;
executed 1 time by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
1
76 }-
77-
78 if (i < 8
i < 8Description
TRUEnever evaluated
FALSEevaluated 1743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-1743
79 ERR_put_error(4,(112),(103),__FILE__,103)-
80 ;-
81 return
never executed: return -1;
-1;
never executed: return -1;
0
82 }-
83 i++;-
84 j -= i;-
85 if (j > tlen
j > tlenDescription
TRUEnever evaluated
FALSEevaluated 1743 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-1743
86 ERR_put_error(4,(112),(109),__FILE__,109);-
87 return
never executed: return -1;
-1;
never executed: return -1;
0
88 }-
89 memcpy(to, p, (unsigned int)j);-
90-
91 return
executed 1743 times by 1 test: return j;
Executed by:
  • libcrypto.so.1.1
j;
executed 1743 times by 1 test: return j;
Executed by:
  • libcrypto.so.1.1
1743
92}-
93-
94int 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)
flen > (tlen - 11)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1-492
101 ERR_put_error(4,(109),(110),__FILE__,125)-
102 ;-
103 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
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
RAND_bytes(p, j) <= 0Description
TRUEnever evaluated
FALSEevaluated 492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-492
115 return
never executed: return 0;
0;
never executed: return 0;
0
116 for (i = 0; i < j
i < jDescription
TRUEevaluated 62886 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++) {
492-62886
117 if (*
*p == '\0'Description
TRUEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 62768 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p == '\0'
*p == '\0'Description
TRUEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 62768 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
118-62768
118 do {-
119 if (RAND_bytes(p, 1) <= 0
RAND_bytes(p, 1) <= 0Description
TRUEnever evaluated
FALSEevaluated 119 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-119
120 return
never executed: return 0;
0;
never executed: return 0;
0
121 }
executed 119 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
while (*
*p == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
p == '\0'
*p == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
);
1-119
122 p++;-
123 }
executed 62886 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
62886
124-
125 *(p++) = '\0';-
126-
127 memcpy(p, from, (unsigned int)flen);-
128 return
executed 492 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 492 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
492
129}-
130-
131int 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
tlen < 0Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| flen < 0
flen < 0Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-31
144 return
never executed: return -1;
-1;
never executed: return -1;
0
145-
146-
147-
148-
149-
150-
151 if (flen > num
flen > numDescription
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-31
152 goto
never executed: goto err;
err;
never executed: goto err;
0
153-
154 if (num < 11
num < 11Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-31
155 goto
never executed: goto err;
err;
never executed: goto err;
0
156-
157 if (flen != num
flen != numDescription
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-31
158 em = CRYPTO_zalloc(num, __FILE__, 179);-
159 if (em ==
em == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
160 ((void *)0)
em == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
161 ) {-
162 ERR_put_error(4,(113),((1|64)),__FILE__,181);-
163 return
never executed: return -1;
-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
i < numDescription
TRUEevaluated 9268 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++) {
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:
  • libcrypto.so.1.1
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
!goodDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
5-26
207 mlen = -1;-
208 goto
executed 5 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
err;
executed 5 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
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:
  • libcrypto.so.1.1
26
214 CRYPTO_clear_free(em, num, __FILE__, 241);-
215 if (mlen == -1
mlen == -1Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.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:
  • libcrypto.so.1.1
5
217 ;
executed 5 times by 1 test: ERR_put_error(4,(113),(159),__FILE__,244) ;
Executed by:
  • libcrypto.so.1.1
5
218 return
executed 31 times by 1 test: return mlen;
Executed by:
  • libcrypto.so.1.1
mlen;
executed 31 times by 1 test: return mlen;
Executed by:
  • libcrypto.so.1.1
31
219}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2