mbed TLS library
Dependents: HTTPClient-SSL WS_SERVER
compat-1.2.h
00001 /** 00002 * \file compat-1.2.h 00003 * 00004 * \brief Backwards compatibility header for PolarSSL-1.2 from PolarSSL-1.3 00005 * 00006 * \deprecated Use native PolarSSL 1.3 functions instead. 00007 * 00008 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved 00009 * 00010 * This file is part of mbed TLS (https://tls.mbed.org) 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License along 00023 * with this program; if not, write to the Free Software Foundation, Inc., 00024 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00025 */ 00026 #if ! defined(POLARSSL_DEPRECATED_REMOVED) 00027 00028 #if defined(POLARSSL_DEPRECATED_WARNING) 00029 #warning "Including compat-1.2.h is deprecated" 00030 #endif 00031 00032 #ifndef POLARSSL_COMPAT_1_2_H 00033 #define POLARSSL_COMPAT_1_2_H 00034 00035 #if !defined(POLARSSL_CONFIG_FILE) 00036 #include "config.h" 00037 #else 00038 #include POLARSSL_CONFIG_FILE 00039 #endif 00040 00041 // Comment out to disable prototype change warnings 00042 #define SHOW_PROTOTYPE_CHANGE_WARNINGS 00043 00044 #if defined(_MSC_VER) && !defined(inline) 00045 #define inline _inline 00046 #else 00047 #if defined(__ARMCC_VERSION) && !defined(inline) 00048 #define inline __inline 00049 #endif /* __ARMCC_VERSION */ 00050 #endif /* _MSC_VER */ 00051 00052 #if defined(_MSC_VER) 00053 // MSVC does not support #warning 00054 #undef SHOW_PROTOTYPE_CHANGE_WARNINGS 00055 #endif 00056 00057 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) 00058 #warning "You can disable these warnings by commenting SHOW_PROTOTYPE_CHANGE_WARNINGS in compat-1.2.h" 00059 #endif 00060 00061 #if defined(POLARSSL_SHA256_C) 00062 #define POLARSSL_SHA2_C 00063 #include "sha256.h" 00064 00065 /* 00066 * SHA-2 -> SHA-256 00067 */ 00068 typedef sha256_context sha2_context; 00069 00070 static inline void sha2_starts( sha256_context *ctx, int is224 ) { 00071 sha256_starts( ctx, is224 ); 00072 } 00073 static inline void sha2_update( sha256_context *ctx, const unsigned char *input, 00074 size_t ilen ) { 00075 sha256_update( ctx, input, ilen ); 00076 } 00077 static inline void sha2_finish( sha256_context *ctx, unsigned char output[32] ) { 00078 sha256_finish( ctx, output ); 00079 } 00080 static inline int sha2_file( const char *path, unsigned char output[32], int is224 ) { 00081 return sha256_file( path, output, is224 ); 00082 } 00083 static inline void sha2( const unsigned char *input, size_t ilen, 00084 unsigned char output[32], int is224 ) { 00085 sha256( input, ilen, output, is224 ); 00086 } 00087 static inline void sha2_hmac_starts( sha256_context *ctx, const unsigned char *key, 00088 size_t keylen, int is224 ) { 00089 sha256_hmac_starts( ctx, key, keylen, is224 ); 00090 } 00091 static inline void sha2_hmac_update( sha256_context *ctx, const unsigned char *input, size_t ilen ) { 00092 sha256_hmac_update( ctx, input, ilen ); 00093 } 00094 static inline void sha2_hmac_finish( sha256_context *ctx, unsigned char output[32] ) { 00095 sha256_hmac_finish( ctx, output ); 00096 } 00097 static inline void sha2_hmac_reset( sha256_context *ctx ) { 00098 sha256_hmac_reset( ctx ); 00099 } 00100 static inline void sha2_hmac( const unsigned char *key, size_t keylen, 00101 const unsigned char *input, size_t ilen, 00102 unsigned char output[32], int is224 ) { 00103 sha256_hmac( key, keylen, input, ilen, output, is224 ); 00104 } 00105 static inline int sha2_self_test( int verbose ) { 00106 return sha256_self_test( verbose ); 00107 } 00108 #endif /* POLARSSL_SHA256_C */ 00109 00110 #if defined(POLARSSL_SHA512_C) 00111 #define POLARSSL_SHA4_C 00112 #include "sha512.h" 00113 00114 /* 00115 * SHA-4 -> SHA-512 00116 */ 00117 typedef sha512_context sha4_context; 00118 00119 static inline void sha4_starts( sha512_context *ctx, int is384 ) { 00120 sha512_starts( ctx, is384 ); 00121 } 00122 static inline void sha4_update( sha512_context *ctx, const unsigned char *input, 00123 size_t ilen ) { 00124 sha512_update( ctx, input, ilen ); 00125 } 00126 static inline void sha4_finish( sha512_context *ctx, unsigned char output[64] ) { 00127 sha512_finish( ctx, output ); 00128 } 00129 static inline int sha4_file( const char *path, unsigned char output[64], int is384 ) { 00130 return sha512_file( path, output, is384 ); 00131 } 00132 static inline void sha4( const unsigned char *input, size_t ilen, 00133 unsigned char output[32], int is384 ) { 00134 sha512( input, ilen, output, is384 ); 00135 } 00136 static inline void sha4_hmac_starts( sha512_context *ctx, const unsigned char *key, 00137 size_t keylen, int is384 ) { 00138 sha512_hmac_starts( ctx, key, keylen, is384 ); 00139 } 00140 static inline void sha4_hmac_update( sha512_context *ctx, const unsigned char *input, size_t ilen ) { 00141 sha512_hmac_update( ctx, input, ilen ); 00142 } 00143 static inline void sha4_hmac_finish( sha512_context *ctx, unsigned char output[64] ) { 00144 sha512_hmac_finish( ctx, output ); 00145 } 00146 static inline void sha4_hmac_reset( sha512_context *ctx ) { 00147 sha512_hmac_reset( ctx ); 00148 } 00149 static inline void sha4_hmac( const unsigned char *key, size_t keylen, 00150 const unsigned char *input, size_t ilen, 00151 unsigned char output[64], int is384 ) { 00152 sha512_hmac( key, keylen, input, ilen, output, is384 ); 00153 } 00154 static inline int sha4_self_test( int verbose ) { 00155 return sha512_self_test( verbose ); 00156 } 00157 #endif /* POLARSSL_SHA512_C */ 00158 00159 #if defined(POLARSSL_CIPHER_C) 00160 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) 00161 #warning "cipher_reset() prototype changed. Manual change required if used" 00162 #endif 00163 #endif 00164 00165 #if defined(POLARSSL_RSA_C) 00166 #define SIG_RSA_RAW POLARSSL_MD_NONE 00167 #define SIG_RSA_MD2 POLARSSL_MD_MD2 00168 #define SIG_RSA_MD4 POLARSSL_MD_MD4 00169 #define SIG_RSA_MD5 POLARSSL_MD_MD5 00170 #define SIG_RSA_SHA1 POLARSSL_MD_SHA1 00171 #define SIG_RSA_SHA224 POLARSSL_MD_SHA224 00172 #define SIG_RSA_SHA256 POLARSSL_MD_SHA256 00173 #define SIG_RSA_SHA384 POLARSSL_MD_SHA384 00174 #define SIG_RSA_SHA512 POLARSSL_MD_SHA512 00175 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) 00176 #warning "rsa_pkcs1_verify() prototype changed. Manual change required if used" 00177 #warning "rsa_pkcs1_decrypt() prototype changed. Manual change required if used" 00178 #endif 00179 #endif /* POLARSSL_RSA_C */ 00180 00181 #if defined(POLARSSL_DHM_C) 00182 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) 00183 #warning "dhm_calc_secret() prototype changed. Manual change required if used" 00184 #endif 00185 #endif 00186 00187 #if defined(POLARSSL_GCM_C) 00188 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) 00189 #warning "gcm_init() prototype changed. Manual change required if used" 00190 #endif 00191 #endif 00192 00193 #if defined(POLARSSL_SSL_CLI_C) 00194 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS) 00195 #warning "ssl_set_own_cert() prototype changed. Change to ssl_set_own_cert_rsa(). Manual change required if used" 00196 #endif 00197 #endif 00198 00199 #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C) 00200 #include "x509.h" 00201 00202 #define POLARSSL_ERR_X509_CERT_INVALID_FORMAT POLARSSL_ERR_X509_INVALID_FORMAT 00203 #define POLARSSL_ERR_X509_CERT_INVALID_VERSION POLARSSL_ERR_X509_INVALID_VERSION 00204 #define POLARSSL_ERR_X509_CERT_INVALID_ALG POLARSSL_ERR_X509_INVALID_ALG 00205 #define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG POLARSSL_ERR_X509_UNKNOWN_SIG_ALG 00206 #define POLARSSL_ERR_X509_CERT_INVALID_NAME POLARSSL_ERR_X509_INVALID_NAME 00207 #define POLARSSL_ERR_X509_CERT_INVALID_DATE POLARSSL_ERR_X509_INVALID_DATE 00208 #define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS POLARSSL_ERR_X509_INVALID_EXTENSIONS 00209 #define POLARSSL_ERR_X509_CERT_SIG_MISMATCH POLARSSL_ERR_X509_SIG_MISMATCH 00210 #define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE POLARSSL_ERR_X509_INVALID_SIGNATURE 00211 #define POLARSSL_ERR_X509_CERT_INVALID_SERIAL POLARSSL_ERR_X509_INVALID_SERIAL 00212 #define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION POLARSSL_ERR_X509_UNKNOWN_VERSION 00213 00214 static inline int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial ) { 00215 return x509_serial_gets( buf, size, serial ); 00216 } 00217 static inline int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn ) { 00218 return x509_dn_gets( buf, size, dn ); 00219 } 00220 static inline int x509parse_time_expired( const x509_time *time ) { 00221 return x509_time_expired( time ); 00222 } 00223 #endif /* POLARSSL_X509_USE_C || POLARSSL_X509_CREATE_C */ 00224 00225 #if defined(POLARSSL_X509_CRT_PARSE_C) 00226 #define POLARSSL_X509_PARSE_C 00227 #include "x509_crt.h" 00228 typedef x509_crt x509_cert; 00229 00230 static inline int x509parse_crt_der( x509_cert *chain, const unsigned char *buf, 00231 size_t buflen ) { 00232 return x509_crt_parse_der( chain, buf, buflen ); 00233 } 00234 static inline int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen ) { 00235 return x509_crt_parse( chain, buf, buflen ); 00236 } 00237 static inline int x509parse_crtfile( x509_cert *chain, const char *path ) { 00238 return x509_crt_parse_file( chain, path ); 00239 } 00240 static inline int x509parse_crtpath( x509_cert *chain, const char *path ) { 00241 return x509_crt_parse_path( chain, path ); 00242 } 00243 static inline int x509parse_cert_info( char *buf, size_t size, const char *prefix, 00244 const x509_cert *crt ) { 00245 return x509_crt_info( buf, size, prefix, crt ); 00246 } 00247 static inline int x509parse_verify( x509_cert *crt, x509_cert *trust_ca, 00248 x509_crl *ca_crl, const char *cn, int *flags, 00249 int (*f_vrfy)(void *, x509_cert *, int, int *), 00250 void *p_vrfy ) { 00251 return x509_crt_verify( crt, trust_ca, ca_crl, cn, flags, f_vrfy, p_vrfy ); 00252 } 00253 static inline int x509parse_revoked( const x509_cert *crt, const x509_crl *crl ) { 00254 return x509_crt_revoked( crt, crl ); 00255 } 00256 static inline void x509_free( x509_cert *crt ) { 00257 x509_crt_free( crt ); 00258 } 00259 #endif /* POLARSSL_X509_CRT_PARSE_C */ 00260 00261 #if defined(POLARSSL_X509_CRL_PARSE_C) 00262 #define POLARSSL_X509_PARSE_C 00263 #include "x509_crl.h" 00264 static inline int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen ) { 00265 return x509_crl_parse( chain, buf, buflen ); 00266 } 00267 static inline int x509parse_crlfile( x509_crl *chain, const char *path ) { 00268 return x509_crl_parse_file( chain, path ); 00269 } 00270 static inline int x509parse_crl_info( char *buf, size_t size, const char *prefix, 00271 const x509_crl *crl ) { 00272 return x509_crl_info( buf, size, prefix, crl ); 00273 } 00274 #endif /* POLARSSL_X509_CRL_PARSE_C */ 00275 00276 #if defined(POLARSSL_X509_CSR_PARSE_C) 00277 #define POLARSSL_X509_PARSE_C 00278 #include "x509_csr.h" 00279 static inline int x509parse_csr( x509_csr *csr, const unsigned char *buf, size_t buflen ) { 00280 return x509_csr_parse( csr, buf, buflen ); 00281 } 00282 static inline int x509parse_csrfile( x509_csr *csr, const char *path ) { 00283 return x509_csr_parse_file( csr, path ); 00284 } 00285 static inline int x509parse_csr_info( char *buf, size_t size, const char *prefix, 00286 const x509_csr *csr ) { 00287 return x509_csr_info( buf, size, prefix, csr ); 00288 } 00289 #endif /* POLARSSL_X509_CSR_PARSE_C */ 00290 00291 #if defined(POLARSSL_SSL_TLS_C) 00292 #include "ssl_ciphersuites.h" 00293 00294 #define ssl_default_ciphersuites ssl_list_ciphersuites() 00295 #endif 00296 00297 #if defined(POLARSSL_PK_PARSE_C) && defined(POLARSSL_RSA_C) 00298 #include "rsa.h" 00299 #include "pk.h" 00300 00301 #define POLARSSL_ERR_X509_PASSWORD_MISMATCH POLARSSL_ERR_PK_PASSWORD_MISMATCH 00302 #define POLARSSL_ERR_X509_KEY_INVALID_FORMAT POLARSSL_ERR_PK_KEY_INVALID_FORMAT 00303 #define POLARSSL_ERR_X509_UNKNOWN_PK_ALG POLARSSL_ERR_PK_UNKNOWN_PK_ALG 00304 #define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY POLARSSL_ERR_PK_INVALID_PUBKEY 00305 00306 #if defined(POLARSSL_FS_IO) 00307 static inline int x509parse_keyfile( rsa_context *rsa, const char *path, 00308 const char *pwd ) { 00309 int ret; 00310 pk_context pk; 00311 pk_init( &pk ); 00312 ret = pk_parse_keyfile( &pk, path, pwd ); 00313 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) 00314 ret = POLARSSL_ERR_PK_TYPE_MISMATCH; 00315 if( ret == 0 ) 00316 rsa_copy( rsa, pk_rsa( pk ) ); 00317 else 00318 rsa_free( rsa ); 00319 pk_free( &pk ); 00320 return( ret ); 00321 } 00322 static inline int x509parse_public_keyfile( rsa_context *rsa, const char *path ) { 00323 int ret; 00324 pk_context pk; 00325 pk_init( &pk ); 00326 ret = pk_parse_public_keyfile( &pk, path ); 00327 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) 00328 ret = POLARSSL_ERR_PK_TYPE_MISMATCH; 00329 if( ret == 0 ) 00330 rsa_copy( rsa, pk_rsa( pk ) ); 00331 else 00332 rsa_free( rsa ); 00333 pk_free( &pk ); 00334 return( ret ); 00335 } 00336 #endif /* POLARSSL_FS_IO */ 00337 00338 static inline int x509parse_key( rsa_context *rsa, const unsigned char *key, 00339 size_t keylen, 00340 const unsigned char *pwd, size_t pwdlen ) { 00341 int ret; 00342 pk_context pk; 00343 pk_init( &pk ); 00344 ret = pk_parse_key( &pk, key, keylen, pwd, pwdlen ); 00345 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) 00346 ret = POLARSSL_ERR_PK_TYPE_MISMATCH; 00347 if( ret == 0 ) 00348 rsa_copy( rsa, pk_rsa( pk ) ); 00349 else 00350 rsa_free( rsa ); 00351 pk_free( &pk ); 00352 return( ret ); 00353 } 00354 00355 static inline int x509parse_public_key( rsa_context *rsa, 00356 const unsigned char *key, size_t keylen ) 00357 { 00358 int ret; 00359 pk_context pk; 00360 pk_init( &pk ); 00361 ret = pk_parse_public_key( &pk, key, keylen ); 00362 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) ) 00363 ret = POLARSSL_ERR_PK_TYPE_MISMATCH; 00364 if( ret == 0 ) 00365 rsa_copy( rsa, pk_rsa( pk ) ); 00366 else 00367 rsa_free( rsa ); 00368 pk_free( &pk ); 00369 return( ret ); 00370 } 00371 #endif /* POLARSSL_PK_PARSE_C && POLARSSL_RSA_C */ 00372 00373 #if defined(POLARSSL_PK_WRITE_C) && defined(POLARSSL_RSA_C) 00374 #include "pk.h" 00375 static inline int x509_write_pubkey_der( unsigned char *buf, size_t len, rsa_context *rsa ) { 00376 int ret; 00377 pk_context ctx; 00378 if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret ); 00379 if( ( ret = rsa_copy( pk_rsa( ctx ), rsa ) ) != 0 ) return( ret ); 00380 ret = pk_write_pubkey_der( &ctx, buf, len ); 00381 pk_free( &ctx ); 00382 return( ret ); 00383 } 00384 static inline int x509_write_key_der( unsigned char *buf, size_t len, rsa_context *rsa ) { 00385 int ret; 00386 pk_context ctx; 00387 if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret ); 00388 if( ( ret = rsa_copy( pk_rsa( ctx ), rsa ) ) != 0 ) return( ret ); 00389 ret = pk_write_key_der( &ctx, buf, len ); 00390 pk_free( &ctx ); 00391 return( ret ); 00392 } 00393 #endif /* POLARSSL_PK_WRITE_C && POLARSSL_RSA_C */ 00394 #endif /* compat-1.2.h */ 00395 #endif /* POLARSSL_DEPRECATED_REMOVED */ 00396
Generated on Tue Jul 12 2022 13:50:36 by 1.7.2