From 2e9db8e9bf54f734c441cd07b10b880cfcb2f7da Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 22 Nov 2022 16:43:29 +0000 Subject: [PATCH] Use mbedtls_xor in DES Signed-off-by: Dave Rodgman --- library/des.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/library/des.c b/library/des.c index 65f5681cf..c56d4d4fe 100644 --- a/library/des.c +++ b/library/des.c @@ -635,7 +635,6 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, const unsigned char *input, unsigned char *output ) { - int i; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char temp[8]; @@ -646,8 +645,7 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, { while( length > 0 ) { - for( i = 0; i < 8; i++ ) - output[i] = (unsigned char)( input[i] ^ iv[i] ); + mbedtls_xor( output, input, iv, 8 ); ret = mbedtls_des_crypt_ecb( ctx, output, output ); if( ret != 0 ) @@ -668,8 +666,7 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, if( ret != 0 ) goto exit; - for( i = 0; i < 8; i++ ) - output[i] = (unsigned char)( output[i] ^ iv[i] ); + mbedtls_xor( output, output, iv, 8 ); memcpy( iv, temp, 8 ); @@ -741,7 +738,6 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, const unsigned char *input, unsigned char *output ) { - int i; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char temp[8]; @@ -752,8 +748,7 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, { while( length > 0 ) { - for( i = 0; i < 8; i++ ) - output[i] = (unsigned char)( input[i] ^ iv[i] ); + mbedtls_xor( output, input, iv, 8 ); ret = mbedtls_des3_crypt_ecb( ctx, output, output ); if( ret != 0 ) @@ -774,8 +769,7 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, if( ret != 0 ) goto exit; - for( i = 0; i < 8; i++ ) - output[i] = (unsigned char)( output[i] ^ iv[i] ); + mbedtls_xor( output, output, iv, 8 ); memcpy( iv, temp, 8 );