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 #ifndef HEADER_ASN1_MAC_H
60 #define HEADER_ASN1_MAC_H
70 #define M_ASN1_D2I_vars(a,type,func) \
75 c.error=ASN1_R_ERROR_STACK; \
76 if ((a == NULL) || ((*a) == NULL)) \
77 { if ((ret=(type)func()) == NULL) goto err; } \
80 #define M_ASN1_D2I_Init() \
82 c.max=(length == 0)?0:(c.p+length);
84 #define M_ASN1_D2I_Finish_2(a) \
85 if (!asn1_Finish(&c)) goto err; \
87 if (a != NULL) (*a)=ret; \
90 #define M_ASN1_D2I_Finish(a,func,e) \
91 M_ASN1_D2I_Finish_2(a); \
93 ASN1err((e),c.error); \
94 asn1_add_error(*pp,(int)(c.q- *pp)); \
95 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
98 #define M_ASN1_D2I_start_sequence() \
99 if (!asn1_GetSequence(&c,&length)) goto err;
101 #define M_ASN1_D2I_end_sequence() \
102 (((c.inf&1) == 0)?(c.slen <= 0): \
103 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
105 #define M_ASN1_D2I_get(b,func) \
107 if (func(&(b),&c.p,c.slen) == NULL) goto err; \
110 #define M_ASN1_D2I_get_opt(b,func,type) \
111 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
112 == (V_ASN1_UNIVERSAL|(type)))) \
114 M_ASN1_D2I_get(b,func); \
117 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
118 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
119 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
123 M_ASN1_next=(tmp& ~V_ASN1_PRIMATIVE_TAG)|type; \
124 M_ASN1_D2I_get(b,func); \
125 M_ASN1_next_prev=tmp; \
128 #define M_ASN1_D2I_get_set(r,func) \
129 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SET,V_ASN1_UNIVERSAL);
131 #define M_ASN1_D2I_get_IMP_set_opt(b,func,tag) \
132 if ((c.slen != 0) && \
134 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
136 M_ASN1_D2I_get_imp_set(b,func,tag,V_ASN1_CONTEXT_SPECIFIC); \
139 #define M_ASN1_D2I_get_seq(r,func) \
140 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
142 #define M_ASN1_D2I_get_seq_opt(r,func) \
143 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
144 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
145 { M_ASN1_D2I_get_seq(r,func); }
147 #define M_ASN1_D2I_get_IMP_set(r,func,x) \
148 M_ASN1_D2I_get_imp_set(r,func,x,V_ASN1_CONTEXT_SPECIFIC);
150 #define M_ASN1_D2I_get_imp_set(r,func,a,b) \
152 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,a,b) == NULL) \
156 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \
158 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
162 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
163 if ((c.slen != 0L) && (M_ASN1_next == \
164 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
166 int Tinf,Ttag,Tclass; \
170 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
172 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \
173 if (func(&(r),&c.p,Tlen) == NULL) \
178 #define M_ASN1_D2I_get_EXP_set_opt(r,func,tag,b) \
179 if ((c.slen != 0) && (M_ASN1_next == \
180 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
182 int Tinf,Ttag,Tclass; \
186 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
188 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \
189 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
190 b,V_ASN1_UNIVERSAL) == NULL) \
196 #define M_ASN1_New_Malloc(ret,type) \
197 if ((ret=(type *)Malloc(sizeof(type))) == NULL) goto err2;
199 #define M_ASN1_New(arg,func) \
200 if (((arg)=func()) == NULL) return(NULL)
202 #define M_ASN1_New_Error(a) \
203 /* err: ASN1err((a),ASN1_R_ERROR_STACK); \
205 err2: ASN1err((a),ERR_R_MALLOC_FAILURE); \
209 #define M_ASN1_next (*c.p)
210 #define M_ASN1_next_prev (*c.q)
212 /*************************************************/
214 #define M_ASN1_I2D_vars(a) int r=0,ret=0; \
216 if (a == NULL) return(0)
219 #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
220 #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
222 #define M_ASN1_I2D_len_SET(a,f) \
223 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL);
225 #define M_ASN1_I2D_len_SEQ(a,f) \
226 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
228 #define M_ASN1_I2D_len_SEQ_opt(a,f) \
229 if ((a != NULL) && (sk_num(a) != 0)) \
230 M_ASN1_I2D_len_SEQ(a,f);
232 #define M_ASN1_I2D_len_IMP_set(a,f,x) \
233 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC);
235 #define M_ASN1_I2D_len_IMP_set_opt(a,f,x) \
236 if ((a != NULL) && (sk_num(a) != 0)) \
237 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC);
239 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
243 ret+=ASN1_object_size(1,v,mtag); \
246 #define M_ASN1_I2D_len_EXP_set_opt(a,f,mtag,tag,v) \
247 if ((a != NULL) && (sk_num(a) != 0))\
249 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL); \
250 ret+=ASN1_object_size(1,v,mtag); \
254 #define M_ASN1_I2D_put(a,f) f(a,&p)
256 #define M_ASN1_I2D_put_IMP_opt(a,f,t) \
259 unsigned char *q=p; \
261 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
264 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
266 #define M_ASN1_I2D_put_IMP_set(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
267 V_ASN1_CONTEXT_SPECIFIC)
269 #define M_ASN1_I2D_put_SEQ(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
272 #define M_ASN1_I2D_put_SEQ_opt(a,f) \
273 if ((a != NULL) && (sk_num(a) != 0)) \
274 M_ASN1_I2D_put_SEQ(a,f);
276 #define M_ASN1_I2D_put_IMP_set_opt(a,f,x) \
277 if ((a != NULL) && (sk_num(a) != 0)) \
278 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC); }
280 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
283 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
287 #define M_ASN1_I2D_put_EXP_set_opt(a,f,mtag,tag,v) \
288 if ((a != NULL) && (sk_num(a) != 0)) \
290 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
291 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL); \
294 #define M_ASN1_I2D_seq_total() \
295 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
296 if (pp == NULL) return(r); \
298 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
300 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \
301 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
304 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
306 #define M_ASN1_I2D_finish() *pp=p; \
310 int asn1_GetSequence(ASN1_CTX *c, long *length);
311 void asn1_add_error(unsigned char *address,int offset);
313 int asn1_GetSequence();
314 void asn1_add_error();