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