OpenCoverage

tasn_enc.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/tasn_enc.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stddef.h>-
11#include <string.h>-
12#include "internal/cryptlib.h"-
13#include <openssl/asn1.h>-
14#include <openssl/asn1t.h>-
15#include <openssl/objects.h>-
16#include "internal/asn1_int.h"-
17#include "asn1_locl.h"-
18-
19static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,-
20 const ASN1_ITEM *it, int tag, int aclass);-
21static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,-
22 int skcontlen, const ASN1_ITEM *item,-
23 int do_sort, int iclass);-
24static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,-
25 const ASN1_TEMPLATE *tt, int tag, int aclass);-
26static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,-
27 const ASN1_ITEM *it, int flags);-
28static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,-
29 const ASN1_ITEM *it);-
30-
31/*-
32 * Top level i2d equivalents: the 'ndef' variant instructs the encoder to use-
33 * indefinite length constructed encoding, where appropriate-
34 */-
35-
36int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out,-
37 const ASN1_ITEM *it)-
38{-
39 return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF);
executed 180 times by 1 test: return asn1_item_flags_i2d(val, out, it, (0x1<<11));
Executed by:
  • libcrypto.so.1.1
180
40}-
41-
42int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)-
43{-
44 return asn1_item_flags_i2d(val, out, it, 0);
executed 137929 times by 2 tests: return asn1_item_flags_i2d(val, out, it, 0);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
137929
45}-
46-
47/*-
48 * Encode an ASN1 item, this is use by the standard 'i2d' function. 'out'-
49 * points to a buffer to output the data to. The new i2d has one additional-
50 * feature. If the output buffer is NULL (i.e. *out == NULL) then a buffer is-
51 * allocated and populated with the encoding.-
52 */-
53-
54static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,-
55 const ASN1_ITEM *it, int flags)-
56{-
57 if (out && !*out) {
outDescription
TRUEevaluated 121463 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 16646 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!*outDescription
TRUEevaluated 110666 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 10797 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
10797-121463
58 unsigned char *p, *buf;-
59 int len;-
60-
61 len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);-
62 if (len <= 0)
len <= 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 110656 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
10-110656
63 return len;
executed 10 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
10
64 if ((buf = OPENSSL_malloc(len)) == NULL) {
(buf = CRYPTO_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 110656 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-110656
65 ASN1err(ASN1_F_ASN1_ITEM_FLAGS_I2D, ERR_R_MALLOC_FAILURE);-
66 return -1;
never executed: return -1;
0
67 }-
68 p = buf;-
69 ASN1_item_ex_i2d(&val, &p, it, -1, flags);-
70 *out = buf;-
71 return len;
executed 110656 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
110656
72 }-
73-
74 return ASN1_item_ex_i2d(&val, out, it, -1, flags);
executed 27443 times by 2 tests: return ASN1_item_ex_i2d(&val, out, it, -1, flags);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
27443
75}-
76-
77/*-
78 * Encode an item, taking care of IMPLICIT tagging (if any). This function-
79 * performs the normal item handling: it can be used in external types.-
80 */-
81-
82int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,-
83 const ASN1_ITEM *it, int tag, int aclass)-
84{-
85 const ASN1_TEMPLATE *tt = NULL;-
86 int i, seqcontlen, seqlen, ndef = 1;-
87 const ASN1_EXTERN_FUNCS *ef;-
88 const ASN1_AUX *aux = it->funcs;-
89 ASN1_aux_cb *asn1_cb = 0;-
90-
91 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
(it->itype != 0x0)Description
TRUEevaluated 1948017 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2978213 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
!*pvalDescription
TRUEevaluated 37110 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1910907 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
37110-2978213
92 return 0;
executed 37110 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
37110
93-
94 if (aux && aux->asn1_cb)
auxDescription
TRUEevaluated 678503 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 4210617 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
aux->asn1_cbDescription
TRUEevaluated 591504 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 86999 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
86999-4210617
95 asn1_cb = aux->asn1_cb;
executed 591504 times by 2 tests: asn1_cb = aux->asn1_cb;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
591504
96-
97 switch (it->itype) {-
98-
99 case ASN1_ITYPE_PRIMITIVE:
executed 2978213 times by 2 tests: case 0x0:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2978213
100 if (it->templates)
it->templatesDescription
TRUEevaluated 233184 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2745029 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
233184-2745029
101 return asn1_template_ex_i2d(pval, out, it->templates,
executed 233184 times by 1 test: return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass);
Executed by:
  • libcrypto.so.1.1
233184
102 tag, aclass);
executed 233184 times by 1 test: return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass);
Executed by:
  • libcrypto.so.1.1
233184
103 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
executed 2745029 times by 2 tests: return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2745029
104-
105 case ASN1_ITYPE_MSTRING:
executed 592012 times by 1 test: case 0x5:
Executed by:
  • libcrypto.so.1.1
592012
106 return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
executed 592012 times by 1 test: return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
Executed by:
  • libcrypto.so.1.1
592012
107-
108 case ASN1_ITYPE_CHOICE:
executed 77111 times by 1 test: case 0x2:
Executed by:
  • libcrypto.so.1.1
77111
109 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
asn1_cbDescription
TRUEevaluated 31841 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 45270 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!asn1_cb(6, pv... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 31841 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45270
110 return 0;
never executed: return 0;
0
111 i = asn1_get_choice_selector(pval, it);-
112 if ((i >= 0) && (i < it->tcount)) {
(i >= 0)Description
TRUEevaluated 77111 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(i < it->tcount)Description
TRUEevaluated 77111 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-77111
113 ASN1_VALUE **pchval;-
114 const ASN1_TEMPLATE *chtt;-
115 chtt = it->templates + i;-
116 pchval = asn1_get_field_ptr(pval, chtt);-
117 return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass);
executed 77111 times by 1 test: return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass);
Executed by:
  • libcrypto.so.1.1
77111
118 }-
119 /* Fixme: error condition if selector out of range */-
120 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
asn1_cbDescription
TRUEnever evaluated
FALSEnever evaluated
!asn1_cb(7, pv... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
121 return 0;
never executed: return 0;
0
122 break;
never executed: break;
0
123-
124 case ASN1_ITYPE_EXTERN:
executed 32353 times by 1 test: case 0x4:
Executed by:
  • libcrypto.so.1.1
32353
125 /* If new style i2d it does all the work */-
126 ef = it->funcs;-
127 return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
executed 32353 times by 1 test: return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
Executed by:
  • libcrypto.so.1.1
32353
128-
129 case ASN1_ITYPE_NDEF_SEQUENCE:
executed 6848 times by 1 test: case 0x6:
Executed by:
  • libcrypto.so.1.1
6848
130 /* Use indefinite length constructed if requested */-
131 if (aclass & ASN1_TFLG_NDEF)
aclass & (0x1<<11)Description
TRUEevaluated 972 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5876 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
972-5876
132 ndef = 2;
executed 972 times by 1 test: ndef = 2;
Executed by:
  • libcrypto.so.1.1
972
133 /* fall through */-
134-
135 case ASN1_ITYPE_SEQUENCE:
code before this statement executed 6848 times by 1 test: case 0x1:
Executed by:
  • libcrypto.so.1.1
executed 1202583 times by 2 tests: case 0x1:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
6848-1202583
136 i = asn1_enc_restore(&seqcontlen, out, pval, it);-
137 /* An error occurred */-
138 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEevaluated 1209431 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-1209431
139 return 0;
never executed: return 0;
0
140 /* We have a valid cached encoding... */-
141 if (i > 0)
i > 0Description
TRUEevaluated 163825 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1045606 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
163825-1045606
142 return seqcontlen;
executed 163825 times by 1 test: return seqcontlen;
Executed by:
  • libcrypto.so.1.1
163825
143 /* Otherwise carry on */-
144 seqcontlen = 0;-
145 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */-
146 if (tag == -1) {
tag == -1Description
TRUEevaluated 1012132 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 33474 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
33474-1012132
147 tag = V_ASN1_SEQUENCE;-
148 /* Retain any other flags in aclass */-
149 aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)-
150 | V_ASN1_UNIVERSAL;-
151 }
executed 1012132 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1012132
152 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
asn1_cbDescription
TRUEevaluated 162422 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 883184 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
!asn1_cb(6, pv... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 162422 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-883184
153 return 0;
never executed: return 0;
0
154 /* First work out sequence content length */-
155 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
i < it->tcountDescription
TRUEevaluated 2578593 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 1045606 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
1045606-2578593
156 const ASN1_TEMPLATE *seqtt;-
157 ASN1_VALUE **pseqval;-
158 int tmplen;-
159 seqtt = asn1_do_adb(pval, tt, 1);-
160 if (!seqtt)
!seqttDescription
TRUEnever evaluated
FALSEevaluated 2578593 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-2578593
161 return 0;
never executed: return 0;
0
162 pseqval = asn1_get_field_ptr(pval, seqtt);-
163 tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, aclass);-
164 if (tmplen == -1 || (tmplen > INT_MAX - seqcontlen))
tmplen == -1Description
TRUEnever evaluated
FALSEevaluated 2578593 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
(tmplen > 0x7f... - seqcontlen)Description
TRUEnever evaluated
FALSEevaluated 2578593 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-2578593
165 return -1;
never executed: return -1;
0
166 seqcontlen += tmplen;-
167 }
executed 2578593 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2578593
168-
169 seqlen = ASN1_object_size(ndef, seqcontlen, tag);-
170 if (!out || seqlen == -1)
!outDescription
TRUEevaluated 700744 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 344862 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
seqlen == -1Description
TRUEnever evaluated
FALSEevaluated 344862 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-700744
171 return seqlen;
executed 700744 times by 1 test: return seqlen;
Executed by:
  • libcrypto.so.1.1
700744
172 /* Output SEQUENCE header */-
173 ASN1_put_object(out, ndef, seqcontlen, tag, aclass);-
174 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
i < it->tcountDescription
TRUEevaluated 873704 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 344862 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
344862-873704
175 const ASN1_TEMPLATE *seqtt;-
176 ASN1_VALUE **pseqval;-
177 seqtt = asn1_do_adb(pval, tt, 1);-
178 if (!seqtt)
!seqttDescription
TRUEnever evaluated
FALSEevaluated 873704 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-873704
179 return 0;
never executed: return 0;
0
180 pseqval = asn1_get_field_ptr(pval, seqtt);-
181 /* FIXME: check for errors in enhanced version */-
182 asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass);-
183 }
executed 873704 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
873704
184 if (ndef == 2)
ndef == 2Description
TRUEevaluated 266 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 344596 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
266-344596
185 ASN1_put_eoc(out);
executed 266 times by 1 test: ASN1_put_eoc(out);
Executed by:
  • libcrypto.so.1.1
266
186 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
asn1_cbDescription
TRUEevaluated 74425 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 270437 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
!asn1_cb(7, pv... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 74425 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-270437
187 return 0;
never executed: return 0;
0
188 return seqlen;
executed 344862 times by 2 tests: return seqlen;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
344862
189-
190 default:
never executed: default:
0
191 return 0;
never executed: return 0;
0
192-
193 }-
194 return 0;
never executed: return 0;
0
195}-
196-
197static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,-
198 const ASN1_TEMPLATE *tt, int tag, int iclass)-
199{-
200 int i, ret, flags, ttag, tclass, ndef;-
201 ASN1_VALUE *tval;-
202 flags = tt->flags;-
203-
204 /*-
205 * If field is embedded then val needs fixing so it is a pointer to-
206 * a pointer to a field.-
207 */-
208 if (flags & ASN1_TFLG_EMBED) {
flags & (0x1 << 12)Description
TRUEevaluated 721182 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3041410 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
721182-3041410
209 tval = (ASN1_VALUE *)pval;-
210 pval = &tval;-
211 }
executed 721182 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
721182
212 /*-
213 * Work out tag and class to use: tagging may come either from the-
214 * template or the arguments, not both because this would create-
215 * ambiguity. Additionally the iclass argument may contain some-
216 * additional flags which should be noted and passed down to other-
217 * levels.-
218 */-
219 if (flags & ASN1_TFLG_TAG_MASK) {
flags & (0x3 << 3)Description
TRUEevaluated 367177 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3395415 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
367177-3395415
220 /* Error if argument and template tagging */-
221 if (tag != -1)
tag != -1Description
TRUEnever evaluated
FALSEevaluated 367177 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-367177
222 /* FIXME: error code here */-
223 return -1;
never executed: return -1;
0
224 /* Get tagging from template */-
225 ttag = tt->tag;-
226 tclass = flags & ASN1_TFLG_TAG_CLASS;-
227 } else if (tag != -1) {
executed 367177 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
tag != -1Description
TRUEnever evaluated
FALSEevaluated 3395415 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
0-3395415
228 /* No template tagging, get from arguments */-
229 ttag = tag;-
230 tclass = iclass & ASN1_TFLG_TAG_CLASS;-
231 } else {
never executed: end of block
0
232 ttag = -1;-
233 tclass = 0;-
234 }
executed 3395415 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3395415
235 /*-
236 * Remove any class mask from iflag.-
237 */-
238 iclass &= ~ASN1_TFLG_TAG_CLASS;-
239-
240 /*-
241 * At this point 'ttag' contains the outer tag to use, 'tclass' is the-
242 * class and iclass is any flags passed to this function.-
243 */-
244-
245 /* if template and arguments require ndef, use it */-
246 if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
(flags & (0x1<<11))Description
TRUEevaluated 2896 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3759696 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
(iclass & (0x1<<11))Description
TRUEevaluated 474 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2422 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
474-3759696
247 ndef = 2;
executed 474 times by 1 test: ndef = 2;
Executed by:
  • libcrypto.so.1.1
474
248 else-
249 ndef = 1;
executed 3762118 times by 2 tests: ndef = 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3762118
250-
251 if (flags & ASN1_TFLG_SK_MASK) {
flags & (0x3 << 1)Description
TRUEevaluated 298804 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3463788 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
298804-3463788
252 /* SET OF, SEQUENCE OF */-
253 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;-
254 int isset, sktag, skaclass;-
255 int skcontlen, sklen;-
256 ASN1_VALUE *skitem;-
257-
258 if (!*pval)
!*pvalDescription
TRUEevaluated 23239 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 275565 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
23239-275565
259 return 0;
executed 23239 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
23239
260-
261 if (flags & ASN1_TFLG_SET_OF) {
flags & (0x1 << 1)Description
TRUEevaluated 244521 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31044 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
31044-244521
262 isset = 1;-
263 /* 2 means we reorder */-
264 if (flags & ASN1_TFLG_SEQUENCE_OF)
flags & (0x2 << 1)Description
TRUEevaluated 210 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 244311 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
210-244311
265 isset = 2;
executed 210 times by 1 test: isset = 2;
Executed by:
  • libcrypto.so.1.1
210
266 } else
executed 244521 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
244521
267 isset = 0;
executed 31044 times by 1 test: isset = 0;
Executed by:
  • libcrypto.so.1.1
31044
268-
269 /*-
270 * Work out inner tag value: if EXPLICIT or no tagging use underlying-
271 * type.-
272 */-
273 if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
(ttag != -1)Description
TRUEevaluated 9227 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 266338 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!(flags & (0x2 << 3))Description
TRUEevaluated 9111 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 116 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
116-266338
274 sktag = ttag;-
275 skaclass = tclass;-
276 } else {
executed 9111 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9111
277 skaclass = V_ASN1_UNIVERSAL;-
278 if (isset)
issetDescription
TRUEevaluated 239430 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27024 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
27024-239430
279 sktag = V_ASN1_SET;
executed 239430 times by 1 test: sktag = 17;
Executed by:
  • libcrypto.so.1.1
239430
280 else-
281 sktag = V_ASN1_SEQUENCE;
executed 27024 times by 1 test: sktag = 16;
Executed by:
  • libcrypto.so.1.1
27024
282 }-
283-
284 /* Determine total length of items */-
285 skcontlen = 0;-
286 for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
i < sk_ASN1_VALUE_num(sk)Description
TRUEevaluated 780284 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 275565 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
275565-780284
287 int tmplen;-
288 skitem = sk_ASN1_VALUE_value(sk, i);-
289 tmplen = ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item),-
290 -1, iclass);-
291 if (tmplen == -1 || (skcontlen > INT_MAX - tmplen))
tmplen == -1Description
TRUEnever evaluated
FALSEevaluated 780284 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(skcontlen > 0...ffff - tmplen)Description
TRUEnever evaluated
FALSEevaluated 780284 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-780284
292 return -1;
never executed: return -1;
0
293 skcontlen += tmplen;-
294 }
executed 780284 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
780284
295 sklen = ASN1_object_size(ndef, skcontlen, sktag);-
296 if (sklen == -1)
sklen == -1Description
TRUEnever evaluated
FALSEevaluated 275565 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-275565
297 return -1;
never executed: return -1;
0
298 /* If EXPLICIT need length of surrounding tag */-
299 if (flags & ASN1_TFLG_EXPTAG)
flags & (0x2 << 3)Description
TRUEevaluated 116 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 275449 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
116-275449
300 ret = ASN1_object_size(ndef, sklen, ttag);
executed 116 times by 1 test: ret = ASN1_object_size(ndef, sklen, ttag);
Executed by:
  • libcrypto.so.1.1
116
301 else-
302 ret = sklen;
executed 275449 times by 1 test: ret = sklen;
Executed by:
  • libcrypto.so.1.1
275449
303-
304 if (!out || ret == -1)
!outDescription
TRUEevaluated 162969 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 112596 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ret == -1Description
TRUEnever evaluated
FALSEevaluated 112596 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-162969
305 return ret;
executed 162969 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
162969
306-
307 /* Now encode this lot... */-
308 /* EXPLICIT tag */-
309 if (flags & ASN1_TFLG_EXPTAG)
flags & (0x2 << 3)Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 112561 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
35-112561
310 ASN1_put_object(out, ndef, sklen, ttag, tclass);
executed 35 times by 1 test: ASN1_put_object(out, ndef, sklen, ttag, tclass);
Executed by:
  • libcrypto.so.1.1
35
311 /* SET or SEQUENCE and IMPLICIT tag */-
312 ASN1_put_object(out, ndef, skcontlen, sktag, skaclass);-
313 /* And the stuff itself */-
314 asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),-
315 isset, iclass);-
316 if (ndef == 2) {
ndef == 2Description
TRUEnever evaluated
FALSEevaluated 112596 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-112596
317 ASN1_put_eoc(out);-
318 if (flags & ASN1_TFLG_EXPTAG)
flags & (0x2 << 3)Description
TRUEnever evaluated
FALSEnever evaluated
0
319 ASN1_put_eoc(out);
never executed: ASN1_put_eoc(out);
0
320 }
never executed: end of block
0
321-
322 return ret;
executed 112596 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
112596
323 }-
324-
325 if (flags & ASN1_TFLG_EXPTAG) {
flags & (0x2 << 3)Description
TRUEevaluated 234511 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3229277 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
234511-3229277
326 /* EXPLICIT tagging */-
327 /* Find length of tagged item */-
328 i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, iclass);-
329 if (!i)
!iDescription
TRUEevaluated 167936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 66575 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
66575-167936
330 return 0;
executed 167936 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
167936
331 /* Find length of EXPLICIT tag */-
332 ret = ASN1_object_size(ndef, i, ttag);-
333 if (out && ret != -1) {
outDescription
TRUEevaluated 19585 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 46990 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ret != -1Description
TRUEevaluated 19585 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-46990
334 /* Output tag and item */-
335 ASN1_put_object(out, ndef, i, ttag, tclass);-
336 ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, iclass);-
337 if (ndef == 2)
ndef == 2Description
TRUEevaluated 124 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 19461 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
124-19461
338 ASN1_put_eoc(out);
executed 124 times by 1 test: ASN1_put_eoc(out);
Executed by:
  • libcrypto.so.1.1
124
339 }
executed 19585 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
19585
340 return ret;
executed 66575 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
66575
341 }-
342-
343 /* Either normal or IMPLICIT tagging: combine class and flags */-
344 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
executed 3229277 times by 2 tests: return ASN1_item_ex_i2d(pval, out, (tt->item), ttag, tclass | iclass);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3229277
345 ttag, tclass | iclass);
executed 3229277 times by 2 tests: return ASN1_item_ex_i2d(pval, out, (tt->item), ttag, tclass | iclass);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3229277
346-
347}-
348-
349/* Temporary structure used to hold DER encoding of items for SET OF */-
350-
351typedef struct {-
352 unsigned char *data;-
353 int length;-
354 ASN1_VALUE *field;-
355} DER_ENC;-
356-
357static int der_cmp(const void *a, const void *b)-
358{-
359 const DER_ENC *d1 = a, *d2 = b;-
360 int cmplen, i;-
361 cmplen = (d1->length < d2->length) ? d1->length : d2->length;
(d1->length < d2->length)Description
TRUEevaluated 18274 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 340247 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
18274-340247
362 i = memcmp(d1->data, d2->data, cmplen);-
363 if (i)
iDescription
TRUEevaluated 179406 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 179115 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
179115-179406
364 return i;
executed 179406 times by 1 test: return i;
Executed by:
  • libcrypto.so.1.1
179406
365 return d1->length - d2->length;
executed 179115 times by 1 test: return d1->length - d2->length;
Executed by:
  • libcrypto.so.1.1
179115
366}-
367-
368/* Output the content octets of SET OF or SEQUENCE OF */-
369-
370static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,-
371 int skcontlen, const ASN1_ITEM *item,-
372 int do_sort, int iclass)-
373{-
374 int i;-
375 ASN1_VALUE *skitem;-
376 unsigned char *tmpdat = NULL, *p = NULL;-
377 DER_ENC *derlst = NULL, *tder;-
378 if (do_sort) {
do_sortDescription
TRUEevaluated 102408 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 10188 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
10188-102408
379 /* Don't need to sort less than 2 items */-
380 if (sk_ASN1_VALUE_num(sk) < 2)
sk_ASN1_VALUE_num(sk) < 2Description
TRUEevaluated 98006 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4402 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4402-98006
381 do_sort = 0;
executed 98006 times by 1 test: do_sort = 0;
Executed by:
  • libcrypto.so.1.1
98006
382 else {-
383 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk)-
384 * sizeof(*derlst));-
385 if (derlst == NULL)
derlst == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4402 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4402
386 return 0;
never executed: return 0;
0
387 tmpdat = OPENSSL_malloc(skcontlen);-
388 if (tmpdat == NULL) {
tmpdat == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4402 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4402
389 OPENSSL_free(derlst);-
390 return 0;
never executed: return 0;
0
391 }-
392 }
executed 4402 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4402
393 }-
394 /* If not sorting just output each item */-
395 if (!do_sort) {
!do_sortDescription
TRUEevaluated 108194 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4402 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4402-108194
396 for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
i < sk_ASN1_VALUE_num(sk)Description
TRUEevaluated 173283 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 108194 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
108194-173283
397 skitem = sk_ASN1_VALUE_value(sk, i);-
398 ASN1_item_ex_i2d(&skitem, out, item, -1, iclass);-
399 }
executed 173283 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
173283
400 return 1;
executed 108194 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
108194
401 }-
402 p = tmpdat;-
403-
404 /* Doing sort: build up a list of each member's DER encoding */-
405 for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
i < sk_ASN1_VALUE_num(sk)Description
TRUEevaluated 80947 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4402 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4402-80947
406 skitem = sk_ASN1_VALUE_value(sk, i);-
407 tder->data = p;-
408 tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass);-
409 tder->field = skitem;-
410 }
executed 80947 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
80947
411-
412 /* Now sort them */-
413 qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);-
414 /* Output sorted DER encoding */-
415 p = *out;-
416 for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
i < sk_ASN1_VALUE_num(sk)Description
TRUEevaluated 80947 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4402 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4402-80947
417 memcpy(p, tder->data, tder->length);-
418 p += tder->length;-
419 }
executed 80947 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
80947
420 *out = p;-
421 /* If do_sort is 2 then reorder the STACK */-
422 if (do_sort == 2) {
do_sort == 2Description
TRUEevaluated 83 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4319 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
83-4319
423 for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
i < sk_ASN1_VALUE_num(sk)Description
TRUEevaluated 783 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 83 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
83-783
424 (void)sk_ASN1_VALUE_set(sk, i, tder->field);
executed 783 times by 1 test: (void)sk_ASN1_VALUE_set(sk, i, tder->field);
Executed by:
  • libcrypto.so.1.1
783
425 }
executed 83 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
83
426 OPENSSL_free(derlst);-
427 OPENSSL_free(tmpdat);-
428 return 1;
executed 4402 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4402
429}-
430-
431static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,-
432 const ASN1_ITEM *it, int tag, int aclass)-
433{-
434 int len;-
435 int utype;-
436 int usetag;-
437 int ndef = 0;-
438-
439 utype = it->utype;-
440-
441 /*-
442 * Get length of content octets and maybe find out the underlying type.-
443 */-
444-
445 len = asn1_ex_i2c(pval, NULL, &utype, it);-
446-
447 /*-
448 * If SEQUENCE, SET or OTHER then header is included in pseudo content-
449 * octets so don't include tag+length. We need to check here because the-
450 * call to asn1_ex_i2c() could change utype.-
451 */-
452 if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
(utype == 16)Description
TRUEevaluated 66334 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3270707 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
(utype == 17)Description
TRUEevaluated 8940 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3261767 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
8940-3270707
453 (utype == V_ASN1_OTHER))
(utype == -3)Description
TRUEevaluated 59936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3201831 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
59936-3201831
454 usetag = 0;
executed 135210 times by 1 test: usetag = 0;
Executed by:
  • libcrypto.so.1.1
135210
455 else-
456 usetag = 1;
executed 3201831 times by 2 tests: usetag = 1;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3201831
457-
458 /* -1 means omit type */-
459-
460 if (len == -1)
len == -1Description
TRUEevaluated 388204 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2948837 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
388204-2948837
461 return 0;
executed 388204 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
388204
462-
463 /* -2 return is special meaning use ndef */-
464 if (len == -2) {
len == -2Description
TRUEevaluated 570 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2948267 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
570-2948267
465 ndef = 2;-
466 len = 0;-
467 }
executed 570 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
570
468-
469 /* If not implicitly tagged get tag from underlying type */-
470 if (tag == -1)
tag == -1Description
TRUEevaluated 2921143 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 27694 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
27694-2921143
471 tag = utype;
executed 2921143 times by 2 tests: tag = utype;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2921143
472-
473 /* Output tag+length followed by content octets */-
474 if (out) {
outDescription
TRUEevaluated 694848 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2253989 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
694848-2253989
475 if (usetag)
usetagDescription
TRUEevaluated 661099 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 33749 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
33749-661099
476 ASN1_put_object(out, ndef, len, tag, aclass);
executed 661099 times by 2 tests: ASN1_put_object(out, ndef, len, tag, aclass);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
661099
477 asn1_ex_i2c(pval, *out, &utype, it);-
478 if (ndef)
ndefDescription
TRUEevaluated 90 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 694758 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
90-694758
479 ASN1_put_eoc(out);
executed 90 times by 1 test: ASN1_put_eoc(out);
Executed by:
  • libcrypto.so.1.1
90
480 else-
481 *out += len;
executed 694758 times by 2 tests: *out += len;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
694758
482 }-
483-
484 if (usetag)
usetagDescription
TRUEevaluated 2813627 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 135210 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
135210-2813627
485 return ASN1_object_size(ndef, len, tag);
executed 2813627 times by 2 tests: return ASN1_object_size(ndef, len, tag);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2813627
486 return len;
executed 135210 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
135210
487}-
488-
489/* Produce content octets from a structure */-
490-
491static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,-
492 const ASN1_ITEM *it)-
493{-
494 ASN1_BOOLEAN *tbool = NULL;-
495 ASN1_STRING *strtmp;-
496 ASN1_OBJECT *otmp;-
497 int utype;-
498 const unsigned char *cont;-
499 unsigned char c;-
500 int len;-
501 const ASN1_PRIMITIVE_FUNCS *pf;-
502 pf = it->funcs;-
503 if (pf && pf->prim_i2c)
pfDescription
TRUEevaluated 341805 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 3690084 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
pf->prim_i2cDescription
TRUEevaluated 341805 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEnever evaluated
0-3690084
504 return pf->prim_i2c(pval, cout, putype, it);
executed 341805 times by 2 tests: return pf->prim_i2c(pval, cout, putype, it);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
341805
505-
506 /* Should type be omitted? */-
507 if ((it->itype != ASN1_ITYPE_PRIMITIVE)
(it->itype != 0x0)Description
TRUEevaluated 739541 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2950543 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
739541-2950543
508 || (it->utype != V_ASN1_BOOLEAN)) {
(it->utype != 1)Description
TRUEevaluated 2859177 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 91366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
91366-2859177
509 if (!*pval)
!*pvalDescription
TRUEevaluated 248951 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3349767 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
248951-3349767
510 return -1;
executed 248951 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
248951
511 }
executed 3349767 times by 2 tests: end of block
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
3349767
512-
513 if (it->itype == ASN1_ITYPE_MSTRING) {
it->itype == 0x5Description
TRUEevaluated 739541 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2701592 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
739541-2701592
514 /* If MSTRING type set the underlying type */-
515 strtmp = (ASN1_STRING *)*pval;-
516 utype = strtmp->type;-
517 *putype = utype;-
518 } else if (it->utype == V_ASN1_ANY) {
executed 739541 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
it->utype == -4Description
TRUEevaluated 714522 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1987070 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
714522-1987070
519 /* If ANY set type and pointer to value */-
520 ASN1_TYPE *typ;-
521 typ = (ASN1_TYPE *)*pval;-
522 utype = typ->type;-
523 *putype = utype;-
524 pval = &typ->value.asn1_value;-
525 } else
executed 714522 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
714522
526 utype = *putype;
executed 1987070 times by 2 tests: utype = *putype;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1987070
527-
528 switch (utype) {-
529 case V_ASN1_OBJECT:
executed 1389267 times by 1 test: case 6:
Executed by:
  • libcrypto.so.1.1
1389267
530 otmp = (ASN1_OBJECT *)*pval;-
531 cont = otmp->data;-
532 len = otmp->length;-
533 if (cont == NULL || len == 0)
cont == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1389267 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
len == 0Description
TRUEnever evaluated
FALSEevaluated 1389267 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1389267
534 return -1;
never executed: return -1;
0
535 break;
executed 1389267 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
1389267
536-
537 case V_ASN1_NULL:
executed 181560 times by 1 test: case 5:
Executed by:
  • libcrypto.so.1.1
181560
538 cont = NULL;-
539 len = 0;-
540 break;
executed 181560 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
181560
541-
542 case V_ASN1_BOOLEAN:
executed 96883 times by 1 test: case 1:
Executed by:
  • libcrypto.so.1.1
96883
543 tbool = (ASN1_BOOLEAN *)pval;-
544 if (*tbool == -1)
*tbool == -1Description
TRUEevaluated 82463 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 14420 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
14420-82463
545 return -1;
executed 82463 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
82463
546 if (it->utype != V_ASN1_ANY) {
it->utype != -4Description
TRUEevaluated 8903 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5517 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5517-8903
547 /*-
548 * Default handling if value == size field then omit-
549 */-
550 if (*tbool && (it->size > 0))
*tboolDescription
TRUEevaluated 4555 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4348 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(it->size > 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4554 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-4555
551 return -1;
executed 1 time by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
1
552 if (!*tbool && !it->size)
!*tboolDescription
TRUEevaluated 4348 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4554 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!it->sizeDescription
TRUEevaluated 1839 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2509 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1839-4554
553 return -1;
executed 1839 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
1839
554 }
executed 7063 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
7063
555 c = (unsigned char)*tbool;-
556 cont = &c;-
557 len = 1;-
558 break;
executed 12580 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
12580
559-
560 case V_ASN1_BIT_STRING:
executed 309577 times by 1 test: case 3:
Executed by:
  • libcrypto.so.1.1
309577
561 return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
executed 309577 times by 1 test: return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : ((void *)0) );
Executed by:
  • libcrypto.so.1.1
309577
562 cout ? &cout : NULL);
executed 309577 times by 1 test: return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : ((void *)0) );
Executed by:
  • libcrypto.so.1.1
309577
563-
564 case V_ASN1_INTEGER:
executed 116344 times by 1 test: case 2:
Executed by:
  • libcrypto.so.1.1
116344
565 case V_ASN1_ENUMERATED:
executed 10863 times by 1 test: case 10:
Executed by:
  • libcrypto.so.1.1
10863
566 /*-
567 * These are all have the same content format as ASN1_INTEGER-
568 */-
569 return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
executed 127207 times by 1 test: return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : ((void *)0) );
Executed by:
  • libcrypto.so.1.1
127207
570-
571 case V_ASN1_OCTET_STRING:
executed 240812 times by 2 tests: case 4:
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
240812
572 case V_ASN1_NUMERICSTRING:
executed 41879 times by 1 test: case 18:
Executed by:
  • libcrypto.so.1.1
41879
573 case V_ASN1_PRINTABLESTRING:
executed 11684 times by 1 test: case 19:
Executed by:
  • libcrypto.so.1.1
11684
574 case V_ASN1_T61STRING:
executed 76427 times by 1 test: case 20:
Executed by:
  • libcrypto.so.1.1
76427
575 case V_ASN1_VIDEOTEXSTRING:
executed 460 times by 1 test: case 21:
Executed by:
  • libcrypto.so.1.1
460
576 case V_ASN1_IA5STRING:
executed 11918 times by 1 test: case 22:
Executed by:
  • libcrypto.so.1.1
11918
577 case V_ASN1_UTCTIME:
executed 4171 times by 1 test: case 23:
Executed by:
  • libcrypto.so.1.1
4171
578 case V_ASN1_GENERALIZEDTIME:
executed 11892 times by 1 test: case 24:
Executed by:
  • libcrypto.so.1.1
11892
579 case V_ASN1_GRAPHICSTRING:
executed 6952 times by 1 test: case 25:
Executed by:
  • libcrypto.so.1.1
6952
580 case V_ASN1_VISIBLESTRING:
executed 8334 times by 1 test: case 26:
Executed by:
  • libcrypto.so.1.1
8334
581 case V_ASN1_GENERALSTRING:
executed 7780 times by 1 test: case 27:
Executed by:
  • libcrypto.so.1.1
7780
582 case V_ASN1_UNIVERSALSTRING:
executed 51715 times by 1 test: case 28:
Executed by:
  • libcrypto.so.1.1
51715
583 case V_ASN1_BMPSTRING:
executed 31457 times by 1 test: case 30:
Executed by:
  • libcrypto.so.1.1
31457
584 case V_ASN1_UTF8STRING:
executed 530827 times by 1 test: case 12:
Executed by:
  • libcrypto.so.1.1
530827
585 case V_ASN1_SEQUENCE:
executed 85325 times by 1 test: case 16:
Executed by:
  • libcrypto.so.1.1
85325
586 case V_ASN1_SET:
executed 10772 times by 1 test: case 17:
Executed by:
  • libcrypto.so.1.1
10772
587 default:
executed 204234 times by 1 test: default:
Executed by:
  • libcrypto.so.1.1
204234
588 /* All based on ASN1_STRING and handled the same */-
589 strtmp = (ASN1_STRING *)*pval;-
590 /* Special handling for NDEF */-
591 if ((it->size == ASN1_TFLG_NDEF)
(it->size == (0x1<<11))Description
TRUEevaluated 852 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1335787 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
852-1335787
592 && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
(strtmp->flags & 0x010)Description
TRUEevaluated 660 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 192 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
192-660
593 if (cout) {
coutDescription
TRUEevaluated 90 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 570 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
90-570
594 strtmp->data = cout;-
595 strtmp->length = 0;-
596 }
executed 90 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
90
597 /* Special return code */-
598 return -2;
executed 660 times by 1 test: return -2;
Executed by:
  • libcrypto.so.1.1
660
599 }-
600 cont = strtmp->data;-
601 len = strtmp->length;-
602-
603 break;
executed 1335979 times by 2 tests: break;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
1335979
604-
605 }-
606 if (cout && len)
coutDescription
TRUEevaluated 548505 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 2370881 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
lenDescription
TRUEevaluated 444637 times by 2 tests
Evaluated by:
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 103868 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
103868-2370881
607 memcpy(cout, cont, len);
executed 444637 times by 2 tests: memcpy(cout, cont, len);
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
444637
608 return len;
executed 2919386 times by 2 tests: return len;
Executed by:
  • libcrypto.so.1.1
  • sm2_internal_test
2919386
609}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2