williamr@2
|
1 |
/* crypto/asn1/asn1_mac.h */
|
williamr@2
|
2 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* This package is an SSL implementation written
|
williamr@2
|
6 |
* by Eric Young (eay@cryptsoft.com).
|
williamr@2
|
7 |
* The implementation was written so as to conform with Netscapes SSL.
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* This library is free for commercial and non-commercial use as long as
|
williamr@2
|
10 |
* the following conditions are aheared to. The following conditions
|
williamr@2
|
11 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
williamr@2
|
12 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
williamr@2
|
13 |
* included with this distribution is covered by the same copyright terms
|
williamr@2
|
14 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
williamr@2
|
15 |
*
|
williamr@2
|
16 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
williamr@2
|
17 |
* the code are not to be removed.
|
williamr@2
|
18 |
* If this package is used in a product, Eric Young should be given attribution
|
williamr@2
|
19 |
* as the author of the parts of the library used.
|
williamr@2
|
20 |
* This can be in the form of a textual message at program startup or
|
williamr@2
|
21 |
* in documentation (online or textual) provided with the package.
|
williamr@2
|
22 |
*
|
williamr@2
|
23 |
* Redistribution and use in source and binary forms, with or without
|
williamr@2
|
24 |
* modification, are permitted provided that the following conditions
|
williamr@2
|
25 |
* are met:
|
williamr@2
|
26 |
* 1. Redistributions of source code must retain the copyright
|
williamr@2
|
27 |
* notice, this list of conditions and the following disclaimer.
|
williamr@2
|
28 |
* 2. Redistributions in binary form must reproduce the above copyright
|
williamr@2
|
29 |
* notice, this list of conditions and the following disclaimer in the
|
williamr@2
|
30 |
* documentation and/or other materials provided with the distribution.
|
williamr@2
|
31 |
* 3. All advertising materials mentioning features or use of this software
|
williamr@2
|
32 |
* must display the following acknowledgement:
|
williamr@2
|
33 |
* "This product includes cryptographic software written by
|
williamr@2
|
34 |
* Eric Young (eay@cryptsoft.com)"
|
williamr@2
|
35 |
* The word 'cryptographic' can be left out if the rouines from the library
|
williamr@2
|
36 |
* being used are not cryptographic related :-).
|
williamr@2
|
37 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
williamr@2
|
38 |
* the apps directory (application code) you must include an acknowledgement:
|
williamr@2
|
39 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
williamr@2
|
40 |
*
|
williamr@2
|
41 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
williamr@2
|
42 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
williamr@2
|
43 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
williamr@2
|
44 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
williamr@2
|
45 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
williamr@2
|
46 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
williamr@2
|
47 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
williamr@2
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
williamr@2
|
49 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
williamr@2
|
50 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
williamr@2
|
51 |
* SUCH DAMAGE.
|
williamr@2
|
52 |
*
|
williamr@2
|
53 |
* The licence and distribution terms for any publically available version or
|
williamr@2
|
54 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
williamr@2
|
55 |
* copied and put under another distribution licence
|
williamr@2
|
56 |
* [including the GNU Public Licence.]
|
williamr@2
|
57 |
*/
|
williamr@2
|
58 |
/*
|
williamr@2
|
59 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
williamr@2
|
60 |
*/
|
williamr@2
|
61 |
|
williamr@2
|
62 |
#ifndef HEADER_ASN1_MAC_H
|
williamr@2
|
63 |
#define HEADER_ASN1_MAC_H
|
williamr@2
|
64 |
|
williamr@2
|
65 |
#if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
|
williamr@2
|
66 |
#define SYMBIAN
|
williamr@2
|
67 |
#endif
|
williamr@2
|
68 |
|
williamr@2
|
69 |
#ifdef SYMBIAN
|
williamr@2
|
70 |
#include <e32def.h>
|
williamr@2
|
71 |
#endif
|
williamr@2
|
72 |
#include <openssl/asn1.h>
|
williamr@2
|
73 |
|
williamr@2
|
74 |
#ifdef __cplusplus
|
williamr@2
|
75 |
extern "C" {
|
williamr@2
|
76 |
#endif
|
williamr@2
|
77 |
|
williamr@2
|
78 |
#ifndef ASN1_MAC_ERR_LIB
|
williamr@2
|
79 |
#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
|
williamr@2
|
80 |
#endif
|
williamr@2
|
81 |
|
williamr@2
|
82 |
#define ASN1_MAC_H_err(f,r,line) \
|
williamr@2
|
83 |
ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
|
williamr@2
|
84 |
|
williamr@2
|
85 |
#define M_ASN1_D2I_vars(a,type,func) \
|
williamr@2
|
86 |
ASN1_const_CTX c; \
|
williamr@2
|
87 |
type ret=NULL; \
|
williamr@2
|
88 |
\
|
williamr@2
|
89 |
c.pp=(const unsigned char **)pp; \
|
williamr@2
|
90 |
c.q= *(const unsigned char **)pp; \
|
williamr@2
|
91 |
c.error=ERR_R_NESTED_ASN1_ERROR; \
|
williamr@2
|
92 |
if ((a == NULL) || ((*a) == NULL)) \
|
williamr@2
|
93 |
{ if ((ret=(type)func()) == NULL) \
|
williamr@2
|
94 |
{ c.line=__LINE__; goto err; } } \
|
williamr@2
|
95 |
else ret=(*a);
|
williamr@2
|
96 |
|
williamr@2
|
97 |
#define M_ASN1_D2I_Init() \
|
williamr@2
|
98 |
c.p= *(const unsigned char **)pp; \
|
williamr@2
|
99 |
c.max=(length == 0)?0:(c.p+length);
|
williamr@2
|
100 |
|
williamr@2
|
101 |
#define M_ASN1_D2I_Finish_2(a) \
|
williamr@2
|
102 |
if (!asn1_const_Finish(&c)) \
|
williamr@2
|
103 |
{ c.line=__LINE__; goto err; } \
|
williamr@2
|
104 |
*(const unsigned char **)pp=c.p; \
|
williamr@2
|
105 |
if (a != NULL) (*a)=ret; \
|
williamr@2
|
106 |
return(ret);
|
williamr@2
|
107 |
|
williamr@2
|
108 |
#define M_ASN1_D2I_Finish(a,func,e) \
|
williamr@2
|
109 |
M_ASN1_D2I_Finish_2(a); \
|
williamr@2
|
110 |
err:\
|
williamr@2
|
111 |
ASN1_MAC_H_err((e),c.error,c.line); \
|
williamr@2
|
112 |
asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \
|
williamr@2
|
113 |
if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
|
williamr@2
|
114 |
return(NULL)
|
williamr@2
|
115 |
|
williamr@2
|
116 |
#define M_ASN1_D2I_start_sequence() \
|
williamr@2
|
117 |
if (!asn1_GetSequence(&c,&length)) \
|
williamr@2
|
118 |
{ c.line=__LINE__; goto err; }
|
williamr@2
|
119 |
/* Begin reading ASN1 without a surrounding sequence */
|
williamr@2
|
120 |
#define M_ASN1_D2I_begin() \
|
williamr@2
|
121 |
c.slen = length;
|
williamr@2
|
122 |
|
williamr@2
|
123 |
/* End reading ASN1 with no check on length */
|
williamr@2
|
124 |
#define M_ASN1_D2I_Finish_nolen(a, func, e) \
|
williamr@2
|
125 |
*pp=c.p; \
|
williamr@2
|
126 |
if (a != NULL) (*a)=ret; \
|
williamr@2
|
127 |
return(ret); \
|
williamr@2
|
128 |
err:\
|
williamr@2
|
129 |
ASN1_MAC_H_err((e),c.error,c.line); \
|
williamr@2
|
130 |
asn1_add_error(*pp,(int)(c.q- *pp)); \
|
williamr@2
|
131 |
if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
|
williamr@2
|
132 |
return(NULL)
|
williamr@2
|
133 |
|
williamr@2
|
134 |
#define M_ASN1_D2I_end_sequence() \
|
williamr@2
|
135 |
(((c.inf&1) == 0)?(c.slen <= 0): \
|
williamr@2
|
136 |
(c.eos=ASN1_const_check_infinite_end(&c.p,c.slen)))
|
williamr@2
|
137 |
|
williamr@2
|
138 |
/* Don't use this with d2i_ASN1_BOOLEAN() */
|
williamr@2
|
139 |
#define M_ASN1_D2I_get(b, func) \
|
williamr@2
|
140 |
c.q=c.p; \
|
williamr@2
|
141 |
if (func(&(b),&c.p,c.slen) == NULL) \
|
williamr@2
|
142 |
{c.line=__LINE__; goto err; } \
|
williamr@2
|
143 |
c.slen-=(c.p-c.q);
|
williamr@2
|
144 |
|
williamr@2
|
145 |
/* Don't use this with d2i_ASN1_BOOLEAN() */
|
williamr@2
|
146 |
#define M_ASN1_D2I_get_x(type,b,func) \
|
williamr@2
|
147 |
c.q=c.p; \
|
williamr@2
|
148 |
if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
|
williamr@2
|
149 |
{c.line=__LINE__; goto err; } \
|
williamr@2
|
150 |
c.slen-=(c.p-c.q);
|
williamr@2
|
151 |
|
williamr@2
|
152 |
/* use this instead () */
|
williamr@2
|
153 |
#define M_ASN1_D2I_get_int(b,func) \
|
williamr@2
|
154 |
c.q=c.p; \
|
williamr@2
|
155 |
if (func(&(b),&c.p,c.slen) < 0) \
|
williamr@2
|
156 |
{c.line=__LINE__; goto err; } \
|
williamr@2
|
157 |
c.slen-=(c.p-c.q);
|
williamr@2
|
158 |
|
williamr@2
|
159 |
#define M_ASN1_D2I_get_opt(b,func,type) \
|
williamr@2
|
160 |
if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
|
williamr@2
|
161 |
== (V_ASN1_UNIVERSAL|(type)))) \
|
williamr@2
|
162 |
{ \
|
williamr@2
|
163 |
M_ASN1_D2I_get(b,func); \
|
williamr@2
|
164 |
}
|
williamr@2
|
165 |
|
williamr@2
|
166 |
#define M_ASN1_D2I_get_imp(b,func, type) \
|
williamr@2
|
167 |
M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
|
williamr@2
|
168 |
c.q=c.p; \
|
williamr@2
|
169 |
if (func(&(b),&c.p,c.slen) == NULL) \
|
williamr@2
|
170 |
{c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
|
williamr@2
|
171 |
c.slen-=(c.p-c.q);\
|
williamr@2
|
172 |
M_ASN1_next_prev=_tmp;
|
williamr@2
|
173 |
|
williamr@2
|
174 |
#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
|
williamr@2
|
175 |
if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
|
williamr@2
|
176 |
(V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
|
williamr@2
|
177 |
{ \
|
williamr@2
|
178 |
unsigned char _tmp = M_ASN1_next; \
|
williamr@2
|
179 |
M_ASN1_D2I_get_imp(b,func, type);\
|
williamr@2
|
180 |
}
|
williamr@2
|
181 |
|
williamr@2
|
182 |
#define M_ASN1_D2I_get_set(r,func,free_func) \
|
williamr@2
|
183 |
M_ASN1_D2I_get_imp_set(r,func,free_func, \
|
williamr@2
|
184 |
V_ASN1_SET,V_ASN1_UNIVERSAL);
|
williamr@2
|
185 |
|
williamr@2
|
186 |
#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
|
williamr@2
|
187 |
M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
|
williamr@2
|
188 |
V_ASN1_SET,V_ASN1_UNIVERSAL);
|
williamr@2
|
189 |
|
williamr@2
|
190 |
#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
|
williamr@2
|
191 |
if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
|
williamr@2
|
192 |
V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
|
williamr@2
|
193 |
{ M_ASN1_D2I_get_set(r,func,free_func); }
|
williamr@2
|
194 |
|
williamr@2
|
195 |
#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
|
williamr@2
|
196 |
if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
|
williamr@2
|
197 |
V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
|
williamr@2
|
198 |
{ M_ASN1_D2I_get_set_type(type,r,func,free_func); }
|
williamr@2
|
199 |
|
williamr@2
|
200 |
#define M_ASN1_I2D_len_SET_opt(a,f) \
|
williamr@2
|
201 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
202 |
M_ASN1_I2D_len_SET(a,f);
|
williamr@2
|
203 |
|
williamr@2
|
204 |
#define M_ASN1_I2D_put_SET_opt(a,f) \
|
williamr@2
|
205 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
206 |
M_ASN1_I2D_put_SET(a,f);
|
williamr@2
|
207 |
|
williamr@2
|
208 |
#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
|
williamr@2
|
209 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
210 |
M_ASN1_I2D_put_SEQUENCE(a,f);
|
williamr@2
|
211 |
|
williamr@2
|
212 |
#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
|
williamr@2
|
213 |
if ((a != NULL) && (sk_##type##_num(a) != 0)) \
|
williamr@2
|
214 |
M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
|
williamr@2
|
215 |
|
williamr@2
|
216 |
#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
|
williamr@2
|
217 |
if ((c.slen != 0) && \
|
williamr@2
|
218 |
(M_ASN1_next == \
|
williamr@2
|
219 |
(V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
|
williamr@2
|
220 |
{ \
|
williamr@2
|
221 |
M_ASN1_D2I_get_imp_set(b,func,free_func,\
|
williamr@2
|
222 |
tag,V_ASN1_CONTEXT_SPECIFIC); \
|
williamr@2
|
223 |
}
|
williamr@2
|
224 |
|
williamr@2
|
225 |
#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
|
williamr@2
|
226 |
if ((c.slen != 0) && \
|
williamr@2
|
227 |
(M_ASN1_next == \
|
williamr@2
|
228 |
(V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
|
williamr@2
|
229 |
{ \
|
williamr@2
|
230 |
M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
|
williamr@2
|
231 |
tag,V_ASN1_CONTEXT_SPECIFIC); \
|
williamr@2
|
232 |
}
|
williamr@2
|
233 |
|
williamr@2
|
234 |
#define M_ASN1_D2I_get_seq(r,func,free_func) \
|
williamr@2
|
235 |
M_ASN1_D2I_get_imp_set(r,func,free_func,\
|
williamr@2
|
236 |
V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
|
williamr@2
|
237 |
|
williamr@2
|
238 |
#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
|
williamr@2
|
239 |
M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
|
williamr@2
|
240 |
V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
|
williamr@2
|
241 |
|
williamr@2
|
242 |
#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
|
williamr@2
|
243 |
if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
|
williamr@2
|
244 |
V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
|
williamr@2
|
245 |
{ M_ASN1_D2I_get_seq(r,func,free_func); }
|
williamr@2
|
246 |
|
williamr@2
|
247 |
#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
|
williamr@2
|
248 |
if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
|
williamr@2
|
249 |
V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
|
williamr@2
|
250 |
{ M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
|
williamr@2
|
251 |
|
williamr@2
|
252 |
#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
|
williamr@2
|
253 |
M_ASN1_D2I_get_imp_set(r,func,free_func,\
|
williamr@2
|
254 |
x,V_ASN1_CONTEXT_SPECIFIC);
|
williamr@2
|
255 |
|
williamr@2
|
256 |
#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
|
williamr@2
|
257 |
M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
|
williamr@2
|
258 |
x,V_ASN1_CONTEXT_SPECIFIC);
|
williamr@2
|
259 |
|
williamr@2
|
260 |
#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
|
williamr@2
|
261 |
c.q=c.p; \
|
williamr@2
|
262 |
if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
|
williamr@2
|
263 |
(void (*)())free_func,a,b) == NULL) \
|
williamr@2
|
264 |
{ c.line=__LINE__; goto err; } \
|
williamr@2
|
265 |
c.slen-=(c.p-c.q);
|
williamr@2
|
266 |
|
williamr@2
|
267 |
#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
|
williamr@2
|
268 |
c.q=c.p; \
|
williamr@2
|
269 |
if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
|
williamr@2
|
270 |
free_func,a,b) == NULL) \
|
williamr@2
|
271 |
{ c.line=__LINE__; goto err; } \
|
williamr@2
|
272 |
c.slen-=(c.p-c.q);
|
williamr@2
|
273 |
|
williamr@2
|
274 |
#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
|
williamr@2
|
275 |
c.q=c.p; \
|
williamr@2
|
276 |
if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
|
williamr@2
|
277 |
{ c.line=__LINE__; goto err; } \
|
williamr@2
|
278 |
c.slen-=(c.p-c.q);
|
williamr@2
|
279 |
|
williamr@2
|
280 |
#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
|
williamr@2
|
281 |
if ((c.slen != 0L) && (M_ASN1_next == \
|
williamr@2
|
282 |
(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
|
williamr@2
|
283 |
{ \
|
williamr@2
|
284 |
int Tinf,Ttag,Tclass; \
|
williamr@2
|
285 |
long Tlen; \
|
williamr@2
|
286 |
\
|
williamr@2
|
287 |
c.q=c.p; \
|
williamr@2
|
288 |
Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
|
williamr@2
|
289 |
if (Tinf & 0x80) \
|
williamr@2
|
290 |
{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
|
williamr@2
|
291 |
c.line=__LINE__; goto err; } \
|
williamr@2
|
292 |
if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
|
williamr@2
|
293 |
Tlen = c.slen - (c.p - c.q) - 2; \
|
williamr@2
|
294 |
if (func(&(r),&c.p,Tlen) == NULL) \
|
williamr@2
|
295 |
{ c.line=__LINE__; goto err; } \
|
williamr@2
|
296 |
if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
|
williamr@2
|
297 |
Tlen = c.slen - (c.p - c.q); \
|
williamr@2
|
298 |
if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \
|
williamr@2
|
299 |
{ c.error=ERR_R_MISSING_ASN1_EOS; \
|
williamr@2
|
300 |
c.line=__LINE__; goto err; } \
|
williamr@2
|
301 |
}\
|
williamr@2
|
302 |
c.slen-=(c.p-c.q); \
|
williamr@2
|
303 |
}
|
williamr@2
|
304 |
|
williamr@2
|
305 |
#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
|
williamr@2
|
306 |
if ((c.slen != 0) && (M_ASN1_next == \
|
williamr@2
|
307 |
(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
|
williamr@2
|
308 |
{ \
|
williamr@2
|
309 |
int Tinf,Ttag,Tclass; \
|
williamr@2
|
310 |
long Tlen; \
|
williamr@2
|
311 |
\
|
williamr@2
|
312 |
c.q=c.p; \
|
williamr@2
|
313 |
Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
|
williamr@2
|
314 |
if (Tinf & 0x80) \
|
williamr@2
|
315 |
{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
|
williamr@2
|
316 |
c.line=__LINE__; goto err; } \
|
williamr@2
|
317 |
if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
|
williamr@2
|
318 |
Tlen = c.slen - (c.p - c.q) - 2; \
|
williamr@2
|
319 |
if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
|
williamr@2
|
320 |
(void (*)())free_func, \
|
williamr@2
|
321 |
b,V_ASN1_UNIVERSAL) == NULL) \
|
williamr@2
|
322 |
{ c.line=__LINE__; goto err; } \
|
williamr@2
|
323 |
if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
|
williamr@2
|
324 |
Tlen = c.slen - (c.p - c.q); \
|
williamr@2
|
325 |
if(!ASN1_check_infinite_end(&c.p, Tlen)) \
|
williamr@2
|
326 |
{ c.error=ERR_R_MISSING_ASN1_EOS; \
|
williamr@2
|
327 |
c.line=__LINE__; goto err; } \
|
williamr@2
|
328 |
}\
|
williamr@2
|
329 |
c.slen-=(c.p-c.q); \
|
williamr@2
|
330 |
}
|
williamr@2
|
331 |
|
williamr@2
|
332 |
#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
|
williamr@2
|
333 |
if ((c.slen != 0) && (M_ASN1_next == \
|
williamr@2
|
334 |
(V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
|
williamr@2
|
335 |
{ \
|
williamr@2
|
336 |
int Tinf,Ttag,Tclass; \
|
williamr@2
|
337 |
long Tlen; \
|
williamr@2
|
338 |
\
|
williamr@2
|
339 |
c.q=c.p; \
|
williamr@2
|
340 |
Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
|
williamr@2
|
341 |
if (Tinf & 0x80) \
|
williamr@2
|
342 |
{ c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
|
williamr@2
|
343 |
c.line=__LINE__; goto err; } \
|
williamr@2
|
344 |
if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
|
williamr@2
|
345 |
Tlen = c.slen - (c.p - c.q) - 2; \
|
williamr@2
|
346 |
if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
|
williamr@2
|
347 |
free_func,b,V_ASN1_UNIVERSAL) == NULL) \
|
williamr@2
|
348 |
{ c.line=__LINE__; goto err; } \
|
williamr@2
|
349 |
if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
|
williamr@2
|
350 |
Tlen = c.slen - (c.p - c.q); \
|
williamr@2
|
351 |
if(!ASN1_check_infinite_end(&c.p, Tlen)) \
|
williamr@2
|
352 |
{ c.error=ERR_R_MISSING_ASN1_EOS; \
|
williamr@2
|
353 |
c.line=__LINE__; goto err; } \
|
williamr@2
|
354 |
}\
|
williamr@2
|
355 |
c.slen-=(c.p-c.q); \
|
williamr@2
|
356 |
}
|
williamr@2
|
357 |
|
williamr@2
|
358 |
/* New macros */
|
williamr@2
|
359 |
#define M_ASN1_New_Malloc(ret,type) \
|
williamr@2
|
360 |
if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \
|
williamr@2
|
361 |
{ c.line=__LINE__; goto err2; }
|
williamr@2
|
362 |
|
williamr@2
|
363 |
#define M_ASN1_New(arg,func) \
|
williamr@2
|
364 |
if (((arg)=func()) == NULL) return(NULL)
|
williamr@2
|
365 |
|
williamr@2
|
366 |
#define M_ASN1_New_Error(a) \
|
williamr@2
|
367 |
/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
|
williamr@2
|
368 |
return(NULL);*/ \
|
williamr@2
|
369 |
err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
|
williamr@2
|
370 |
return(NULL)
|
williamr@2
|
371 |
|
williamr@2
|
372 |
|
williamr@2
|
373 |
/* BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately,
|
williamr@2
|
374 |
some macros that use ASN1_const_CTX still insist on writing in the input
|
williamr@2
|
375 |
stream. ARGH! ARGH! ARGH! Let's get rid of this macro package.
|
williamr@2
|
376 |
Please? -- Richard Levitte */
|
williamr@2
|
377 |
#define M_ASN1_next (*((unsigned char *)(c.p)))
|
williamr@2
|
378 |
#define M_ASN1_next_prev (*((unsigned char *)(c.q)))
|
williamr@2
|
379 |
|
williamr@2
|
380 |
/*************************************************/
|
williamr@2
|
381 |
|
williamr@2
|
382 |
#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
|
williamr@2
|
383 |
unsigned char *p; \
|
williamr@2
|
384 |
if (a == NULL) return(0)
|
williamr@2
|
385 |
|
williamr@2
|
386 |
/* Length Macros */
|
williamr@2
|
387 |
#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
|
williamr@2
|
388 |
#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
|
williamr@2
|
389 |
|
williamr@2
|
390 |
#define M_ASN1_I2D_len_SET(a,f) \
|
williamr@2
|
391 |
ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
|
williamr@2
|
392 |
|
williamr@2
|
393 |
#define M_ASN1_I2D_len_SET_type(type,a,f) \
|
williamr@2
|
394 |
ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
|
williamr@2
|
395 |
V_ASN1_UNIVERSAL,IS_SET);
|
williamr@2
|
396 |
|
williamr@2
|
397 |
#define M_ASN1_I2D_len_SEQUENCE(a,f) \
|
williamr@2
|
398 |
ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
|
williamr@2
|
399 |
IS_SEQUENCE);
|
williamr@2
|
400 |
|
williamr@2
|
401 |
#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
|
williamr@2
|
402 |
ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
|
williamr@2
|
403 |
V_ASN1_UNIVERSAL,IS_SEQUENCE)
|
williamr@2
|
404 |
|
williamr@2
|
405 |
#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
|
williamr@2
|
406 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
407 |
M_ASN1_I2D_len_SEQUENCE(a,f);
|
williamr@2
|
408 |
|
williamr@2
|
409 |
#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
|
williamr@2
|
410 |
if ((a != NULL) && (sk_##type##_num(a) != 0)) \
|
williamr@2
|
411 |
M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
|
williamr@2
|
412 |
|
williamr@2
|
413 |
#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
|
williamr@2
|
414 |
ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
|
williamr@2
|
415 |
|
williamr@2
|
416 |
#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
|
williamr@2
|
417 |
ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
|
williamr@2
|
418 |
V_ASN1_CONTEXT_SPECIFIC,IS_SET);
|
williamr@2
|
419 |
|
williamr@2
|
420 |
#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
|
williamr@2
|
421 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
422 |
ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
423 |
IS_SET);
|
williamr@2
|
424 |
|
williamr@2
|
425 |
#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
|
williamr@2
|
426 |
if ((a != NULL) && (sk_##type##_num(a) != 0)) \
|
williamr@2
|
427 |
ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
|
williamr@2
|
428 |
V_ASN1_CONTEXT_SPECIFIC,IS_SET);
|
williamr@2
|
429 |
|
williamr@2
|
430 |
#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
|
williamr@2
|
431 |
ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
432 |
IS_SEQUENCE);
|
williamr@2
|
433 |
|
williamr@2
|
434 |
#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
|
williamr@2
|
435 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
436 |
ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
437 |
IS_SEQUENCE);
|
williamr@2
|
438 |
|
williamr@2
|
439 |
#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
|
williamr@2
|
440 |
if ((a != NULL) && (sk_##type##_num(a) != 0)) \
|
williamr@2
|
441 |
ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
|
williamr@2
|
442 |
V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
443 |
IS_SEQUENCE);
|
williamr@2
|
444 |
|
williamr@2
|
445 |
#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
|
williamr@2
|
446 |
if (a != NULL)\
|
williamr@2
|
447 |
{ \
|
williamr@2
|
448 |
v=f(a,NULL); \
|
williamr@2
|
449 |
ret+=ASN1_object_size(1,v,mtag); \
|
williamr@2
|
450 |
}
|
williamr@2
|
451 |
|
williamr@2
|
452 |
#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
|
williamr@2
|
453 |
if ((a != NULL) && (sk_num(a) != 0))\
|
williamr@2
|
454 |
{ \
|
williamr@2
|
455 |
v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
|
williamr@2
|
456 |
ret+=ASN1_object_size(1,v,mtag); \
|
williamr@2
|
457 |
}
|
williamr@2
|
458 |
|
williamr@2
|
459 |
#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
|
williamr@2
|
460 |
if ((a != NULL) && (sk_num(a) != 0))\
|
williamr@2
|
461 |
{ \
|
williamr@2
|
462 |
v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
|
williamr@2
|
463 |
IS_SEQUENCE); \
|
williamr@2
|
464 |
ret+=ASN1_object_size(1,v,mtag); \
|
williamr@2
|
465 |
}
|
williamr@2
|
466 |
|
williamr@2
|
467 |
#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
|
williamr@2
|
468 |
if ((a != NULL) && (sk_##type##_num(a) != 0))\
|
williamr@2
|
469 |
{ \
|
williamr@2
|
470 |
v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
|
williamr@2
|
471 |
V_ASN1_UNIVERSAL, \
|
williamr@2
|
472 |
IS_SEQUENCE); \
|
williamr@2
|
473 |
ret+=ASN1_object_size(1,v,mtag); \
|
williamr@2
|
474 |
}
|
williamr@2
|
475 |
|
williamr@2
|
476 |
/* Put Macros */
|
williamr@2
|
477 |
#define M_ASN1_I2D_put(a,f) f(a,&p)
|
williamr@2
|
478 |
|
williamr@2
|
479 |
#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
|
williamr@2
|
480 |
if (a != NULL) \
|
williamr@2
|
481 |
{ \
|
williamr@2
|
482 |
unsigned char *q=p; \
|
williamr@2
|
483 |
f(a,&p); \
|
williamr@2
|
484 |
*q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
|
williamr@2
|
485 |
}
|
williamr@2
|
486 |
|
williamr@2
|
487 |
#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
|
williamr@2
|
488 |
V_ASN1_UNIVERSAL,IS_SET)
|
williamr@2
|
489 |
#define M_ASN1_I2D_put_SET_type(type,a,f) \
|
williamr@2
|
490 |
i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
|
williamr@2
|
491 |
#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
|
williamr@2
|
492 |
V_ASN1_CONTEXT_SPECIFIC,IS_SET)
|
williamr@2
|
493 |
#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
|
williamr@2
|
494 |
i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
|
williamr@2
|
495 |
#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
|
williamr@2
|
496 |
V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
|
williamr@2
|
497 |
|
williamr@2
|
498 |
#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
|
williamr@2
|
499 |
V_ASN1_UNIVERSAL,IS_SEQUENCE)
|
williamr@2
|
500 |
|
williamr@2
|
501 |
#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
|
williamr@2
|
502 |
i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
|
williamr@2
|
503 |
IS_SEQUENCE)
|
williamr@2
|
504 |
|
williamr@2
|
505 |
#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
|
williamr@2
|
506 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
507 |
M_ASN1_I2D_put_SEQUENCE(a,f);
|
williamr@2
|
508 |
|
williamr@2
|
509 |
#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
|
williamr@2
|
510 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
511 |
{ i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
512 |
IS_SET); }
|
williamr@2
|
513 |
|
williamr@2
|
514 |
#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
|
williamr@2
|
515 |
if ((a != NULL) && (sk_##type##_num(a) != 0)) \
|
williamr@2
|
516 |
{ i2d_ASN1_SET_OF_##type(a,&p,f,x, \
|
williamr@2
|
517 |
V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
518 |
IS_SET); }
|
williamr@2
|
519 |
|
williamr@2
|
520 |
#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
|
williamr@2
|
521 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
522 |
{ i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
523 |
IS_SEQUENCE); }
|
williamr@2
|
524 |
|
williamr@2
|
525 |
#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
|
williamr@2
|
526 |
if ((a != NULL) && (sk_##type##_num(a) != 0)) \
|
williamr@2
|
527 |
{ i2d_ASN1_SET_OF_##type(a,&p,f,x, \
|
williamr@2
|
528 |
V_ASN1_CONTEXT_SPECIFIC, \
|
williamr@2
|
529 |
IS_SEQUENCE); }
|
williamr@2
|
530 |
|
williamr@2
|
531 |
#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
|
williamr@2
|
532 |
if (a != NULL) \
|
williamr@2
|
533 |
{ \
|
williamr@2
|
534 |
ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
|
williamr@2
|
535 |
f(a,&p); \
|
williamr@2
|
536 |
}
|
williamr@2
|
537 |
|
williamr@2
|
538 |
#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
|
williamr@2
|
539 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
540 |
{ \
|
williamr@2
|
541 |
ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
|
williamr@2
|
542 |
i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
|
williamr@2
|
543 |
}
|
williamr@2
|
544 |
|
williamr@2
|
545 |
#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
|
williamr@2
|
546 |
if ((a != NULL) && (sk_num(a) != 0)) \
|
williamr@2
|
547 |
{ \
|
williamr@2
|
548 |
ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
|
williamr@2
|
549 |
i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
|
williamr@2
|
550 |
}
|
williamr@2
|
551 |
|
williamr@2
|
552 |
#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
|
williamr@2
|
553 |
if ((a != NULL) && (sk_##type##_num(a) != 0)) \
|
williamr@2
|
554 |
{ \
|
williamr@2
|
555 |
ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
|
williamr@2
|
556 |
i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
|
williamr@2
|
557 |
IS_SEQUENCE); \
|
williamr@2
|
558 |
}
|
williamr@2
|
559 |
|
williamr@2
|
560 |
#define M_ASN1_I2D_seq_total() \
|
williamr@2
|
561 |
r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
|
williamr@2
|
562 |
if (pp == NULL) return(r); \
|
williamr@2
|
563 |
p= *pp; \
|
williamr@2
|
564 |
ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
|
williamr@2
|
565 |
|
williamr@2
|
566 |
#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
|
williamr@2
|
567 |
*(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
|
williamr@2
|
568 |
*(p++)=0x80
|
williamr@2
|
569 |
|
williamr@2
|
570 |
#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
|
williamr@2
|
571 |
|
williamr@2
|
572 |
#define M_ASN1_I2D_finish() *pp=p; \
|
williamr@2
|
573 |
return(r);
|
williamr@2
|
574 |
|
williamr@2
|
575 |
IMPORT_C int asn1_GetSequence(ASN1_const_CTX *c, long *length);
|
williamr@2
|
576 |
IMPORT_C void asn1_add_error(const unsigned char *address,int offset);
|
williamr@2
|
577 |
#ifdef __cplusplus
|
williamr@2
|
578 |
}
|
williamr@2
|
579 |
#endif
|
williamr@2
|
580 |
|
williamr@2
|
581 |
#endif
|