Factor out some common code

This commit is contained in:
Manuel Pégourié-Gonnard 2014-01-24 19:28:43 +01:00
parent 39868ee301
commit cf975a3857
6 changed files with 43 additions and 73 deletions

View File

@ -1,5 +1,8 @@
PolarSSL ChangeLog (Sorted per branch, date) PolarSSL ChangeLog (Sorted per branch, date)
TODO: bump SOVERSION
(internal-but-not-static function x509_get_sig_alg() changed prototype)
= PolarSSL 1.3 branch = PolarSSL 1.3 branch
Features Features
* Add CCM module and cipher mode to Cipher Layer * Add CCM module and cipher mode to Cipher Layer
@ -157,7 +160,6 @@ Bugfix
* Fix typo in rsa_copy() that impacted PKCS#1 v2 contexts * Fix typo in rsa_copy() that impacted PKCS#1 v2 contexts
* x509_get_current_time() uses localtime_r() to prevent thread issues * x509_get_current_time() uses localtime_r() to prevent thread issues
= PolarSSL 1.3.4 released on 2014-01-27
Features Features
* Support for the Koblitz curves: secp192k1, secp224k1, secp256k1 * Support for the Koblitz curves: secp192k1, secp224k1, secp256k1
* Support for RIPEMD-160 * Support for RIPEMD-160

View File

@ -284,8 +284,8 @@ int x509_get_rsassa_pss_params( const x509_buf *params,
int *salt_len, int *trailer_field ); int *salt_len, int *trailer_field );
#endif #endif
int x509_get_sig( unsigned char **p, const unsigned char *end, x509_buf *sig ); int x509_get_sig( unsigned char **p, const unsigned char *end, x509_buf *sig );
int x509_get_sig_alg( const x509_buf *sig_oid, md_type_t *md_alg, int x509_get_sig_alg( const x509_buf *sig_oid, const x509_buf *sig_params,
pk_type_t *pk_alg ); md_type_t *md_alg, pk_type_t *pk_alg );
int x509_get_time( unsigned char **p, const unsigned char *end, int x509_get_time( unsigned char **p, const unsigned char *end,
x509_time *time ); x509_time *time );
int x509_get_serial( unsigned char **p, const unsigned char *end, int x509_get_serial( unsigned char **p, const unsigned char *end,

View File

@ -547,14 +547,39 @@ int x509_get_sig( unsigned char **p, const unsigned char *end, x509_buf *sig )
return( 0 ); return( 0 );
} }
int x509_get_sig_alg( const x509_buf *sig_oid, md_type_t *md_alg, /*
pk_type_t *pk_alg ) * Get signature algorithm from alg OID and optional parameters
*/
int x509_get_sig_alg( const x509_buf *sig_oid, const x509_buf *sig_params,
md_type_t *md_alg, pk_type_t *pk_alg )
{ {
int ret = oid_get_sig_alg( sig_oid, md_alg, pk_alg ); int ret;
if( ret != 0 ) if( ( ret = oid_get_sig_alg( sig_oid, md_alg, pk_alg ) ) != 0 )
return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG + ret ); return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG + ret );
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
if( *pk_alg == POLARSSL_PK_RSASSA_PSS )
{
int salt_len, trailer_field;
md_type_t mgf_md;
/* Make sure params are valid */
ret = x509_get_rsassa_pss_params( sig_params,
md_alg, &mgf_md, &salt_len, &trailer_field );
if( ret != 0 )
return( ret );
}
else
#endif
{
/* Make sure parameters are absent or NULL */
if( ( sig_params->tag != ASN1_NULL && sig_params->tag != 0 ) ||
sig_params->len != 0 )
return( POLARSSL_ERR_X509_INVALID_ALG );
}
return( 0 ); return( 0 );
} }

View File

@ -397,35 +397,16 @@ int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen )
return( POLARSSL_ERR_X509_UNKNOWN_VERSION ); return( POLARSSL_ERR_X509_UNKNOWN_VERSION );
} }
if( ( ret = x509_get_sig_alg( &crl->sig_oid1, &crl->sig_md, if( ( ret = x509_get_sig_alg( &crl->sig_oid1, &sig_params,
&crl->sig_pk ) ) != 0 ) &crl->sig_md, &crl->sig_pk ) ) != 0 )
{ {
x509_crl_free( crl ); x509_crl_free( crl );
return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG ); return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG );
} }
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES) #if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
if( crl->sig_pk == POLARSSL_PK_RSASSA_PSS ) memcpy( &crl->sig_params, &sig_params, sizeof( x509_buf ) );
{
int salt_len, trailer_field;
md_type_t mgf_md;
/* Make sure params are valid */
ret = x509_get_rsassa_pss_params( &sig_params,
&crl->sig_md, &mgf_md, &salt_len, &trailer_field );
if( ret != 0 )
return( ret );
memcpy( &crl->sig_params, &sig_params, sizeof( x509_buf ) );
}
else
#endif #endif
{
/* Make sure parameters are absent or NULL */
if( ( sig_params.tag != ASN1_NULL && sig_params.tag != 0 ) ||
sig_params.len != 0 )
return( POLARSSL_ERR_X509_INVALID_ALG );
}
/* /*
* issuer Name * issuer Name

View File

@ -615,35 +615,16 @@ static int x509_crt_parse_der_core( x509_crt *crt, const unsigned char *buf,
return( POLARSSL_ERR_X509_UNKNOWN_VERSION ); return( POLARSSL_ERR_X509_UNKNOWN_VERSION );
} }
if( ( ret = x509_get_sig_alg( &crt->sig_oid1, &crt->sig_md, if( ( ret = x509_get_sig_alg( &crt->sig_oid1, &sig_params,
&crt->sig_pk ) ) != 0 ) &crt->sig_md, &crt->sig_pk ) ) != 0 )
{ {
x509_crt_free( crt ); x509_crt_free( crt );
return( ret ); return( ret );
} }
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES) #if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
if( crt->sig_pk == POLARSSL_PK_RSASSA_PSS ) memcpy( &crt->sig_params, &sig_params, sizeof( x509_buf ) );
{
int salt_len, trailer_field;
md_type_t mgf_md;
/* Make sure params are valid */
ret = x509_get_rsassa_pss_params( &sig_params,
&crt->sig_md, &mgf_md, &salt_len, &trailer_field );
if( ret != 0 )
return( ret );
memcpy( &crt->sig_params, &sig_params, sizeof( x509_buf ) );
}
else
#endif #endif
{
/* Make sure parameters are absent or NULL */
if( ( sig_params.tag != ASN1_NULL && sig_params.tag != 0 ) ||
sig_params.len != 0 )
return( POLARSSL_ERR_X509_INVALID_ALG );
}
/* /*
* issuer Name * issuer Name

View File

@ -254,35 +254,16 @@ int x509_csr_parse( x509_csr *csr, const unsigned char *buf, size_t buflen )
return( ret ); return( ret );
} }
if( ( ret = x509_get_sig_alg( &csr->sig_oid, &csr->sig_md, if( ( ret = x509_get_sig_alg( &csr->sig_oid, &sig_params,
&csr->sig_pk ) ) != 0 ) &csr->sig_md, &csr->sig_pk ) ) != 0 )
{ {
x509_csr_free( csr ); x509_csr_free( csr );
return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG ); return( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG );
} }
#if defined(POLARSSL_RSASSA_PSS_CERTIFICATES) #if defined(POLARSSL_RSASSA_PSS_CERTIFICATES)
if( csr->sig_pk == POLARSSL_PK_RSASSA_PSS ) memcpy( &csr->sig_params, &sig_params, sizeof( x509_buf ) );
{
int salt_len, trailer_field;
md_type_t mgf_md;
/* Make sure params are valid */
ret = x509_get_rsassa_pss_params( &sig_params,
&csr->sig_md, &mgf_md, &salt_len, &trailer_field );
if( ret != 0 )
return( ret );
memcpy( &csr->sig_params, &sig_params, sizeof( x509_buf ) );
}
else
#endif #endif
{
/* Make sure parameters are absent or NULL */
if( ( sig_params.tag != ASN1_NULL && sig_params.tag != 0 ) ||
sig_params.len != 0 )
return( POLARSSL_ERR_X509_INVALID_ALG );
}
if( ( ret = x509_get_sig( &p, end, &csr->sig ) ) != 0 ) if( ( ret = x509_get_sig( &p, end, &csr->sig ) ) != 0 )
{ {