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 | * |
| 6 | * Copyright (C) 2006-2013, Brainspark B.V. |
| 7 | * |
| 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 10 | * |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 26 | */ |
| 27 | #ifndef POLARSSL_COMPAT_1_2_H |
| 28 | #define POLARSSL_COMPAT_1_2_H |
| 29 | |
| 30 | #include "config.h" |
| 31 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame^] | 32 | // Comment out to disable prototype change warnings |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 33 | #define SHOW_PROTOTYPE_CHANGE_WARNINGS |
| 34 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame^] | 35 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 36 | #warning "You can disable these warnings by commenting SHOW_PROTOTYPE_CHANGE_WARNINGS in compat-1.2.h" |
| 37 | #endif |
| 38 | |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 39 | #if defined(POLARSSL_SHA256_C) |
| 40 | #define POLARSSL_SHA2_C |
| 41 | #include "sha256.h" |
| 42 | |
| 43 | /* |
| 44 | * SHA-2 -> SHA-256 |
| 45 | */ |
| 46 | typedef sha256_context sha2_context; |
| 47 | |
| 48 | inline void sha2_starts( sha256_context *ctx, int is224 ) { |
| 49 | sha256_starts( ctx, is224 ); |
| 50 | } |
| 51 | inline void sha2_update( sha256_context *ctx, const unsigned char *input, |
| 52 | size_t ilen ) { |
| 53 | sha256_update( ctx, input, ilen ); |
| 54 | } |
| 55 | inline void sha2_finish( sha256_context *ctx, unsigned char output[32] ) { |
| 56 | return sha256_finish( ctx, output ); |
| 57 | } |
| 58 | inline int sha2_file( const char *path, unsigned char output[32], int is224 ) { |
| 59 | return sha256_file( path, output, is224 ); |
| 60 | } |
| 61 | inline void sha2( const unsigned char *input, size_t ilen, |
| 62 | unsigned char output[32], int is224 ) { |
| 63 | return sha256( input, ilen, output, is224 ); |
| 64 | } |
| 65 | inline void sha2_hmac_starts( sha256_context *ctx, const unsigned char *key, |
| 66 | size_t keylen, int is224 ) { |
| 67 | sha256_hmac_starts( ctx, key, keylen, is224 ); |
| 68 | } |
| 69 | inline void sha2_hmac_update( sha256_context *ctx, const unsigned char *input, size_t ilen ) { |
| 70 | sha256_hmac_update( ctx, input, ilen ); |
| 71 | } |
| 72 | inline void sha2_hmac_finish( sha256_context *ctx, unsigned char output[32] ) { |
| 73 | sha256_hmac_finish( ctx, output ); |
| 74 | } |
| 75 | inline void sha2_hmac_reset( sha256_context *ctx ) { |
| 76 | sha256_hmac_reset( ctx ); |
| 77 | } |
| 78 | inline void sha2_hmac( const unsigned char *key, size_t keylen, |
| 79 | const unsigned char *input, size_t ilen, |
| 80 | unsigned char output[32], int is224 ) { |
| 81 | sha256_hmac( key, keylen, input, ilen, output, is224 ); |
| 82 | } |
| 83 | inline int sha2_self_test( int verbose ) { |
| 84 | return sha256_self_test( verbose ); |
| 85 | } |
| 86 | #endif /* POLARSSL_SHA256_C */ |
| 87 | |
| 88 | #if defined(POLARSSL_SHA512_C) |
| 89 | #define POLARSSL_SHA4_C |
| 90 | #include "sha512.h" |
| 91 | |
| 92 | /* |
| 93 | * SHA-4 -> SHA-512 |
| 94 | */ |
| 95 | typedef sha512_context sha4_context; |
| 96 | |
| 97 | inline void sha4_starts( sha512_context *ctx, int is384 ) { |
| 98 | sha512_starts( ctx, is384 ); |
| 99 | } |
| 100 | inline void sha4_update( sha512_context *ctx, const unsigned char *input, |
| 101 | size_t ilen ) { |
| 102 | sha512_update( ctx, input, ilen ); |
| 103 | } |
| 104 | inline void sha4_finish( sha512_context *ctx, unsigned char output[64] ) { |
| 105 | return sha512_finish( ctx, output ); |
| 106 | } |
| 107 | inline int sha4_file( const char *path, unsigned char output[64], int is384 ) { |
| 108 | return sha512_file( path, output, is384 ); |
| 109 | } |
| 110 | inline void sha4( const unsigned char *input, size_t ilen, |
| 111 | unsigned char output[32], int is384 ) { |
| 112 | return sha512( input, ilen, output, is384 ); |
| 113 | } |
| 114 | inline void sha4_hmac_starts( sha512_context *ctx, const unsigned char *key, |
| 115 | size_t keylen, int is384 ) { |
| 116 | sha512_hmac_starts( ctx, key, keylen, is384 ); |
| 117 | } |
| 118 | inline void sha4_hmac_update( sha512_context *ctx, const unsigned char *input, size_t ilen ) { |
| 119 | sha512_hmac_update( ctx, input, ilen ); |
| 120 | } |
| 121 | inline void sha4_hmac_finish( sha512_context *ctx, unsigned char output[64] ) { |
| 122 | sha512_hmac_finish( ctx, output ); |
| 123 | } |
| 124 | inline void sha4_hmac_reset( sha512_context *ctx ) { |
| 125 | sha512_hmac_reset( ctx ); |
| 126 | } |
| 127 | inline void sha4_hmac( const unsigned char *key, size_t keylen, |
| 128 | const unsigned char *input, size_t ilen, |
| 129 | unsigned char output[64], int is384 ) { |
| 130 | sha512_hmac( key, keylen, input, ilen, output, is384 ); |
| 131 | } |
| 132 | inline int sha4_self_test( int verbose ) { |
| 133 | return sha512_self_test( verbose ); |
| 134 | } |
| 135 | #endif /* POLARSSL_SHA512_C */ |
| 136 | |
| 137 | #if defined(POLARSSL_CIPHER_C) |
| 138 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 139 | #warning "cipher_reset() prototype changed. Manual change required if used" |
| 140 | #endif |
| 141 | #endif |
| 142 | |
| 143 | #if defined(POLARSSL_RSA_C) |
| 144 | #define SIG_RSA_RAW POLARSSL_MD_NONE |
| 145 | #define SIG_RSA_MD2 POLARSSL_MD_MD2 |
| 146 | #define SIG_RSA_MD4 POLARSSL_MD_MD4 |
| 147 | #define SIG_RSA_MD5 POLARSSL_MD_MD5 |
| 148 | #define SIG_RSA_SHA1 POLARSSL_MD_SHA1 |
| 149 | #define SIG_RSA_SHA224 POLARSSL_MD_SHA224 |
| 150 | #define SIG_RSA_SHA256 POLARSSL_MD_SHA256 |
| 151 | #define SIG_RSA_SHA384 POLARSSL_MD_SHA384 |
| 152 | #define SIG_RSA_SHA512 POLARSSL_MD_SHA512 |
| 153 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 154 | #warning "rsa_pkcs1_verify() prototype changed. Manual change required if used" |
| 155 | #warning "rsa_pkcs1_decrypt() prototype changed. Manual change required if used" |
| 156 | #endif |
| 157 | #endif |
| 158 | |
| 159 | #if defined(POLARSSL_DHM_C) |
| 160 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 161 | #warning "dhm_calc_secret() prototype changed. Manual change required if used" |
| 162 | #endif |
| 163 | #endif |
| 164 | |
| 165 | #if defined(POLARSSL_GCM_C) |
| 166 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 167 | #warning "gcm_init() prototype changed. Manual change required if used" |
| 168 | #endif |
| 169 | #endif |
| 170 | |
| 171 | #if defined(POLARSSL_SSL_CLI_C) |
| 172 | #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) |
| 173 | #warning "ssl_set_own_cert() prototype changed. Change to ssl_set_own_cert_rsa(). Manual change required if used" |
| 174 | #endif |
| 175 | #endif |
| 176 | |
Paul Bakker | 5187656 | 2013-09-17 14:36:05 +0200 | [diff] [blame^] | 177 | #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C) |
| 178 | #define POLARSSL_ERR_X509_CERT_INVALID_FORMAT POLARSSL_ERR_X509_INVALID_FORMAT |
| 179 | #define POLARSSL_ERR_X509_CERT_INVALID_VERSION POLARSSL_ERR_X509_INVALID_VERSION |
| 180 | #define POLARSSL_ERR_X509_CERT_INVALID_ALG POLARSSL_ERR_X509_INVALID_ALG |
| 181 | #define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG POLARSSL_ERR_X509_UNKNOWN_SIG_ALG |
| 182 | #define POLARSSL_ERR_X509_CERT_INVALID_NAME POLARSSL_ERR_X509_INVALID_NAME |
| 183 | #define POLARSSL_ERR_X509_CERT_INVALID_DATE POLARSSL_ERR_X509_INVALID_DATE |
| 184 | #define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS POLARSSL_ERR_X509_INVALID_EXTENSIONS |
| 185 | #define POLARSSL_ERR_X509_CERT_SIG_MISMATCH POLARSSL_ERR_X509_SIG_MISMATCH |
| 186 | #define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE POLARSSL_ERR_X509_INVALID_SIGNATURE |
| 187 | #define POLARSSL_ERR_X509_CERT_INVALID_SERIAL POLARSSL_ERR_X509_INVALID_SERIAL |
| 188 | #define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION POLARSSL_ERR_X509_UNKNOWN_VERSION |
| 189 | #endif /* POLARSSL_X509_USE_C || POLARSSL_X509_CREATE_C */ |
| 190 | |
Paul Bakker | d1a983f | 2013-09-16 22:26:53 +0200 | [diff] [blame] | 191 | #if defined(POLARSSL_X509_CRT_PARSE_C) |
| 192 | #define POLARSSL_X509_PARSE_C |
| 193 | #include "x509_crt.h" |
| 194 | |
| 195 | inline void x509_free( x509_cert *crt ) { |
| 196 | return x509_crt_free( crt ); |
| 197 | } |
| 198 | #endif /* POLARSSL_X509_CRT_PARSE_C */ |
| 199 | |
| 200 | #if defined(POLARSSL_SSL_TLS_C) |
| 201 | #include "ssl_ciphersuites.h" |
| 202 | |
| 203 | #define ssl_default_ciphersuites ssl_list_ciphersuites() |
| 204 | #endif |
| 205 | |
| 206 | #if defined(POLARSSL_PK_PARSE_C) && defined(POLARSSL_RSA_C) |
| 207 | #include "rsa.h" |
| 208 | #include "pk.h" |
| 209 | |
| 210 | #define POLARSSL_ERR_X509_PASSWORD_MISMATCH POLARSSL_ERR_PK_PASSWORD_MISMATCH |
| 211 | #define POLARSSL_ERR_X509_KEY_INVALID_FORMAT POLARSSL_ERR_PK_KEY_INVALID_FORMAT |
| 212 | #define POLARSSL_ERR_X509_UNKNOWN_PK_ALG POLARSSL_ERR_PK_UNKNOWN_PK_ALG |
| 213 | #define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY POLARSSL_ERR_PK_INVALID_PUBKEY |
| 214 | |
| 215 | #if defined(POLARSSL_FS_IO) |
| 216 | inline int x509parse_keyfile( rsa_context *rsa, const char *path, |
| 217 | const char *pwd ) { |
| 218 | int ret; |
| 219 | pk_context pk; |
| 220 | pk_init( &pk ); |
| 221 | ret = pk_parse_keyfile( &pk, path, pwd ); |
| 222 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 223 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 224 | if( ret == 0 ) |
| 225 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 226 | else |
| 227 | rsa_free( rsa ); |
| 228 | pk_free( &pk ); |
| 229 | return( ret ); |
| 230 | } |
| 231 | inline int x509parse_public_keyfile( rsa_context *rsa, const char *path ) { |
| 232 | int ret; |
| 233 | pk_context pk; |
| 234 | pk_init( &pk ); |
| 235 | ret = pk_parse_public_keyfile( &pk, path ); |
| 236 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 237 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 238 | if( ret == 0 ) |
| 239 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 240 | else |
| 241 | rsa_free( rsa ); |
| 242 | pk_free( &pk ); |
| 243 | return( ret ); |
| 244 | } |
| 245 | #endif /* POLARSSL_FS_IO */ |
| 246 | |
| 247 | inline int x509parse_key( rsa_context *rsa, const unsigned char *key, |
| 248 | size_t keylen, |
| 249 | const unsigned char *pwd, size_t pwdlen ) { |
| 250 | int ret; |
| 251 | pk_context pk; |
| 252 | pk_init( &pk ); |
| 253 | ret = pk_parse_key( &pk, key, keylen, pwd, pwdlen ); |
| 254 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 255 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 256 | if( ret == 0 ) |
| 257 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 258 | else |
| 259 | rsa_free( rsa ); |
| 260 | pk_free( &pk ); |
| 261 | return( ret ); |
| 262 | } |
| 263 | |
| 264 | inline int x509parse_public_key( rsa_context *rsa, |
| 265 | const unsigned char *key, size_t keylen ) |
| 266 | { |
| 267 | int ret; |
| 268 | pk_context pk; |
| 269 | pk_init( &pk ); |
| 270 | ret = pk_parse_public_key( &pk, key, keylen ); |
| 271 | if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) |
| 272 | ret = POLARSSL_ERR_PK_TYPE_MISMATCH; |
| 273 | if( ret == 0 ) |
| 274 | rsa_copy( rsa, pk_rsa( pk ) ); |
| 275 | else |
| 276 | rsa_free( rsa ); |
| 277 | pk_free( &pk ); |
| 278 | return( ret ); |
| 279 | } |
| 280 | #endif /* POLARSSL_PK_PARSE_C && POLARSSL_RSA_C */ |
| 281 | |
| 282 | #if defined(POLARSSL_PK_WRITE_C) && defined(POLARSSL_RSA_C) |
| 283 | #include "pk.h" |
| 284 | inline int x509_write_pubkey_der( unsigned char *buf, size_t len, rsa_context *rsa ) { |
| 285 | int ret; |
| 286 | pk_context ctx; |
| 287 | if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret ); |
| 288 | if( ( ret = rsa_copy( ctx.pk_ctx, rsa ) ) != 0 ) return( ret ); |
| 289 | ret = pk_write_pubkey_der( &ctx, buf, len ); |
| 290 | pk_free( &ctx ); |
| 291 | return( ret ); |
| 292 | } |
| 293 | inline int x509_write_key_der( unsigned char *buf, size_t len, rsa_context *rsa ) { |
| 294 | int ret; |
| 295 | pk_context ctx; |
| 296 | if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret ); |
| 297 | if( ( ret = rsa_copy( ctx.pk_ctx, rsa ) ) != 0 ) return( ret ); |
| 298 | ret = pk_write_key_der( &ctx, buf, len ); |
| 299 | pk_free( &ctx ); |
| 300 | return( ret ); |
| 301 | } |
| 302 | #endif /* POLARSSL_PK_WRITE_C && POLARSSL_RSA_C */ |
| 303 | #endif /* compat-1.2.h */ |