From ed6cdd318bc146a593a50881c35594850042ca86 Mon Sep 17 00:00:00 2001 From: Brian Gladman Date: Tue, 2 Oct 2018 23:15:17 +0100 Subject: [PATCH] 1. change how the encryption and encryption contexts are declared (does not change the result). 2. minor improvements to some of the test code --- aes.h | 10 ++++------ aes_avs.c | 16 +++++++++------- aestst.h | 20 +++++++------------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/aes.h b/aes.h index cd879f6..62484c4 100644 --- a/aes.h +++ b/aes.h @@ -15,7 +15,7 @@ This software is provided 'as is' with no explicit or implied warranties in respect of its operation, including, but not limited to, correctness and fitness for purpose. --------------------------------------------------------------------------- -Issue Date: 02/08/2018 +Issue Date: 02/09/2018 This file contains the definitions required to use AES in C. See aesopt.h for optimisation details. @@ -94,12 +94,10 @@ typedef union typedef struct ALIGNED_(16) { uint32_t ks[KS_LENGTH]; aes_inf inf; -} aes_encrypt_ctx; +} aes_crypt_ctx; -typedef struct ALIGNED_(16) -{ uint32_t ks[KS_LENGTH]; - aes_inf inf; -} aes_decrypt_ctx; +typedef aes_crypt_ctx aes_encrypt_ctx; +typedef aes_crypt_ctx aes_decrypt_ctx; #ifdef _MSC_VER # pragma warning( default : 4324 ) diff --git a/aes_avs.c b/aes_avs.c index d61feef..c09ff64 100644 --- a/aes_avs.c +++ b/aes_avs.c @@ -112,7 +112,7 @@ void do_decrypt(mode mm, const unsigned char key[], unsigned char iv[], } void do_mct_encrypt(mode mm, const unsigned char key[], unsigned char iv[], - unsigned char pt[], unsigned char ct[], int key_len, int block_len) + unsigned char pt[], unsigned char ct[], int key_len) { aes_encrypt_ctx ctx[1]; unsigned char tmp[BLOCK_SIZE]; int i; @@ -151,7 +151,7 @@ void do_mct_encrypt(mode mm, const unsigned char key[], unsigned char iv[], } void do_mct_decrypt(mode mm, const unsigned char key[], unsigned char iv[], - unsigned char ct[], unsigned char pt[], int key_len, int block_len) + unsigned char ct[], unsigned char pt[], int key_len) { aes_decrypt_ctx ctx[1]; unsigned char tmp[BLOCK_SIZE]; int i; @@ -234,10 +234,10 @@ void run_aes_avs_test(mode mm, type tt) pt_len = block_in(pt, inbuf); if(pt_len == ct_len) { - if(tt != MCT) - do_decrypt(mm, key, iv, ct, rt, key_len, pt_len); + if(tt == MCT) + do_mct_decrypt(mm, key, iv, ct, rt, key_len); else - do_mct_decrypt(mm, key, iv, ct, rt, key_len, pt_len); + do_decrypt(mm, key, iv, ct, rt, key_len, pt_len); if(memcmp(pt, rt, pt_len)){ printf("\nError on file %s, on test %i", path, cnt); ++err; @@ -249,7 +249,7 @@ void run_aes_avs_test(mode mm, type tt) if(ct_len == pt_len) { if(tt == MCT) - do_mct_encrypt(mm, key, iv, pt, rt, key_len, pt_len); + do_mct_encrypt(mm, key, iv, pt, rt, key_len); else do_encrypt(mm, key, iv, pt, rt, key_len, pt_len); if(memcmp(ct, rt, pt_len)){ @@ -277,13 +277,15 @@ int main(void) #if defined( DLL_IMPORT ) && defined( DLL_DYNAMIC_LOAD ) HINSTANCE h_dll; + printf("Testing with the AES DLL (with dynamic loading)"); if(!(h_dll = init_dll(&fn))) return -1; #else + printf("Testing with the AES static Linbrary"); aes_init(); #endif -for( i = 0 ; i < 4 ; ++i ) + for( i = 0 ; i < 4 ; ++i ) for( j = 0 ; j < 6 ; ++j) run_aes_avs_test((mode)i, (type)j); diff --git a/aestst.h b/aestst.h index 2054947..a192f38 100644 --- a/aestst.h +++ b/aestst.h @@ -72,19 +72,13 @@ typedef AES_RETURN g_dec_blk(const unsigned char*, unsigned char*, const aes_dec typedef AES_RETURN g_talign(unsigned int n); typedef AES_RETURN g_reset(const aes_encrypt_ctx[1]); -typedef AES_RETURN g_enc1(const unsigned char*, unsigned char*, int, - const aes_encrypt_ctx[1]); -typedef AES_RETURN g_dec1(const unsigned char*, unsigned char*, int, - const aes_decrypt_ctx[1]); -typedef AES_RETURN g_enc2(const unsigned char*, unsigned char*, int, - unsigned char*, const aes_encrypt_ctx[1]); -typedef AES_RETURN g_dec2(const unsigned char*, unsigned char*, int, - unsigned char*, const aes_decrypt_ctx[1]); -typedef AES_RETURN g_enc3(const unsigned char*, unsigned char*, int, - unsigned char*, aes_encrypt_ctx[1]); -typedef void cif(unsigned char*); -typedef AES_RETURN g_enc4(const unsigned char*, unsigned char*, int, - unsigned char*, cif, aes_encrypt_ctx[1]); +typedef AES_RETURN g_enc1(const unsigned char*, unsigned char*, int, const aes_encrypt_ctx[1]); +typedef AES_RETURN g_dec1(const unsigned char*, unsigned char*, int, const aes_decrypt_ctx[1]); +typedef AES_RETURN g_enc2(const unsigned char*, unsigned char*, int, unsigned char*, const aes_encrypt_ctx[1]); +typedef AES_RETURN g_dec2(const unsigned char*, unsigned char*, int, unsigned char*, const aes_decrypt_ctx[1]); +typedef AES_RETURN g_enc3(const unsigned char*, unsigned char*, int, unsigned char*, aes_encrypt_ctx[1]); +typedef void (*cif)(unsigned char*); +typedef AES_RETURN g_enc4(const unsigned char*, unsigned char*, int, unsigned char*, cif, aes_encrypt_ctx[1]); typedef struct // initialised with subroutine addresses when the DLL is loaded {