diff options
author | Matt Johnston <matt@ucc.asn.au> | 2018-02-09 21:44:05 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2018-02-09 21:44:05 +0800 |
commit | 4f2eb1914bdac3ed3ee504ad86061281dbe0d074 (patch) | |
tree | 078293375c3f3ee2d485cf9559a08d65d460786a /libtomcrypt/src/ciphers/aes/aes.c | |
parent | d72f50ff3284e15124a0f233c26339229fe305ac (diff) |
Update to libtomcrypt 1.18.1, merged with Dropbear changes
Diffstat (limited to 'libtomcrypt/src/ciphers/aes/aes.c')
-rw-r--r-- | libtomcrypt/src/ciphers/aes/aes.c | 50 |
1 files changed, 13 insertions, 37 deletions
diff --git a/libtomcrypt/src/ciphers/aes/aes.c b/libtomcrypt/src/ciphers/aes/aes.c index 3481fe2..4d74a9d 100644 --- a/libtomcrypt/src/ciphers/aes/aes.c +++ b/libtomcrypt/src/ciphers/aes/aes.c @@ -5,8 +5,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ /* AES implementation by Tom St Denis @@ -50,7 +48,7 @@ const struct ltc_cipher_descriptor rijndael_desc = 6, 16, 32, 16, 10, SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; #endif @@ -60,7 +58,7 @@ const struct ltc_cipher_descriptor aes_desc = 6, 16, 32, 16, 10, SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; #else @@ -76,7 +74,7 @@ const struct ltc_cipher_descriptor rijndael_enc_desc = 6, 16, 32, 16, 10, SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; const struct ltc_cipher_descriptor aes_enc_desc = @@ -85,11 +83,12 @@ const struct ltc_cipher_descriptor aes_enc_desc = 6, 16, 32, 16, 10, SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; #endif +#define __LTC_AES_TAB_C__ #include "aes_tab.c" static ulong32 setup_mix(ulong32 temp) @@ -149,9 +148,6 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s LOAD32H(rk[2], key + 8); LOAD32H(rk[3], key + 12); if (keylen == 16) { - #ifndef ENCRYPT_ONLY - j = 44; - #endif for (;;) { temp = rk[3]; rk[4] = rk[0] ^ setup_mix(temp) ^ rcon[i]; @@ -164,9 +160,6 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s rk += 4; } } else if (keylen == 24) { - #ifndef ENCRYPT_ONLY - j = 52; - #endif LOAD32H(rk[4], key + 16); LOAD32H(rk[5], key + 20); for (;;) { @@ -187,9 +180,6 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s rk += 6; } } else if (keylen == 32) { - #ifndef ENCRYPT_ONLY - j = 60; - #endif LOAD32H(rk[4], key + 16); LOAD32H(rk[5], key + 20); LOAD32H(rk[6], key + 24); @@ -216,13 +206,14 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s } } else { /* this can't happen */ + /* coverity[dead_error_line] */ return CRYPT_ERROR; } #ifndef ENCRYPT_ONLY /* setup the inverse key now */ rk = skey->rijndael.dK; - rrk = skey->rijndael.eK + j - 4; + rrk = skey->rijndael.eK + (28 + keylen) - 4; /* apply the inverse MixColumn transform to all round keys but the first and the last: */ /* copy first */ @@ -697,23 +688,8 @@ int ECB_TEST(void) rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key); rijndael_ecb_decrypt(tmp[0], tmp[1], &key); - if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) { -#if 0 - printf("\n\nTest %d failed\n", i); - if (XMEMCMP(tmp[0], tests[i].ct, 16)) { - printf("CT: "); - for (i = 0; i < 16; i++) { - printf("%02x ", tmp[0][i]); - } - printf("\n"); - } else { - printf("PT: "); - for (i = 0; i < 16; i++) { - printf("%02x ", tmp[1][i]); - } - printf("\n"); - } -#endif + if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "AES Encrypt", i) || + compare_testvector(tmp[1], 16, tests[i].pt, 16, "AES Decrypt", i)) { return CRYPT_FAIL_TESTVECTOR; } @@ -735,7 +711,7 @@ int ECB_TEST(void) */ void ECB_DONE(symmetric_key *skey) { - (void)skey; + LTC_UNUSED_PARAM(skey); } @@ -765,6 +741,6 @@ int ECB_KS(int *keysize) #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ |