summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/tasn_utl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/tasn_utl.c')
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
index 9715dac931..e1051c2c3e 100644
--- a/src/lib/libcrypto/asn1/tasn_utl.c
+++ b/src/lib/libcrypto/asn1/tasn_utl.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -56,7 +56,6 @@
56 * 56 *
57 */ 57 */
58 58
59
60#include <stddef.h> 59#include <stddef.h>
61#include <string.h> 60#include <string.h>
62#include <openssl/asn1.h> 61#include <openssl/asn1.h>
@@ -73,7 +72,8 @@
73 * the selector value 72 * the selector value
74 */ 73 */
75 74
76int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) 75int
76asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
77{ 77{
78 int *sel = offset2ptr(*pval, it->utype); 78 int *sel = offset2ptr(*pval, it->utype);
79 return *sel; 79 return *sel;
@@ -83,8 +83,9 @@ int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
83 * the selector value, return old value. 83 * the selector value, return old value.
84 */ 84 */
85 85
86int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) 86int
87{ 87asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
88{
88 int *sel, ret; 89 int *sel, ret;
89 sel = offset2ptr(*pval, it->utype); 90 sel = offset2ptr(*pval, it->utype);
90 ret = *sel; 91 ret = *sel;
@@ -92,18 +93,20 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
92 return ret; 93 return ret;
93} 94}
94 95
95/* Do reference counting. The value 'op' decides what to do. 96/* Do reference counting. The value 'op' decides what to do.
96 * if it is +1 then the count is incremented. If op is 0 count is 97 * if it is +1 then the count is incremented. If op is 0 count is
97 * set to 1. If op is -1 count is decremented and the return value 98 * set to 1. If op is -1 count is decremented and the return value
98 * is the current refrence count or 0 if no reference count exists. 99 * is the current refrence count or 0 if no reference count exists.
99 */ 100 */
100 101
101int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) 102int
103asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
102{ 104{
103 const ASN1_AUX *aux; 105 const ASN1_AUX *aux;
104 int *lck, ret; 106 int *lck, ret;
105 if ((it->itype != ASN1_ITYPE_SEQUENCE) 107
106 && (it->itype != ASN1_ITYPE_NDEF_SEQUENCE)) 108 if ((it->itype != ASN1_ITYPE_SEQUENCE) &&
109 (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
107 return 0; 110 return 0;
108 aux = it->funcs; 111 aux = it->funcs;
109 if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) 112 if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
@@ -117,9 +120,11 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
117 return ret; 120 return ret;
118} 121}
119 122
120static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) 123static ASN1_ENCODING *
124asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
121{ 125{
122 const ASN1_AUX *aux; 126 const ASN1_AUX *aux;
127
123 if (!pval || !*pval) 128 if (!pval || !*pval)
124 return NULL; 129 return NULL;
125 aux = it->funcs; 130 aux = it->funcs;
@@ -128,9 +133,11 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
128 return offset2ptr(*pval, aux->enc_offset); 133 return offset2ptr(*pval, aux->enc_offset);
129} 134}
130 135
131void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) 136void
137asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
132{ 138{
133 ASN1_ENCODING *enc; 139 ASN1_ENCODING *enc;
140
134 enc = asn1_get_enc_ptr(pval, it); 141 enc = asn1_get_enc_ptr(pval, it);
135 if (enc) { 142 if (enc) {
136 enc->enc = NULL; 143 enc->enc = NULL;
@@ -139,9 +146,11 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
139 } 146 }
140} 147}
141 148
142void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 149void
150asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
143{ 151{
144 ASN1_ENCODING *enc; 152 ASN1_ENCODING *enc;
153
145 enc = asn1_get_enc_ptr(pval, it); 154 enc = asn1_get_enc_ptr(pval, it);
146 if (enc) { 155 if (enc) {
147 if (enc->enc) 156 if (enc->enc)
@@ -152,10 +161,12 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
152 } 161 }
153} 162}
154 163
155int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, 164int
156 const ASN1_ITEM *it) 165asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
166 const ASN1_ITEM *it)
157{ 167{
158 ASN1_ENCODING *enc; 168 ASN1_ENCODING *enc;
169
159 enc = asn1_get_enc_ptr(pval, it); 170 enc = asn1_get_enc_ptr(pval, it);
160 if (!enc) 171 if (!enc)
161 return 1; 172 return 1;
@@ -171,11 +182,13 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
171 182
172 return 1; 183 return 1;
173} 184}
174 185
175int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, 186int
176 const ASN1_ITEM *it) 187asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
188 const ASN1_ITEM *it)
177{ 189{
178 ASN1_ENCODING *enc; 190 ASN1_ENCODING *enc;
191
179 enc = asn1_get_enc_ptr(pval, it); 192 enc = asn1_get_enc_ptr(pval, it);
180 if (!enc || enc->modified) 193 if (!enc || enc->modified)
181 return 0; 194 return 0;
@@ -189,9 +202,11 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
189} 202}
190 203
191/* Given an ASN1_TEMPLATE get a pointer to a field */ 204/* Given an ASN1_TEMPLATE get a pointer to a field */
192ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 205ASN1_VALUE **
206asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
193{ 207{
194 ASN1_VALUE **pvaltmp; 208 ASN1_VALUE **pvaltmp;
209
195 if (tt->flags & ASN1_TFLG_COMBINE) 210 if (tt->flags & ASN1_TFLG_COMBINE)
196 return pval; 211 return pval;
197 pvaltmp = offset2ptr(*pval, tt->offset); 212 pvaltmp = offset2ptr(*pval, tt->offset);
@@ -206,14 +221,15 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
206 * the relevant ASN1_TEMPLATE in the table and return it. 221 * the relevant ASN1_TEMPLATE in the table and return it.
207 */ 222 */
208 223
209const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, 224const ASN1_TEMPLATE *
210 int nullerr) 225asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
211{ 226{
212 const ASN1_ADB *adb; 227 const ASN1_ADB *adb;
213 const ASN1_ADB_TABLE *atbl; 228 const ASN1_ADB_TABLE *atbl;
214 long selector; 229 long selector;
215 ASN1_VALUE **sfld; 230 ASN1_VALUE **sfld;
216 int i; 231 int i;
232
217 if (!(tt->flags & ASN1_TFLG_ADB_MASK)) 233 if (!(tt->flags & ASN1_TFLG_ADB_MASK))
218 return tt; 234 return tt;
219 235
@@ -234,9 +250,9 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
234 * NB: don't check for NID_undef here because it 250 * NB: don't check for NID_undef here because it
235 * might be a legitimate value in the table 251 * might be a legitimate value in the table
236 */ 252 */
237 if (tt->flags & ASN1_TFLG_ADB_OID) 253 if (tt->flags & ASN1_TFLG_ADB_OID)
238 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld); 254 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
239 else 255 else
240 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld); 256 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
241 257
242 /* Try to find matching entry in table 258 /* Try to find matching entry in table
@@ -255,13 +271,13 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
255 271
256 /* No match, return default type */ 272 /* No match, return default type */
257 if (!adb->default_tt) 273 if (!adb->default_tt)
258 goto err; 274 goto err;
259 return adb->default_tt; 275 return adb->default_tt;
260 276
261 err: 277err:
262 /* FIXME: should log the value or OID of unsupported type */ 278 /* FIXME: should log the value or OID of unsupported type */
263 if (nullerr) 279 if (nullerr)
264 ASN1err(ASN1_F_ASN1_DO_ADB, 280 ASN1err(ASN1_F_ASN1_DO_ADB,
265 ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); 281 ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
266 return NULL; 282 return NULL;
267} 283}