From 6e0643762d119ac8dd3f9b84c25222a057a9da4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 19 Mar 2015 16:54:56 +0000 Subject: [PATCH] Reverse meaning of OID_CMP --- include/mbedtls/asn1.h | 6 ++---- library/pkcs5.c | 4 ++-- library/pkparse.c | 4 ++-- library/x509.c | 2 +- library/x509_crt.c | 4 ++-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/mbedtls/asn1.h b/include/mbedtls/asn1.h index 0bfa92934..01081ad16 100644 --- a/include/mbedtls/asn1.h +++ b/include/mbedtls/asn1.h @@ -99,12 +99,10 @@ * * Only works for 'defined' oid_str values (OID_HMAC_SHA1), you cannot use a * 'unsigned char *oid' here! - * - * Warning: returns true when the OIDs are equal (unlike memcmp)! */ #define OID_CMP(oid_str, oid_buf) \ - ( ( OID_SIZE(oid_str) == (oid_buf)->len ) && \ - memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) == 0 ) + ( ( OID_SIZE(oid_str) != (oid_buf)->len ) || \ + memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 ) #ifdef __cplusplus extern "C" { diff --git a/library/pkcs5.c b/library/pkcs5.c index 79d67e9a5..280453a1c 100644 --- a/library/pkcs5.c +++ b/library/pkcs5.c @@ -97,7 +97,7 @@ static int pkcs5_parse_pbkdf2_params( const asn1_buf *params, if( ( ret = asn1_get_alg_null( &p, end, &prf_alg_oid ) ) != 0 ) return( POLARSSL_ERR_PKCS5_INVALID_FORMAT + ret ); - if( !OID_CMP( OID_HMAC_SHA1, &prf_alg_oid ) ) + if( OID_CMP( OID_HMAC_SHA1, &prf_alg_oid ) != 0 ) return( POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE ); *md_type = POLARSSL_MD_SHA1; @@ -145,7 +145,7 @@ int pkcs5_pbes2( const asn1_buf *pbe_params, int mode, // Only PBKDF2 supported at the moment // - if( !OID_CMP( OID_PKCS5_PBKDF2, &kdf_alg_oid ) ) + if( OID_CMP( OID_PKCS5_PBKDF2, &kdf_alg_oid ) != 0 ) return( POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE ); if( ( ret = pkcs5_parse_pbkdf2_params( &kdf_alg_params, diff --git a/library/pkparse.c b/library/pkparse.c index 1529a9395..b42bf8b82 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -997,7 +997,7 @@ static int pk_parse_key_pkcs8_encrypted_der( decrypted = 1; } - else if( OID_CMP( OID_PKCS12_PBE_SHA1_RC4_128, &pbe_alg_oid ) ) + else if( OID_CMP( OID_PKCS12_PBE_SHA1_RC4_128, &pbe_alg_oid ) == 0 ) { if( ( ret = pkcs12_pbe_sha1_rc4_128( &pbe_params, PKCS12_PBE_DECRYPT, @@ -1018,7 +1018,7 @@ static int pk_parse_key_pkcs8_encrypted_der( else #endif /* POLARSSL_PKCS12_C */ #if defined(POLARSSL_PKCS5_C) - if( OID_CMP( OID_PKCS5_PBES2, &pbe_alg_oid ) ) + if( OID_CMP( OID_PKCS5_PBES2, &pbe_alg_oid ) == 0 ) { if( ( ret = pkcs5_pbes2( &pbe_params, PKCS5_DECRYPT, pwd, pwdlen, p, len, buf ) ) != 0 ) diff --git a/library/x509.c b/library/x509.c index c1fd8ad7d..33b1ac384 100644 --- a/library/x509.c +++ b/library/x509.c @@ -269,7 +269,7 @@ int x509_get_rsassa_pss_params( const x509_buf *params, return( ret ); /* Only MFG1 is recognised for now */ - if( ! OID_CMP( OID_MGF1, &alg_id ) ) + if( OID_CMP( OID_MGF1, &alg_id ) != 0 ) return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE + POLARSSL_ERR_OID_NOT_FOUND ); diff --git a/library/x509_crt.c b/library/x509_crt.c index 84e441506..8b9347364 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1417,7 +1417,7 @@ int x509_crt_check_extended_key_usage( const x509_crt *crt, return( 0 ); } - if( OID_CMP( OID_ANY_EXTENDED_KEY_USAGE, cur_oid ) ) + if( OID_CMP( OID_ANY_EXTENDED_KEY_USAGE, cur_oid ) == 0 ) return( 0 ); } @@ -1961,7 +1961,7 @@ int x509_crt_verify( x509_crt *crt, { while( name != NULL ) { - if( OID_CMP( OID_AT_CN, &name->oid ) ) + if( OID_CMP( OID_AT_CN, &name->oid ) == 0 ) { if( name->val.len == cn_len && x509_memcasecmp( name->val.p, cn, cn_len ) == 0 )