1 #include "polarssl/bignum.h"
2 #include "polarssl/part-x509.h"
3 #include "polarssl/private-x509parse_c.h"
5 #ifndef POLARSSL_PRIVATE_X509_PARSE_C_H
6 #define POLARSSL_PRIVATE_X509_PARSE_C_H
7 /* *************** begin copy from x509parse.c ********************/
9 * X.509 certificate and private key decoding
11 * Copyright (C) 2006-2010, Brainspark B.V.
13 * This file is part of PolarSSL (http://www.polarssl.org)
14 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
16 * All rights reserved.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 * The ITU-T X.509 standard defines a certificat format for PKI.
35 * http://www.ietf.org/rfc/rfc2459.txt
36 * http://www.ietf.org/rfc/rfc3279.txt
38 * ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-1v2.asc
40 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
41 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
46 * ASN.1 DER decoding routines
48 static int asn1_get_len( unsigned char **p
,
49 const unsigned char *end
,
52 if( ( end
- *p
) < 1 )
53 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
55 if( ( **p
& 0x80 ) == 0 )
62 if( ( end
- *p
) < 2 )
63 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
70 if( ( end
- *p
) < 3 )
71 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
73 *len
= ( (*p
)[1] << 8 ) | (*p
)[2];
78 return( POLARSSL_ERR_ASN1_INVALID_LENGTH
);
83 if( *len
> (int) ( end
- *p
) )
84 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
89 /* This function is not exported by PolarSSL 0.14.2
91 int asn1_get_tag( unsigned char **p
,
92 const unsigned char *end
,
95 if( ( end
- *p
) < 1 )
96 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
99 return( POLARSSL_ERR_ASN1_UNEXPECTED_TAG
);
103 return( asn1_get_len( p
, end
, len
) );
106 /* This function is not exported by PolarSSL 0.14.2
108 int asn1_get_int( unsigned char **p
,
109 const unsigned char *end
,
114 if( ( ret
= asn1_get_tag( p
, end
, &len
, ASN1_INTEGER
) ) != 0 )
117 if( len
> (int) sizeof( int ) || ( **p
& 0x80 ) != 0 )
118 return( POLARSSL_ERR_ASN1_INVALID_LENGTH
);
124 *val
= ( *val
<< 8 ) | **p
;
131 /* This function is not exported by PolarSSL 0.14.2
133 int asn1_get_mpi( unsigned char **p
,
134 const unsigned char *end
,
139 if( ( ret
= asn1_get_tag( p
, end
, &len
, ASN1_INTEGER
) ) != 0 )
142 ret
= mpi_read_binary( X
, *p
, len
);
148 /* *************** end copy from x509parse.c ********************/
149 #endif /* private-x509parse_c.h */