epoc32/include/stdapis/openssl/asn1_mac.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
     1.1 --- a/epoc32/include/stdapis/openssl/asn1_mac.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/stdapis/openssl/asn1_mac.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,581 @@
     1.4 -asn1_mac.h
     1.5 +/* crypto/asn1/asn1_mac.h */
     1.6 +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * This package is an SSL implementation written
    1.10 + * by Eric Young (eay@cryptsoft.com).
    1.11 + * The implementation was written so as to conform with Netscapes SSL.
    1.12 + * 
    1.13 + * This library is free for commercial and non-commercial use as long as
    1.14 + * the following conditions are aheared to.  The following conditions
    1.15 + * apply to all code found in this distribution, be it the RC4, RSA,
    1.16 + * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
    1.17 + * included with this distribution is covered by the same copyright terms
    1.18 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
    1.19 + * 
    1.20 + * Copyright remains Eric Young's, and as such any Copyright notices in
    1.21 + * the code are not to be removed.
    1.22 + * If this package is used in a product, Eric Young should be given attribution
    1.23 + * as the author of the parts of the library used.
    1.24 + * This can be in the form of a textual message at program startup or
    1.25 + * in documentation (online or textual) provided with the package.
    1.26 + * 
    1.27 + * Redistribution and use in source and binary forms, with or without
    1.28 + * modification, are permitted provided that the following conditions
    1.29 + * are met:
    1.30 + * 1. Redistributions of source code must retain the copyright
    1.31 + *    notice, this list of conditions and the following disclaimer.
    1.32 + * 2. Redistributions in binary form must reproduce the above copyright
    1.33 + *    notice, this list of conditions and the following disclaimer in the
    1.34 + *    documentation and/or other materials provided with the distribution.
    1.35 + * 3. All advertising materials mentioning features or use of this software
    1.36 + *    must display the following acknowledgement:
    1.37 + *    "This product includes cryptographic software written by
    1.38 + *     Eric Young (eay@cryptsoft.com)"
    1.39 + *    The word 'cryptographic' can be left out if the rouines from the library
    1.40 + *    being used are not cryptographic related :-).
    1.41 + * 4. If you include any Windows specific code (or a derivative thereof) from 
    1.42 + *    the apps directory (application code) you must include an acknowledgement:
    1.43 + *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
    1.44 + * 
    1.45 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
    1.46 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.47 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.48 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
    1.49 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.50 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.51 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.52 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.53 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.54 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.55 + * SUCH DAMAGE.
    1.56 + * 
    1.57 + * The licence and distribution terms for any publically available version or
    1.58 + * derivative of this code cannot be changed.  i.e. this code cannot simply be
    1.59 + * copied and put under another distribution licence
    1.60 + * [including the GNU Public Licence.]
    1.61 + */
    1.62 + /*
    1.63 + © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
    1.64 + */
    1.65 +
    1.66 +#ifndef HEADER_ASN1_MAC_H
    1.67 +#define HEADER_ASN1_MAC_H
    1.68 +
    1.69 +#if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
    1.70 +#define SYMBIAN
    1.71 +#endif
    1.72 +
    1.73 +#ifdef SYMBIAN
    1.74 +#include <e32def.h>
    1.75 +#endif
    1.76 +#include <openssl/asn1.h>
    1.77 +
    1.78 +#ifdef  __cplusplus
    1.79 +extern "C" {
    1.80 +#endif
    1.81 +
    1.82 +#ifndef ASN1_MAC_ERR_LIB
    1.83 +#define ASN1_MAC_ERR_LIB	ERR_LIB_ASN1
    1.84 +#endif 
    1.85 +
    1.86 +#define ASN1_MAC_H_err(f,r,line) \
    1.87 +	ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
    1.88 +
    1.89 +#define M_ASN1_D2I_vars(a,type,func) \
    1.90 +	ASN1_const_CTX c; \
    1.91 +	type ret=NULL; \
    1.92 +	\
    1.93 +	c.pp=(const unsigned char **)pp; \
    1.94 +	c.q= *(const unsigned char **)pp; \
    1.95 +	c.error=ERR_R_NESTED_ASN1_ERROR; \
    1.96 +	if ((a == NULL) || ((*a) == NULL)) \
    1.97 +		{ if ((ret=(type)func()) == NULL) \
    1.98 +			{ c.line=__LINE__; goto err; } } \
    1.99 +	else	ret=(*a);
   1.100 +
   1.101 +#define M_ASN1_D2I_Init() \
   1.102 +	c.p= *(const unsigned char **)pp; \
   1.103 +	c.max=(length == 0)?0:(c.p+length);
   1.104 +
   1.105 +#define M_ASN1_D2I_Finish_2(a) \
   1.106 +	if (!asn1_const_Finish(&c)) \
   1.107 +		{ c.line=__LINE__; goto err; } \
   1.108 +	*(const unsigned char **)pp=c.p; \
   1.109 +	if (a != NULL) (*a)=ret; \
   1.110 +	return(ret);
   1.111 +
   1.112 +#define M_ASN1_D2I_Finish(a,func,e) \
   1.113 +	M_ASN1_D2I_Finish_2(a); \
   1.114 +err:\
   1.115 +	ASN1_MAC_H_err((e),c.error,c.line); \
   1.116 +	asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \
   1.117 +	if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
   1.118 +	return(NULL)
   1.119 +
   1.120 +#define M_ASN1_D2I_start_sequence() \
   1.121 +	if (!asn1_GetSequence(&c,&length)) \
   1.122 +		{ c.line=__LINE__; goto err; }
   1.123 +/* Begin reading ASN1 without a surrounding sequence */
   1.124 +#define M_ASN1_D2I_begin() \
   1.125 +	c.slen = length;
   1.126 +
   1.127 +/* End reading ASN1 with no check on length */
   1.128 +#define M_ASN1_D2I_Finish_nolen(a, func, e) \
   1.129 +	*pp=c.p; \
   1.130 +	if (a != NULL) (*a)=ret; \
   1.131 +	return(ret); \
   1.132 +err:\
   1.133 +	ASN1_MAC_H_err((e),c.error,c.line); \
   1.134 +	asn1_add_error(*pp,(int)(c.q- *pp)); \
   1.135 +	if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
   1.136 +	return(NULL)
   1.137 +
   1.138 +#define M_ASN1_D2I_end_sequence() \
   1.139 +	(((c.inf&1) == 0)?(c.slen <= 0): \
   1.140 +		(c.eos=ASN1_const_check_infinite_end(&c.p,c.slen)))
   1.141 +
   1.142 +/* Don't use this with d2i_ASN1_BOOLEAN() */
   1.143 +#define M_ASN1_D2I_get(b, func) \
   1.144 +	c.q=c.p; \
   1.145 +	if (func(&(b),&c.p,c.slen) == NULL) \
   1.146 +		{c.line=__LINE__; goto err; } \
   1.147 +	c.slen-=(c.p-c.q);
   1.148 +
   1.149 +/* Don't use this with d2i_ASN1_BOOLEAN() */
   1.150 +#define M_ASN1_D2I_get_x(type,b,func) \
   1.151 +	c.q=c.p; \
   1.152 +	if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
   1.153 +		{c.line=__LINE__; goto err; } \
   1.154 +	c.slen-=(c.p-c.q);
   1.155 +
   1.156 +/* use this instead () */
   1.157 +#define M_ASN1_D2I_get_int(b,func) \
   1.158 +	c.q=c.p; \
   1.159 +	if (func(&(b),&c.p,c.slen) < 0) \
   1.160 +		{c.line=__LINE__; goto err; } \
   1.161 +	c.slen-=(c.p-c.q);
   1.162 +
   1.163 +#define M_ASN1_D2I_get_opt(b,func,type) \
   1.164 +	if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
   1.165 +		== (V_ASN1_UNIVERSAL|(type)))) \
   1.166 +		{ \
   1.167 +		M_ASN1_D2I_get(b,func); \
   1.168 +		}
   1.169 +
   1.170 +#define M_ASN1_D2I_get_imp(b,func, type) \
   1.171 +	M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
   1.172 +	c.q=c.p; \
   1.173 +	if (func(&(b),&c.p,c.slen) == NULL) \
   1.174 +		{c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
   1.175 +	c.slen-=(c.p-c.q);\
   1.176 +	M_ASN1_next_prev=_tmp;
   1.177 +
   1.178 +#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
   1.179 +	if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
   1.180 +		(V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
   1.181 +		{ \
   1.182 +		unsigned char _tmp = M_ASN1_next; \
   1.183 +		M_ASN1_D2I_get_imp(b,func, type);\
   1.184 +		}
   1.185 +
   1.186 +#define M_ASN1_D2I_get_set(r,func,free_func) \
   1.187 +		M_ASN1_D2I_get_imp_set(r,func,free_func, \
   1.188 +			V_ASN1_SET,V_ASN1_UNIVERSAL);
   1.189 +
   1.190 +#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
   1.191 +		M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
   1.192 +			V_ASN1_SET,V_ASN1_UNIVERSAL);
   1.193 +
   1.194 +#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
   1.195 +	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
   1.196 +		V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
   1.197 +		{ M_ASN1_D2I_get_set(r,func,free_func); }
   1.198 +
   1.199 +#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
   1.200 +	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
   1.201 +		V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
   1.202 +		{ M_ASN1_D2I_get_set_type(type,r,func,free_func); }
   1.203 +
   1.204 +#define M_ASN1_I2D_len_SET_opt(a,f) \
   1.205 +	if ((a != NULL) && (sk_num(a) != 0)) \
   1.206 +		M_ASN1_I2D_len_SET(a,f);
   1.207 +
   1.208 +#define M_ASN1_I2D_put_SET_opt(a,f) \
   1.209 +	if ((a != NULL) && (sk_num(a) != 0)) \
   1.210 +		M_ASN1_I2D_put_SET(a,f);
   1.211 +
   1.212 +#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
   1.213 +	if ((a != NULL) && (sk_num(a) != 0)) \
   1.214 +		M_ASN1_I2D_put_SEQUENCE(a,f);
   1.215 +
   1.216 +#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
   1.217 +	if ((a != NULL) && (sk_##type##_num(a) != 0)) \
   1.218 +		M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
   1.219 +
   1.220 +#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
   1.221 +	if ((c.slen != 0) && \
   1.222 +		(M_ASN1_next == \
   1.223 +		(V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
   1.224 +		{ \
   1.225 +		M_ASN1_D2I_get_imp_set(b,func,free_func,\
   1.226 +			tag,V_ASN1_CONTEXT_SPECIFIC); \
   1.227 +		}
   1.228 +
   1.229 +#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
   1.230 +	if ((c.slen != 0) && \
   1.231 +		(M_ASN1_next == \
   1.232 +		(V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
   1.233 +		{ \
   1.234 +		M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
   1.235 +			tag,V_ASN1_CONTEXT_SPECIFIC); \
   1.236 +		}
   1.237 +
   1.238 +#define M_ASN1_D2I_get_seq(r,func,free_func) \
   1.239 +		M_ASN1_D2I_get_imp_set(r,func,free_func,\
   1.240 +			V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
   1.241 +
   1.242 +#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
   1.243 +		M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
   1.244 +					    V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
   1.245 +
   1.246 +#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
   1.247 +	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
   1.248 +		V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
   1.249 +		{ M_ASN1_D2I_get_seq(r,func,free_func); }
   1.250 +
   1.251 +#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
   1.252 +	if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
   1.253 +		V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
   1.254 +		{ M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
   1.255 +
   1.256 +#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
   1.257 +		M_ASN1_D2I_get_imp_set(r,func,free_func,\
   1.258 +			x,V_ASN1_CONTEXT_SPECIFIC);
   1.259 +
   1.260 +#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
   1.261 +		M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
   1.262 +			x,V_ASN1_CONTEXT_SPECIFIC);
   1.263 +
   1.264 +#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
   1.265 +	c.q=c.p; \
   1.266 +	if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
   1.267 +		(void (*)())free_func,a,b) == NULL) \
   1.268 +		{ c.line=__LINE__; goto err; } \
   1.269 +	c.slen-=(c.p-c.q);
   1.270 +
   1.271 +#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
   1.272 +	c.q=c.p; \
   1.273 +	if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
   1.274 +				   free_func,a,b) == NULL) \
   1.275 +		{ c.line=__LINE__; goto err; } \
   1.276 +	c.slen-=(c.p-c.q);
   1.277 +
   1.278 +#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
   1.279 +	c.q=c.p; \
   1.280 +	if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
   1.281 +		{ c.line=__LINE__; goto err; } \
   1.282 +	c.slen-=(c.p-c.q);
   1.283 +
   1.284 +#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
   1.285 +	if ((c.slen != 0L) && (M_ASN1_next == \
   1.286 +		(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
   1.287 +		{ \
   1.288 +		int Tinf,Ttag,Tclass; \
   1.289 +		long Tlen; \
   1.290 +		\
   1.291 +		c.q=c.p; \
   1.292 +		Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
   1.293 +		if (Tinf & 0x80) \
   1.294 +			{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
   1.295 +			c.line=__LINE__; goto err; } \
   1.296 +		if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
   1.297 +					Tlen = c.slen - (c.p - c.q) - 2; \
   1.298 +		if (func(&(r),&c.p,Tlen) == NULL) \
   1.299 +			{ c.line=__LINE__; goto err; } \
   1.300 +		if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
   1.301 +			Tlen = c.slen - (c.p - c.q); \
   1.302 +			if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \
   1.303 +				{ c.error=ERR_R_MISSING_ASN1_EOS; \
   1.304 +				c.line=__LINE__; goto err; } \
   1.305 +		}\
   1.306 +		c.slen-=(c.p-c.q); \
   1.307 +		}
   1.308 +
   1.309 +#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
   1.310 +	if ((c.slen != 0) && (M_ASN1_next == \
   1.311 +		(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
   1.312 +		{ \
   1.313 +		int Tinf,Ttag,Tclass; \
   1.314 +		long Tlen; \
   1.315 +		\
   1.316 +		c.q=c.p; \
   1.317 +		Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
   1.318 +		if (Tinf & 0x80) \
   1.319 +			{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
   1.320 +			c.line=__LINE__; goto err; } \
   1.321 +		if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
   1.322 +					Tlen = c.slen - (c.p - c.q) - 2; \
   1.323 +		if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
   1.324 +			(void (*)())free_func, \
   1.325 +			b,V_ASN1_UNIVERSAL) == NULL) \
   1.326 +			{ c.line=__LINE__; goto err; } \
   1.327 +		if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
   1.328 +			Tlen = c.slen - (c.p - c.q); \
   1.329 +			if(!ASN1_check_infinite_end(&c.p, Tlen)) \
   1.330 +				{ c.error=ERR_R_MISSING_ASN1_EOS; \
   1.331 +				c.line=__LINE__; goto err; } \
   1.332 +		}\
   1.333 +		c.slen-=(c.p-c.q); \
   1.334 +		}
   1.335 +
   1.336 +#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
   1.337 +	if ((c.slen != 0) && (M_ASN1_next == \
   1.338 +		(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
   1.339 +		{ \
   1.340 +		int Tinf,Ttag,Tclass; \
   1.341 +		long Tlen; \
   1.342 +		\
   1.343 +		c.q=c.p; \
   1.344 +		Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
   1.345 +		if (Tinf & 0x80) \
   1.346 +			{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
   1.347 +			c.line=__LINE__; goto err; } \
   1.348 +		if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
   1.349 +					Tlen = c.slen - (c.p - c.q) - 2; \
   1.350 +		if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
   1.351 +			free_func,b,V_ASN1_UNIVERSAL) == NULL) \
   1.352 +			{ c.line=__LINE__; goto err; } \
   1.353 +		if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
   1.354 +			Tlen = c.slen - (c.p - c.q); \
   1.355 +			if(!ASN1_check_infinite_end(&c.p, Tlen)) \
   1.356 +				{ c.error=ERR_R_MISSING_ASN1_EOS; \
   1.357 +				c.line=__LINE__; goto err; } \
   1.358 +		}\
   1.359 +		c.slen-=(c.p-c.q); \
   1.360 +		}
   1.361 +
   1.362 +/* New macros */
   1.363 +#define M_ASN1_New_Malloc(ret,type) \
   1.364 +	if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
   1.365 +		{ c.line=__LINE__; goto err2; }
   1.366 +
   1.367 +#define M_ASN1_New(arg,func) \
   1.368 +	if (((arg)=func()) == NULL) return(NULL)
   1.369 +
   1.370 +#define M_ASN1_New_Error(a) \
   1.371 +/*	err:	ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
   1.372 +		return(NULL);*/ \
   1.373 +	err2:	ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
   1.374 +		return(NULL)
   1.375 +
   1.376 +
   1.377 +/* BIG UGLY WARNING!  This is so damn ugly I wanna puke.  Unfortunately,
   1.378 +   some macros that use ASN1_const_CTX still insist on writing in the input
   1.379 +   stream.  ARGH!  ARGH!  ARGH!  Let's get rid of this macro package.
   1.380 +   Please?						-- Richard Levitte */
   1.381 +#define M_ASN1_next		(*((unsigned char *)(c.p)))
   1.382 +#define M_ASN1_next_prev	(*((unsigned char *)(c.q)))
   1.383 +
   1.384 +/*************************************************/
   1.385 +
   1.386 +#define M_ASN1_I2D_vars(a)	int r=0,ret=0; \
   1.387 +				unsigned char *p; \
   1.388 +				if (a == NULL) return(0)
   1.389 +
   1.390 +/* Length Macros */
   1.391 +#define M_ASN1_I2D_len(a,f)	ret+=f(a,NULL)
   1.392 +#define M_ASN1_I2D_len_IMP_opt(a,f)	if (a != NULL) M_ASN1_I2D_len(a,f)
   1.393 +
   1.394 +#define M_ASN1_I2D_len_SET(a,f) \
   1.395 +		ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
   1.396 +
   1.397 +#define M_ASN1_I2D_len_SET_type(type,a,f) \
   1.398 +		ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
   1.399 +					    V_ASN1_UNIVERSAL,IS_SET);
   1.400 +
   1.401 +#define M_ASN1_I2D_len_SEQUENCE(a,f) \
   1.402 +		ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
   1.403 +				  IS_SEQUENCE);
   1.404 +
   1.405 +#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
   1.406 +		ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
   1.407 +					    V_ASN1_UNIVERSAL,IS_SEQUENCE)
   1.408 +
   1.409 +#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
   1.410 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.411 +			M_ASN1_I2D_len_SEQUENCE(a,f);
   1.412 +
   1.413 +#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
   1.414 +		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
   1.415 +			M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
   1.416 +
   1.417 +#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
   1.418 +		ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
   1.419 +
   1.420 +#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
   1.421 +		ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
   1.422 +					    V_ASN1_CONTEXT_SPECIFIC,IS_SET);
   1.423 +
   1.424 +#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
   1.425 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.426 +			ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
   1.427 +					  IS_SET);
   1.428 +
   1.429 +#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
   1.430 +		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
   1.431 +			ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
   1.432 +					       V_ASN1_CONTEXT_SPECIFIC,IS_SET);
   1.433 +
   1.434 +#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
   1.435 +		ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
   1.436 +				  IS_SEQUENCE);
   1.437 +
   1.438 +#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
   1.439 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.440 +			ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
   1.441 +					  IS_SEQUENCE);
   1.442 +
   1.443 +#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
   1.444 +		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
   1.445 +			ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
   1.446 +						    V_ASN1_CONTEXT_SPECIFIC, \
   1.447 +						    IS_SEQUENCE);
   1.448 +
   1.449 +#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
   1.450 +		if (a != NULL)\
   1.451 +			{ \
   1.452 +			v=f(a,NULL); \
   1.453 +			ret+=ASN1_object_size(1,v,mtag); \
   1.454 +			}
   1.455 +
   1.456 +#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
   1.457 +		if ((a != NULL) && (sk_num(a) != 0))\
   1.458 +			{ \
   1.459 +			v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
   1.460 +			ret+=ASN1_object_size(1,v,mtag); \
   1.461 +			}
   1.462 +
   1.463 +#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
   1.464 +		if ((a != NULL) && (sk_num(a) != 0))\
   1.465 +			{ \
   1.466 +			v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
   1.467 +				       IS_SEQUENCE); \
   1.468 +			ret+=ASN1_object_size(1,v,mtag); \
   1.469 +			}
   1.470 +
   1.471 +#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
   1.472 +		if ((a != NULL) && (sk_##type##_num(a) != 0))\
   1.473 +			{ \
   1.474 +			v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
   1.475 +						 V_ASN1_UNIVERSAL, \
   1.476 +						 IS_SEQUENCE); \
   1.477 +			ret+=ASN1_object_size(1,v,mtag); \
   1.478 +			}
   1.479 +
   1.480 +/* Put Macros */
   1.481 +#define M_ASN1_I2D_put(a,f)	f(a,&p)
   1.482 +
   1.483 +#define M_ASN1_I2D_put_IMP_opt(a,f,t)	\
   1.484 +		if (a != NULL) \
   1.485 +			{ \
   1.486 +			unsigned char *q=p; \
   1.487 +			f(a,&p); \
   1.488 +			*q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
   1.489 +			}
   1.490 +
   1.491 +#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
   1.492 +			V_ASN1_UNIVERSAL,IS_SET)
   1.493 +#define M_ASN1_I2D_put_SET_type(type,a,f) \
   1.494 +     i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
   1.495 +#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
   1.496 +			V_ASN1_CONTEXT_SPECIFIC,IS_SET)
   1.497 +#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
   1.498 +     i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
   1.499 +#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
   1.500 +			V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
   1.501 +
   1.502 +#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
   1.503 +					     V_ASN1_UNIVERSAL,IS_SEQUENCE)
   1.504 +
   1.505 +#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
   1.506 +     i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
   1.507 +			    IS_SEQUENCE)
   1.508 +
   1.509 +#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
   1.510 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.511 +			M_ASN1_I2D_put_SEQUENCE(a,f);
   1.512 +
   1.513 +#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
   1.514 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.515 +			{ i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
   1.516 +				       IS_SET); }
   1.517 +
   1.518 +#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
   1.519 +		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
   1.520 +			{ i2d_ASN1_SET_OF_##type(a,&p,f,x, \
   1.521 +						 V_ASN1_CONTEXT_SPECIFIC, \
   1.522 +						 IS_SET); }
   1.523 +
   1.524 +#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
   1.525 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.526 +			{ i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
   1.527 +				       IS_SEQUENCE); }
   1.528 +
   1.529 +#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
   1.530 +		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
   1.531 +			{ i2d_ASN1_SET_OF_##type(a,&p,f,x, \
   1.532 +						 V_ASN1_CONTEXT_SPECIFIC, \
   1.533 +						 IS_SEQUENCE); }
   1.534 +
   1.535 +#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
   1.536 +		if (a != NULL) \
   1.537 +			{ \
   1.538 +			ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
   1.539 +			f(a,&p); \
   1.540 +			}
   1.541 +
   1.542 +#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
   1.543 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.544 +			{ \
   1.545 +			ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
   1.546 +			i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
   1.547 +			}
   1.548 +
   1.549 +#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
   1.550 +		if ((a != NULL) && (sk_num(a) != 0)) \
   1.551 +			{ \
   1.552 +			ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
   1.553 +			i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
   1.554 +			}
   1.555 +
   1.556 +#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
   1.557 +		if ((a != NULL) && (sk_##type##_num(a) != 0)) \
   1.558 +			{ \
   1.559 +			ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
   1.560 +			i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
   1.561 +					       IS_SEQUENCE); \
   1.562 +			}
   1.563 +
   1.564 +#define M_ASN1_I2D_seq_total() \
   1.565 +		r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
   1.566 +		if (pp == NULL) return(r); \
   1.567 +		p= *pp; \
   1.568 +		ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
   1.569 +
   1.570 +#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
   1.571 +		*(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
   1.572 +		*(p++)=0x80
   1.573 +
   1.574 +#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
   1.575 +
   1.576 +#define M_ASN1_I2D_finish()	*pp=p; \
   1.577 +				return(r);
   1.578 +
   1.579 +IMPORT_C int asn1_GetSequence(ASN1_const_CTX *c, long *length);
   1.580 +IMPORT_C void asn1_add_error(const unsigned char *address,int offset);
   1.581 +#ifdef  __cplusplus
   1.582 +}
   1.583 +#endif
   1.584 +
   1.585 +#endif