From c1999d57467112ad4bd0a40ee5e0264b4d9503c5 Mon Sep 17 00:00:00 2001 From: Werner Lewis Date: Tue, 5 Jul 2022 11:55:15 +0100 Subject: [PATCH] Add fallback when rk unaligned with padlock Signed-off-by: Werner Lewis --- library/padlock.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/padlock.c b/library/padlock.c index 2fb4e8342..a1287759e 100644 --- a/library/padlock.c +++ b/library/padlock.c @@ -82,7 +82,11 @@ int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, uint32_t *ctrl; unsigned char buf[256]; - rk = ctx->buf + ctx->rk_offset; + rk = ctx->buf + ctx->rk_offset; + + if( ( (long) rk & 15 ) != 0 ) + return( MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED ); + blk = MBEDTLS_PADLOCK_ALIGN16( buf ); memcpy( blk, input, 16 ); @@ -125,11 +129,13 @@ int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, uint32_t *ctrl; unsigned char buf[256]; + rk = ctx->buf + ctx->rk_offset; + if( ( (long) input & 15 ) != 0 || - ( (long) output & 15 ) != 0 ) + ( (long) output & 15 ) != 0 || + ( (long) rk & 15 ) != 0 ) return( MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED ); - rk = ctx->buf + ctx->rk_offset; iw = MBEDTLS_PADLOCK_ALIGN16( buf ); memcpy( iw, iv, 16 );