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