- Added handling of missing POLARSSL_MD5_C define and POLARSSL_SHA1_c define

This commit is contained in:
Paul Bakker 2009-10-03 19:58:52 +00:00
parent ccff1671ae
commit de4d2eae95

View file

@ -1495,7 +1495,7 @@ int x509parse_crlfile( x509_crl *chain, char *path )
return( ret ); return( ret );
} }
#if defined(POLARSSL_DES_C) #if defined(POLARSSL_DES_C) && defined(POLARSSL_MD5_C)
/* /*
* Read a 16-byte hex string and convert it to binary * Read a 16-byte hex string and convert it to binary
*/ */
@ -1569,7 +1569,12 @@ int x509parse_key( rsa_context *rsa, unsigned char *buf, int buflen,
int ret, len, enc; int ret, len, enc;
unsigned char *s1, *s2; unsigned char *s1, *s2;
unsigned char *p, *end; unsigned char *p, *end;
#if defined(POLARSSL_DES_C) && defined(POLARSSL_MD5_C)
unsigned char des3_iv[8]; unsigned char des3_iv[8];
#else
((void) pwd);
((void) pwdlen);
#endif
s1 = (unsigned char *) strstr( (char *) buf, s1 = (unsigned char *) strstr( (char *) buf,
"-----BEGIN RSA PRIVATE KEY-----" ); "-----BEGIN RSA PRIVATE KEY-----" );
@ -1591,7 +1596,7 @@ int x509parse_key( rsa_context *rsa, unsigned char *buf, int buflen,
if( memcmp( s1, "Proc-Type: 4,ENCRYPTED", 22 ) == 0 ) if( memcmp( s1, "Proc-Type: 4,ENCRYPTED", 22 ) == 0 )
{ {
#if defined(POLARSSL_DES_C) #if defined(POLARSSL_DES_C) && defined(POLARSSL_MD5_C)
enc++; enc++;
s1 += 22; s1 += 22;
@ -1634,7 +1639,7 @@ int x509parse_key( rsa_context *rsa, unsigned char *buf, int buflen,
if( enc != 0 ) if( enc != 0 )
{ {
#if defined(POLARSSL_DES_C) #if defined(POLARSSL_DES_C) && defined(POLARSSL_MD5_C)
if( pwd == NULL ) if( pwd == NULL )
{ {
free( buf ); free( buf );
@ -2126,6 +2131,11 @@ int x509parse_revoked( x509_cert *crt, x509_crl *crl )
return( 0 ); return( 0 );
} }
/*
* Wrapper for x509 hashes.
*
* @param out Buffer to receive the hash (Should be at least 64 bytes)
*/
static void x509_hash( unsigned char *in, int len, int alg, static void x509_hash( unsigned char *in, int len, int alg,
unsigned char *out ) unsigned char *out )
{ {
@ -2137,8 +2147,12 @@ static void x509_hash( unsigned char *in, int len, int alg,
#if defined(POLARSSL_MD4_C) #if defined(POLARSSL_MD4_C)
case SIG_RSA_MD4 : md4( in, len, out ); break; case SIG_RSA_MD4 : md4( in, len, out ); break;
#endif #endif
#if defined(POLARSSL_MD5_C)
case SIG_RSA_MD5 : md5( in, len, out ); break; case SIG_RSA_MD5 : md5( in, len, out ); break;
#endif
#if defined(POLARSSL_SHA1_C)
case SIG_RSA_SHA1 : sha1( in, len, out ); break; case SIG_RSA_SHA1 : sha1( in, len, out ); break;
#endif
#if defined(POLARSSL_SHA2_C) #if defined(POLARSSL_SHA2_C)
case SIG_RSA_SHA224 : sha2( in, len, out, 1 ); break; case SIG_RSA_SHA224 : sha2( in, len, out, 1 ); break;
case SIG_RSA_SHA256 : sha2( in, len, out, 0 ); break; case SIG_RSA_SHA256 : sha2( in, len, out, 0 ); break;
@ -2148,7 +2162,7 @@ static void x509_hash( unsigned char *in, int len, int alg,
case SIG_RSA_SHA512 : sha4( in, len, out, 0 ); break; case SIG_RSA_SHA512 : sha4( in, len, out, 0 ); break;
#endif #endif
default: default:
memset( out, '\xFF', len ); memset( out, '\xFF', 64 );
break; break;
} }
} }
@ -2447,6 +2461,7 @@ void x509_crl_free( x509_crl *crl )
*/ */
int x509_self_test( int verbose ) int x509_self_test( int verbose )
{ {
#if defined(POLARSSL_MD5_C)
int ret, i, j; int ret, i, j;
x509_cert cacert; x509_cert cacert;
x509_cert clicert; x509_cert clicert;
@ -2515,6 +2530,10 @@ int x509_self_test( int verbose )
rsa_free( &rsa ); rsa_free( &rsa );
return( 0 ); return( 0 );
#else
((void) verbose);
return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE );
#endif
} }
#endif #endif