diff options
| author | John Hurst <jhurst@cinecert.com> | 2021-01-10 11:47:26 -0800 |
|---|---|---|
| committer | John Hurst <jhurst@cinecert.com> | 2021-01-10 11:47:26 -0800 |
| commit | 45a0fe9c7270cd3d9bb69068e664c725857df02a (patch) | |
| tree | eb98981da9a72f24ebeccbcbd9285dfc42e1431b /src/KM_aes.cpp | |
| parent | 1ff6109984f5c1496b84875342447fe150769197 (diff) | |
Altered int8 decalrations to use common asdcp typenames.
Diffstat (limited to 'src/KM_aes.cpp')
| -rw-r--r-- | src/KM_aes.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/KM_aes.cpp b/src/KM_aes.cpp index bad03e5..53b3913 100644 --- a/src/KM_aes.cpp +++ b/src/KM_aes.cpp @@ -28,12 +28,12 @@ using namespace Kumu; /* Private variables: */ /*****************************************************************************/ // state - array holding the intermediate results during decryption. -typedef uint8_t state_t[4][4]; +typedef ui8_t state_t[4][4]; // The lookup-tables are marked const so they can be placed in read-only storage instead of RAM // The numbers below can be computed dynamically trading ROM for RAM - // This can be useful in (embedded) bootloader applications, where ROM is often limited. -static const uint8_t sbox[256] = { +static const ui8_t sbox[256] = { //0 1 2 3 4 5 6 7 8 9 A B C D E F 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, @@ -52,7 +52,7 @@ static const uint8_t sbox[256] = { 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; -static const uint8_t rsbox[256] = { +static const ui8_t rsbox[256] = { 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, @@ -72,7 +72,7 @@ static const uint8_t rsbox[256] = { // The round constant word array, Rcon[i], contains the values given by // 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] = { +static const ui8_t Rcon[11] = { 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; /* @@ -90,14 +90,14 @@ static const uint8_t Rcon[11] = { /* Private functions: */ /*****************************************************************************/ /* -static uint8_t getSBoxValue(uint8_t num) +static ui8_t getSBoxValue(ui8_t num) { return sbox[num]; } */ #define getSBoxValue(num) (sbox[(num)]) /* -static uint8_t getSBoxInvert(uint8_t num) +static ui8_t getSBoxInvert(ui8_t num) { return rsbox[num]; } @@ -106,10 +106,10 @@ static uint8_t getSBoxInvert(uint8_t num) // This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states. static void -KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) +KeyExpansion(ui8_t* RoundKey, const ui8_t* Key) { unsigned i, j, k; - uint8_t tempa[4]; // Used for the column/row operations + ui8_t tempa[4]; // Used for the column/row operations // The first round key is the key itself. for (i = 0; i < Nk; ++i) @@ -139,7 +139,7 @@ KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) // Function RotWord() { - const uint8_t u8tmp = tempa[0]; + const ui8_t u8tmp = tempa[0]; tempa[0] = tempa[1]; tempa[1] = tempa[2]; tempa[2] = tempa[3]; @@ -170,7 +170,7 @@ KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) // void -Kumu::AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key) +Kumu::AES_init_ctx(struct AES_ctx* ctx, const ui8_t* key) { KeyExpansion(ctx->RoundKey, key); } @@ -178,9 +178,9 @@ Kumu::AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key) // This function adds the round key to state. // The round key is added to the state by an XOR function. static void -AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey) +AddRoundKey(ui8_t round, state_t* state, const ui8_t* RoundKey) { - uint8_t i,j; + ui8_t i,j; for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) @@ -195,7 +195,7 @@ AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey) static void SubBytes(state_t* state) { - uint8_t i, j; + ui8_t i, j; for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) @@ -211,7 +211,7 @@ SubBytes(state_t* state) static void ShiftRows(state_t* state) { - uint8_t temp; + ui8_t temp; // Rotate first row 1 columns to left temp = (*state)[0][1]; @@ -237,8 +237,8 @@ ShiftRows(state_t* state) (*state)[1][3] = temp; } -static uint8_t -xtime(uint8_t x) +static ui8_t +xtime(ui8_t x) { return ((x<<1) ^ (((x>>7) & 1) * 0x1b)); } @@ -247,8 +247,8 @@ xtime(uint8_t x) static void MixColumns(state_t* state) { - uint8_t i; - uint8_t Tmp, Tm, t; + ui8_t i; + ui8_t Tmp, Tm, t; for (i = 0; i < 4; ++i) { t = (*state)[i][0]; @@ -278,7 +278,7 @@ static void InvMixColumns(state_t* state) { int i; - uint8_t a, b, c, d; + ui8_t a, b, c, d; for (i = 0; i < 4; ++i) { a = (*state)[i][0]; @@ -299,7 +299,7 @@ InvMixColumns(state_t* state) static void InvSubBytes(state_t* state) { - uint8_t i, j; + ui8_t i, j; for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) @@ -312,7 +312,7 @@ InvSubBytes(state_t* state) static void InvShiftRows(state_t* state) { - uint8_t temp; + ui8_t temp; // Rotate first row 1 columns to right temp = (*state)[3][1]; @@ -341,9 +341,9 @@ InvShiftRows(state_t* state) // Cipher is the main function that encrypts the PlainText. static void -Cipher(state_t* state, const uint8_t* RoundKey) +Cipher(state_t* state, const ui8_t* RoundKey) { - uint8_t round = 0; + ui8_t round = 0; // Add the First round key to the state before starting the rounds. AddRoundKey(0, state, RoundKey); @@ -367,9 +367,9 @@ Cipher(state_t* state, const uint8_t* RoundKey) } static void -InvCipher(state_t* state, const uint8_t* RoundKey) +InvCipher(state_t* state, const ui8_t* RoundKey) { - uint8_t round = 0; + ui8_t round = 0; // Add the First round key to the state before starting the rounds. AddRoundKey(Nr, state, RoundKey); @@ -397,14 +397,14 @@ InvCipher(state_t* state, const uint8_t* RoundKey) /*****************************************************************************/ void -Kumu::AES_encrypt(const struct Kumu::AES_ctx* ctx, uint8_t* buf) +Kumu::AES_encrypt(const struct Kumu::AES_ctx* ctx, ui8_t* buf) { // The next function call encrypts the PlainText with the Key using AES algorithm. Cipher((state_t*)buf, ctx->RoundKey); } void -Kumu::AES_decrypt(const struct Kumu::AES_ctx* ctx, uint8_t* buf) +Kumu::AES_decrypt(const struct Kumu::AES_ctx* ctx, ui8_t* buf) { // The next function call decrypts the PlainText with the Key using AES algorithm. InvCipher((state_t*)buf, ctx->RoundKey); |
