00001
00027 #ifndef POLARSSL_COMPAT_1_2_H
00028 #define POLARSSL_COMPAT_1_2_H
00029
00030 #include "config.h"
00031
00032
00033 #define SHOW_PROTOTYPE_CHANGE_WARNINGS
00034
00035 #if defined(_MSC_VER) && !defined(inline)
00036 #define inline _inline
00037 #else
00038 #if defined(__ARMCC_VERSION) && !defined(inline)
00039 #define inline __inline
00040 #endif
00041 #endif
00042
00043 #if defined(_MSC_VER)
00044
00045 #undef SHOW_PROTOTYPE_CHANGE_WARNINGS
00046 #endif
00047
00048 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
00049 #warning "You can disable these warnings by commenting SHOW_PROTOTYPE_CHANGE_WARNINGS in compat-1.2.h"
00050 #endif
00051
00052 #if defined(POLARSSL_SHA256_C)
00053 #define POLARSSL_SHA2_C
00054 #include "sha256.h"
00055
00056
00057
00058
00059 typedef sha256_context sha2_context;
00060
00061 inline void sha2_starts( sha256_context *ctx, int is224 ) {
00062 sha256_starts( ctx, is224 );
00063 }
00064 inline void sha2_update( sha256_context *ctx, const unsigned char *input,
00065 size_t ilen ) {
00066 sha256_update( ctx, input, ilen );
00067 }
00068 inline void sha2_finish( sha256_context *ctx, unsigned char output[32] ) {
00069 sha256_finish( ctx, output );
00070 }
00071 inline int sha2_file( const char *path, unsigned char output[32], int is224 ) {
00072 return sha256_file( path, output, is224 );
00073 }
00074 inline void sha2( const unsigned char *input, size_t ilen,
00075 unsigned char output[32], int is224 ) {
00076 sha256( input, ilen, output, is224 );
00077 }
00078 inline void sha2_hmac_starts( sha256_context *ctx, const unsigned char *key,
00079 size_t keylen, int is224 ) {
00080 sha256_hmac_starts( ctx, key, keylen, is224 );
00081 }
00082 inline void sha2_hmac_update( sha256_context *ctx, const unsigned char *input, size_t ilen ) {
00083 sha256_hmac_update( ctx, input, ilen );
00084 }
00085 inline void sha2_hmac_finish( sha256_context *ctx, unsigned char output[32] ) {
00086 sha256_hmac_finish( ctx, output );
00087 }
00088 inline void sha2_hmac_reset( sha256_context *ctx ) {
00089 sha256_hmac_reset( ctx );
00090 }
00091 inline void sha2_hmac( const unsigned char *key, size_t keylen,
00092 const unsigned char *input, size_t ilen,
00093 unsigned char output[32], int is224 ) {
00094 sha256_hmac( key, keylen, input, ilen, output, is224 );
00095 }
00096 inline int sha2_self_test( int verbose ) {
00097 return sha256_self_test( verbose );
00098 }
00099 #endif
00100
00101 #if defined(POLARSSL_SHA512_C)
00102 #define POLARSSL_SHA4_C
00103 #include "sha512.h"
00104
00105
00106
00107
00108 typedef sha512_context sha4_context;
00109
00110 inline void sha4_starts( sha512_context *ctx, int is384 ) {
00111 sha512_starts( ctx, is384 );
00112 }
00113 inline void sha4_update( sha512_context *ctx, const unsigned char *input,
00114 size_t ilen ) {
00115 sha512_update( ctx, input, ilen );
00116 }
00117 inline void sha4_finish( sha512_context *ctx, unsigned char output[64] ) {
00118 sha512_finish( ctx, output );
00119 }
00120 inline int sha4_file( const char *path, unsigned char output[64], int is384 ) {
00121 return sha512_file( path, output, is384 );
00122 }
00123 inline void sha4( const unsigned char *input, size_t ilen,
00124 unsigned char output[32], int is384 ) {
00125 sha512( input, ilen, output, is384 );
00126 }
00127 inline void sha4_hmac_starts( sha512_context *ctx, const unsigned char *key,
00128 size_t keylen, int is384 ) {
00129 sha512_hmac_starts( ctx, key, keylen, is384 );
00130 }
00131 inline void sha4_hmac_update( sha512_context *ctx, const unsigned char *input, size_t ilen ) {
00132 sha512_hmac_update( ctx, input, ilen );
00133 }
00134 inline void sha4_hmac_finish( sha512_context *ctx, unsigned char output[64] ) {
00135 sha512_hmac_finish( ctx, output );
00136 }
00137 inline void sha4_hmac_reset( sha512_context *ctx ) {
00138 sha512_hmac_reset( ctx );
00139 }
00140 inline void sha4_hmac( const unsigned char *key, size_t keylen,
00141 const unsigned char *input, size_t ilen,
00142 unsigned char output[64], int is384 ) {
00143 sha512_hmac( key, keylen, input, ilen, output, is384 );
00144 }
00145 inline int sha4_self_test( int verbose ) {
00146 return sha512_self_test( verbose );
00147 }
00148 #endif
00149
00150 #if defined(POLARSSL_CIPHER_C)
00151 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
00152 #warning "cipher_reset() prototype changed. Manual change required if used"
00153 #endif
00154 #endif
00155
00156 #if defined(POLARSSL_RSA_C)
00157 #define SIG_RSA_RAW POLARSSL_MD_NONE
00158 #define SIG_RSA_MD2 POLARSSL_MD_MD2
00159 #define SIG_RSA_MD4 POLARSSL_MD_MD4
00160 #define SIG_RSA_MD5 POLARSSL_MD_MD5
00161 #define SIG_RSA_SHA1 POLARSSL_MD_SHA1
00162 #define SIG_RSA_SHA224 POLARSSL_MD_SHA224
00163 #define SIG_RSA_SHA256 POLARSSL_MD_SHA256
00164 #define SIG_RSA_SHA384 POLARSSL_MD_SHA384
00165 #define SIG_RSA_SHA512 POLARSSL_MD_SHA512
00166 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
00167 #warning "rsa_pkcs1_verify() prototype changed. Manual change required if used"
00168 #warning "rsa_pkcs1_decrypt() prototype changed. Manual change required if used"
00169 #endif
00170 #endif
00171
00172 #if defined(POLARSSL_DHM_C)
00173 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
00174 #warning "dhm_calc_secret() prototype changed. Manual change required if used"
00175 #endif
00176 #endif
00177
00178 #if defined(POLARSSL_GCM_C)
00179 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
00180 #warning "gcm_init() prototype changed. Manual change required if used"
00181 #endif
00182 #endif
00183
00184 #if defined(POLARSSL_SSL_CLI_C)
00185 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
00186 #warning "ssl_set_own_cert() prototype changed. Change to ssl_set_own_cert_rsa(). Manual change required if used"
00187 #endif
00188 #endif
00189
00190 #if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
00191 #include "x509.h"
00192
00193 #define POLARSSL_ERR_X509_CERT_INVALID_FORMAT POLARSSL_ERR_X509_INVALID_FORMAT
00194 #define POLARSSL_ERR_X509_CERT_INVALID_VERSION POLARSSL_ERR_X509_INVALID_VERSION
00195 #define POLARSSL_ERR_X509_CERT_INVALID_ALG POLARSSL_ERR_X509_INVALID_ALG
00196 #define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG POLARSSL_ERR_X509_UNKNOWN_SIG_ALG
00197 #define POLARSSL_ERR_X509_CERT_INVALID_NAME POLARSSL_ERR_X509_INVALID_NAME
00198 #define POLARSSL_ERR_X509_CERT_INVALID_DATE POLARSSL_ERR_X509_INVALID_DATE
00199 #define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS POLARSSL_ERR_X509_INVALID_EXTENSIONS
00200 #define POLARSSL_ERR_X509_CERT_SIG_MISMATCH POLARSSL_ERR_X509_SIG_MISMATCH
00201 #define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE POLARSSL_ERR_X509_INVALID_SIGNATURE
00202 #define POLARSSL_ERR_X509_CERT_INVALID_SERIAL POLARSSL_ERR_X509_INVALID_SERIAL
00203 #define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION POLARSSL_ERR_X509_UNKNOWN_VERSION
00204
00205 inline int x509parse_serial_gets( char *buf, size_t size, const x509_buf *serial ) {
00206 return x509_serial_gets( buf, size, serial );
00207 }
00208 inline int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn ) {
00209 return x509_dn_gets( buf, size, dn );
00210 }
00211 inline int x509parse_time_expired( const x509_time *time ) {
00212 return x509_time_expired( time );
00213 }
00214 #endif
00215
00216 #if defined(POLARSSL_X509_CRT_PARSE_C)
00217 #define POLARSSL_X509_PARSE_C
00218 #include "x509_crt.h"
00219 typedef x509_crt x509_cert;
00220
00221 inline int x509parse_crt_der( x509_cert *chain, const unsigned char *buf,
00222 size_t buflen ) {
00223 return x509_crt_parse_der( chain, buf, buflen );
00224 }
00225 inline int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen ) {
00226 return x509_crt_parse( chain, buf, buflen );
00227 }
00228 inline int x509parse_crtfile( x509_cert *chain, const char *path ) {
00229 return x509_crt_parse_file( chain, path );
00230 }
00231 inline int x509parse_crtpath( x509_cert *chain, const char *path ) {
00232 return x509_crt_parse_path( chain, path );
00233 }
00234 inline int x509parse_cert_info( char *buf, size_t size, const char *prefix,
00235 const x509_cert *crt ) {
00236 return x509_crt_info( buf, size, prefix, crt );
00237 }
00238 inline int x509parse_verify( x509_cert *crt, x509_cert *trust_ca,
00239 x509_crl *ca_crl, const char *cn, int *flags,
00240 int (*f_vrfy)(void *, x509_cert *, int, int *),
00241 void *p_vrfy ) {
00242 return x509_crt_verify( crt, trust_ca, ca_crl, cn, flags, f_vrfy, p_vrfy );
00243 }
00244 inline int x509parse_revoked( const x509_cert *crt, const x509_crl *crl ) {
00245 return x509_crt_revoked( crt, crl );
00246 }
00247 inline void x509_free( x509_cert *crt ) {
00248 x509_crt_free( crt );
00249 }
00250 #endif
00251
00252 #if defined(POLARSSL_X509_CRL_PARSE_C)
00253 #define POLARSSL_X509_PARSE_C
00254 #include "x509_crl.h"
00255 inline int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen ) {
00256 return x509_crl_parse( chain, buf, buflen );
00257 }
00258 inline int x509parse_crlfile( x509_crl *chain, const char *path ) {
00259 return x509_crl_parse_file( chain, path );
00260 }
00261 inline int x509parse_crl_info( char *buf, size_t size, const char *prefix,
00262 const x509_crl *crl ) {
00263 return x509_crl_info( buf, size, prefix, crl );
00264 }
00265 #endif
00266
00267 #if defined(POLARSSL_X509_CSR_PARSE_C)
00268 #define POLARSSL_X509_PARSE_C
00269 #include "x509_csr.h"
00270 inline int x509parse_csr( x509_csr *csr, const unsigned char *buf, size_t buflen ) {
00271 return x509_csr_parse( csr, buf, buflen );
00272 }
00273 inline int x509parse_csrfile( x509_csr *csr, const char *path ) {
00274 return x509_csr_parse_file( csr, path );
00275 }
00276 inline int x509parse_csr_info( char *buf, size_t size, const char *prefix,
00277 const x509_csr *csr ) {
00278 return x509_csr_info( buf, size, prefix, csr );
00279 }
00280 #endif
00281
00282 #if defined(POLARSSL_SSL_TLS_C)
00283 #include "ssl_ciphersuites.h"
00284
00285 #define ssl_default_ciphersuites ssl_list_ciphersuites()
00286 #endif
00287
00288 #if defined(POLARSSL_PK_PARSE_C) && defined(POLARSSL_RSA_C)
00289 #include "rsa.h"
00290 #include "pk.h"
00291
00292 #define POLARSSL_ERR_X509_PASSWORD_MISMATCH POLARSSL_ERR_PK_PASSWORD_MISMATCH
00293 #define POLARSSL_ERR_X509_KEY_INVALID_FORMAT POLARSSL_ERR_PK_KEY_INVALID_FORMAT
00294 #define POLARSSL_ERR_X509_UNKNOWN_PK_ALG POLARSSL_ERR_PK_UNKNOWN_PK_ALG
00295 #define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY POLARSSL_ERR_PK_INVALID_PUBKEY
00296
00297 #if defined(POLARSSL_FS_IO)
00298 inline int x509parse_keyfile( rsa_context *rsa, const char *path,
00299 const char *pwd ) {
00300 int ret;
00301 pk_context pk;
00302 pk_init( &pk );
00303 ret = pk_parse_keyfile( &pk, path, pwd );
00304 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) )
00305 ret = POLARSSL_ERR_PK_TYPE_MISMATCH;
00306 if( ret == 0 )
00307 rsa_copy( rsa, pk_rsa( pk ) );
00308 else
00309 rsa_free( rsa );
00310 pk_free( &pk );
00311 return( ret );
00312 }
00313 inline int x509parse_public_keyfile( rsa_context *rsa, const char *path ) {
00314 int ret;
00315 pk_context pk;
00316 pk_init( &pk );
00317 ret = pk_parse_public_keyfile( &pk, path );
00318 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) )
00319 ret = POLARSSL_ERR_PK_TYPE_MISMATCH;
00320 if( ret == 0 )
00321 rsa_copy( rsa, pk_rsa( pk ) );
00322 else
00323 rsa_free( rsa );
00324 pk_free( &pk );
00325 return( ret );
00326 }
00327 #endif
00328
00329 inline int x509parse_key( rsa_context *rsa, const unsigned char *key,
00330 size_t keylen,
00331 const unsigned char *pwd, size_t pwdlen ) {
00332 int ret;
00333 pk_context pk;
00334 pk_init( &pk );
00335 ret = pk_parse_key( &pk, key, keylen, pwd, pwdlen );
00336 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) )
00337 ret = POLARSSL_ERR_PK_TYPE_MISMATCH;
00338 if( ret == 0 )
00339 rsa_copy( rsa, pk_rsa( pk ) );
00340 else
00341 rsa_free( rsa );
00342 pk_free( &pk );
00343 return( ret );
00344 }
00345
00346 inline int x509parse_public_key( rsa_context *rsa,
00347 const unsigned char *key, size_t keylen )
00348 {
00349 int ret;
00350 pk_context pk;
00351 pk_init( &pk );
00352 ret = pk_parse_public_key( &pk, key, keylen );
00353 if( ret == 0 && ! pk_can_do( &pk, POLARSSL_PK_RSA ) )
00354 ret = POLARSSL_ERR_PK_TYPE_MISMATCH;
00355 if( ret == 0 )
00356 rsa_copy( rsa, pk_rsa( pk ) );
00357 else
00358 rsa_free( rsa );
00359 pk_free( &pk );
00360 return( ret );
00361 }
00362 #endif
00363
00364 #if defined(POLARSSL_PK_WRITE_C) && defined(POLARSSL_RSA_C)
00365 #include "pk.h"
00366 inline int x509_write_pubkey_der( unsigned char *buf, size_t len, rsa_context *rsa ) {
00367 int ret;
00368 pk_context ctx;
00369 if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret );
00370 if( ( ret = rsa_copy( pk_rsa( ctx ), rsa ) ) != 0 ) return( ret );
00371 ret = pk_write_pubkey_der( &ctx, buf, len );
00372 pk_free( &ctx );
00373 return( ret );
00374 }
00375 inline int x509_write_key_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_key_der( &ctx, buf, len );
00381 pk_free( &ctx );
00382 return( ret );
00383 }
00384 #endif
00385 #endif