]>
Commit | Line | Data |
---|---|---|
d02b48c6 | 1 | /* crypto/asn1/asn1_mac.h */ |
58964a49 | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
d02b48c6 RE |
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. | |
40720ce3 | 8 | * |
d02b48c6 RE |
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). | |
40720ce3 | 15 | * |
d02b48c6 RE |
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. | |
40720ce3 | 22 | * |
d02b48c6 RE |
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 :-). | |
40720ce3 | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
d02b48c6 RE |
38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | |
40720ce3 | 40 | * |
d02b48c6 RE |
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. | |
40720ce3 | 52 | * |
d02b48c6 RE |
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 | #ifndef HEADER_ASN1_MAC_H | |
40720ce3 | 60 | # define HEADER_ASN1_MAC_H |
d02b48c6 | 61 | |
40720ce3 | 62 | # include <openssl/asn1.h> |
82271cee | 63 | |
d02b48c6 RE |
64 | #ifdef __cplusplus |
65 | extern "C" { | |
66 | #endif | |
67 | ||
40720ce3 MC |
68 | # ifndef ASN1_MAC_ERR_LIB |
69 | # define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 | |
70 | # endif | |
71 | ||
72 | # define ASN1_MAC_H_err(f,r,line) \ | |
73 | ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line)) | |
74 | ||
75 | # define M_ASN1_D2I_vars(a,type,func) \ | |
76 | ASN1_const_CTX c; \ | |
77 | type ret=NULL; \ | |
78 | \ | |
79 | c.pp=(const unsigned char **)pp; \ | |
80 | c.q= *(const unsigned char **)pp; \ | |
81 | c.error=ERR_R_NESTED_ASN1_ERROR; \ | |
82 | if ((a == NULL) || ((*a) == NULL)) \ | |
83 | { if ((ret=(type)func()) == NULL) \ | |
84 | { c.line=__LINE__; goto err; } } \ | |
85 | else ret=(*a); | |
86 | ||
87 | # define M_ASN1_D2I_Init() \ | |
88 | c.p= *(const unsigned char **)pp; \ | |
89 | c.max=(length == 0)?0:(c.p+length); | |
90 | ||
91 | # define M_ASN1_D2I_Finish_2(a) \ | |
92 | if (!asn1_const_Finish(&c)) \ | |
93 | { c.line=__LINE__; goto err; } \ | |
94 | *(const unsigned char **)pp=c.p; \ | |
95 | if (a != NULL) (*a)=ret; \ | |
96 | return(ret); | |
97 | ||
98 | # define M_ASN1_D2I_Finish(a,func,e) \ | |
99 | M_ASN1_D2I_Finish_2(a); \ | |
d02b48c6 | 100 | err:\ |
40720ce3 MC |
101 | ASN1_MAC_H_err((e),c.error,c.line); \ |
102 | asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \ | |
103 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ | |
104 | return(NULL) | |
105 | ||
106 | # define M_ASN1_D2I_start_sequence() \ | |
107 | if (!asn1_GetSequence(&c,&length)) \ | |
108 | { c.line=__LINE__; goto err; } | |
ce1b4fe1 | 109 | /* Begin reading ASN1 without a surrounding sequence */ |
40720ce3 MC |
110 | # define M_ASN1_D2I_begin() \ |
111 | c.slen = length; | |
ce1b4fe1 DSH |
112 | |
113 | /* End reading ASN1 with no check on length */ | |
40720ce3 MC |
114 | # define M_ASN1_D2I_Finish_nolen(a, func, e) \ |
115 | *pp=c.p; \ | |
116 | if (a != NULL) (*a)=ret; \ | |
117 | return(ret); \ | |
ce1b4fe1 | 118 | err:\ |
40720ce3 MC |
119 | ASN1_MAC_H_err((e),c.error,c.line); \ |
120 | asn1_add_error(*pp,(int)(c.q- *pp)); \ | |
121 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ | |
122 | return(NULL) | |
d02b48c6 | 123 | |
40720ce3 MC |
124 | # define M_ASN1_D2I_end_sequence() \ |
125 | (((c.inf&1) == 0)?(c.slen <= 0): \ | |
126 | (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen))) | |
d02b48c6 | 127 | |
dfeab068 | 128 | /* Don't use this with d2i_ASN1_BOOLEAN() */ |
40720ce3 MC |
129 | # define M_ASN1_D2I_get(b, func) \ |
130 | c.q=c.p; \ | |
131 | if (func(&(b),&c.p,c.slen) == NULL) \ | |
132 | {c.line=__LINE__; goto err; } \ | |
133 | c.slen-=(c.p-c.q); | |
2c45bf2b DSH |
134 | |
135 | /* Don't use this with d2i_ASN1_BOOLEAN() */ | |
40720ce3 MC |
136 | # define M_ASN1_D2I_get_x(type,b,func) \ |
137 | c.q=c.p; \ | |
138 | if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \ | |
139 | {c.line=__LINE__; goto err; } \ | |
140 | c.slen-=(c.p-c.q); | |
dfeab068 RE |
141 | |
142 | /* use this instead () */ | |
40720ce3 MC |
143 | # define M_ASN1_D2I_get_int(b,func) \ |
144 | c.q=c.p; \ | |
145 | if (func(&(b),&c.p,c.slen) < 0) \ | |
146 | {c.line=__LINE__; goto err; } \ | |
147 | c.slen-=(c.p-c.q); | |
148 | ||
149 | # define M_ASN1_D2I_get_opt(b,func,type) \ | |
150 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ | |
151 | == (V_ASN1_UNIVERSAL|(type)))) \ | |
152 | { \ | |
153 | M_ASN1_D2I_get(b,func); \ | |
154 | } | |
155 | ||
156 | # define M_ASN1_D2I_get_imp(b,func, type) \ | |
157 | M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \ | |
158 | c.q=c.p; \ | |
159 | if (func(&(b),&c.p,c.slen) == NULL) \ | |
160 | {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \ | |
161 | c.slen-=(c.p-c.q);\ | |
162 | M_ASN1_next_prev=_tmp; | |
163 | ||
164 | # define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ | |
165 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ | |
166 | (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ | |
167 | { \ | |
168 | unsigned char _tmp = M_ASN1_next; \ | |
169 | M_ASN1_D2I_get_imp(b,func, type);\ | |
170 | } | |
171 | ||
172 | # define M_ASN1_D2I_get_set(r,func,free_func) \ | |
173 | M_ASN1_D2I_get_imp_set(r,func,free_func, \ | |
174 | V_ASN1_SET,V_ASN1_UNIVERSAL); | |
175 | ||
176 | # define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ | |
177 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ | |
178 | V_ASN1_SET,V_ASN1_UNIVERSAL); | |
179 | ||
180 | # define M_ASN1_D2I_get_set_opt(r,func,free_func) \ | |
181 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | |
182 | V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ | |
183 | { M_ASN1_D2I_get_set(r,func,free_func); } | |
184 | ||
185 | # define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ | |
186 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | |
187 | V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ | |
188 | { M_ASN1_D2I_get_set_type(type,r,func,free_func); } | |
189 | ||
190 | # define M_ASN1_I2D_len_SET_opt(a,f) \ | |
191 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
192 | M_ASN1_I2D_len_SET(a,f); | |
193 | ||
194 | # define M_ASN1_I2D_put_SET_opt(a,f) \ | |
195 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
196 | M_ASN1_I2D_put_SET(a,f); | |
197 | ||
198 | # define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ | |
199 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
200 | M_ASN1_I2D_put_SEQUENCE(a,f); | |
201 | ||
202 | # define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \ | |
203 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | |
204 | M_ASN1_I2D_put_SEQUENCE_type(type,a,f); | |
205 | ||
206 | # define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \ | |
207 | if ((c.slen != 0) && \ | |
208 | (M_ASN1_next == \ | |
209 | (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ | |
210 | { \ | |
211 | M_ASN1_D2I_get_imp_set(b,func,free_func,\ | |
212 | tag,V_ASN1_CONTEXT_SPECIFIC); \ | |
213 | } | |
214 | ||
215 | # define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ | |
216 | if ((c.slen != 0) && \ | |
217 | (M_ASN1_next == \ | |
218 | (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ | |
219 | { \ | |
220 | M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\ | |
221 | tag,V_ASN1_CONTEXT_SPECIFIC); \ | |
222 | } | |
223 | ||
224 | # define M_ASN1_D2I_get_seq(r,func,free_func) \ | |
225 | M_ASN1_D2I_get_imp_set(r,func,free_func,\ | |
226 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | |
227 | ||
228 | # define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ | |
229 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ | |
230 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) | |
231 | ||
232 | # define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ | |
233 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | |
234 | V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ | |
235 | { M_ASN1_D2I_get_seq(r,func,free_func); } | |
236 | ||
237 | # define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ | |
238 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | |
239 | V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ | |
240 | { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } | |
241 | ||
242 | # define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ | |
243 | M_ASN1_D2I_get_imp_set(r,func,free_func,\ | |
244 | x,V_ASN1_CONTEXT_SPECIFIC); | |
245 | ||
246 | # define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ | |
247 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ | |
248 | x,V_ASN1_CONTEXT_SPECIFIC); | |
249 | ||
250 | # define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ | |
251 | c.q=c.p; \ | |
252 | if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ | |
253 | (void (*)())free_func,a,b) == NULL) \ | |
254 | { c.line=__LINE__; goto err; } \ | |
255 | c.slen-=(c.p-c.q); | |
256 | ||
257 | # define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ | |
258 | c.q=c.p; \ | |
259 | if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ | |
260 | free_func,a,b) == NULL) \ | |
261 | { c.line=__LINE__; goto err; } \ | |
262 | c.slen-=(c.p-c.q); | |
263 | ||
264 | # define M_ASN1_D2I_get_set_strings(r,func,a,b) \ | |
265 | c.q=c.p; \ | |
266 | if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ | |
267 | { c.line=__LINE__; goto err; } \ | |
268 | c.slen-=(c.p-c.q); | |
269 | ||
270 | # define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ | |
271 | if ((c.slen != 0L) && (M_ASN1_next == \ | |
272 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | |
273 | { \ | |
274 | int Tinf,Ttag,Tclass; \ | |
275 | long Tlen; \ | |
276 | \ | |
277 | c.q=c.p; \ | |
278 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | |
279 | if (Tinf & 0x80) \ | |
280 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | |
281 | c.line=__LINE__; goto err; } \ | |
282 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | |
283 | Tlen = c.slen - (c.p - c.q) - 2; \ | |
284 | if (func(&(r),&c.p,Tlen) == NULL) \ | |
285 | { c.line=__LINE__; goto err; } \ | |
286 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | |
287 | Tlen = c.slen - (c.p - c.q); \ | |
288 | if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \ | |
289 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | |
290 | c.line=__LINE__; goto err; } \ | |
291 | }\ | |
292 | c.slen-=(c.p-c.q); \ | |
293 | } | |
294 | ||
295 | # define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ | |
296 | if ((c.slen != 0) && (M_ASN1_next == \ | |
297 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | |
298 | { \ | |
299 | int Tinf,Ttag,Tclass; \ | |
300 | long Tlen; \ | |
301 | \ | |
302 | c.q=c.p; \ | |
303 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | |
304 | if (Tinf & 0x80) \ | |
305 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | |
306 | c.line=__LINE__; goto err; } \ | |
307 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | |
308 | Tlen = c.slen - (c.p - c.q) - 2; \ | |
309 | if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ | |
310 | (void (*)())free_func, \ | |
311 | b,V_ASN1_UNIVERSAL) == NULL) \ | |
312 | { c.line=__LINE__; goto err; } \ | |
313 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | |
314 | Tlen = c.slen - (c.p - c.q); \ | |
315 | if(!ASN1_check_infinite_end(&c.p, Tlen)) \ | |
316 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | |
317 | c.line=__LINE__; goto err; } \ | |
318 | }\ | |
319 | c.slen-=(c.p-c.q); \ | |
320 | } | |
321 | ||
322 | # define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ | |
323 | if ((c.slen != 0) && (M_ASN1_next == \ | |
324 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | |
325 | { \ | |
326 | int Tinf,Ttag,Tclass; \ | |
327 | long Tlen; \ | |
328 | \ | |
329 | c.q=c.p; \ | |
330 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | |
331 | if (Tinf & 0x80) \ | |
332 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | |
333 | c.line=__LINE__; goto err; } \ | |
334 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | |
335 | Tlen = c.slen - (c.p - c.q) - 2; \ | |
336 | if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \ | |
337 | free_func,b,V_ASN1_UNIVERSAL) == NULL) \ | |
338 | { c.line=__LINE__; goto err; } \ | |
339 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | |
340 | Tlen = c.slen - (c.p - c.q); \ | |
341 | if(!ASN1_check_infinite_end(&c.p, Tlen)) \ | |
342 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | |
343 | c.line=__LINE__; goto err; } \ | |
344 | }\ | |
345 | c.slen-=(c.p-c.q); \ | |
346 | } | |
0b3f827c | 347 | |
d02b48c6 | 348 | /* New macros */ |
40720ce3 MC |
349 | # define M_ASN1_New_Malloc(ret,type) \ |
350 | if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \ | |
351 | { c.line=__LINE__; goto err2; } | |
352 | ||
353 | # define M_ASN1_New(arg,func) \ | |
354 | if (((arg)=func()) == NULL) return(NULL) | |
355 | ||
356 | # define M_ASN1_New_Error(a) \ | |
357 | /*- err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ | |
358 | return(NULL);*/ \ | |
359 | err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ | |
360 | return(NULL) | |
361 | ||
362 | /* | |
363 | * BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately, some | |
364 | * macros that use ASN1_const_CTX still insist on writing in the input | |
365 | * stream. ARGH! ARGH! ARGH! Let's get rid of this macro package. Please? -- | |
366 | * Richard Levitte | |
367 | */ | |
368 | # define M_ASN1_next (*((unsigned char *)(c.p))) | |
369 | # define M_ASN1_next_prev (*((unsigned char *)(c.q))) | |
d02b48c6 RE |
370 | |
371 | /*************************************************/ | |
372 | ||
40720ce3 MC |
373 | # define M_ASN1_I2D_vars(a) int r=0,ret=0; \ |
374 | unsigned char *p; \ | |
375 | if (a == NULL) return(0) | |
d02b48c6 RE |
376 | |
377 | /* Length Macros */ | |
40720ce3 MC |
378 | # define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) |
379 | # define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) | |
380 | ||
381 | # define M_ASN1_I2D_len_SET(a,f) \ | |
382 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); | |
383 | ||
384 | # define M_ASN1_I2D_len_SET_type(type,a,f) \ | |
385 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ | |
386 | V_ASN1_UNIVERSAL,IS_SET); | |
387 | ||
388 | # define M_ASN1_I2D_len_SEQUENCE(a,f) \ | |
389 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ | |
390 | IS_SEQUENCE); | |
391 | ||
392 | # define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ | |
393 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ | |
394 | V_ASN1_UNIVERSAL,IS_SEQUENCE) | |
395 | ||
396 | # define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \ | |
397 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
398 | M_ASN1_I2D_len_SEQUENCE(a,f); | |
399 | ||
400 | # define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \ | |
401 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | |
402 | M_ASN1_I2D_len_SEQUENCE_type(type,a,f); | |
403 | ||
404 | # define M_ASN1_I2D_len_IMP_SET(a,f,x) \ | |
405 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); | |
406 | ||
407 | # define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ | |
408 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | |
409 | V_ASN1_CONTEXT_SPECIFIC,IS_SET); | |
410 | ||
411 | # define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ | |
412 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
413 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | |
414 | IS_SET); | |
415 | ||
416 | # define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ | |
417 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | |
418 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | |
419 | V_ASN1_CONTEXT_SPECIFIC,IS_SET); | |
420 | ||
421 | # define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ | |
422 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | |
423 | IS_SEQUENCE); | |
424 | ||
425 | # define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \ | |
426 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
427 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | |
428 | IS_SEQUENCE); | |
429 | ||
430 | # define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ | |
431 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | |
432 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | |
433 | V_ASN1_CONTEXT_SPECIFIC, \ | |
434 | IS_SEQUENCE); | |
435 | ||
436 | # define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ | |
437 | if (a != NULL)\ | |
438 | { \ | |
439 | v=f(a,NULL); \ | |
440 | ret+=ASN1_object_size(1,v,mtag); \ | |
441 | } | |
442 | ||
443 | # define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \ | |
444 | if ((a != NULL) && (sk_num(a) != 0))\ | |
445 | { \ | |
446 | v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ | |
447 | ret+=ASN1_object_size(1,v,mtag); \ | |
448 | } | |
449 | ||
450 | # define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ | |
451 | if ((a != NULL) && (sk_num(a) != 0))\ | |
452 | { \ | |
453 | v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \ | |
454 | IS_SEQUENCE); \ | |
455 | ret+=ASN1_object_size(1,v,mtag); \ | |
456 | } | |
457 | ||
458 | # define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ | |
459 | if ((a != NULL) && (sk_##type##_num(a) != 0))\ | |
460 | { \ | |
461 | v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \ | |
462 | V_ASN1_UNIVERSAL, \ | |
463 | IS_SEQUENCE); \ | |
464 | ret+=ASN1_object_size(1,v,mtag); \ | |
465 | } | |
0b3f827c | 466 | |
d02b48c6 | 467 | /* Put Macros */ |
40720ce3 MC |
468 | # define M_ASN1_I2D_put(a,f) f(a,&p) |
469 | ||
470 | # define M_ASN1_I2D_put_IMP_opt(a,f,t) \ | |
471 | if (a != NULL) \ | |
472 | { \ | |
473 | unsigned char *q=p; \ | |
474 | f(a,&p); \ | |
475 | *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ | |
476 | } | |
477 | ||
478 | # define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ | |
479 | V_ASN1_UNIVERSAL,IS_SET) | |
480 | # define M_ASN1_I2D_put_SET_type(type,a,f) \ | |
426edadf | 481 | i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) |
40720ce3 MC |
482 | # define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ |
483 | V_ASN1_CONTEXT_SPECIFIC,IS_SET) | |
484 | # define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ | |
d500de16 | 485 | i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) |
40720ce3 MC |
486 | # define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ |
487 | V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) | |
4098e89c | 488 | |
40720ce3 MC |
489 | # define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ |
490 | V_ASN1_UNIVERSAL,IS_SEQUENCE) | |
d02b48c6 | 491 | |
40720ce3 | 492 | # define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ |
cfdcfede | 493 | i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ |
40720ce3 MC |
494 | IS_SEQUENCE) |
495 | ||
496 | # define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ | |
497 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
498 | M_ASN1_I2D_put_SEQUENCE(a,f); | |
499 | ||
500 | # define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \ | |
501 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
502 | { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | |
503 | IS_SET); } | |
504 | ||
505 | # define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ | |
506 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | |
507 | { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ | |
508 | V_ASN1_CONTEXT_SPECIFIC, \ | |
509 | IS_SET); } | |
510 | ||
511 | # define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ | |
512 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
513 | { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | |
514 | IS_SEQUENCE); } | |
515 | ||
516 | # define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ | |
517 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | |
518 | { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ | |
519 | V_ASN1_CONTEXT_SPECIFIC, \ | |
520 | IS_SEQUENCE); } | |
521 | ||
522 | # define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ | |
523 | if (a != NULL) \ | |
524 | { \ | |
525 | ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \ | |
526 | f(a,&p); \ | |
527 | } | |
528 | ||
529 | # define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \ | |
530 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
531 | { \ | |
532 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | |
533 | i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ | |
534 | } | |
535 | ||
536 | # define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ | |
537 | if ((a != NULL) && (sk_num(a) != 0)) \ | |
538 | { \ | |
539 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | |
540 | i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \ | |
541 | } | |
542 | ||
543 | # define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ | |
544 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | |
545 | { \ | |
546 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | |
547 | i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \ | |
548 | IS_SEQUENCE); \ | |
549 | } | |
550 | ||
551 | # define M_ASN1_I2D_seq_total() \ | |
552 | r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \ | |
553 | if (pp == NULL) return(r); \ | |
554 | p= *pp; \ | |
555 | ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) | |
556 | ||
557 | # define M_ASN1_I2D_INF_seq_start(tag,ctx) \ | |
558 | *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \ | |
559 | *(p++)=0x80 | |
560 | ||
561 | # define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00 | |
562 | ||
563 | # define M_ASN1_I2D_finish() *pp=p; \ | |
564 | return(r); | |
d02b48c6 | 565 | |
875a644a | 566 | int asn1_GetSequence(ASN1_const_CTX *c, long *length); |
40720ce3 | 567 | void asn1_add_error(const unsigned char *address, int offset); |
d02b48c6 RE |
568 | #ifdef __cplusplus |
569 | } | |
570 | #endif | |
571 | ||
572 | #endif |