Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /* crypto/asn1/asn1_mac.h */
 
     2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
 
     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.
 
     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).
 
    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.
 
    23  * Redistribution and use in source and binary forms, with or without
 
    24  * modification, are permitted provided that the following conditions
 
    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)"
 
    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
 
    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.]
 
    59  © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
 
    62 #ifndef HEADER_ASN1_MAC_H
 
    63 #define HEADER_ASN1_MAC_H
 
    65 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
 
    72 #include <openssl/asn1.h>
 
    78 #ifndef ASN1_MAC_ERR_LIB
 
    79 #define ASN1_MAC_ERR_LIB	ERR_LIB_ASN1
 
    82 #define ASN1_MAC_H_err(f,r,line) \
 
    83 	ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
 
    85 #define M_ASN1_D2I_vars(a,type,func) \
 
    89 	c.pp=(const unsigned char **)pp; \
 
    90 	c.q= *(const unsigned char **)pp; \
 
    91 	c.error=ERR_R_NESTED_ASN1_ERROR; \
 
    92 	if ((a == NULL) || ((*a) == NULL)) \
 
    93 		{ if ((ret=(type)func()) == NULL) \
 
    94 			{ c.line=__LINE__; goto err; } } \
 
    97 #define M_ASN1_D2I_Init() \
 
    98 	c.p= *(const unsigned char **)pp; \
 
    99 	c.max=(length == 0)?0:(c.p+length);
 
   101 #define M_ASN1_D2I_Finish_2(a) \
 
   102 	if (!asn1_const_Finish(&c)) \
 
   103 		{ c.line=__LINE__; goto err; } \
 
   104 	*(const unsigned char **)pp=c.p; \
 
   105 	if (a != NULL) (*a)=ret; \
 
   108 #define M_ASN1_D2I_Finish(a,func,e) \
 
   109 	M_ASN1_D2I_Finish_2(a); \
 
   111 	ASN1_MAC_H_err((e),c.error,c.line); \
 
   112 	asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \
 
   113 	if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
 
   116 #define M_ASN1_D2I_start_sequence() \
 
   117 	if (!asn1_GetSequence(&c,&length)) \
 
   118 		{ c.line=__LINE__; goto err; }
 
   119 /* Begin reading ASN1 without a surrounding sequence */
 
   120 #define M_ASN1_D2I_begin() \
 
   123 /* End reading ASN1 with no check on length */
 
   124 #define M_ASN1_D2I_Finish_nolen(a, func, e) \
 
   126 	if (a != NULL) (*a)=ret; \
 
   129 	ASN1_MAC_H_err((e),c.error,c.line); \
 
   130 	asn1_add_error(*pp,(int)(c.q- *pp)); \
 
   131 	if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
 
   134 #define M_ASN1_D2I_end_sequence() \
 
   135 	(((c.inf&1) == 0)?(c.slen <= 0): \
 
   136 		(c.eos=ASN1_const_check_infinite_end(&c.p,c.slen)))
 
   138 /* Don't use this with d2i_ASN1_BOOLEAN() */
 
   139 #define M_ASN1_D2I_get(b, func) \
 
   141 	if (func(&(b),&c.p,c.slen) == NULL) \
 
   142 		{c.line=__LINE__; goto err; } \
 
   145 /* Don't use this with d2i_ASN1_BOOLEAN() */
 
   146 #define M_ASN1_D2I_get_x(type,b,func) \
 
   148 	if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
 
   149 		{c.line=__LINE__; goto err; } \
 
   152 /* use this instead () */
 
   153 #define M_ASN1_D2I_get_int(b,func) \
 
   155 	if (func(&(b),&c.p,c.slen) < 0) \
 
   156 		{c.line=__LINE__; goto err; } \
 
   159 #define M_ASN1_D2I_get_opt(b,func,type) \
 
   160 	if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
 
   161 		== (V_ASN1_UNIVERSAL|(type)))) \
 
   163 		M_ASN1_D2I_get(b,func); \
 
   166 #define M_ASN1_D2I_get_imp(b,func, type) \
 
   167 	M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
 
   169 	if (func(&(b),&c.p,c.slen) == NULL) \
 
   170 		{c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
 
   172 	M_ASN1_next_prev=_tmp;
 
   174 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
 
   175 	if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
 
   176 		(V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
 
   178 		unsigned char _tmp = M_ASN1_next; \
 
   179 		M_ASN1_D2I_get_imp(b,func, type);\
 
   182 #define M_ASN1_D2I_get_set(r,func,free_func) \
 
   183 		M_ASN1_D2I_get_imp_set(r,func,free_func, \
 
   184 			V_ASN1_SET,V_ASN1_UNIVERSAL);
 
   186 #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
 
   187 		M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
 
   188 			V_ASN1_SET,V_ASN1_UNIVERSAL);
 
   190 #define M_ASN1_D2I_get_set_opt(r,func,free_func) \
 
   191 	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
 
   192 		V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
 
   193 		{ M_ASN1_D2I_get_set(r,func,free_func); }
 
   195 #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
 
   196 	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
 
   197 		V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
 
   198 		{ M_ASN1_D2I_get_set_type(type,r,func,free_func); }
 
   200 #define M_ASN1_I2D_len_SET_opt(a,f) \
 
   201 	if ((a != NULL) && (sk_num(a) != 0)) \
 
   202 		M_ASN1_I2D_len_SET(a,f);
 
   204 #define M_ASN1_I2D_put_SET_opt(a,f) \
 
   205 	if ((a != NULL) && (sk_num(a) != 0)) \
 
   206 		M_ASN1_I2D_put_SET(a,f);
 
   208 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
 
   209 	if ((a != NULL) && (sk_num(a) != 0)) \
 
   210 		M_ASN1_I2D_put_SEQUENCE(a,f);
 
   212 #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
 
   213 	if ((a != NULL) && (sk_##type##_num(a) != 0)) \
 
   214 		M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
 
   216 #define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
 
   217 	if ((c.slen != 0) && \
 
   219 		(V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
 
   221 		M_ASN1_D2I_get_imp_set(b,func,free_func,\
 
   222 			tag,V_ASN1_CONTEXT_SPECIFIC); \
 
   225 #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
 
   226 	if ((c.slen != 0) && \
 
   228 		(V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
 
   230 		M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
 
   231 			tag,V_ASN1_CONTEXT_SPECIFIC); \
 
   234 #define M_ASN1_D2I_get_seq(r,func,free_func) \
 
   235 		M_ASN1_D2I_get_imp_set(r,func,free_func,\
 
   236 			V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
 
   238 #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
 
   239 		M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
 
   240 					    V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
 
   242 #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
 
   243 	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
 
   244 		V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
 
   245 		{ M_ASN1_D2I_get_seq(r,func,free_func); }
 
   247 #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
 
   248 	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
 
   249 		V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
 
   250 		{ M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
 
   252 #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
 
   253 		M_ASN1_D2I_get_imp_set(r,func,free_func,\
 
   254 			x,V_ASN1_CONTEXT_SPECIFIC);
 
   256 #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
 
   257 		M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
 
   258 			x,V_ASN1_CONTEXT_SPECIFIC);
 
   260 #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
 
   262 	if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
 
   263 		(void (*)())free_func,a,b) == NULL) \
 
   264 		{ c.line=__LINE__; goto err; } \
 
   267 #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
 
   269 	if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
 
   270 				   free_func,a,b) == NULL) \
 
   271 		{ c.line=__LINE__; goto err; } \
 
   274 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \
 
   276 	if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
 
   277 		{ c.line=__LINE__; goto err; } \
 
   280 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
 
   281 	if ((c.slen != 0L) && (M_ASN1_next == \
 
   282 		(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
 
   284 		int Tinf,Ttag,Tclass; \
 
   288 		Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
 
   290 			{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
 
   291 			c.line=__LINE__; goto err; } \
 
   292 		if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
 
   293 					Tlen = c.slen - (c.p - c.q) - 2; \
 
   294 		if (func(&(r),&c.p,Tlen) == NULL) \
 
   295 			{ c.line=__LINE__; goto err; } \
 
   296 		if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
 
   297 			Tlen = c.slen - (c.p - c.q); \
 
   298 			if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \
 
   299 				{ c.error=ERR_R_MISSING_ASN1_EOS; \
 
   300 				c.line=__LINE__; goto err; } \
 
   305 #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
 
   306 	if ((c.slen != 0) && (M_ASN1_next == \
 
   307 		(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
 
   309 		int Tinf,Ttag,Tclass; \
 
   313 		Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
 
   315 			{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
 
   316 			c.line=__LINE__; goto err; } \
 
   317 		if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
 
   318 					Tlen = c.slen - (c.p - c.q) - 2; \
 
   319 		if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
 
   320 			(void (*)())free_func, \
 
   321 			b,V_ASN1_UNIVERSAL) == NULL) \
 
   322 			{ c.line=__LINE__; goto err; } \
 
   323 		if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
 
   324 			Tlen = c.slen - (c.p - c.q); \
 
   325 			if(!ASN1_check_infinite_end(&c.p, Tlen)) \
 
   326 				{ c.error=ERR_R_MISSING_ASN1_EOS; \
 
   327 				c.line=__LINE__; goto err; } \
 
   332 #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
 
   333 	if ((c.slen != 0) && (M_ASN1_next == \
 
   334 		(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
 
   336 		int Tinf,Ttag,Tclass; \
 
   340 		Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
 
   342 			{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
 
   343 			c.line=__LINE__; goto err; } \
 
   344 		if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
 
   345 					Tlen = c.slen - (c.p - c.q) - 2; \
 
   346 		if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
 
   347 			free_func,b,V_ASN1_UNIVERSAL) == NULL) \
 
   348 			{ c.line=__LINE__; goto err; } \
 
   349 		if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
 
   350 			Tlen = c.slen - (c.p - c.q); \
 
   351 			if(!ASN1_check_infinite_end(&c.p, Tlen)) \
 
   352 				{ c.error=ERR_R_MISSING_ASN1_EOS; \
 
   353 				c.line=__LINE__; goto err; } \
 
   359 #define M_ASN1_New_Malloc(ret,type) \
 
   360 	if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
 
   361 		{ c.line=__LINE__; goto err2; }
 
   363 #define M_ASN1_New(arg,func) \
 
   364 	if (((arg)=func()) == NULL) return(NULL)
 
   366 #define M_ASN1_New_Error(a) \
 
   367 /*	err:	ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
 
   369 	err2:	ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
 
   373 /* BIG UGLY WARNING!  This is so damn ugly I wanna puke.  Unfortunately,
 
   374    some macros that use ASN1_const_CTX still insist on writing in the input
 
   375    stream.  ARGH!  ARGH!  ARGH!  Let's get rid of this macro package.
 
   376    Please?						-- Richard Levitte */
 
   377 #define M_ASN1_next		(*((unsigned char *)(c.p)))
 
   378 #define M_ASN1_next_prev	(*((unsigned char *)(c.q)))
 
   380 /*************************************************/
 
   382 #define M_ASN1_I2D_vars(a)	int r=0,ret=0; \
 
   384 				if (a == NULL) return(0)
 
   387 #define M_ASN1_I2D_len(a,f)	ret+=f(a,NULL)
 
   388 #define M_ASN1_I2D_len_IMP_opt(a,f)	if (a != NULL) M_ASN1_I2D_len(a,f)
 
   390 #define M_ASN1_I2D_len_SET(a,f) \
 
   391 		ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
 
   393 #define M_ASN1_I2D_len_SET_type(type,a,f) \
 
   394 		ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
 
   395 					    V_ASN1_UNIVERSAL,IS_SET);
 
   397 #define M_ASN1_I2D_len_SEQUENCE(a,f) \
 
   398 		ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
 
   401 #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
 
   402 		ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
 
   403 					    V_ASN1_UNIVERSAL,IS_SEQUENCE)
 
   405 #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
 
   406 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   407 			M_ASN1_I2D_len_SEQUENCE(a,f);
 
   409 #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
 
   410 		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
 
   411 			M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
 
   413 #define M_ASN1_I2D_len_IMP_SET(a,f,x) \
 
   414 		ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
 
   416 #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
 
   417 		ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
 
   418 					    V_ASN1_CONTEXT_SPECIFIC,IS_SET);
 
   420 #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
 
   421 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   422 			ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
 
   425 #define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
 
   426 		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
 
   427 			ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
 
   428 					       V_ASN1_CONTEXT_SPECIFIC,IS_SET);
 
   430 #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
 
   431 		ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
 
   434 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
 
   435 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   436 			ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
 
   439 #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
 
   440 		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
 
   441 			ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
 
   442 						    V_ASN1_CONTEXT_SPECIFIC, \
 
   445 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
 
   449 			ret+=ASN1_object_size(1,v,mtag); \
 
   452 #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
 
   453 		if ((a != NULL) && (sk_num(a) != 0))\
 
   455 			v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
 
   456 			ret+=ASN1_object_size(1,v,mtag); \
 
   459 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
 
   460 		if ((a != NULL) && (sk_num(a) != 0))\
 
   462 			v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
 
   464 			ret+=ASN1_object_size(1,v,mtag); \
 
   467 #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
 
   468 		if ((a != NULL) && (sk_##type##_num(a) != 0))\
 
   470 			v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
 
   473 			ret+=ASN1_object_size(1,v,mtag); \
 
   477 #define M_ASN1_I2D_put(a,f)	f(a,&p)
 
   479 #define M_ASN1_I2D_put_IMP_opt(a,f,t)	\
 
   482 			unsigned char *q=p; \
 
   484 			*q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
 
   487 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
 
   488 			V_ASN1_UNIVERSAL,IS_SET)
 
   489 #define M_ASN1_I2D_put_SET_type(type,a,f) \
 
   490      i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
 
   491 #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
 
   492 			V_ASN1_CONTEXT_SPECIFIC,IS_SET)
 
   493 #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
 
   494      i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
 
   495 #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
 
   496 			V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
 
   498 #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
 
   499 					     V_ASN1_UNIVERSAL,IS_SEQUENCE)
 
   501 #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
 
   502      i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
 
   505 #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
 
   506 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   507 			M_ASN1_I2D_put_SEQUENCE(a,f);
 
   509 #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
 
   510 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   511 			{ i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
 
   514 #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
 
   515 		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
 
   516 			{ i2d_ASN1_SET_OF_##type(a,&p,f,x, \
 
   517 						 V_ASN1_CONTEXT_SPECIFIC, \
 
   520 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
 
   521 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   522 			{ i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
 
   525 #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
 
   526 		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
 
   527 			{ i2d_ASN1_SET_OF_##type(a,&p,f,x, \
 
   528 						 V_ASN1_CONTEXT_SPECIFIC, \
 
   531 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
 
   534 			ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
 
   538 #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
 
   539 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   541 			ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
 
   542 			i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
 
   545 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
 
   546 		if ((a != NULL) && (sk_num(a) != 0)) \
 
   548 			ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
 
   549 			i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
 
   552 #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
 
   553 		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
 
   555 			ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
 
   556 			i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
 
   560 #define M_ASN1_I2D_seq_total() \
 
   561 		r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
 
   562 		if (pp == NULL) return(r); \
 
   564 		ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
 
   566 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \
 
   567 		*(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
 
   570 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
 
   572 #define M_ASN1_I2D_finish()	*pp=p; \
 
   575 IMPORT_C int asn1_GetSequence(ASN1_const_CTX *c, long *length);
 
   576 IMPORT_C void asn1_add_error(const unsigned char *address,int offset);