|
|
@@ -54,20 +54,20 @@
|
|
|
#ifndef GET_ULONG_LE
|
|
|
#define GET_ULONG_LE(n,b,i) \
|
|
|
{ \
|
|
|
- (n) = ( (unsigned long) (b)[(i) ] ) \
|
|
|
- | ( (unsigned long) (b)[(i) + 1] << 8 ) \
|
|
|
- | ( (unsigned long) (b)[(i) + 2] << 16 ) \
|
|
|
- | ( (unsigned long) (b)[(i) + 3] << 24 ); \
|
|
|
+ (n) = ( (uint32_t) (b)[(i) ] ) \
|
|
|
+ | ( (uint32_t) (b)[(i) + 1] << 8 ) \
|
|
|
+ | ( (uint32_t) (b)[(i) + 2] << 16 ) \
|
|
|
+ | ( (uint32_t) (b)[(i) + 3] << 24 ); \
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
#ifndef PUT_ULONG_LE
|
|
|
#define PUT_ULONG_LE(n,b,i) \
|
|
|
{ \
|
|
|
- (b)[(i) ] = (unsigned char) ( (n) ); \
|
|
|
- (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
|
|
|
- (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
|
|
|
- (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
|
|
|
+ (b)[(i) ] = (uint8_t) ( (n) ); \
|
|
|
+ (b)[(i) + 1] = (uint8_t) ( (n) >> 8 ); \
|
|
|
+ (b)[(i) + 2] = (uint8_t) ( (n) >> 16 ); \
|
|
|
+ (b)[(i) + 3] = (uint8_t) ( (n) >> 24 ); \
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
@@ -75,7 +75,7 @@
|
|
|
/*
|
|
|
* Forward S-box
|
|
|
*/
|
|
|
-static const unsigned char FSb[256] = {
|
|
|
+static const uint8_t FSb[256] = {
|
|
|
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
|
|
|
0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
|
|
|
0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
|
|
|
@@ -181,22 +181,22 @@ static const unsigned char FSb[256] = {
|
|
|
V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C)
|
|
|
|
|
|
#define V(a,b,c,d) 0x##a##b##c##d
|
|
|
-static const unsigned long FT0[256] = { FT };
|
|
|
+static const uint32_t FT0[256] = { FT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
#define V(a,b,c,d) 0x##b##c##d##a
|
|
|
-static const unsigned long FT1[256] = { FT };
|
|
|
+static const uint32_t FT1[256] = { FT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
#define V(a,b,c,d) 0x##c##d##a##b
|
|
|
-static const unsigned long FT2[256] = { FT };
|
|
|
+static const uint32_t FT2[256] = { FT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
#define V(a,b,c,d) 0x##d##a##b##c
|
|
|
-static const unsigned long FT3[256] = { FT };
|
|
|
+static const uint32_t FT3[256] = { FT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
@@ -205,7 +205,7 @@ static const unsigned long FT3[256] = { FT };
|
|
|
/*
|
|
|
* Reverse S-box
|
|
|
*/
|
|
|
-static const unsigned char RSb[256] = {
|
|
|
+static const uint8_t RSb[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,
|
|
|
@@ -311,22 +311,22 @@ static const unsigned char RSb[256] = {
|
|
|
V(61,84,CB,7B), V(70,B6,32,D5), V(74,5C,6C,48), V(42,57,B8,D0)
|
|
|
|
|
|
#define V(a,b,c,d) 0x##a##b##c##d
|
|
|
-static const unsigned long RT0[256] = { RT };
|
|
|
+static const uint32_t RT0[256] = { RT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
#define V(a,b,c,d) 0x##b##c##d##a
|
|
|
-static const unsigned long RT1[256] = { RT };
|
|
|
+static const uint32_t RT1[256] = { RT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
#define V(a,b,c,d) 0x##c##d##a##b
|
|
|
-static const unsigned long RT2[256] = { RT };
|
|
|
+static const uint32_t RT2[256] = { RT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
#define V(a,b,c,d) 0x##d##a##b##c
|
|
|
-static const unsigned long RT3[256] = { RT };
|
|
|
+static const uint32_t RT3[256] = { RT };
|
|
|
|
|
|
#undef V
|
|
|
|
|
|
@@ -335,7 +335,7 @@ static const unsigned long RT3[256] = { RT };
|
|
|
/*
|
|
|
* Round constants
|
|
|
*/
|
|
|
-static const unsigned long RCON[10] = {
|
|
|
+static const uint32_t RCON[10] = {
|
|
|
0x00000001, 0x00000002, 0x00000004, 0x00000008,
|
|
|
0x00000010, 0x00000020, 0x00000040, 0x00000080,
|
|
|
0x0000001B, 0x00000036
|
|
|
@@ -346,25 +346,25 @@ static const unsigned long RCON[10] = {
|
|
|
/*
|
|
|
* Forward S-box & tables
|
|
|
*/
|
|
|
-static unsigned char FSb[256];
|
|
|
-static unsigned long FT0[256];
|
|
|
-static unsigned long FT1[256];
|
|
|
-static unsigned long FT2[256];
|
|
|
-static unsigned long FT3[256];
|
|
|
+static uint8_t FSb[256];
|
|
|
+static uint32_t FT0[256];
|
|
|
+static uint32_t FT1[256];
|
|
|
+static uint32_t FT2[256];
|
|
|
+static uint32_t FT3[256];
|
|
|
|
|
|
/*
|
|
|
* Reverse S-box & tables
|
|
|
*/
|
|
|
-static unsigned char RSb[256];
|
|
|
-static unsigned long RT0[256];
|
|
|
-static unsigned long RT1[256];
|
|
|
-static unsigned long RT2[256];
|
|
|
-static unsigned long RT3[256];
|
|
|
+static uint8_t RSb[256];
|
|
|
+static uint32_t RT0[256];
|
|
|
+static uint32_t RT1[256];
|
|
|
+static uint32_t RT2[256];
|
|
|
+static uint32_t RT3[256];
|
|
|
|
|
|
/*
|
|
|
* Round constants
|
|
|
*/
|
|
|
-static unsigned long RCON[10];
|
|
|
+static uint32_t RCON[10];
|
|
|
|
|
|
/*
|
|
|
* Tables generation code
|
|
|
@@ -394,7 +394,7 @@ static void aes_gen_tables(void)
|
|
|
* calculate the round constants
|
|
|
*/
|
|
|
for (i = 0, x = 1; i < 10; i++) {
|
|
|
- RCON[i] = (unsigned long)x;
|
|
|
+ RCON[i] = (uint32_t)x;
|
|
|
x = XTIME(x) & 0xFF;
|
|
|
}
|
|
|
|
|
|
@@ -417,8 +417,8 @@ static void aes_gen_tables(void)
|
|
|
y = ((y << 1) | (y >> 7)) & 0xFF;
|
|
|
x ^= y ^ 0x63;
|
|
|
|
|
|
- FSb[i] = (unsigned char)x;
|
|
|
- RSb[x] = (unsigned char)i;
|
|
|
+ FSb[i] = (uint8_t)x;
|
|
|
+ RSb[x] = (uint8_t)i;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -429,9 +429,9 @@ static void aes_gen_tables(void)
|
|
|
y = XTIME(x) & 0xFF;
|
|
|
z = (y ^ x) & 0xFF;
|
|
|
|
|
|
- FT0[i] = ((unsigned long)y) ^
|
|
|
- ((unsigned long)x << 8) ^
|
|
|
- ((unsigned long)x << 16) ^ ((unsigned long)z << 24);
|
|
|
+ FT0[i] = ((uint32_t)y) ^
|
|
|
+ ((uint32_t)x << 8) ^
|
|
|
+ ((uint32_t)x << 16) ^ ((uint32_t)z << 24);
|
|
|
|
|
|
FT1[i] = ROTL8(FT0[i]);
|
|
|
FT2[i] = ROTL8(FT1[i]);
|
|
|
@@ -439,10 +439,10 @@ static void aes_gen_tables(void)
|
|
|
|
|
|
x = RSb[i];
|
|
|
|
|
|
- RT0[i] = ((unsigned long)MUL(0x0E, x)) ^
|
|
|
- ((unsigned long)MUL(0x09, x) << 8) ^
|
|
|
- ((unsigned long)MUL(0x0D, x) << 16) ^
|
|
|
- ((unsigned long)MUL(0x0B, x) << 24);
|
|
|
+ RT0[i] = ((uint32_t)MUL(0x0E, x)) ^
|
|
|
+ ((uint32_t)MUL(0x09, x) << 8) ^
|
|
|
+ ((uint32_t)MUL(0x0D, x) << 16) ^
|
|
|
+ ((uint32_t)MUL(0x0B, x) << 24);
|
|
|
|
|
|
RT1[i] = ROTL8(RT0[i]);
|
|
|
RT2[i] = ROTL8(RT1[i]);
|
|
|
@@ -455,10 +455,10 @@ static void aes_gen_tables(void)
|
|
|
/*
|
|
|
* AES key schedule (encryption)
|
|
|
*/
|
|
|
-void tiny_aes_setkey_enc(tiny_aes_context * ctx, unsigned char *key, int keysize)
|
|
|
+void tiny_aes_setkey_enc(tiny_aes_context * ctx, uint8_t *key, int keysize)
|
|
|
{
|
|
|
int i;
|
|
|
- unsigned long *RK;
|
|
|
+ uint32_t *RK;
|
|
|
|
|
|
#if !defined(TINY_CRYPT_AES_ROM_TABLES)
|
|
|
if (aes_init_done == 0) {
|
|
|
@@ -492,10 +492,10 @@ void tiny_aes_setkey_enc(tiny_aes_context * ctx, unsigned char *key, int keysize
|
|
|
|
|
|
for (i = 0; i < 10; i++, RK += 4) {
|
|
|
RK[4] = RK[0] ^ RCON[i] ^
|
|
|
- ((unsigned long)FSb[(RK[3] >> 8) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(RK[3] >> 16) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(RK[3] >> 24) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(RK[3]) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(RK[3] >> 8) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(RK[3] >> 16) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(RK[3] >> 24) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(RK[3]) & 0xFF] << 24);
|
|
|
|
|
|
RK[5] = RK[1] ^ RK[4];
|
|
|
RK[6] = RK[2] ^ RK[5];
|
|
|
@@ -507,10 +507,10 @@ void tiny_aes_setkey_enc(tiny_aes_context * ctx, unsigned char *key, int keysize
|
|
|
|
|
|
for (i = 0; i < 8; i++, RK += 6) {
|
|
|
RK[6] = RK[0] ^ RCON[i] ^
|
|
|
- ((unsigned long)FSb[(RK[5] >> 8) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(RK[5] >> 16) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(RK[5] >> 24) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(RK[5]) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(RK[5] >> 8) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(RK[5] >> 16) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(RK[5] >> 24) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(RK[5]) & 0xFF] << 24);
|
|
|
|
|
|
RK[7] = RK[1] ^ RK[6];
|
|
|
RK[8] = RK[2] ^ RK[7];
|
|
|
@@ -524,20 +524,20 @@ void tiny_aes_setkey_enc(tiny_aes_context * ctx, unsigned char *key, int keysize
|
|
|
|
|
|
for (i = 0; i < 7; i++, RK += 8) {
|
|
|
RK[8] = RK[0] ^ RCON[i] ^
|
|
|
- ((unsigned long)FSb[(RK[7] >> 8) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(RK[7] >> 16) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(RK[7] >> 24) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(RK[7]) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(RK[7] >> 8) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(RK[7] >> 16) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(RK[7] >> 24) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(RK[7]) & 0xFF] << 24);
|
|
|
|
|
|
RK[9] = RK[1] ^ RK[8];
|
|
|
RK[10] = RK[2] ^ RK[9];
|
|
|
RK[11] = RK[3] ^ RK[10];
|
|
|
|
|
|
RK[12] = RK[4] ^
|
|
|
- ((unsigned long)FSb[(RK[11]) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(RK[11] >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(RK[11] >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(RK[11] >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(RK[11]) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(RK[11] >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(RK[11] >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(RK[11] >> 24) & 0xFF] << 24);
|
|
|
|
|
|
RK[13] = RK[5] ^ RK[12];
|
|
|
RK[14] = RK[6] ^ RK[13];
|
|
|
@@ -554,12 +554,12 @@ void tiny_aes_setkey_enc(tiny_aes_context * ctx, unsigned char *key, int keysize
|
|
|
/*
|
|
|
* AES key schedule (decryption)
|
|
|
*/
|
|
|
-void tiny_aes_setkey_dec(tiny_aes_context * ctx, unsigned char *key, int keysize)
|
|
|
+void tiny_aes_setkey_dec(tiny_aes_context * ctx, uint8_t *key, int keysize)
|
|
|
{
|
|
|
int i, j;
|
|
|
tiny_aes_context cty;
|
|
|
- unsigned long *RK;
|
|
|
- unsigned long *SK;
|
|
|
+ uint32_t *RK;
|
|
|
+ uint32_t *SK;
|
|
|
|
|
|
switch (keysize) {
|
|
|
case 128:
|
|
|
@@ -652,10 +652,10 @@ void tiny_aes_setkey_dec(tiny_aes_context * ctx, unsigned char *key, int keysize
|
|
|
* AES-ECB block encryption/decryption
|
|
|
*/
|
|
|
void tiny_aes_crypt_ecb(tiny_aes_context * ctx,
|
|
|
- int mode, unsigned char input[16], unsigned char output[16])
|
|
|
+ int mode, uint8_t input[16], uint8_t output[16])
|
|
|
{
|
|
|
int i;
|
|
|
- unsigned long *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
|
|
|
+ uint32_t *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
|
|
|
|
|
|
RK = ctx->rk;
|
|
|
|
|
|
@@ -677,28 +677,28 @@ void tiny_aes_crypt_ecb(tiny_aes_context * ctx,
|
|
|
AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
|
|
|
|
|
|
X0 = *RK++ ^
|
|
|
- ((unsigned long)RSb[(Y0) & 0xFF]) ^
|
|
|
- ((unsigned long)RSb[(Y3 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)RSb[(Y2 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)RSb[(Y1 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)RSb[(Y0) & 0xFF]) ^
|
|
|
+ ((uint32_t)RSb[(Y3 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)RSb[(Y2 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)RSb[(Y1 >> 24) & 0xFF] << 24);
|
|
|
|
|
|
X1 = *RK++ ^
|
|
|
- ((unsigned long)RSb[(Y1) & 0xFF]) ^
|
|
|
- ((unsigned long)RSb[(Y0 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)RSb[(Y3 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)RSb[(Y2 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)RSb[(Y1) & 0xFF]) ^
|
|
|
+ ((uint32_t)RSb[(Y0 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)RSb[(Y3 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)RSb[(Y2 >> 24) & 0xFF] << 24);
|
|
|
|
|
|
X2 = *RK++ ^
|
|
|
- ((unsigned long)RSb[(Y2) & 0xFF]) ^
|
|
|
- ((unsigned long)RSb[(Y1 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)RSb[(Y0 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)RSb[(Y3 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)RSb[(Y2) & 0xFF]) ^
|
|
|
+ ((uint32_t)RSb[(Y1 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)RSb[(Y0 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)RSb[(Y3 >> 24) & 0xFF] << 24);
|
|
|
|
|
|
X3 = *RK++ ^
|
|
|
- ((unsigned long)RSb[(Y3) & 0xFF]) ^
|
|
|
- ((unsigned long)RSb[(Y2 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)RSb[(Y1 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)RSb[(Y0 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)RSb[(Y3) & 0xFF]) ^
|
|
|
+ ((uint32_t)RSb[(Y2 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)RSb[(Y1 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)RSb[(Y0 >> 24) & 0xFF] << 24);
|
|
|
} else { /* AES_ENCRYPT */
|
|
|
for (i = (ctx->nr >> 1) - 1; i > 0; i--) {
|
|
|
AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
|
|
|
@@ -708,28 +708,28 @@ void tiny_aes_crypt_ecb(tiny_aes_context * ctx,
|
|
|
AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
|
|
|
|
|
|
X0 = *RK++ ^
|
|
|
- ((unsigned long)FSb[(Y0) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(Y1 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(Y2 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(Y3 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(Y0) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(Y1 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(Y2 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(Y3 >> 24) & 0xFF] << 24);
|
|
|
|
|
|
X1 = *RK++ ^
|
|
|
- ((unsigned long)FSb[(Y1) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(Y2 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(Y3 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(Y0 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(Y1) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(Y2 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(Y3 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(Y0 >> 24) & 0xFF] << 24);
|
|
|
|
|
|
X2 = *RK++ ^
|
|
|
- ((unsigned long)FSb[(Y2) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(Y3 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(Y0 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(Y1 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(Y2) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(Y3 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(Y0 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(Y1 >> 24) & 0xFF] << 24);
|
|
|
|
|
|
X3 = *RK++ ^
|
|
|
- ((unsigned long)FSb[(Y3) & 0xFF]) ^
|
|
|
- ((unsigned long)FSb[(Y0 >> 8) & 0xFF] << 8) ^
|
|
|
- ((unsigned long)FSb[(Y1 >> 16) & 0xFF] << 16) ^
|
|
|
- ((unsigned long)FSb[(Y2 >> 24) & 0xFF] << 24);
|
|
|
+ ((uint32_t)FSb[(Y3) & 0xFF]) ^
|
|
|
+ ((uint32_t)FSb[(Y0 >> 8) & 0xFF] << 8) ^
|
|
|
+ ((uint32_t)FSb[(Y1 >> 16) & 0xFF] << 16) ^
|
|
|
+ ((uint32_t)FSb[(Y2 >> 24) & 0xFF] << 24);
|
|
|
}
|
|
|
|
|
|
PUT_ULONG_LE(X0, output, 0);
|
|
|
@@ -744,11 +744,11 @@ void tiny_aes_crypt_ecb(tiny_aes_context * ctx,
|
|
|
void tiny_aes_crypt_cbc(tiny_aes_context * ctx,
|
|
|
int mode,
|
|
|
int length,
|
|
|
- unsigned char iv[16],
|
|
|
- unsigned char *input, unsigned char *output)
|
|
|
+ uint8_t iv[16],
|
|
|
+ uint8_t *input, uint8_t *output)
|
|
|
{
|
|
|
int i;
|
|
|
- unsigned char temp[16];
|
|
|
+ uint8_t temp[16];
|
|
|
|
|
|
if (mode == AES_DECRYPT) {
|
|
|
while (length > 0) {
|
|
|
@@ -756,7 +756,7 @@ void tiny_aes_crypt_cbc(tiny_aes_context * ctx,
|
|
|
tiny_aes_crypt_ecb(ctx, mode, input, output);
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
- output[i] = (unsigned char)(output[i] ^ iv[i]);
|
|
|
+ output[i] = (uint8_t)(output[i] ^ iv[i]);
|
|
|
|
|
|
memcpy(iv, temp, 16);
|
|
|
|
|
|
@@ -767,7 +767,7 @@ void tiny_aes_crypt_cbc(tiny_aes_context * ctx,
|
|
|
} else {
|
|
|
while (length > 0) {
|
|
|
for (i = 0; i < 16; i++)
|
|
|
- output[i] = (unsigned char)(input[i] ^ iv[i]);
|
|
|
+ output[i] = (uint8_t)(input[i] ^ iv[i]);
|
|
|
|
|
|
tiny_aes_crypt_ecb(ctx, mode, output, output);
|
|
|
memcpy(iv, output, 16);
|
|
|
@@ -786,8 +786,8 @@ void tiny_aes_crypt_cfb128(tiny_aes_context * ctx,
|
|
|
int mode,
|
|
|
int length,
|
|
|
int *iv_off,
|
|
|
- unsigned char iv[16],
|
|
|
- unsigned char *input, unsigned char *output)
|
|
|
+ uint8_t iv[16],
|
|
|
+ uint8_t *input, uint8_t *output)
|
|
|
{
|
|
|
int c, n = *iv_off;
|
|
|
|
|
|
@@ -797,8 +797,8 @@ void tiny_aes_crypt_cfb128(tiny_aes_context * ctx,
|
|
|
tiny_aes_crypt_ecb(ctx, AES_ENCRYPT, iv, iv);
|
|
|
|
|
|
c = *input++;
|
|
|
- *output++ = (unsigned char)(c ^ iv[n]);
|
|
|
- iv[n] = (unsigned char)c;
|
|
|
+ *output++ = (uint8_t)(c ^ iv[n]);
|
|
|
+ iv[n] = (uint8_t)c;
|
|
|
|
|
|
n = (n + 1) & 0x0F;
|
|
|
}
|
|
|
@@ -807,7 +807,7 @@ void tiny_aes_crypt_cfb128(tiny_aes_context * ctx,
|
|
|
if (n == 0)
|
|
|
tiny_aes_crypt_ecb(ctx, AES_ENCRYPT, iv, iv);
|
|
|
|
|
|
- iv[n] = *output++ = (unsigned char)(iv[n] ^ *input++);
|
|
|
+ iv[n] = *output++ = (uint8_t)(iv[n] ^ *input++);
|
|
|
|
|
|
n = (n + 1) & 0x0F;
|
|
|
}
|