Move length check into mbedtls_x509_memcasecmp()
At every occasion where we're using `mbedtls_x509_memcasecmp()` we're
checking that the two buffer lengths coincide before making the call.
This commit saves a few bytes of code by moving this length check
to `mbedtls_x509_memcasecmp()`.
diff --git a/library/x509_crt.c b/library/x509_crt.c
index c9bc163..5959c0a 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -254,8 +254,8 @@
if( cn_idx == 0 )
return( -1 );
- if( cn_len - cn_idx == buf_len - 1 &&
- mbedtls_x509_memcasecmp( buf + 1, cn + cn_idx, buf_len - 1 ) == 0 )
+ if( mbedtls_x509_memcasecmp( buf + 1, cn + cn_idx,
+ buf_len - 1, cn_len - cn_idx ) == 0 )
{
return( 0 );
}
@@ -2387,11 +2387,8 @@
size_t cn_len )
{
/* Try exact match */
- if( buflen == cn_len &&
- mbedtls_x509_memcasecmp( cn, buf, cn_len ) == 0 )
- {
+ if( mbedtls_x509_memcasecmp( cn, buf, buflen, cn_len ) == 0 )
return( 0 );
- }
/* try wildcard match */
if( x509_check_wildcard( cn, cn_len, buf, buflen ) == 0 )