From 0dbd87f84d6e4af4e60cdc3aa500c57bf2eaaeb7 Mon Sep 17 00:00:00 2001 From: kokke Date: Mon, 4 Dec 2017 20:47:58 +0100 Subject: Update aes.c --- aes.c | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/aes.c b/aes.c index 087c628..0b4e764 100644 --- a/aes.c +++ b/aes.c @@ -44,7 +44,7 @@ NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0) /*****************************************************************************/ // The number of columns comprising a state in AES. This is a constant in AES. Value=4 #define Nb 4 -#define BLOCKLEN 16 //Block length in bytes AES is 128b block only +#define BLOCKLEN 16 // Block length in bytes AES is 128b block only #if defined(AES256) && (AES256 == 1) #define Nk 8 @@ -130,7 +130,7 @@ static const uint8_t rsbox[256] = { 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d }; // The round constant word array, Rcon[i], contains the values given by -// x to th e power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8) +// x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8) static const uint8_t Rcon[11] = { 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; @@ -142,28 +142,8 @@ static const uint8_t Rcon[11] = { * * "Only the first some of these constants are actually used – up to rcon[10] for AES-128 (as 11 round keys are needed), * up to rcon[8] for AES-192, up to rcon[7] for AES-256. rcon[0] is not used in AES algorithm." - * - * ... which is why the full array below has been 'disabled' below. */ -#if 0 -static const uint8_t Rcon[256] = { - 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, - 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, - 0x72, 0xe4, 0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 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, - 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, - 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d }; -#endif + /*****************************************************************************/ /* Private functions: */ @@ -198,10 +178,10 @@ static void KeyExpansion(void) for (; i < Nb * (Nr + 1); ++i) { { - tempa[0]=RoundKey[(i-1) * 4 + 0]; - tempa[1]=RoundKey[(i-1) * 4 + 1]; - tempa[2]=RoundKey[(i-1) * 4 + 2]; - tempa[3]=RoundKey[(i-1) * 4 + 3]; + tempa[0] = RoundKey[(i-1) * 4 + 0]; + tempa[1] = RoundKey[(i-1) * 4 + 1]; + tempa[2] = RoundKey[(i-1) * 4 + 2]; + tempa[3] = RoundKey[(i-1) * 4 + 3]; } if (i % Nk == 0) @@ -259,7 +239,7 @@ static void AddRoundKey(uint8_t round) { for (j = 0; j < 4; ++j) { - (*state)[i][j] ^= RoundKey[round * Nb * 4 + i * Nb + j]; + (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j]; } } } -- cgit v1.2.3