1 /* crypto/asn1/asn1_mac.h */
2 /* Copyright (C) 1995-1997 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 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
97 #define M_ASN1_D2I_start_sequence() \
98 if (!asn1_GetSequence(&c,&length)) goto err;
100 #define M_ASN1_D2I_end_sequence() \
101 (((c.inf&1) == 0)?(c.slen <= 0): \
102 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
104 #define M_ASN1_D2I_get(b,func) \
106 if (func(&(b),&c.p,c.slen) == NULL) goto err; \
109 #define M_ASN1_D2I_get_opt(b,func,type) \
110 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
111 == (V_ASN1_UNIVERSAL|(type)))) \
113 M_ASN1_D2I_get(b,func); \
116 #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
117 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
118 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
122 M_ASN1_next=(tmp& ~V_ASN1_PRIMATIVE_TAG)|type; \
123 M_ASN1_D2I_get(b,func); \
124 M_ASN1_next_prev=tmp; \
127 #define M_ASN1_D2I_get_set(r,func) \
128 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SET,V_ASN1_UNIVERSAL);
130 #define M_ASN1_D2I_get_IMP_set_opt(b,func,tag) \
131 if ((c.slen != 0) && \
133 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
135 M_ASN1_D2I_get_imp_set(b,func,tag,V_ASN1_CONTEXT_SPECIFIC); \
138 #define M_ASN1_D2I_get_seq(r,func) \
139 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
141 #define M_ASN1_D2I_get_seq_opt(r,func) \
142 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
143 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
144 { M_ASN1_D2I_get_seq(r,func); }
146 #define M_ASN1_D2I_get_IMP_set(r,func,x) \
147 M_ASN1_D2I_get_imp_set(r,func,x,V_ASN1_CONTEXT_SPECIFIC);
149 #define M_ASN1_D2I_get_imp_set(r,func,a,b) \
151 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,a,b) == NULL) \
155 #define M_ASN1_D2I_get_set_strings(r,func,a,b) \
157 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
161 #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
162 if ((c.slen != 0L) && (M_ASN1_next == \
163 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
165 int Tinf,Ttag,Tclass; \
169 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
171 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \
172 if (func(&(r),&c.p,Tlen) == NULL) \
177 #define M_ASN1_D2I_get_EXP_set_opt(r,func,tag,b) \
178 if ((c.slen != 0) && (M_ASN1_next == \
179 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
181 int Tinf,Ttag,Tclass; \
185 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
187 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \
188 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
189 b,V_ASN1_UNIVERSAL) == NULL) \
195 #define M_ASN1_New_Malloc(ret,type) \
196 if ((ret=(type *)Malloc(sizeof(type))) == NULL) goto err2;
198 #define M_ASN1_New(arg,func) \
199 if (((arg)=func()) == NULL) return(NULL)
201 #define M_ASN1_New_Error(a) \
202 /* err: ASN1err((a),ASN1_R_ERROR_STACK); \
204 err2: ASN1err((a),ERR_R_MALLOC_FAILURE); \
208 #define M_ASN1_next (*c.p)
209 #define M_ASN1_next_prev (*c.q)
211 /*************************************************/
213 #define M_ASN1_I2D_vars(a) int r=0,ret=0; \
215 if (a == NULL) return(0)
218 #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
219 #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
221 #define M_ASN1_I2D_len_SET(a,f) \
222 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL);
224 #define M_ASN1_I2D_len_SEQ(a,f) \
225 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
227 #define M_ASN1_I2D_len_SEQ_opt(a,f) \
228 if ((a != NULL) && (sk_num(a) != 0)) \
229 M_ASN1_I2D_len_SEQ(a,f);
231 #define M_ASN1_I2D_len_IMP_set(a,f,x) \
232 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC);
234 #define M_ASN1_I2D_len_IMP_set_opt(a,f,x) \
235 if ((a != NULL) && (sk_num(a) != 0)) \
236 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC);
238 #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
242 ret+=ASN1_object_size(1,v,mtag); \
245 #define M_ASN1_I2D_len_EXP_set_opt(a,f,mtag,tag,v) \
246 if ((a != NULL) && (sk_num(a) != 0))\
248 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL); \
249 ret+=ASN1_object_size(1,v,mtag); \
253 #define M_ASN1_I2D_put(a,f) f(a,&p)
255 #define M_ASN1_I2D_put_IMP_opt(a,f,t) \
258 unsigned char *q=p; \
260 *q=(V_ASN1_CONTEXT_SPECIFIC|t); \
263 #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
265 #define M_ASN1_I2D_put_IMP_set(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
266 V_ASN1_CONTEXT_SPECIFIC)
268 #define M_ASN1_I2D_put_SEQ(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
271 #define M_ASN1_I2D_put_SEQ_opt(a,f) \
272 if ((a != NULL) && (sk_num(a) != 0)) \
273 M_ASN1_I2D_put_SEQ(a,f);
275 #define M_ASN1_I2D_put_IMP_set_opt(a,f,x) \
276 if ((a != NULL) && (sk_num(a) != 0)) \
277 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC); }
279 #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
282 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
286 #define M_ASN1_I2D_put_EXP_set_opt(a,f,mtag,tag,v) \
287 if ((a != NULL) && (sk_num(a) != 0)) \
289 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
290 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL); \
293 #define M_ASN1_I2D_seq_total() \
294 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
295 if (pp == NULL) return(r); \
297 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
299 #define M_ASN1_I2D_INF_seq_start(tag,ctx) \
300 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
303 #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
305 #define M_ASN1_I2D_finish() *pp=p; \
309 int asn1_GetSequence(ASN1_CTX *c, long *length);
311 int asn1_GetSequence();