|
1 /* crypto/asn1/asn1_mac.h */ |
|
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
|
3 * All rights reserved. |
|
4 * |
|
5 * This package is an SSL implementation written |
|
6 * by Eric Young (eay@cryptsoft.com). |
|
7 * The implementation was written so as to conform with Netscapes SSL. |
|
8 * |
|
9 * This library is free for commercial and non-commercial use as long as |
|
10 * the following conditions are aheared to. The following conditions |
|
11 * apply to all code found in this distribution, be it the RC4, RSA, |
|
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
|
13 * included with this distribution is covered by the same copyright terms |
|
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
|
15 * |
|
16 * Copyright remains Eric Young's, and as such any Copyright notices in |
|
17 * the code are not to be removed. |
|
18 * If this package is used in a product, Eric Young should be given attribution |
|
19 * as the author of the parts of the library used. |
|
20 * This can be in the form of a textual message at program startup or |
|
21 * in documentation (online or textual) provided with the package. |
|
22 * |
|
23 * Redistribution and use in source and binary forms, with or without |
|
24 * modification, are permitted provided that the following conditions |
|
25 * are met: |
|
26 * 1. Redistributions of source code must retain the copyright |
|
27 * notice, this list of conditions and the following disclaimer. |
|
28 * 2. Redistributions in binary form must reproduce the above copyright |
|
29 * notice, this list of conditions and the following disclaimer in the |
|
30 * documentation and/or other materials provided with the distribution. |
|
31 * 3. All advertising materials mentioning features or use of this software |
|
32 * must display the following acknowledgement: |
|
33 * "This product includes cryptographic software written by |
|
34 * Eric Young (eay@cryptsoft.com)" |
|
35 * The word 'cryptographic' can be left out if the rouines from the library |
|
36 * being used are not cryptographic related :-). |
|
37 * 4. If you include any Windows specific code (or a derivative thereof) from |
|
38 * the apps directory (application code) you must include an acknowledgement: |
|
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
|
40 * |
|
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
|
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
51 * SUCH DAMAGE. |
|
52 * |
|
53 * The licence and distribution terms for any publically available version or |
|
54 * derivative of this code cannot be changed. i.e. this code cannot simply be |
|
55 * copied and put under another distribution licence |
|
56 * [including the GNU Public Licence.] |
|
57 */ |
|
58 /* |
|
59 © Portions copyright (c) 2006 Nokia Corporation. All rights reserved. |
|
60 */ |
|
61 |
|
62 #ifndef HEADER_ASN1_MAC_H |
|
63 #define HEADER_ASN1_MAC_H |
|
64 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN)) |
|
65 #define SYMBIAN |
|
66 #endif |
|
67 |
|
68 #ifdef SYMBIAN |
|
69 #include <e32def.h> |
|
70 #endif |
|
71 #include <openssl/asn1.h> |
|
72 |
|
73 #ifdef __cplusplus |
|
74 extern "C" { |
|
75 #endif |
|
76 |
|
77 #ifndef ASN1_MAC_ERR_LIB |
|
78 #define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 |
|
79 #endif |
|
80 |
|
81 #define ASN1_MAC_H_err(f,r,line) \ |
|
82 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line)) |
|
83 |
|
84 #define M_ASN1_D2I_vars(a,type,func) \ |
|
85 ASN1_const_CTX c; \ |
|
86 type ret=NULL; \ |
|
87 \ |
|
88 c.pp=(const unsigned char **)pp; \ |
|
89 c.q= *(const unsigned char **)pp; \ |
|
90 c.error=ERR_R_NESTED_ASN1_ERROR; \ |
|
91 if ((a == NULL) || ((*a) == NULL)) \ |
|
92 { if ((ret=(type)func()) == NULL) \ |
|
93 { c.line=__LINE__; goto err; } } \ |
|
94 else ret=(*a); |
|
95 |
|
96 #define M_ASN1_D2I_Init() \ |
|
97 c.p= *(const unsigned char **)pp; \ |
|
98 c.max=(length == 0)?0:(c.p+length); |
|
99 |
|
100 #define M_ASN1_D2I_Finish_2(a) \ |
|
101 if (!asn1_const_Finish(&c)) \ |
|
102 { c.line=__LINE__; goto err; } \ |
|
103 *(const unsigned char **)pp=c.p; \ |
|
104 if (a != NULL) (*a)=ret; \ |
|
105 return(ret); |
|
106 |
|
107 #define M_ASN1_D2I_Finish(a,func,e) \ |
|
108 M_ASN1_D2I_Finish_2(a); \ |
|
109 err:\ |
|
110 ASN1_MAC_H_err((e),c.error,c.line); \ |
|
111 asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \ |
|
112 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ |
|
113 return(NULL) |
|
114 |
|
115 #define M_ASN1_D2I_start_sequence() \ |
|
116 if (!asn1_GetSequence(&c,&length)) \ |
|
117 { c.line=__LINE__; goto err; } |
|
118 /* Begin reading ASN1 without a surrounding sequence */ |
|
119 #define M_ASN1_D2I_begin() \ |
|
120 c.slen = length; |
|
121 |
|
122 /* End reading ASN1 with no check on length */ |
|
123 #define M_ASN1_D2I_Finish_nolen(a, func, e) \ |
|
124 *pp=c.p; \ |
|
125 if (a != NULL) (*a)=ret; \ |
|
126 return(ret); \ |
|
127 err:\ |
|
128 ASN1_MAC_H_err((e),c.error,c.line); \ |
|
129 asn1_add_error(*pp,(int)(c.q- *pp)); \ |
|
130 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ |
|
131 return(NULL) |
|
132 |
|
133 #define M_ASN1_D2I_end_sequence() \ |
|
134 (((c.inf&1) == 0)?(c.slen <= 0): \ |
|
135 (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen))) |
|
136 |
|
137 /* Don't use this with d2i_ASN1_BOOLEAN() */ |
|
138 #define M_ASN1_D2I_get(b, func) \ |
|
139 c.q=c.p; \ |
|
140 if (func(&(b),&c.p,c.slen) == NULL) \ |
|
141 {c.line=__LINE__; goto err; } \ |
|
142 c.slen-=(c.p-c.q); |
|
143 |
|
144 /* Don't use this with d2i_ASN1_BOOLEAN() */ |
|
145 #define M_ASN1_D2I_get_x(type,b,func) \ |
|
146 c.q=c.p; \ |
|
147 if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \ |
|
148 {c.line=__LINE__; goto err; } \ |
|
149 c.slen-=(c.p-c.q); |
|
150 |
|
151 /* use this instead () */ |
|
152 #define M_ASN1_D2I_get_int(b,func) \ |
|
153 c.q=c.p; \ |
|
154 if (func(&(b),&c.p,c.slen) < 0) \ |
|
155 {c.line=__LINE__; goto err; } \ |
|
156 c.slen-=(c.p-c.q); |
|
157 |
|
158 #define M_ASN1_D2I_get_opt(b,func,type) \ |
|
159 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ |
|
160 == (V_ASN1_UNIVERSAL|(type)))) \ |
|
161 { \ |
|
162 M_ASN1_D2I_get(b,func); \ |
|
163 } |
|
164 |
|
165 #define M_ASN1_D2I_get_imp(b,func, type) \ |
|
166 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \ |
|
167 c.q=c.p; \ |
|
168 if (func(&(b),&c.p,c.slen) == NULL) \ |
|
169 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \ |
|
170 c.slen-=(c.p-c.q);\ |
|
171 M_ASN1_next_prev=_tmp; |
|
172 |
|
173 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ |
|
174 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ |
|
175 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ |
|
176 { \ |
|
177 unsigned char _tmp = M_ASN1_next; \ |
|
178 M_ASN1_D2I_get_imp(b,func, type);\ |
|
179 } |
|
180 |
|
181 #define M_ASN1_D2I_get_set(r,func,free_func) \ |
|
182 M_ASN1_D2I_get_imp_set(r,func,free_func, \ |
|
183 V_ASN1_SET,V_ASN1_UNIVERSAL); |
|
184 |
|
185 #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ |
|
186 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ |
|
187 V_ASN1_SET,V_ASN1_UNIVERSAL); |
|
188 |
|
189 #define M_ASN1_D2I_get_set_opt(r,func,free_func) \ |
|
190 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ |
|
191 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ |
|
192 { M_ASN1_D2I_get_set(r,func,free_func); } |
|
193 |
|
194 #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ |
|
195 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ |
|
196 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ |
|
197 { M_ASN1_D2I_get_set_type(type,r,func,free_func); } |
|
198 |
|
199 #define M_ASN1_I2D_len_SET_opt(a,f) \ |
|
200 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
201 M_ASN1_I2D_len_SET(a,f); |
|
202 |
|
203 #define M_ASN1_I2D_put_SET_opt(a,f) \ |
|
204 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
205 M_ASN1_I2D_put_SET(a,f); |
|
206 |
|
207 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ |
|
208 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
209 M_ASN1_I2D_put_SEQUENCE(a,f); |
|
210 |
|
211 #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \ |
|
212 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ |
|
213 M_ASN1_I2D_put_SEQUENCE_type(type,a,f); |
|
214 |
|
215 #define M_ASN1_D2I_get_IMP_set_opt(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(b,func,free_func,\ |
|
221 tag,V_ASN1_CONTEXT_SPECIFIC); \ |
|
222 } |
|
223 |
|
224 #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ |
|
225 if ((c.slen != 0) && \ |
|
226 (M_ASN1_next == \ |
|
227 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ |
|
228 { \ |
|
229 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\ |
|
230 tag,V_ASN1_CONTEXT_SPECIFIC); \ |
|
231 } |
|
232 |
|
233 #define M_ASN1_D2I_get_seq(r,func,free_func) \ |
|
234 M_ASN1_D2I_get_imp_set(r,func,free_func,\ |
|
235 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); |
|
236 |
|
237 #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ |
|
238 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ |
|
239 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) |
|
240 |
|
241 #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ |
|
242 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ |
|
243 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ |
|
244 { M_ASN1_D2I_get_seq(r,func,free_func); } |
|
245 |
|
246 #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ |
|
247 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ |
|
248 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ |
|
249 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } |
|
250 |
|
251 #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ |
|
252 M_ASN1_D2I_get_imp_set(r,func,free_func,\ |
|
253 x,V_ASN1_CONTEXT_SPECIFIC); |
|
254 |
|
255 #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ |
|
256 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ |
|
257 x,V_ASN1_CONTEXT_SPECIFIC); |
|
258 |
|
259 #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ |
|
260 c.q=c.p; \ |
|
261 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ |
|
262 (void (*)())free_func,a,b) == NULL) \ |
|
263 { c.line=__LINE__; goto err; } \ |
|
264 c.slen-=(c.p-c.q); |
|
265 |
|
266 #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ |
|
267 c.q=c.p; \ |
|
268 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ |
|
269 free_func,a,b) == NULL) \ |
|
270 { c.line=__LINE__; goto err; } \ |
|
271 c.slen-=(c.p-c.q); |
|
272 |
|
273 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \ |
|
274 c.q=c.p; \ |
|
275 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ |
|
276 { c.line=__LINE__; goto err; } \ |
|
277 c.slen-=(c.p-c.q); |
|
278 |
|
279 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ |
|
280 if ((c.slen != 0L) && (M_ASN1_next == \ |
|
281 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ |
|
282 { \ |
|
283 int Tinf,Ttag,Tclass; \ |
|
284 long Tlen; \ |
|
285 \ |
|
286 c.q=c.p; \ |
|
287 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ |
|
288 if (Tinf & 0x80) \ |
|
289 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ |
|
290 c.line=__LINE__; goto err; } \ |
|
291 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ |
|
292 Tlen = c.slen - (c.p - c.q) - 2; \ |
|
293 if (func(&(r),&c.p,Tlen) == NULL) \ |
|
294 { c.line=__LINE__; goto err; } \ |
|
295 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ |
|
296 Tlen = c.slen - (c.p - c.q); \ |
|
297 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \ |
|
298 { c.error=ERR_R_MISSING_ASN1_EOS; \ |
|
299 c.line=__LINE__; goto err; } \ |
|
300 }\ |
|
301 c.slen-=(c.p-c.q); \ |
|
302 } |
|
303 |
|
304 #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ |
|
305 if ((c.slen != 0) && (M_ASN1_next == \ |
|
306 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ |
|
307 { \ |
|
308 int Tinf,Ttag,Tclass; \ |
|
309 long Tlen; \ |
|
310 \ |
|
311 c.q=c.p; \ |
|
312 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ |
|
313 if (Tinf & 0x80) \ |
|
314 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ |
|
315 c.line=__LINE__; goto err; } \ |
|
316 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ |
|
317 Tlen = c.slen - (c.p - c.q) - 2; \ |
|
318 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ |
|
319 (void (*)())free_func, \ |
|
320 b,V_ASN1_UNIVERSAL) == NULL) \ |
|
321 { c.line=__LINE__; goto err; } \ |
|
322 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ |
|
323 Tlen = c.slen - (c.p - c.q); \ |
|
324 if(!ASN1_check_infinite_end(&c.p, Tlen)) \ |
|
325 { c.error=ERR_R_MISSING_ASN1_EOS; \ |
|
326 c.line=__LINE__; goto err; } \ |
|
327 }\ |
|
328 c.slen-=(c.p-c.q); \ |
|
329 } |
|
330 |
|
331 #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ |
|
332 if ((c.slen != 0) && (M_ASN1_next == \ |
|
333 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ |
|
334 { \ |
|
335 int Tinf,Ttag,Tclass; \ |
|
336 long Tlen; \ |
|
337 \ |
|
338 c.q=c.p; \ |
|
339 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ |
|
340 if (Tinf & 0x80) \ |
|
341 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ |
|
342 c.line=__LINE__; goto err; } \ |
|
343 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ |
|
344 Tlen = c.slen - (c.p - c.q) - 2; \ |
|
345 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \ |
|
346 free_func,b,V_ASN1_UNIVERSAL) == NULL) \ |
|
347 { c.line=__LINE__; goto err; } \ |
|
348 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ |
|
349 Tlen = c.slen - (c.p - c.q); \ |
|
350 if(!ASN1_check_infinite_end(&c.p, Tlen)) \ |
|
351 { c.error=ERR_R_MISSING_ASN1_EOS; \ |
|
352 c.line=__LINE__; goto err; } \ |
|
353 }\ |
|
354 c.slen-=(c.p-c.q); \ |
|
355 } |
|
356 |
|
357 /* New macros */ |
|
358 #define M_ASN1_New_Malloc(ret,type) \ |
|
359 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \ |
|
360 { c.line=__LINE__; goto err2; } |
|
361 |
|
362 #define M_ASN1_New(arg,func) \ |
|
363 if (((arg)=func()) == NULL) return(NULL) |
|
364 |
|
365 #define M_ASN1_New_Error(a) \ |
|
366 /* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ |
|
367 return(NULL);*/ \ |
|
368 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ |
|
369 return(NULL) |
|
370 |
|
371 |
|
372 /* BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately, |
|
373 some macros that use ASN1_const_CTX still insist on writing in the input |
|
374 stream. ARGH! ARGH! ARGH! Let's get rid of this macro package. |
|
375 Please? -- Richard Levitte */ |
|
376 #define M_ASN1_next (*((unsigned char *)(c.p))) |
|
377 #define M_ASN1_next_prev (*((unsigned char *)(c.q))) |
|
378 |
|
379 /*************************************************/ |
|
380 |
|
381 #define M_ASN1_I2D_vars(a) int r=0,ret=0; \ |
|
382 unsigned char *p; \ |
|
383 if (a == NULL) return(0) |
|
384 |
|
385 /* Length Macros */ |
|
386 #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) |
|
387 #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) |
|
388 |
|
389 #define M_ASN1_I2D_len_SET(a,f) \ |
|
390 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); |
|
391 |
|
392 #define M_ASN1_I2D_len_SET_type(type,a,f) \ |
|
393 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ |
|
394 V_ASN1_UNIVERSAL,IS_SET); |
|
395 |
|
396 #define M_ASN1_I2D_len_SEQUENCE(a,f) \ |
|
397 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ |
|
398 IS_SEQUENCE); |
|
399 |
|
400 #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ |
|
401 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ |
|
402 V_ASN1_UNIVERSAL,IS_SEQUENCE) |
|
403 |
|
404 #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \ |
|
405 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
406 M_ASN1_I2D_len_SEQUENCE(a,f); |
|
407 |
|
408 #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \ |
|
409 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ |
|
410 M_ASN1_I2D_len_SEQUENCE_type(type,a,f); |
|
411 |
|
412 #define M_ASN1_I2D_len_IMP_SET(a,f,x) \ |
|
413 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); |
|
414 |
|
415 #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ |
|
416 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ |
|
417 V_ASN1_CONTEXT_SPECIFIC,IS_SET); |
|
418 |
|
419 #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ |
|
420 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
421 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ |
|
422 IS_SET); |
|
423 |
|
424 #define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ |
|
425 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ |
|
426 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ |
|
427 V_ASN1_CONTEXT_SPECIFIC,IS_SET); |
|
428 |
|
429 #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ |
|
430 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ |
|
431 IS_SEQUENCE); |
|
432 |
|
433 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \ |
|
434 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
435 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ |
|
436 IS_SEQUENCE); |
|
437 |
|
438 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ |
|
439 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ |
|
440 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ |
|
441 V_ASN1_CONTEXT_SPECIFIC, \ |
|
442 IS_SEQUENCE); |
|
443 |
|
444 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ |
|
445 if (a != NULL)\ |
|
446 { \ |
|
447 v=f(a,NULL); \ |
|
448 ret+=ASN1_object_size(1,v,mtag); \ |
|
449 } |
|
450 |
|
451 #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \ |
|
452 if ((a != NULL) && (sk_num(a) != 0))\ |
|
453 { \ |
|
454 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ |
|
455 ret+=ASN1_object_size(1,v,mtag); \ |
|
456 } |
|
457 |
|
458 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ |
|
459 if ((a != NULL) && (sk_num(a) != 0))\ |
|
460 { \ |
|
461 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \ |
|
462 IS_SEQUENCE); \ |
|
463 ret+=ASN1_object_size(1,v,mtag); \ |
|
464 } |
|
465 |
|
466 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ |
|
467 if ((a != NULL) && (sk_##type##_num(a) != 0))\ |
|
468 { \ |
|
469 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \ |
|
470 V_ASN1_UNIVERSAL, \ |
|
471 IS_SEQUENCE); \ |
|
472 ret+=ASN1_object_size(1,v,mtag); \ |
|
473 } |
|
474 |
|
475 /* Put Macros */ |
|
476 #define M_ASN1_I2D_put(a,f) f(a,&p) |
|
477 |
|
478 #define M_ASN1_I2D_put_IMP_opt(a,f,t) \ |
|
479 if (a != NULL) \ |
|
480 { \ |
|
481 unsigned char *q=p; \ |
|
482 f(a,&p); \ |
|
483 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ |
|
484 } |
|
485 |
|
486 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ |
|
487 V_ASN1_UNIVERSAL,IS_SET) |
|
488 #define M_ASN1_I2D_put_SET_type(type,a,f) \ |
|
489 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) |
|
490 #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ |
|
491 V_ASN1_CONTEXT_SPECIFIC,IS_SET) |
|
492 #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ |
|
493 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) |
|
494 #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ |
|
495 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) |
|
496 |
|
497 #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ |
|
498 V_ASN1_UNIVERSAL,IS_SEQUENCE) |
|
499 |
|
500 #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ |
|
501 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ |
|
502 IS_SEQUENCE) |
|
503 |
|
504 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ |
|
505 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
506 M_ASN1_I2D_put_SEQUENCE(a,f); |
|
507 |
|
508 #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \ |
|
509 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
510 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ |
|
511 IS_SET); } |
|
512 |
|
513 #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ |
|
514 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ |
|
515 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ |
|
516 V_ASN1_CONTEXT_SPECIFIC, \ |
|
517 IS_SET); } |
|
518 |
|
519 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ |
|
520 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
521 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ |
|
522 IS_SEQUENCE); } |
|
523 |
|
524 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ |
|
525 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ |
|
526 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ |
|
527 V_ASN1_CONTEXT_SPECIFIC, \ |
|
528 IS_SEQUENCE); } |
|
529 |
|
530 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ |
|
531 if (a != NULL) \ |
|
532 { \ |
|
533 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \ |
|
534 f(a,&p); \ |
|
535 } |
|
536 |
|
537 #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \ |
|
538 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
539 { \ |
|
540 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ |
|
541 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ |
|
542 } |
|
543 |
|
544 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ |
|
545 if ((a != NULL) && (sk_num(a) != 0)) \ |
|
546 { \ |
|
547 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ |
|
548 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \ |
|
549 } |
|
550 |
|
551 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ |
|
552 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ |
|
553 { \ |
|
554 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ |
|
555 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \ |
|
556 IS_SEQUENCE); \ |
|
557 } |
|
558 |
|
559 #define M_ASN1_I2D_seq_total() \ |
|
560 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \ |
|
561 if (pp == NULL) return(r); \ |
|
562 p= *pp; \ |
|
563 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) |
|
564 |
|
565 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \ |
|
566 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \ |
|
567 *(p++)=0x80 |
|
568 |
|
569 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00 |
|
570 |
|
571 #define M_ASN1_I2D_finish() *pp=p; \ |
|
572 return(r); |
|
573 |
|
574 IMPORT_C int asn1_GetSequence(ASN1_const_CTX *c, long *length); |
|
575 IMPORT_C void asn1_add_error(const unsigned char *address,int offset); |
|
576 #ifdef __cplusplus |
|
577 } |
|
578 #endif |
|
579 |
|
580 #endif |