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