Go to the documentation of this file.
59 #ifndef HEADER_ASN1_MAC_H
60 #define HEADER_ASN1_MAC_H
68 #ifndef ASN1_MAC_ERR_LIB
69 #define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
72 #define ASN1_MAC_H_err(f,r,line) \
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
75 #define M_ASN1_D2I_vars(a,type,func) \
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; } } \
87 #define M_ASN1_D2I_Init() \
88 c.p= *(const unsigned char **)pp; \
89 c.max=(length == 0)?0:(c.p+length);
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; \
98 #define M_ASN1_D2I_Finish(a,func,e) \
99 M_ASN1_D2I_Finish_2(a); \
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); \
106 #define M_ASN1_D2I_start_sequence() \
107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; }
110 #define M_ASN1_D2I_begin() \
114 #define M_ASN1_D2I_Finish_nolen(a, func, e) \
116 if (a != NULL) (*a)=ret; \
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); \
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)))
129 #define M_ASN1_D2I_get(b, func) \
131 if (func(&(b),&c.p,c.slen) == NULL) \
132 {c.line=__LINE__; goto err; } \
136 #define M_ASN1_D2I_get_x(type,b,func) \
138 if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
139 {c.line=__LINE__; goto err; } \
143 #define M_ASN1_D2I_get_int(b,func) \
145 if (func(&(b),&c.p,c.slen) < 0) \
146 {c.line=__LINE__; goto err; } \
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)))) \
153 M_ASN1_D2I_get(b,func); \
156 #define M_ASN1_D2I_get_int_opt(b,func,type) \
157 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
158 == (V_ASN1_UNIVERSAL|(type)))) \
160 M_ASN1_D2I_get_int(b,func); \
163 #define M_ASN1_D2I_get_imp(b,func, type) \
164 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
166 if (func(&(b),&c.p,c.slen) == NULL) \
167 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
169 M_ASN1_next_prev=_tmp;
171 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
172 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
173 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
175 unsigned char _tmp = M_ASN1_next; \
176 M_ASN1_D2I_get_imp(b,func, type);\
179 #define M_ASN1_D2I_get_set(r,func,free_func) \
180 M_ASN1_D2I_get_imp_set(r,func,free_func, \
181 V_ASN1_SET,V_ASN1_UNIVERSAL);
183 #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
184 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
185 V_ASN1_SET,V_ASN1_UNIVERSAL);
187 #define M_ASN1_D2I_get_set_opt(r,func,free_func) \
188 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
189 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
190 { M_ASN1_D2I_get_set(r,func,free_func); }
192 #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
193 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
194 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
195 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
197 #define M_ASN1_I2D_len_SET_opt(a,f) \
198 if ((a != NULL) && (sk_num(a) != 0)) \
199 M_ASN1_I2D_len_SET(a,f);
201 #define M_ASN1_I2D_put_SET_opt(a,f) \
202 if ((a != NULL) && (sk_num(a) != 0)) \
203 M_ASN1_I2D_put_SET(a,f);
205 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
206 if ((a != NULL) && (sk_num(a) != 0)) \
207 M_ASN1_I2D_put_SEQUENCE(a,f);
209 #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
210 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
211 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
213 #define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
214 if ((c.slen != 0) && \
216 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
218 M_ASN1_D2I_get_imp_set(b,func,free_func,\
219 tag,V_ASN1_CONTEXT_SPECIFIC); \
222 #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
223 if ((c.slen != 0) && \
225 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
227 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
228 tag,V_ASN1_CONTEXT_SPECIFIC); \
231 #define M_ASN1_D2I_get_seq(r,func,free_func) \
232 M_ASN1_D2I_get_imp_set(r,func,free_func,\
233 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
235 #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
236 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
237 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
239 #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
240 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
241 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
242 { M_ASN1_D2I_get_seq(r,func,free_func); }
244 #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
245 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
246 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
247 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
249 #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
250 M_ASN1_D2I_get_imp_set(r,func,free_func,\
251 x,V_ASN1_CONTEXT_SPECIFIC);
253 #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
254 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
255 x,V_ASN1_CONTEXT_SPECIFIC);
257 #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
259 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
260 (void (*)())free_func,a,b) == NULL) \
261 { c.line=__LINE__; goto err; } \
264 #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
266 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
267 free_func,a,b) == NULL) \
268 { c.line=__LINE__; goto err; } \
271 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \
273 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
274 { c.line=__LINE__; goto err; } \
277 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
278 if ((c.slen != 0L) && (M_ASN1_next == \
279 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
281 int Tinf,Ttag,Tclass; \
285 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
287 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
288 c.line=__LINE__; goto err; } \
289 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
290 Tlen = c.slen - (c.p - c.q) - 2; \
291 if (func(&(r),&c.p,Tlen) == NULL) \
292 { c.line=__LINE__; goto err; } \
293 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
294 Tlen = c.slen - (c.p - c.q); \
295 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \
296 { c.error=ERR_R_MISSING_ASN1_EOS; \
297 c.line=__LINE__; goto err; } \
302 #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
303 if ((c.slen != 0) && (M_ASN1_next == \
304 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
306 int Tinf,Ttag,Tclass; \
310 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
312 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
313 c.line=__LINE__; goto err; } \
314 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
315 Tlen = c.slen - (c.p - c.q) - 2; \
316 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
317 (void (*)())free_func, \
318 b,V_ASN1_UNIVERSAL) == NULL) \
319 { c.line=__LINE__; goto err; } \
320 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
321 Tlen = c.slen - (c.p - c.q); \
322 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
323 { c.error=ERR_R_MISSING_ASN1_EOS; \
324 c.line=__LINE__; goto err; } \
329 #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
330 if ((c.slen != 0) && (M_ASN1_next == \
331 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
333 int Tinf,Ttag,Tclass; \
337 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
339 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
340 c.line=__LINE__; goto err; } \
341 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
342 Tlen = c.slen - (c.p - c.q) - 2; \
343 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
344 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
345 { c.line=__LINE__; goto err; } \
346 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
347 Tlen = c.slen - (c.p - c.q); \
348 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
349 { c.error=ERR_R_MISSING_ASN1_EOS; \
350 c.line=__LINE__; goto err; } \
356 #define M_ASN1_New_Malloc(ret,type) \
357 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
358 { c.line=__LINE__; goto err2; }
360 #define M_ASN1_New(arg,func) \
361 if (((arg)=func()) == NULL) return(NULL)
363 #define M_ASN1_New_Error(a) \
366 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
374 #define M_ASN1_next (*((unsigned char *)(c.p)))
375 #define M_ASN1_next_prev (*((unsigned char *)(c.q)))
379 #define M_ASN1_I2D_vars(a) int r=0,ret=0; \
381 if (a == NULL) return(0)
384 #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
385 #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
387 #define M_ASN1_I2D_len_SET(a,f) \
388 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
390 #define M_ASN1_I2D_len_SET_type(type,a,f) \
391 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
392 V_ASN1_UNIVERSAL,IS_SET);
394 #define M_ASN1_I2D_len_SEQUENCE(a,f) \
395 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
398 #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
399 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
400 V_ASN1_UNIVERSAL,IS_SEQUENCE)
402 #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
403 if ((a != NULL) && (sk_num(a) != 0)) \
404 M_ASN1_I2D_len_SEQUENCE(a,f);
406 #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
407 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
408 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
410 #define M_ASN1_I2D_len_IMP_SET(a,f,x) \
411 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
413 #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
414 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
415 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
417 #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
418 if ((a != NULL) && (sk_num(a) != 0)) \
419 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
422 #define M_ASN1_I2D_len_IMP_SET_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,IS_SET);
427 #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
428 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
431 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
432 if ((a != NULL) && (sk_num(a) != 0)) \
433 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
436 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
437 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
438 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
439 V_ASN1_CONTEXT_SPECIFIC, \
442 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
446 ret+=ASN1_object_size(1,v,mtag); \
449 #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
450 if ((a != NULL) && (sk_num(a) != 0))\
452 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
453 ret+=ASN1_object_size(1,v,mtag); \
456 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
457 if ((a != NULL) && (sk_num(a) != 0))\
459 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
461 ret+=ASN1_object_size(1,v,mtag); \
464 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
465 if ((a != NULL) && (sk_##type##_num(a) != 0))\
467 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
470 ret+=ASN1_object_size(1,v,mtag); \
474 #define M_ASN1_I2D_put(a,f) f(a,&p)
476 #define M_ASN1_I2D_put_IMP_opt(a,f,t) \
479 unsigned char *q=p; \
481 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
484 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
485 V_ASN1_UNIVERSAL,IS_SET)
486 #define M_ASN1_I2D_put_SET_type(type,a,f) \
487 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
488 #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
489 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
490 #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
491 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
492 #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
493 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
495 #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
496 V_ASN1_UNIVERSAL,IS_SEQUENCE)
498 #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
499 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
502 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
503 if ((a != NULL) && (sk_num(a) != 0)) \
504 M_ASN1_I2D_put_SEQUENCE(a,f);
506 #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
507 if ((a != NULL) && (sk_num(a) != 0)) \
508 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
511 #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
512 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
513 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
514 V_ASN1_CONTEXT_SPECIFIC, \
517 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
518 if ((a != NULL) && (sk_num(a) != 0)) \
519 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
522 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
523 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
524 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
525 V_ASN1_CONTEXT_SPECIFIC, \
528 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
531 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
535 #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
536 if ((a != NULL) && (sk_num(a) != 0)) \
538 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
539 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
542 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
543 if ((a != NULL) && (sk_num(a) != 0)) \
545 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
546 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
549 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
550 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
552 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
553 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
557 #define M_ASN1_I2D_seq_total() \
558 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
559 if (pp == NULL) return(r); \
561 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
563 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \
564 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
567 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
569 #define M_ASN1_I2D_finish() *pp=p; \