LTKCPP-- LLRP Toolkit C Plus Plus Library
|
00001 /* crypto/asn1/asn1_mac.h */ 00002 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 00003 * All rights reserved. 00004 * 00005 * This package is an SSL implementation written 00006 * by Eric Young (eay@cryptsoft.com). 00007 * The implementation was written so as to conform with Netscapes SSL. 00008 * 00009 * This library is free for commercial and non-commercial use as long as 00010 * the following conditions are aheared to. The following conditions 00011 * apply to all code found in this distribution, be it the RC4, RSA, 00012 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 00013 * included with this distribution is covered by the same copyright terms 00014 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 00015 * 00016 * Copyright remains Eric Young's, and as such any Copyright notices in 00017 * the code are not to be removed. 00018 * If this package is used in a product, Eric Young should be given attribution 00019 * as the author of the parts of the library used. 00020 * This can be in the form of a textual message at program startup or 00021 * in documentation (online or textual) provided with the package. 00022 * 00023 * Redistribution and use in source and binary forms, with or without 00024 * modification, are permitted provided that the following conditions 00025 * are met: 00026 * 1. Redistributions of source code must retain the copyright 00027 * notice, this list of conditions and the following disclaimer. 00028 * 2. Redistributions in binary form must reproduce the above copyright 00029 * notice, this list of conditions and the following disclaimer in the 00030 * documentation and/or other materials provided with the distribution. 00031 * 3. All advertising materials mentioning features or use of this software 00032 * must display the following acknowledgement: 00033 * "This product includes cryptographic software written by 00034 * Eric Young (eay@cryptsoft.com)" 00035 * The word 'cryptographic' can be left out if the rouines from the library 00036 * being used are not cryptographic related :-). 00037 * 4. If you include any Windows specific code (or a derivative thereof) from 00038 * the apps directory (application code) you must include an acknowledgement: 00039 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 00040 * 00041 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 00042 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00043 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00044 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00045 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00046 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00047 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00048 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00049 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00050 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00051 * SUCH DAMAGE. 00052 * 00053 * The licence and distribution terms for any publically available version or 00054 * derivative of this code cannot be changed. i.e. this code cannot simply be 00055 * copied and put under another distribution licence 00056 * [including the GNU Public Licence.] 00057 */ 00058 00059 #ifndef HEADER_ASN1_MAC_H 00060 # define HEADER_ASN1_MAC_H 00061 00062 # include <openssl/asn1.h> 00063 00064 #ifdef __cplusplus 00065 extern "C" { 00066 #endif 00067 00068 # ifndef ASN1_MAC_ERR_LIB 00069 # define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 00070 # endif 00071 00072 # define ASN1_MAC_H_err(f,r,line) \ 00073 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line)) 00074 00075 # define M_ASN1_D2I_vars(a,type,func) \ 00076 ASN1_const_CTX c; \ 00077 type ret=NULL; \ 00078 \ 00079 c.pp=(const unsigned char **)pp; \ 00080 c.q= *(const unsigned char **)pp; \ 00081 c.error=ERR_R_NESTED_ASN1_ERROR; \ 00082 if ((a == NULL) || ((*a) == NULL)) \ 00083 { if ((ret=(type)func()) == NULL) \ 00084 { c.line=__LINE__; goto err; } } \ 00085 else ret=(*a); 00086 00087 # define M_ASN1_D2I_Init() \ 00088 c.p= *(const unsigned char **)pp; \ 00089 c.max=(length == 0)?0:(c.p+length); 00090 00091 # define M_ASN1_D2I_Finish_2(a) \ 00092 if (!asn1_const_Finish(&c)) \ 00093 { c.line=__LINE__; goto err; } \ 00094 *(const unsigned char **)pp=c.p; \ 00095 if (a != NULL) (*a)=ret; \ 00096 return(ret); 00097 00098 # define M_ASN1_D2I_Finish(a,func,e) \ 00099 M_ASN1_D2I_Finish_2(a); \ 00100 err:\ 00101 ASN1_MAC_H_err((e),c.error,c.line); \ 00102 asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \ 00103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ 00104 return(NULL) 00105 00106 # define M_ASN1_D2I_start_sequence() \ 00107 if (!asn1_GetSequence(&c,&length)) \ 00108 { c.line=__LINE__; goto err; } 00109 /* Begin reading ASN1 without a surrounding sequence */ 00110 # define M_ASN1_D2I_begin() \ 00111 c.slen = length; 00112 00113 /* End reading ASN1 with no check on length */ 00114 # define M_ASN1_D2I_Finish_nolen(a, func, e) \ 00115 *pp=c.p; \ 00116 if (a != NULL) (*a)=ret; \ 00117 return(ret); \ 00118 err:\ 00119 ASN1_MAC_H_err((e),c.error,c.line); \ 00120 asn1_add_error(*pp,(int)(c.q- *pp)); \ 00121 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ 00122 return(NULL) 00123 00124 # define M_ASN1_D2I_end_sequence() \ 00125 (((c.inf&1) == 0)?(c.slen <= 0): \ 00126 (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen))) 00127 00128 /* Don't use this with d2i_ASN1_BOOLEAN() */ 00129 # define M_ASN1_D2I_get(b, func) \ 00130 c.q=c.p; \ 00131 if (func(&(b),&c.p,c.slen) == NULL) \ 00132 {c.line=__LINE__; goto err; } \ 00133 c.slen-=(c.p-c.q); 00134 00135 /* Don't use this with d2i_ASN1_BOOLEAN() */ 00136 # define M_ASN1_D2I_get_x(type,b,func) \ 00137 c.q=c.p; \ 00138 if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \ 00139 {c.line=__LINE__; goto err; } \ 00140 c.slen-=(c.p-c.q); 00141 00142 /* use this instead () */ 00143 # define M_ASN1_D2I_get_int(b,func) \ 00144 c.q=c.p; \ 00145 if (func(&(b),&c.p,c.slen) < 0) \ 00146 {c.line=__LINE__; goto err; } \ 00147 c.slen-=(c.p-c.q); 00148 00149 # define M_ASN1_D2I_get_opt(b,func,type) \ 00150 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ 00151 == (V_ASN1_UNIVERSAL|(type)))) \ 00152 { \ 00153 M_ASN1_D2I_get(b,func); \ 00154 } 00155 00156 # define M_ASN1_D2I_get_int_opt(b,func,type) \ 00157 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ 00158 == (V_ASN1_UNIVERSAL|(type)))) \ 00159 { \ 00160 M_ASN1_D2I_get_int(b,func); \ 00161 } 00162 00163 # define M_ASN1_D2I_get_imp(b,func, type) \ 00164 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \ 00165 c.q=c.p; \ 00166 if (func(&(b),&c.p,c.slen) == NULL) \ 00167 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \ 00168 c.slen-=(c.p-c.q);\ 00169 M_ASN1_next_prev=_tmp; 00170 00171 # define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ 00172 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ 00173 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ 00174 { \ 00175 unsigned char _tmp = M_ASN1_next; \ 00176 M_ASN1_D2I_get_imp(b,func, type);\ 00177 } 00178 00179 # define M_ASN1_D2I_get_set(r,func,free_func) \ 00180 M_ASN1_D2I_get_imp_set(r,func,free_func, \ 00181 V_ASN1_SET,V_ASN1_UNIVERSAL); 00182 00183 # define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ 00184 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ 00185 V_ASN1_SET,V_ASN1_UNIVERSAL); 00186 00187 # define M_ASN1_D2I_get_set_opt(r,func,free_func) \ 00188 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ 00189 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ 00190 { M_ASN1_D2I_get_set(r,func,free_func); } 00191 00192 # define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ 00193 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ 00194 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ 00195 { M_ASN1_D2I_get_set_type(type,r,func,free_func); } 00196 00197 # define M_ASN1_I2D_len_SET_opt(a,f) \ 00198 if ((a != NULL) && (sk_num(a) != 0)) \ 00199 M_ASN1_I2D_len_SET(a,f); 00200 00201 # define M_ASN1_I2D_put_SET_opt(a,f) \ 00202 if ((a != NULL) && (sk_num(a) != 0)) \ 00203 M_ASN1_I2D_put_SET(a,f); 00204 00205 # define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ 00206 if ((a != NULL) && (sk_num(a) != 0)) \ 00207 M_ASN1_I2D_put_SEQUENCE(a,f); 00208 00209 # define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \ 00210 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 00211 M_ASN1_I2D_put_SEQUENCE_type(type,a,f); 00212 00213 # define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \ 00214 if ((c.slen != 0) && \ 00215 (M_ASN1_next == \ 00216 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ 00217 { \ 00218 M_ASN1_D2I_get_imp_set(b,func,free_func,\ 00219 tag,V_ASN1_CONTEXT_SPECIFIC); \ 00220 } 00221 00222 # define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ 00223 if ((c.slen != 0) && \ 00224 (M_ASN1_next == \ 00225 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ 00226 { \ 00227 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\ 00228 tag,V_ASN1_CONTEXT_SPECIFIC); \ 00229 } 00230 00231 # define M_ASN1_D2I_get_seq(r,func,free_func) \ 00232 M_ASN1_D2I_get_imp_set(r,func,free_func,\ 00233 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); 00234 00235 # define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ 00236 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ 00237 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) 00238 00239 # define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ 00240 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ 00241 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ 00242 { M_ASN1_D2I_get_seq(r,func,free_func); } 00243 00244 # define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ 00245 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ 00246 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ 00247 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } 00248 00249 # define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ 00250 M_ASN1_D2I_get_imp_set(r,func,free_func,\ 00251 x,V_ASN1_CONTEXT_SPECIFIC); 00252 00253 # define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ 00254 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ 00255 x,V_ASN1_CONTEXT_SPECIFIC); 00256 00257 # define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ 00258 c.q=c.p; \ 00259 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ 00260 (void (*)())free_func,a,b) == NULL) \ 00261 { c.line=__LINE__; goto err; } \ 00262 c.slen-=(c.p-c.q); 00263 00264 # define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ 00265 c.q=c.p; \ 00266 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ 00267 free_func,a,b) == NULL) \ 00268 { c.line=__LINE__; goto err; } \ 00269 c.slen-=(c.p-c.q); 00270 00271 # define M_ASN1_D2I_get_set_strings(r,func,a,b) \ 00272 c.q=c.p; \ 00273 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ 00274 { c.line=__LINE__; goto err; } \ 00275 c.slen-=(c.p-c.q); 00276 00277 # define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ 00278 if ((c.slen != 0L) && (M_ASN1_next == \ 00279 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ 00280 { \ 00281 int Tinf,Ttag,Tclass; \ 00282 long Tlen; \ 00283 \ 00284 c.q=c.p; \ 00285 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ 00286 if (Tinf & 0x80) \ 00287 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ 00288 c.line=__LINE__; goto err; } \ 00289 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ 00290 Tlen = c.slen - (c.p - c.q) - 2; \ 00291 if (func(&(r),&c.p,Tlen) == NULL) \ 00292 { c.line=__LINE__; goto err; } \ 00293 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ 00294 Tlen = c.slen - (c.p - c.q); \ 00295 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \ 00296 { c.error=ERR_R_MISSING_ASN1_EOS; \ 00297 c.line=__LINE__; goto err; } \ 00298 }\ 00299 c.slen-=(c.p-c.q); \ 00300 } 00301 00302 # define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ 00303 if ((c.slen != 0) && (M_ASN1_next == \ 00304 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ 00305 { \ 00306 int Tinf,Ttag,Tclass; \ 00307 long Tlen; \ 00308 \ 00309 c.q=c.p; \ 00310 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ 00311 if (Tinf & 0x80) \ 00312 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ 00313 c.line=__LINE__; goto err; } \ 00314 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ 00315 Tlen = c.slen - (c.p - c.q) - 2; \ 00316 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ 00317 (void (*)())free_func, \ 00318 b,V_ASN1_UNIVERSAL) == NULL) \ 00319 { c.line=__LINE__; goto err; } \ 00320 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ 00321 Tlen = c.slen - (c.p - c.q); \ 00322 if(!ASN1_check_infinite_end(&c.p, Tlen)) \ 00323 { c.error=ERR_R_MISSING_ASN1_EOS; \ 00324 c.line=__LINE__; goto err; } \ 00325 }\ 00326 c.slen-=(c.p-c.q); \ 00327 } 00328 00329 # define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ 00330 if ((c.slen != 0) && (M_ASN1_next == \ 00331 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ 00332 { \ 00333 int Tinf,Ttag,Tclass; \ 00334 long Tlen; \ 00335 \ 00336 c.q=c.p; \ 00337 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ 00338 if (Tinf & 0x80) \ 00339 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ 00340 c.line=__LINE__; goto err; } \ 00341 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ 00342 Tlen = c.slen - (c.p - c.q) - 2; \ 00343 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \ 00344 free_func,b,V_ASN1_UNIVERSAL) == NULL) \ 00345 { c.line=__LINE__; goto err; } \ 00346 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ 00347 Tlen = c.slen - (c.p - c.q); \ 00348 if(!ASN1_check_infinite_end(&c.p, Tlen)) \ 00349 { c.error=ERR_R_MISSING_ASN1_EOS; \ 00350 c.line=__LINE__; goto err; } \ 00351 }\ 00352 c.slen-=(c.p-c.q); \ 00353 } 00354 00355 /* New macros */ 00356 # define M_ASN1_New_Malloc(ret,type) \ 00357 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \ 00358 { c.line=__LINE__; goto err2; } 00359 00360 # define M_ASN1_New(arg,func) \ 00361 if (((arg)=func()) == NULL) return(NULL) 00362 00363 # define M_ASN1_New_Error(a) \ 00364 /*- err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ 00365 return(NULL);*/ \ 00366 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ 00367 return(NULL) 00368 00369 /* 00370 * BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately, some 00371 * macros that use ASN1_const_CTX still insist on writing in the input 00372 * stream. ARGH! ARGH! ARGH! Let's get rid of this macro package. Please? -- 00373 * Richard Levitte 00374 */ 00375 # define M_ASN1_next (*((unsigned char *)(c.p))) 00376 # define M_ASN1_next_prev (*((unsigned char *)(c.q))) 00377 00378 /*************************************************/ 00379 00380 # define M_ASN1_I2D_vars(a) int r=0,ret=0; \ 00381 unsigned char *p; \ 00382 if (a == NULL) return(0) 00383 00384 /* Length Macros */ 00385 # define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) 00386 # define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) 00387 00388 # define M_ASN1_I2D_len_SET(a,f) \ 00389 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); 00390 00391 # define M_ASN1_I2D_len_SET_type(type,a,f) \ 00392 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ 00393 V_ASN1_UNIVERSAL,IS_SET); 00394 00395 # define M_ASN1_I2D_len_SEQUENCE(a,f) \ 00396 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ 00397 IS_SEQUENCE); 00398 00399 # define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ 00400 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ 00401 V_ASN1_UNIVERSAL,IS_SEQUENCE) 00402 00403 # define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \ 00404 if ((a != NULL) && (sk_num(a) != 0)) \ 00405 M_ASN1_I2D_len_SEQUENCE(a,f); 00406 00407 # define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \ 00408 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 00409 M_ASN1_I2D_len_SEQUENCE_type(type,a,f); 00410 00411 # define M_ASN1_I2D_len_IMP_SET(a,f,x) \ 00412 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); 00413 00414 # define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ 00415 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ 00416 V_ASN1_CONTEXT_SPECIFIC,IS_SET); 00417 00418 # define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ 00419 if ((a != NULL) && (sk_num(a) != 0)) \ 00420 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ 00421 IS_SET); 00422 00423 # define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ 00424 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 00425 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ 00426 V_ASN1_CONTEXT_SPECIFIC,IS_SET); 00427 00428 # define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ 00429 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ 00430 IS_SEQUENCE); 00431 00432 # define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \ 00433 if ((a != NULL) && (sk_num(a) != 0)) \ 00434 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ 00435 IS_SEQUENCE); 00436 00437 # define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ 00438 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 00439 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ 00440 V_ASN1_CONTEXT_SPECIFIC, \ 00441 IS_SEQUENCE); 00442 00443 # define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ 00444 if (a != NULL)\ 00445 { \ 00446 v=f(a,NULL); \ 00447 ret+=ASN1_object_size(1,v,mtag); \ 00448 } 00449 00450 # define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \ 00451 if ((a != NULL) && (sk_num(a) != 0))\ 00452 { \ 00453 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ 00454 ret+=ASN1_object_size(1,v,mtag); \ 00455 } 00456 00457 # define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ 00458 if ((a != NULL) && (sk_num(a) != 0))\ 00459 { \ 00460 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \ 00461 IS_SEQUENCE); \ 00462 ret+=ASN1_object_size(1,v,mtag); \ 00463 } 00464 00465 # define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ 00466 if ((a != NULL) && (sk_##type##_num(a) != 0))\ 00467 { \ 00468 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \ 00469 V_ASN1_UNIVERSAL, \ 00470 IS_SEQUENCE); \ 00471 ret+=ASN1_object_size(1,v,mtag); \ 00472 } 00473 00474 /* Put Macros */ 00475 # define M_ASN1_I2D_put(a,f) f(a,&p) 00476 00477 # define M_ASN1_I2D_put_IMP_opt(a,f,t) \ 00478 if (a != NULL) \ 00479 { \ 00480 unsigned char *q=p; \ 00481 f(a,&p); \ 00482 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ 00483 } 00484 00485 # define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ 00486 V_ASN1_UNIVERSAL,IS_SET) 00487 # define M_ASN1_I2D_put_SET_type(type,a,f) \ 00488 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) 00489 # define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ 00490 V_ASN1_CONTEXT_SPECIFIC,IS_SET) 00491 # define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ 00492 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) 00493 # define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ 00494 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) 00495 00496 # define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ 00497 V_ASN1_UNIVERSAL,IS_SEQUENCE) 00498 00499 # define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ 00500 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ 00501 IS_SEQUENCE) 00502 00503 # define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ 00504 if ((a != NULL) && (sk_num(a) != 0)) \ 00505 M_ASN1_I2D_put_SEQUENCE(a,f); 00506 00507 # define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \ 00508 if ((a != NULL) && (sk_num(a) != 0)) \ 00509 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ 00510 IS_SET); } 00511 00512 # define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ 00513 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 00514 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ 00515 V_ASN1_CONTEXT_SPECIFIC, \ 00516 IS_SET); } 00517 00518 # define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ 00519 if ((a != NULL) && (sk_num(a) != 0)) \ 00520 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ 00521 IS_SEQUENCE); } 00522 00523 # define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ 00524 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 00525 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ 00526 V_ASN1_CONTEXT_SPECIFIC, \ 00527 IS_SEQUENCE); } 00528 00529 # define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ 00530 if (a != NULL) \ 00531 { \ 00532 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \ 00533 f(a,&p); \ 00534 } 00535 00536 # define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \ 00537 if ((a != NULL) && (sk_num(a) != 0)) \ 00538 { \ 00539 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ 00540 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ 00541 } 00542 00543 # define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ 00544 if ((a != NULL) && (sk_num(a) != 0)) \ 00545 { \ 00546 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ 00547 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \ 00548 } 00549 00550 # define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ 00551 if ((a != NULL) && (sk_##type##_num(a) != 0)) \ 00552 { \ 00553 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ 00554 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \ 00555 IS_SEQUENCE); \ 00556 } 00557 00558 # define M_ASN1_I2D_seq_total() \ 00559 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \ 00560 if (pp == NULL) return(r); \ 00561 p= *pp; \ 00562 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) 00563 00564 # define M_ASN1_I2D_INF_seq_start(tag,ctx) \ 00565 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \ 00566 *(p++)=0x80 00567 00568 # define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00 00569 00570 # define M_ASN1_I2D_finish() *pp=p; \ 00571 return(r); 00572 00573 int asn1_GetSequence(ASN1_const_CTX *c, long *length); 00574 void asn1_add_error(const unsigned char *address, int offset); 00575 #ifdef __cplusplus 00576 } 00577 #endif 00578 00579 #endif