OpenCoverage

a_int.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/asn1/a_int.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: a_int.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */-
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)-
3 * All rights reserved.-
4 *-
5 * This package is an SSL implementation written-
6 * by Eric Young (eay@cryptsoft.com).-
7 * The implementation was written so as to conform with Netscapes SSL.-
8 *-
9 * This library is free for commercial and non-commercial use as long as-
10 * the following conditions are aheared to. The following conditions-
11 * apply to all code found in this distribution, be it the RC4, RSA,-
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation-
13 * included with this distribution is covered by the same copyright terms-
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).-
15 *-
16 * Copyright remains Eric Young's, and as such any Copyright notices in-
17 * the code are not to be removed.-
18 * If this package is used in a product, Eric Young should be given attribution-
19 * as the author of the parts of the library used.-
20 * This can be in the form of a textual message at program startup or-
21 * in documentation (online or textual) provided with the package.-
22 *-
23 * Redistribution and use in source and binary forms, with or without-
24 * modification, are permitted provided that the following conditions-
25 * are met:-
26 * 1. Redistributions of source code must retain the copyright-
27 * notice, this list of conditions and the following disclaimer.-
28 * 2. Redistributions in binary form must reproduce the above copyright-
29 * notice, this list of conditions and the following disclaimer in the-
30 * documentation and/or other materials provided with the distribution.-
31 * 3. All advertising materials mentioning features or use of this software-
32 * must display the following acknowledgement:-
33 * "This product includes cryptographic software written by-
34 * Eric Young (eay@cryptsoft.com)"-
35 * The word 'cryptographic' can be left out if the rouines from the library-
36 * being used are not cryptographic related :-).-
37 * 4. If you include any Windows specific code (or a derivative thereof) from-
38 * the apps directory (application code) you must include an acknowledgement:-
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"-
40 *-
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND-
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE-
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE-
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE-
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL-
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS-
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)-
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT-
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY-
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF-
51 * SUCH DAMAGE.-
52 *-
53 * The licence and distribution terms for any publically available version or-
54 * derivative of this code cannot be changed. i.e. this code cannot simply be-
55 * copied and put under another distribution licence-
56 * [including the GNU Public Licence.]-
57 */-
58-
59#include <stdio.h>-
60#include <string.h>-
61-
62#include <openssl/asn1.h>-
63#include <openssl/bn.h>-
64#include <openssl/err.h>-
65-
66ASN1_INTEGER *-
67ASN1_INTEGER_dup(const ASN1_INTEGER *x)-
68{-
69 return ASN1_STRING_dup(x);
never executed: return ASN1_STRING_dup(x);
0
70}-
71-
72int-
73ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)-
74{-
75 int neg, ret;-
76-
77 /* Compare signs */-
78 neg = x->type & V_ASN1_NEG;-
79 if (neg != (y->type & V_ASN1_NEG)) {
neg != (y->type & 0x100)Description
TRUEnever evaluated
FALSEnever evaluated
0
80 if (neg)
negDescription
TRUEnever evaluated
FALSEnever evaluated
0
81 return -1;
never executed: return -1;
0
82 else-
83 return 1;
never executed: return 1;
0
84 }-
85-
86 ret = ASN1_STRING_cmp(x, y);-
87-
88 if (neg)
negDescription
TRUEnever evaluated
FALSEnever evaluated
0
89 return -ret;
never executed: return -ret;
0
90 else-
91 return ret;
never executed: return ret;
0
92}-
93-
94-
95/*-
96 * This converts an ASN1 INTEGER into its content encoding.-
97 * The internal representation is an ASN1_STRING whose data is a big endian-
98 * representation of the value, ignoring the sign. The sign is determined by-
99 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.-
100 *-
101 * Positive integers are no problem: they are almost the same as the DER-
102 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.-
103 *-
104 * Negative integers are a bit trickier...-
105 * The DER representation of negative integers is in 2s complement form.-
106 * The internal form is converted by complementing each octet and finally-
107 * adding one to the result. This can be done less messily with a little trick.-
108 * If the internal form has trailing zeroes then they will become FF by the-
109 * complement and 0 by the add one (due to carry) so just copy as many trailing-
110 * zeros to the destination as there are in the source. The carry will add one-
111 * to the last none zero octet: so complement this octet and add one and finally-
112 * complement any left over until you get to the start of the string.-
113 *-
114 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad-
115 * with 0xff. However if the first byte is 0x80 and one of the following bytes-
116 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80-
117 * followed by optional zeros isn't padded.-
118 */-
119-
120int-
121i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)-
122{-
123 int pad = 0, ret, i, neg;-
124 unsigned char *p, *n, pb = 0;-
125-
126 if (a == NULL)
a == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 206 times by 4 tests
Evaluated by:
  • asn1evp
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
0-206
127 return (0);
never executed: return (0);
0
128 neg = a->type & V_ASN1_NEG;-
129 if (a->length == 0)
a->length == 0Description
TRUEevaluated 18 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 188 times by 4 tests
Evaluated by:
  • asn1evp
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
18-188
130 ret = 1;
executed 18 times by 2 tests: ret = 1;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
18
131 else {-
132 ret = a->length;-
133 i = a->data[0];-
134 if (!neg && (i > 127)) {
!negDescription
TRUEevaluated 188 times by 4 tests
Evaluated by:
  • asn1evp
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEnever evaluated
(i > 127)Description
TRUEevaluated 133 times by 3 tests
Evaluated by:
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 55 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
0-188
135 pad = 1;-
136 pb = 0;-
137 } else if (neg) {
executed 133 times by 3 tests: end of block
Executed by:
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
negDescription
TRUEnever evaluated
FALSEevaluated 55 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
0-133
138 if (i > 128) {
i > 128Description
TRUEnever evaluated
FALSEnever evaluated
0
139 pad = 1;-
140 pb = 0xFF;-
141 } else if (i == 128) {
never executed: end of block
i == 128Description
TRUEnever evaluated
FALSEnever evaluated
0
142 /*-
143 * Special case: if any other bytes non zero we pad:-
144 * otherwise we don't.-
145 */-
146 for (i = 1; i < a->length; i++) if (a->data[i]) {
a->data[i]Description
TRUEnever evaluated
FALSEnever evaluated
i < a->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
147 pad = 1;-
148 pb = 0xFF;-
149 break;
never executed: break;
0
150 }-
151 }
never executed: end of block
0
152 }
never executed: end of block
0
153 ret += pad;-
154 }
executed 188 times by 4 tests: end of block
Executed by:
  • asn1evp
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
188
155 if (pp == NULL)
pp == ((void *)0)Description
TRUEevaluated 184 times by 4 tests
Evaluated by:
  • asn1evp
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
22-184
156 return (ret);
executed 184 times by 4 tests: return (ret);
Executed by:
  • asn1evp
  • ecdsatest
  • libcrypto.so.44.0.1
  • pkcs7test
184
157 p= *pp;-
158-
159 if (pad)
padDescription
TRUEevaluated 9 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 13 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
9-13
160 *(p++) = pb;
executed 9 times by 2 tests: *(p++) = pb;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
9
161 if (a->length == 0)
a->length == 0Description
TRUEevaluated 3 times by 2 tests
Evaluated by:
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 19 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
3-19
162 *(p++) = 0;
executed 3 times by 2 tests: *(p++) = 0;
Executed by:
  • libcrypto.so.44.0.1
  • pkcs7test
3
163 else if (!neg)
!negDescription
TRUEevaluated 19 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEnever evaluated
0-19
164 memcpy(p, a->data, a->length);
executed 19 times by 3 tests: memcpy(p, a->data, a->length);
Executed by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
19
165 else {-
166 /* Begin at the end of the encoding */-
167 n = a->data + a->length - 1;-
168 p += a->length - 1;-
169 i = a->length;-
170 /* Copy zeros to destination as long as source is zero */-
171 while (!*n) {
!*nDescription
TRUEnever evaluated
FALSEnever evaluated
0
172 *(p--) = 0;-
173 n--;-
174 i--;-
175 }
never executed: end of block
0
176 /* Complement and increment next octet */-
177 *(p--) = ((*(n--)) ^ 0xff) + 1;-
178 i--;-
179 /* Complement any octets left */-
180 for (; i > 0; i--)
i > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
181 *(p--) = *(n--) ^ 0xff;
never executed: *(p--) = *(n--) ^ 0xff;
0
182 }
never executed: end of block
0
183-
184 *pp += ret;-
185 return (ret);
executed 22 times by 3 tests: return (ret);
Executed by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
22
186}-
187-
188/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */-
189-
190ASN1_INTEGER *-
191c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)-
192{-
193 ASN1_INTEGER *ret = NULL;-
194 const unsigned char *p, *pend;-
195 unsigned char *to, *s;-
196 int i;-
197-
198 if ((a == NULL) || ((*a) == NULL)) {
(a == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 449 times by 8 tests
Evaluated by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
((*a) == ((void *)0) )Description
TRUEevaluated 219 times by 7 tests
Evaluated by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
FALSEevaluated 230 times by 8 tests
Evaluated by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-449
199 if ((ret = ASN1_INTEGER_new()) == NULL)
(ret = ASN1_IN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 219 times by 7 tests
Evaluated by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-219
200 return (NULL);
never executed: return ( ((void *)0) );
0
201 } else
executed 219 times by 7 tests: end of block
Executed by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
219
202 ret = (*a);
executed 230 times by 8 tests: ret = (*a);
Executed by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
230
203-
204 p = *pp;-
205 pend = p + len;-
206-
207 /* We must malloc stuff, even for 0 bytes otherwise it-
208 * signifies a missing NULL parameter. */-
209 s = malloc(len + 1);-
210 if (s == NULL) {
s == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 449 times by 8 tests
Evaluated by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-449
211 i = ERR_R_MALLOC_FAILURE;-
212 goto err;
never executed: goto err;
0
213 }-
214 to = s;-
215 if (!len) {
!lenDescription
TRUEnever evaluated
FALSEevaluated 449 times by 8 tests
Evaluated by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-449
216 /* Strictly speaking this is an illegal INTEGER but we-
217 * tolerate it.-
218 */-
219 ret->type = V_ASN1_INTEGER;-
220 } else if (*p & 0x80) /* a negative number */ {
never executed: end of block
*p & 0x80Description
TRUEnever evaluated
FALSEevaluated 449 times by 8 tests
Evaluated by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-449
221 ret->type = V_ASN1_NEG_INTEGER;-
222 if ((*p == 0xff) && (len != 1)) {
(*p == 0xff)Description
TRUEnever evaluated
FALSEnever evaluated
(len != 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
223 p++;-
224 len--;-
225 }
never executed: end of block
0
226 i = len;-
227 p += i - 1;-
228 to += i - 1;-
229 while((!*p) && i) {
(!*p)Description
TRUEnever evaluated
FALSEnever evaluated
iDescription
TRUEnever evaluated
FALSEnever evaluated
0
230 *(to--) = 0;-
231 i--;-
232 p--;-
233 }
never executed: end of block
0
234 /* Special case: if all zeros then the number will be of-
235 * the form FF followed by n zero bytes: this corresponds to-
236 * 1 followed by n zero bytes. We've already written n zeros-
237 * so we just append an extra one and set the first byte to-
238 * a 1. This is treated separately because it is the only case-
239 * where the number of bytes is larger than len.-
240 */-
241 if (!i) {
!iDescription
TRUEnever evaluated
FALSEnever evaluated
0
242 *s = 1;-
243 s[len] = 0;-
244 len++;-
245 } else {
never executed: end of block
0
246 *(to--) = (*(p--) ^ 0xff) + 1;-
247 i--;-
248 for (; i > 0; i--)
i > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
249 *(to--) = *(p--) ^ 0xff;
never executed: *(to--) = *(p--) ^ 0xff;
0
250 }
never executed: end of block
0
251 } else {-
252 ret->type = V_ASN1_INTEGER;-
253 if ((*p == 0) && (len != 1)) {
(*p == 0)Description
TRUEevaluated 226 times by 7 tests
Evaluated by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
FALSEevaluated 223 times by 8 tests
Evaluated by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
(len != 1)Description
TRUEevaluated 224 times by 7 tests
Evaluated by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
FALSEevaluated 2 times by 1 test
Evaluated by:
  • pkcs7test
2-226
254 p++;-
255 len--;-
256 }
executed 224 times by 7 tests: end of block
Executed by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
224
257 memcpy(s, p, len);-
258 }
executed 449 times by 8 tests: end of block
Executed by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
449
259-
260 free(ret->data);-
261 ret->data = s;-
262 ret->length = (int)len;-
263 if (a != NULL)
a != ((void *)0)Description
TRUEevaluated 449 times by 8 tests
Evaluated by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
FALSEnever evaluated
0-449
264 (*a) = ret;
executed 449 times by 8 tests: (*a) = ret;
Executed by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
449
265 *pp = pend;-
266 return (ret);
executed 449 times by 8 tests: return (ret);
Executed by:
  • asn1evp
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
449
267-
268err:-
269 ASN1error(i);-
270 if (a == NULL || *a != ret)
a == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
*a != retDescription
TRUEnever evaluated
FALSEnever evaluated
0
271 ASN1_INTEGER_free(ret);
never executed: ASN1_INTEGER_free(ret);
0
272 return (NULL);
never executed: return ( ((void *)0) );
0
273}-
274-
275-
276/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of-
277 * ASN1 integers: some broken software can encode a positive INTEGER-
278 * with its MSB set as negative (it doesn't add a padding zero).-
279 */-
280-
281ASN1_INTEGER *-
282d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)-
283{-
284 ASN1_INTEGER *ret = NULL;-
285 const unsigned char *p;-
286 unsigned char *s;-
287 long len;-
288 int inf, tag, xclass;-
289 int i;-
290-
291 if ((a == NULL) || ((*a) == NULL)) {
(a == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
((*a) == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
292 if ((ret = ASN1_INTEGER_new()) == NULL)
(ret = ASN1_IN...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
293 return (NULL);
never executed: return ( ((void *)0) );
0
294 } else
never executed: end of block
0
295 ret = (*a);
never executed: ret = (*a);
0
296-
297 p = *pp;-
298 inf = ASN1_get_object(&p, &len, &tag, &xclass, length);-
299 if (inf & 0x80) {
inf & 0x80Description
TRUEnever evaluated
FALSEnever evaluated
0
300 i = ASN1_R_BAD_OBJECT_HEADER;-
301 goto err;
never executed: goto err;
0
302 }-
303-
304 if (tag != V_ASN1_INTEGER) {
tag != 2Description
TRUEnever evaluated
FALSEnever evaluated
0
305 i = ASN1_R_EXPECTING_AN_INTEGER;-
306 goto err;
never executed: goto err;
0
307 }-
308-
309 /* We must malloc stuff, even for 0 bytes otherwise it-
310 * signifies a missing NULL parameter. */-
311 s = malloc(len + 1);-
312 if (s == NULL) {
s == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
313 i = ERR_R_MALLOC_FAILURE;-
314 goto err;
never executed: goto err;
0
315 }-
316 ret->type = V_ASN1_INTEGER;-
317 if (len) {
lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
318 if ((*p == 0) && (len != 1)) {
(*p == 0)Description
TRUEnever evaluated
FALSEnever evaluated
(len != 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
319 p++;-
320 len--;-
321 }
never executed: end of block
0
322 memcpy(s, p, len);-
323 p += len;-
324 }
never executed: end of block
0
325-
326 free(ret->data);-
327 ret->data = s;-
328 ret->length = (int)len;-
329 if (a != NULL)
a != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
330 (*a) = ret;
never executed: (*a) = ret;
0
331 *pp = p;-
332 return (ret);
never executed: return (ret);
0
333-
334err:-
335 ASN1error(i);-
336 if (a == NULL || *a != ret)
a == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
*a != retDescription
TRUEnever evaluated
FALSEnever evaluated
0
337 ASN1_INTEGER_free(ret);
never executed: ASN1_INTEGER_free(ret);
0
338 return (NULL);
never executed: return ( ((void *)0) );
0
339}-
340-
341int-
342ASN1_INTEGER_set(ASN1_INTEGER *a, long v)-
343{-
344 int j, k;-
345 unsigned int i;-
346 unsigned char buf[sizeof(long) + 1];-
347 long d;-
348-
349 a->type = V_ASN1_INTEGER;-
350 /* XXX ssl/ssl_asn1.c:i2d_SSL_SESSION() depends upon this bound vae */-
351 if (a->length < (int)(sizeof(long) + 1)) {
a->length < (i...eof(long) + 1)Description
TRUEevaluated 16 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEnever evaluated
0-16
352 free(a->data);-
353 a->data = calloc(1, sizeof(long) + 1);-
354 }
executed 16 times by 3 tests: end of block
Executed by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
16
355 if (a->data == NULL) {
a->data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 16 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
0-16
356 ASN1error(ERR_R_MALLOC_FAILURE);-
357 return (0);
never executed: return (0);
0
358 }-
359 d = v;-
360 if (d < 0) {
d < 0Description
TRUEnever evaluated
FALSEevaluated 16 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
0-16
361 d = -d;-
362 a->type = V_ASN1_NEG_INTEGER;-
363 }
never executed: end of block
0
364-
365 for (i = 0; i < sizeof(long); i++) {
i < sizeof(long)Description
TRUEevaluated 30 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEnever evaluated
0-30
366 if (d == 0)
d == 0Description
TRUEevaluated 16 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • asn1evp
  • pkcs7test
14-16
367 break;
executed 16 times by 3 tests: break;
Executed by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
16
368 buf[i] = (int)d & 0xff;-
369 d >>= 8;-
370 }
executed 14 times by 2 tests: end of block
Executed by:
  • asn1evp
  • pkcs7test
14
371 j = 0;-
372 for (k = i - 1; k >= 0; k--)
k >= 0Description
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • asn1evp
  • pkcs7test
FALSEevaluated 16 times by 3 tests
Evaluated by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
14-16
373 a->data[j++] = buf[k];
executed 14 times by 2 tests: a->data[j++] = buf[k];
Executed by:
  • asn1evp
  • pkcs7test
14
374 a->length = j;-
375 return (1);
executed 16 times by 3 tests: return (1);
Executed by:
  • asn1evp
  • libcrypto.so.44.0.1
  • pkcs7test
16
376}-
377-
378long-
379ASN1_INTEGER_get(const ASN1_INTEGER *a)-
380{-
381 int neg = 0, i;-
382 long r = 0;-
383-
384 if (a == NULL)
a == ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
FALSEevaluated 204 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
2-204
385 return (0L);
executed 2 times by 1 test: return (0L);
Executed by:
  • libcrypto.so.44.0.1
2
386 i = a->type;-
387 if (i == V_ASN1_NEG_INTEGER)
i == (2 | 0x100)Description
TRUEnever evaluated
FALSEevaluated 204 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-204
388 neg = 1;
never executed: neg = 1;
0
389 else if (i != V_ASN1_INTEGER)
i != 2Description
TRUEnever evaluated
FALSEevaluated 204 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-204
390 return -1;
never executed: return -1;
0
391-
392 if (a->length > (int)sizeof(long)) {
a->length > (int)sizeof(long)Description
TRUEnever evaluated
FALSEevaluated 204 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-204
393 /* hmm... a bit ugly, return all ones */-
394 return -1;
never executed: return -1;
0
395 }-
396 if (a->data == NULL)
a->data == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 204 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-204
397 return 0;
never executed: return 0;
0
398-
399 for (i = 0; i < a->length; i++) {
i < a->lengthDescription
TRUEevaluated 231 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
FALSEevaluated 204 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
204-231
400 r <<= 8;-
401 r |= (unsigned char)a->data[i];-
402 }
executed 231 times by 7 tests: end of block
Executed by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
231
403 if (neg)
negDescription
TRUEnever evaluated
FALSEevaluated 204 times by 7 tests
Evaluated by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
0-204
404 r = -r;
never executed: r = -r;
0
405 return (r);
executed 204 times by 7 tests: return (r);
Executed by:
  • asn1evp
  • asn1test
  • libcrypto.so.44.0.1
  • pkcs7test
  • servertest
  • ssltest
  • tlstest
204
406}-
407-
408ASN1_INTEGER *-
409BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)-
410{-
411 ASN1_INTEGER *ret;-
412 int len, j;-
413-
414 if (ai == NULL)
ai == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
1-2
415 ret = ASN1_INTEGER_new();
executed 1 time by 1 test: ret = ASN1_INTEGER_new();
Executed by:
  • libcrypto.so.44.0.1
1
416 else-
417 ret = ai;
executed 2 times by 1 test: ret = ai;
Executed by:
  • libcrypto.so.44.0.1
2
418 if (ret == NULL) {
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
0-3
419 ASN1error(ERR_R_NESTED_ASN1_ERROR);-
420 goto err;
never executed: goto err;
0
421 }-
422 if (BN_is_negative(bn))
((bn)->neg != 0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
0-3
423 ret->type = V_ASN1_NEG_INTEGER;
never executed: ret->type = (2 | 0x100);
0
424 else-
425 ret->type = V_ASN1_INTEGER;
executed 3 times by 1 test: ret->type = 2;
Executed by:
  • libcrypto.so.44.0.1
3
426 j = BN_num_bits(bn);-
427 len = ((j == 0) ? 0 : ((j / 8) + 1));
(j == 0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
0-3
428 if (ret->length < len + 4) {
ret->length < len + 4Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
FALSEnever evaluated
0-3
429 unsigned char *new_data = realloc(ret->data, len + 4);-
430 if (!new_data) {
!new_dataDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
0-3
431 ASN1error(ERR_R_MALLOC_FAILURE);-
432 goto err;
never executed: goto err;
0
433 }-
434 ret->data = new_data;-
435 }
executed 3 times by 1 test: end of block
Executed by:
  • libcrypto.so.44.0.1
3
436 ret->length = BN_bn2bin(bn, ret->data);-
437-
438 /* Correct zero case */-
439 if (!ret->length) {
!ret->lengthDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
0-3
440 ret->data[0] = 0;-
441 ret->length = 1;-
442 }
never executed: end of block
0
443 return (ret);
executed 3 times by 1 test: return (ret);
Executed by:
  • libcrypto.so.44.0.1
3
444-
445err:-
446 if (ret != ai)
ret != aiDescription
TRUEnever evaluated
FALSEnever evaluated
0
447 ASN1_INTEGER_free(ret);
never executed: ASN1_INTEGER_free(ret);
0
448 return (NULL);
never executed: return ( ((void *)0) );
0
449}-
450-
451BIGNUM *-
452ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)-
453{-
454 BIGNUM *ret;-
455-
456 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
(ret = BN_bin2...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
0-2
457 ASN1error(ASN1_R_BN_LIB);
never executed: ERR_put_error(13,(0xfff),(105),__FILE__,457);
0
458 else if (ai->type == V_ASN1_NEG_INTEGER)
ai->type == (2 | 0x100)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.44.0.1
0-2
459 BN_set_negative(ret, 1);
never executed: BN_set_negative(ret, 1);
0
460 return (ret);
executed 2 times by 1 test: return (ret);
Executed by:
  • libcrypto.so.44.0.1
2
461}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2