From 12e18369e86be6b5550f33a3ad7f0796db4a4be8 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 7 May 2021 00:55:52 -0700 Subject: [PATCH] aes: Check aes_padlock_ace > 0 before calling padlock Sometime user may forget to call mbedtls_aes_setkey_enc or mbedtls_aes_setkey_dec before mbedtls_aes_crypt_ecb and then the code normally crash inside the assembly code. With this patch, the code will stop inside the C source code which is more convenient to locate the problem. Signed-off-by: Xiang Xiao Change-Id: I0e1d6b219f8709f8acaee5f345344335fc82fed3 --- library/aes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/aes.c b/library/aes.c index b36b81c73c..c10d4ae2d0 100644 --- a/library/aes.c +++ b/library/aes.c @@ -1023,7 +1023,7 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, #endif #if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) - if( aes_padlock_ace ) + if( aes_padlock_ace > 0) { if( mbedtls_padlock_xcryptecb( ctx, mode, input, output ) == 0 ) return( 0 ); @@ -1065,7 +1065,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); #if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) - if( aes_padlock_ace ) + if( aes_padlock_ace > 0 ) { if( mbedtls_padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 ) return( 0 );