3 #ifdef SHA_POLARSSL /* remainder of file */
5 #include "polarssl/bignum.h"
6 #include "polarssl/part-x509.h"
7 #include "polarssl/private-x509parse_c.h"
9 /* all calls are from src/pdkim/pdkim-rsa.c */
11 /* *************** begin copy from x509parse.c ********************/
13 * X.509 certificate and private key decoding
15 * Copyright (C) 2006-2010, Brainspark B.V.
17 * This file is part of PolarSSL (http://www.polarssl.org)
18 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
20 * All rights reserved.
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License along
33 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37 * The ITU-T X.509 standard defines a certificat format for PKI.
39 * http://www.ietf.org/rfc/rfc2459.txt
40 * http://www.ietf.org/rfc/rfc3279.txt
42 * ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-1v2.asc
44 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.680-0207.pdf
45 * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
50 * ASN.1 DER decoding routines
52 static int asn1_get_len( unsigned char **p
,
53 const unsigned char *end
,
56 if( ( end
- *p
) < 1 )
57 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
59 if( ( **p
& 0x80 ) == 0 )
66 if( ( end
- *p
) < 2 )
67 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
74 if( ( end
- *p
) < 3 )
75 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
77 *len
= ( (*p
)[1] << 8 ) | (*p
)[2];
82 return( POLARSSL_ERR_ASN1_INVALID_LENGTH
);
87 if( *len
> (int) ( end
- *p
) )
88 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
93 /* This function is not exported by PolarSSL 0.14.2
95 int asn1_get_tag( unsigned char **p
,
96 const unsigned char *end
,
99 if( ( end
- *p
) < 1 )
100 return( POLARSSL_ERR_ASN1_OUT_OF_DATA
);
103 return( POLARSSL_ERR_ASN1_UNEXPECTED_TAG
);
107 return( asn1_get_len( p
, end
, len
) );
110 /* This function is not exported by PolarSSL 0.14.2
112 int asn1_get_int( unsigned char **p
,
113 const unsigned char *end
,
118 if( ( ret
= asn1_get_tag( p
, end
, &len
, ASN1_INTEGER
) ) != 0 )
121 if( len
> (int) sizeof( int ) || ( **p
& 0x80 ) != 0 )
122 return( POLARSSL_ERR_ASN1_INVALID_LENGTH
);
128 *val
= ( *val
<< 8 ) | **p
;
135 /* This function is not exported by PolarSSL 0.14.2
137 int asn1_get_mpi( unsigned char **p
,
138 const unsigned char *end
,
143 if( ( ret
= asn1_get_tag( p
, end
, &len
, ASN1_INTEGER
) ) != 0 )
146 ret
= mpi_read_binary( X
, *p
, len
);
152 /* *************** end copy from x509parse.c ********************/