Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file compat-1.2.h |
| 3 | * |
| 4 | * \brief Backwards compatibility header for PolarSSL-1.2 from PolarSSL-1.3 |
| 5 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 7 | * |
Manuel Pégourié-Gonnard | 860b516 | 2015-01-28 17:12:07 +0000 | [diff] [blame^] | 8 | * This file is part of mbed TLS (https://polarssl.org) |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 9 | * |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 | */ |
| 24 | #ifndef POLARSSL_COMPAT_1_2_H |
| 25 | #define POLARSSL_COMPAT_1_2_H |
| 26 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 28 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #else |
| 30 | #include POLARSSL_CONFIG_FILE |
| 31 | #endif |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 32 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 33 | // Comment out to disable prototype change warnings |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 34 | #define SHOW_PROTOTYPE_CHANGE_WARNINGS |
| 35 | |
Paul Bakker | fa6a620 | 2013-10-28 18:48:30 +0100 | [diff] [blame] | 36 | #if defined(_MSC_VER) && !defined(inline) |
| 37 | #define inline _inline |
| 38 | #else |
| 39 | #if defined(__ARMCC_VERSION) && !defined(inline) |
| 40 | #define inline __inline |
| 41 | #endif /* __ARMCC_VERSION */ |
Paul Bakker | d46a9f1 | 2013-10-31 14:34:19 +0100 | [diff] [blame] | 42 | #endif /* _MSC_VER */ |
Paul Bakker | fa6a620 | 2013-10-28 18:48:30 +0100 | [diff] [blame] | 43 | |
| 44 | #if defined(_MSC_VER) |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 45 | // MSVC does not support #warning |
| 46 | #undef SHOW_PROTOTYPE_CHANGE_WARNINGS |
| 47 | #endif |
| 48 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 49 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 50 | #warning "You can disable these warnings by commenting SHOW_PROTOTYPE_CHANGE_WARNINGS in compat-1.2.h" |
| 51 | #endif |
| 52 | |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 53 | #if defined(POLARSSL_SHA256_C) |
| 54 | #define POLARSSL_SHA2_C |
| 55 | #include "sha256.h" |
| 56 | |
| 57 | /* |
| 58 | * SHA-2 -> SHA-256 |
| 59 | */ |
| 60 | typedef sha256_context sha2_context; |
| 61 | |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 62 | static inline void sha2_starts( sha256_context *ctx, int is224 ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 63 | sha256_starts( ctx, is224 ); |
| 64 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 65 | static inline void sha2_update( sha256_context *ctx, const unsigned char *input, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 66 | size_t ilen ) { |
| 67 | sha256_update( ctx, input, ilen ); |
| 68 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 69 | static inline void sha2_finish( sha256_context *ctx, unsigned char output[32] ) { |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 70 | sha256_finish( ctx, output ); |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 71 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 72 | static inline int sha2_file( const char *path, unsigned char output[32], int is224 ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 73 | return sha256_file( path, output, is224 ); |
| 74 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 75 | static inline void sha2( const unsigned char *input, size_t ilen, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 76 | unsigned char output[32], int is224 ) { |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 77 | sha256( input, ilen, output, is224 ); |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 78 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 79 | static inline void sha2_hmac_starts( sha256_context *ctx, const unsigned char *key, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 80 | size_t keylen, int is224 ) { |
| 81 | sha256_hmac_starts( ctx, key, keylen, is224 ); |
| 82 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 83 | static inline void sha2_hmac_update( sha256_context *ctx, const unsigned char *input, size_t ilen ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 84 | sha256_hmac_update( ctx, input, ilen ); |
| 85 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 86 | static inline void sha2_hmac_finish( sha256_context *ctx, unsigned char output[32] ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 87 | sha256_hmac_finish( ctx, output ); |
| 88 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 89 | static inline void sha2_hmac_reset( sha256_context *ctx ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 90 | sha256_hmac_reset( ctx ); |
| 91 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 92 | static inline void sha2_hmac( const unsigned char *key, size_t keylen, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 93 | const unsigned char *input, size_t ilen, |
| 94 | unsigned char output[32], int is224 ) { |
| 95 | sha256_hmac( key, keylen, input, ilen, output, is224 ); |
| 96 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 97 | static inline int sha2_self_test( int verbose ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 98 | return sha256_self_test( verbose ); |
| 99 | } |
| 100 | #endif /* POLARSSL_SHA256_C */ |
| 101 | |
| 102 | #if defined(POLARSSL_SHA512_C) |
| 103 | #define POLARSSL_SHA4_C |
| 104 | #include "sha512.h" |
| 105 | |
| 106 | /* |
| 107 | * SHA-4 -> SHA-512 |
| 108 | */ |
| 109 | typedef sha512_context sha4_context; |
| 110 | |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 111 | static inline void sha4_starts( sha512_context *ctx, int is384 ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 112 | sha512_starts( ctx, is384 ); |
| 113 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 114 | static inline void sha4_update( sha512_context *ctx, const unsigned char *input, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 115 | size_t ilen ) { |
| 116 | sha512_update( ctx, input, ilen ); |
| 117 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 118 | static inline void sha4_finish( sha512_context *ctx, unsigned char output[64] ) { |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 119 | sha512_finish( ctx, output ); |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 120 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 121 | static inline int sha4_file( const char *path, unsigned char output[64], int is384 ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 122 | return sha512_file( path, output, is384 ); |
| 123 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 124 | static inline void sha4( const unsigned char *input, size_t ilen, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 125 | unsigned char output[32], int is384 ) { |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 126 | sha512( input, ilen, output, is384 ); |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 127 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 128 | static inline void sha4_hmac_starts( sha512_context *ctx, const unsigned char *key, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 129 | size_t keylen, int is384 ) { |
| 130 | sha512_hmac_starts( ctx, key, keylen, is384 ); |
| 131 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 132 | static inline void sha4_hmac_update( sha512_context *ctx, const unsigned char *input, size_t ilen ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 133 | sha512_hmac_update( ctx, input, ilen ); |
| 134 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 135 | static inline void sha4_hmac_finish( sha512_context *ctx, unsigned char output[64] ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 136 | sha512_hmac_finish( ctx, output ); |
| 137 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 138 | static inline void sha4_hmac_reset( sha512_context *ctx ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 139 | sha512_hmac_reset( ctx ); |
| 140 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 141 | static inline void sha4_hmac( const unsigned char *key, size_t keylen, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 142 | const unsigned char *input, size_t ilen, |
| 143 | unsigned char output[64], int is384 ) { |
| 144 | sha512_hmac( key, keylen, input, ilen, output, is384 ); |
| 145 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 146 | static inline int sha4_self_test( int verbose ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 147 | return sha512_self_test( verbose ); |
| 148 | } |
| 149 | #endif /* POLARSSL_SHA512_C */ |
| 150 | |
| 151 | #if defined(POLARSSL_CIPHER_C) |
| 152 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 153 | #warning "cipher_reset() prototype changed. Manual change required if used" |
| 154 | #endif |
| 155 | #endif |
| 156 | |
| 157 | #if defined(POLARSSL_RSA_C) |
| 158 | #define SIG_RSA_RAW POLARSSL_MD_NONE |
| 159 | #define SIG_RSA_MD2 POLARSSL_MD_MD2 |
| 160 | #define SIG_RSA_MD4 POLARSSL_MD_MD4 |
| 161 | #define SIG_RSA_MD5 POLARSSL_MD_MD5 |
| 162 | #define SIG_RSA_SHA1 POLARSSL_MD_SHA1 |
| 163 | #define SIG_RSA_SHA224 POLARSSL_MD_SHA224 |
| 164 | #define SIG_RSA_SHA256 POLARSSL_MD_SHA256 |
| 165 | #define SIG_RSA_SHA384 POLARSSL_MD_SHA384 |
| 166 | #define SIG_RSA_SHA512 POLARSSL_MD_SHA512 |
| 167 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 168 | #warning "rsa_pkcs1_verify() prototype changed. Manual change required if used" |
| 169 | #warning "rsa_pkcs1_decrypt() prototype changed. Manual change required if used" |
| 170 | #endif |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 171 | #endif /* POLARSSL_RSA_C */ |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 172 | |
| 173 | #if defined(POLARSSL_DHM_C) |
| 174 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 175 | #warning "dhm_calc_secret() prototype changed. Manual change required if used" |
| 176 | #endif |
| 177 | #endif |
| 178 | |
| 179 | #if defined(POLARSSL_GCM_C) |
| 180 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 181 | #warning "gcm_init() prototype changed. Manual change required if used" |
| 182 | #endif |
| 183 | #endif |
| 184 | |
| 185 | #if defined(POLARSSL_SSL_CLI_C) |
| 186 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 187 | #warning "ssl_set_own_cert() prototype changed. Change to ssl_set_own_cert_rsa(). Manual change required if used" |
| 188 | #endif |
| 189 | #endif |
| 190 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 191 | #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C) |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 192 | #include "x509.h" |
| 193 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 194 | #define POLARSSL_ERR_X509_CERT_INVALID_FORMAT POLARSSL_ERR_X509_INVALID_FORMAT |
| 195 | #define POLARSSL_ERR_X509_CERT_INVALID_VERSION POLARSSL_ERR_X509_INVALID_VERSION |
| 196 | #define POLARSSL_ERR_X509_CERT_INVALID_ALG POLARSSL_ERR_X509_INVALID_ALG |
| 197 | #define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG POLARSSL_ERR_X509_UNKNOWN_SIG_ALG |
| 198 | #define POLARSSL_ERR_X509_CERT_INVALID_NAME POLARSSL_ERR_X509_INVALID_NAME |
| 199 | #define POLARSSL_ERR_X509_CERT_INVALID_DATE POLARSSL_ERR_X509_INVALID_DATE |
| 200 | #define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS POLARSSL_ERR_X509_INVALID_EXTENSIONS |
| 201 | #define POLARSSL_ERR_X509_CERT_SIG_MISMATCH POLARSSL_ERR_X509_SIG_MISMATCH |
| 202 | #define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE POLARSSL_ERR_X509_INVALID_SIGNATURE |
| 203 | #define POLARSSL_ERR_X509_CERT_INVALID_SERIAL POLARSSL_ERR_X509_INVALID_SERIAL |
| 204 | #define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION POLARSSL_ERR_X509_UNKNOWN_VERSION |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 205 | |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 206 | static inline int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial ) { |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 207 | return x509_serial_gets( buf, size, serial ); |
| 208 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 209 | static inline int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn ) { |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 210 | return x509_dn_gets( buf, size, dn ); |
| 211 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 212 | static inline int x509parse_time_expired( const x509_time *time ) { |
Paul Bakker | 86d0c19 | 2013-09-18 11:11:02 +0200 | [diff] [blame] | 213 | return x509_time_expired( time ); |
| 214 | } |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame] | 215 | #endif /* POLARSSL_X509_USE_C || POLARSSL_X509_CREATE_C */ |
| 216 | |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 217 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
| 218 | #define POLARSSL_X509_PARSE_C |
| 219 | #include "x509_crt.h" |
Paul Bakker | c559c7a | 2013-09-18 14:13:26 +0200 | [diff] [blame] | 220 | typedef x509_crt x509_cert; |
| 221 | |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 222 | static inline int x509parse_crt_der( x509_cert *chain, const unsigned char *buf, |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 223 | size_t buflen ) { |
| 224 | return x509_crt_parse_der( chain, buf, buflen ); |
| 225 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 226 | static inline int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 227 | return x509_crt_parse( chain, buf, buflen ); |
| 228 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 229 | static inline int x509parse_crtfile( x509_cert *chain, const char *path ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 230 | return x509_crt_parse_file( chain, path ); |
| 231 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 232 | static inline int x509parse_crtpath( x509_cert *chain, const char *path ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 233 | return x509_crt_parse_path( chain, path ); |
| 234 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 235 | static inline int x509parse_cert_info( char *buf, size_t size, const char *prefix, |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 236 | const x509_cert *crt ) { |
| 237 | return x509_crt_info( buf, size, prefix, crt ); |
| 238 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 239 | static inline int x509parse_verify( x509_cert *crt, x509_cert *trust_ca, |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 240 | x509_crl *ca_crl, const char *cn, int *flags, |
| 241 | int (*f_vrfy)(void *, x509_cert *, int, int *), |
| 242 | void *p_vrfy ) { |
| 243 | return x509_crt_verify( crt, trust_ca, ca_crl, cn, flags, f_vrfy, p_vrfy ); |
| 244 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 245 | static inline int x509parse_revoked( const x509_cert *crt, const x509_crl *crl ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 246 | return x509_crt_revoked( crt, crl ); |
| 247 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 248 | static inline void x509_free( x509_cert *crt ) { |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 249 | x509_crt_free( crt ); |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 250 | } |
| 251 | #endif /* POLARSSL_X509_CRT_PARSE_C */ |
| 252 | |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 253 | #if defined(POLARSSL_X509_CRL_PARSE_C) |
| 254 | #define POLARSSL_X509_PARSE_C |
| 255 | #include "x509_crl.h" |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 256 | static inline int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 257 | return x509_crl_parse( chain, buf, buflen ); |
| 258 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 259 | static inline int x509parse_crlfile( x509_crl *chain, const char *path ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 260 | return x509_crl_parse_file( chain, path ); |
| 261 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 262 | static inline int x509parse_crl_info( char *buf, size_t size, const char *prefix, |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 263 | const x509_crl *crl ) { |
| 264 | return x509_crl_info( buf, size, prefix, crl ); |
| 265 | } |
| 266 | #endif /* POLARSSL_X509_CRL_PARSE_C */ |
| 267 | |
| 268 | #if defined(POLARSSL_X509_CSR_PARSE_C) |
| 269 | #define POLARSSL_X509_PARSE_C |
| 270 | #include "x509_csr.h" |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 271 | static inline int x509parse_csr( x509_csr *csr, const unsigned char *buf, size_t buflen ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 272 | return x509_csr_parse( csr, buf, buflen ); |
| 273 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 274 | static inline int x509parse_csrfile( x509_csr *csr, const char *path ) { |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 275 | return x509_csr_parse_file( csr, path ); |
| 276 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 277 | static inline int x509parse_csr_info( char *buf, size_t size, const char *prefix, |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 278 | const x509_csr *csr ) { |
| 279 | return x509_csr_info( buf, size, prefix, csr ); |
| 280 | } |
| 281 | #endif /* POLARSSL_X509_CSR_PARSE_C */ |
| 282 | |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 283 | #if defined(POLARSSL_SSL_TLS_C) |
| 284 | #include "ssl_ciphersuites.h" |
| 285 | |
| 286 | #define ssl_default_ciphersuites ssl_list_ciphersuites() |
| 287 | #endif |
| 288 | |
| 289 | #if defined(POLARSSL_PK_PARSE_C) && defined(POLARSSL_RSA_C) |
| 290 | #include "rsa.h" |
| 291 | #include "pk.h" |
| 292 | |
| 293 | #define POLARSSL_ERR_X509_PASSWORD_MISMATCH POLARSSL_ERR_PK_PASSWORD_MISMATCH |
| 294 | #define POLARSSL_ERR_X509_KEY_INVALID_FORMAT POLARSSL_ERR_PK_KEY_INVALID_FORMAT |
| 295 | #define POLARSSL_ERR_X509_UNKNOWN_PK_ALG POLARSSL_ERR_PK_UNKNOWN_PK_ALG |
| 296 | #define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY POLARSSL_ERR_PK_INVALID_PUBKEY |
| 297 | |
| 298 | #if defined(POLARSSL_FS_IO) |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 299 | static inline int x509parse_keyfile( rsa_context *rsa, const char *path, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 300 | const char *pwd ) { |
| 301 | int ret; |
| 302 | pk_context pk; |
| 303 | pk_init( &pk ); |
| 304 | ret = pk_parse_keyfile( &pk, path, pwd ); |
| 305 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 306 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 307 | if( ret == 0 ) |
| 308 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 309 | else |
| 310 | rsa_free( rsa ); |
| 311 | pk_free( &pk ); |
| 312 | return( ret ); |
| 313 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 314 | static inline int x509parse_public_keyfile( rsa_context *rsa, const char *path ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 315 | int ret; |
| 316 | pk_context pk; |
| 317 | pk_init( &pk ); |
| 318 | ret = pk_parse_public_keyfile( &pk, path ); |
| 319 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 320 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 321 | if( ret == 0 ) |
| 322 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 323 | else |
| 324 | rsa_free( rsa ); |
| 325 | pk_free( &pk ); |
| 326 | return( ret ); |
| 327 | } |
| 328 | #endif /* POLARSSL_FS_IO */ |
| 329 | |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 330 | static inline int x509parse_key( rsa_context *rsa, const unsigned char *key, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 331 | size_t keylen, |
| 332 | const unsigned char *pwd, size_t pwdlen ) { |
| 333 | int ret; |
| 334 | pk_context pk; |
| 335 | pk_init( &pk ); |
| 336 | ret = pk_parse_key( &pk, key, keylen, pwd, pwdlen ); |
| 337 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 338 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 339 | if( ret == 0 ) |
| 340 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 341 | else |
| 342 | rsa_free( rsa ); |
| 343 | pk_free( &pk ); |
| 344 | return( ret ); |
| 345 | } |
| 346 | |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 347 | static inline int x509parse_public_key( rsa_context *rsa, |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 348 | const unsigned char *key, size_t keylen ) |
| 349 | { |
| 350 | int ret; |
| 351 | pk_context pk; |
| 352 | pk_init( &pk ); |
| 353 | ret = pk_parse_public_key( &pk, key, keylen ); |
| 354 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 355 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 356 | if( ret == 0 ) |
| 357 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 358 | else |
| 359 | rsa_free( rsa ); |
| 360 | pk_free( &pk ); |
| 361 | return( ret ); |
| 362 | } |
| 363 | #endif /* POLARSSL_PK_PARSE_C && POLARSSL_RSA_C */ |
| 364 | |
| 365 | #if defined(POLARSSL_PK_WRITE_C) && defined(POLARSSL_RSA_C) |
| 366 | #include "pk.h" |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 367 | static inline int x509_write_pubkey_der( unsigned char *buf, size_t len, rsa_context *rsa ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 368 | int ret; |
| 369 | pk_context ctx; |
| 370 | if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret ); |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 371 | if( ( ret = rsa_copy( pk_rsa( ctx ), rsa ) ) != 0 ) return( ret ); |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 372 | ret = pk_write_pubkey_der( &ctx, buf, len ); |
| 373 | pk_free( &ctx ); |
| 374 | return( ret ); |
| 375 | } |
Steffan Karger | 44cf68f | 2013-11-12 10:34:55 +0100 | [diff] [blame] | 376 | static inline int x509_write_key_der( unsigned char *buf, size_t len, rsa_context *rsa ) { |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 377 | int ret; |
| 378 | pk_context ctx; |
| 379 | if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret ); |
Paul Bakker | 4aa40d4 | 2013-10-11 10:49:24 +0200 | [diff] [blame] | 380 | if( ( ret = rsa_copy( pk_rsa( ctx ), rsa ) ) != 0 ) return( ret ); |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 381 | ret = pk_write_key_der( &ctx, buf, len ); |
| 382 | pk_free( &ctx ); |
| 383 | return( ret ); |
| 384 | } |
| 385 | #endif /* POLARSSL_PK_WRITE_C && POLARSSL_RSA_C */ |
| 386 | #endif /* compat-1.2.h */ |