Skip to content

Commit

Permalink
1. change how the encryption and encryption contexts are declared (do…
Browse files Browse the repository at this point in the history
…es not change the result).

2. minor improvements to some of the test code
  • Loading branch information
BrianGladman committed Oct 2, 2018
1 parent d0fe2e5 commit ed6cdd3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
10 changes: 4 additions & 6 deletions aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 )
Expand Down
16 changes: 9 additions & 7 deletions aes_avs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)){
Expand Down Expand Up @@ -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);

Expand Down
20 changes: 7 additions & 13 deletions aestst.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ed6cdd3

Please sign in to comment.