Fix several alignment problems in this implementation due to its use of
word32 pointers to access data stored in word8 arrays: * align transformation tables on 32-bit boundaries, * align key schedule on 32-bit boundary, * align temporaries on 32-bit boundaries, * align plaintext and ciphertext used in round transformations on 32-bit boundaries.
This commit is contained in:
parent
a842e90102
commit
5c9e69f795
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: boxes-fst.dat,v 1.3 2001/02/21 21:39:53 jdolecek Exp $ */
|
||||
/* $NetBSD: boxes-fst.dat,v 1.4 2001/05/22 23:45:41 kleink Exp $ */
|
||||
/* $KAME: boxes-fst.dat,v 1.5 2000/10/02 17:14:26 itojun Exp $ */
|
||||
|
||||
const word8 S[256] = {
|
||||
|
@ -41,7 +41,13 @@ static const word8 Si[256] = {
|
|||
};
|
||||
#endif /* INTERMEDIATE_VALUE_KAT */
|
||||
|
||||
static const word8 T1[256][4] = {
|
||||
union xtab {
|
||||
word32 xt32[256];
|
||||
word8 xt8[256][4];
|
||||
};
|
||||
|
||||
static const union xtab xT1 = {
|
||||
.xt8 = {
|
||||
{0xc6,0x63,0x63,0xa5}, {0xf8,0x7c,0x7c,0x84}, {0xee,0x77,0x77,0x99}, {0xf6,0x7b,0x7b,0x8d},
|
||||
{0xff,0xf2,0xf2,0x0d}, {0xd6,0x6b,0x6b,0xbd}, {0xde,0x6f,0x6f,0xb1}, {0x91,0xc5,0xc5,0x54},
|
||||
{0x60,0x30,0x30,0x50}, {0x02,0x01,0x01,0x03}, {0xce,0x67,0x67,0xa9}, {0x56,0x2b,0x2b,0x7d},
|
||||
|
@ -106,9 +112,12 @@ static const word8 T1[256][4] = {
|
|||
{0x65,0xbf,0xbf,0xda}, {0xd7,0xe6,0xe6,0x31}, {0x84,0x42,0x42,0xc6}, {0xd0,0x68,0x68,0xb8},
|
||||
{0x82,0x41,0x41,0xc3}, {0x29,0x99,0x99,0xb0}, {0x5a,0x2d,0x2d,0x77}, {0x1e,0x0f,0x0f,0x11},
|
||||
{0x7b,0xb0,0xb0,0xcb}, {0xa8,0x54,0x54,0xfc}, {0x6d,0xbb,0xbb,0xd6}, {0x2c,0x16,0x16,0x3a}
|
||||
}
|
||||
};
|
||||
#define T1 xT1.xt8
|
||||
|
||||
static const word8 T2[256][4] = {
|
||||
static const union xtab xT2 = {
|
||||
.xt8 = {
|
||||
{0xa5,0xc6,0x63,0x63}, {0x84,0xf8,0x7c,0x7c}, {0x99,0xee,0x77,0x77}, {0x8d,0xf6,0x7b,0x7b},
|
||||
{0x0d,0xff,0xf2,0xf2}, {0xbd,0xd6,0x6b,0x6b}, {0xb1,0xde,0x6f,0x6f}, {0x54,0x91,0xc5,0xc5},
|
||||
{0x50,0x60,0x30,0x30}, {0x03,0x02,0x01,0x01}, {0xa9,0xce,0x67,0x67}, {0x7d,0x56,0x2b,0x2b},
|
||||
|
@ -173,9 +182,12 @@ static const word8 T2[256][4] = {
|
|||
{0xda,0x65,0xbf,0xbf}, {0x31,0xd7,0xe6,0xe6}, {0xc6,0x84,0x42,0x42}, {0xb8,0xd0,0x68,0x68},
|
||||
{0xc3,0x82,0x41,0x41}, {0xb0,0x29,0x99,0x99}, {0x77,0x5a,0x2d,0x2d}, {0x11,0x1e,0x0f,0x0f},
|
||||
{0xcb,0x7b,0xb0,0xb0}, {0xfc,0xa8,0x54,0x54}, {0xd6,0x6d,0xbb,0xbb}, {0x3a,0x2c,0x16,0x16}
|
||||
}
|
||||
};
|
||||
#define T2 xT2.xt8
|
||||
|
||||
static const word8 T3[256][4] = {
|
||||
static const union xtab xT3 = {
|
||||
.xt8 = {
|
||||
{0x63,0xa5,0xc6,0x63}, {0x7c,0x84,0xf8,0x7c}, {0x77,0x99,0xee,0x77}, {0x7b,0x8d,0xf6,0x7b},
|
||||
{0xf2,0x0d,0xff,0xf2}, {0x6b,0xbd,0xd6,0x6b}, {0x6f,0xb1,0xde,0x6f}, {0xc5,0x54,0x91,0xc5},
|
||||
{0x30,0x50,0x60,0x30}, {0x01,0x03,0x02,0x01}, {0x67,0xa9,0xce,0x67}, {0x2b,0x7d,0x56,0x2b},
|
||||
|
@ -240,9 +252,12 @@ static const word8 T3[256][4] = {
|
|||
{0xbf,0xda,0x65,0xbf}, {0xe6,0x31,0xd7,0xe6}, {0x42,0xc6,0x84,0x42}, {0x68,0xb8,0xd0,0x68},
|
||||
{0x41,0xc3,0x82,0x41}, {0x99,0xb0,0x29,0x99}, {0x2d,0x77,0x5a,0x2d}, {0x0f,0x11,0x1e,0x0f},
|
||||
{0xb0,0xcb,0x7b,0xb0}, {0x54,0xfc,0xa8,0x54}, {0xbb,0xd6,0x6d,0xbb}, {0x16,0x3a,0x2c,0x16}
|
||||
}
|
||||
};
|
||||
#define T3 xT3.xt8
|
||||
|
||||
static const word8 T4[256][4] = {
|
||||
static const union xtab xT4 = {
|
||||
.xt8 = {
|
||||
{0x63,0x63,0xa5,0xc6}, {0x7c,0x7c,0x84,0xf8}, {0x77,0x77,0x99,0xee}, {0x7b,0x7b,0x8d,0xf6},
|
||||
{0xf2,0xf2,0x0d,0xff}, {0x6b,0x6b,0xbd,0xd6}, {0x6f,0x6f,0xb1,0xde}, {0xc5,0xc5,0x54,0x91},
|
||||
{0x30,0x30,0x50,0x60}, {0x01,0x01,0x03,0x02}, {0x67,0x67,0xa9,0xce}, {0x2b,0x2b,0x7d,0x56},
|
||||
|
@ -307,9 +322,12 @@ static const word8 T4[256][4] = {
|
|||
{0xbf,0xbf,0xda,0x65}, {0xe6,0xe6,0x31,0xd7}, {0x42,0x42,0xc6,0x84}, {0x68,0x68,0xb8,0xd0},
|
||||
{0x41,0x41,0xc3,0x82}, {0x99,0x99,0xb0,0x29}, {0x2d,0x2d,0x77,0x5a}, {0x0f,0x0f,0x11,0x1e},
|
||||
{0xb0,0xb0,0xcb,0x7b}, {0x54,0x54,0xfc,0xa8}, {0xbb,0xbb,0xd6,0x6d}, {0x16,0x16,0x3a,0x2c}
|
||||
}
|
||||
};
|
||||
#define T4 xT4.xt8
|
||||
|
||||
static const word8 T5[256][4] = {
|
||||
static const union xtab xT5 = {
|
||||
.xt8 = {
|
||||
{0x51,0xf4,0xa7,0x50}, {0x7e,0x41,0x65,0x53}, {0x1a,0x17,0xa4,0xc3}, {0x3a,0x27,0x5e,0x96},
|
||||
{0x3b,0xab,0x6b,0xcb}, {0x1f,0x9d,0x45,0xf1}, {0xac,0xfa,0x58,0xab}, {0x4b,0xe3,0x03,0x93},
|
||||
{0x20,0x30,0xfa,0x55}, {0xad,0x76,0x6d,0xf6}, {0x88,0xcc,0x76,0x91}, {0xf5,0x02,0x4c,0x25},
|
||||
|
@ -374,9 +392,12 @@ static const word8 T5[256][4] = {
|
|||
{0x16,0x1d,0xc3,0x72}, {0xbc,0xe2,0x25,0x0c}, {0x28,0x3c,0x49,0x8b}, {0xff,0x0d,0x95,0x41},
|
||||
{0x39,0xa8,0x01,0x71}, {0x08,0x0c,0xb3,0xde}, {0xd8,0xb4,0xe4,0x9c}, {0x64,0x56,0xc1,0x90},
|
||||
{0x7b,0xcb,0x84,0x61}, {0xd5,0x32,0xb6,0x70}, {0x48,0x6c,0x5c,0x74}, {0xd0,0xb8,0x57,0x42}
|
||||
}
|
||||
};
|
||||
#define T5 xT5.xt8
|
||||
|
||||
static const word8 T6[256][4] = {
|
||||
static const union xtab xT6 = {
|
||||
.xt8 = {
|
||||
{0x50,0x51,0xf4,0xa7}, {0x53,0x7e,0x41,0x65}, {0xc3,0x1a,0x17,0xa4}, {0x96,0x3a,0x27,0x5e},
|
||||
{0xcb,0x3b,0xab,0x6b}, {0xf1,0x1f,0x9d,0x45}, {0xab,0xac,0xfa,0x58}, {0x93,0x4b,0xe3,0x03},
|
||||
{0x55,0x20,0x30,0xfa}, {0xf6,0xad,0x76,0x6d}, {0x91,0x88,0xcc,0x76}, {0x25,0xf5,0x02,0x4c},
|
||||
|
@ -441,9 +462,12 @@ static const word8 T6[256][4] = {
|
|||
{0x72,0x16,0x1d,0xc3}, {0x0c,0xbc,0xe2,0x25}, {0x8b,0x28,0x3c,0x49}, {0x41,0xff,0x0d,0x95},
|
||||
{0x71,0x39,0xa8,0x01}, {0xde,0x08,0x0c,0xb3}, {0x9c,0xd8,0xb4,0xe4}, {0x90,0x64,0x56,0xc1},
|
||||
{0x61,0x7b,0xcb,0x84}, {0x70,0xd5,0x32,0xb6}, {0x74,0x48,0x6c,0x5c}, {0x42,0xd0,0xb8,0x57}
|
||||
}
|
||||
};
|
||||
#define T6 xT6.xt8
|
||||
|
||||
static const word8 T7[256][4] = {
|
||||
static const union xtab xT7 = {
|
||||
.xt8 = {
|
||||
{0xa7,0x50,0x51,0xf4}, {0x65,0x53,0x7e,0x41}, {0xa4,0xc3,0x1a,0x17}, {0x5e,0x96,0x3a,0x27},
|
||||
{0x6b,0xcb,0x3b,0xab}, {0x45,0xf1,0x1f,0x9d}, {0x58,0xab,0xac,0xfa}, {0x03,0x93,0x4b,0xe3},
|
||||
{0xfa,0x55,0x20,0x30}, {0x6d,0xf6,0xad,0x76}, {0x76,0x91,0x88,0xcc}, {0x4c,0x25,0xf5,0x02},
|
||||
|
@ -508,9 +532,12 @@ static const word8 T7[256][4] = {
|
|||
{0xc3,0x72,0x16,0x1d}, {0x25,0x0c,0xbc,0xe2}, {0x49,0x8b,0x28,0x3c}, {0x95,0x41,0xff,0x0d},
|
||||
{0x01,0x71,0x39,0xa8}, {0xb3,0xde,0x08,0x0c}, {0xe4,0x9c,0xd8,0xb4}, {0xc1,0x90,0x64,0x56},
|
||||
{0x84,0x61,0x7b,0xcb}, {0xb6,0x70,0xd5,0x32}, {0x5c,0x74,0x48,0x6c}, {0x57,0x42,0xd0,0xb8}
|
||||
}
|
||||
};
|
||||
#define T7 xT7.xt8
|
||||
|
||||
static const word8 T8[256][4] = {
|
||||
static const union xtab xT8 = {
|
||||
.xt8 = {
|
||||
{0xf4,0xa7,0x50,0x51}, {0x41,0x65,0x53,0x7e}, {0x17,0xa4,0xc3,0x1a}, {0x27,0x5e,0x96,0x3a},
|
||||
{0xab,0x6b,0xcb,0x3b}, {0x9d,0x45,0xf1,0x1f}, {0xfa,0x58,0xab,0xac}, {0xe3,0x03,0x93,0x4b},
|
||||
{0x30,0xfa,0x55,0x20}, {0x76,0x6d,0xf6,0xad}, {0xcc,0x76,0x91,0x88}, {0x02,0x4c,0x25,0xf5},
|
||||
|
@ -575,7 +602,9 @@ static const word8 T8[256][4] = {
|
|||
{0x1d,0xc3,0x72,0x16}, {0xe2,0x25,0x0c,0xbc}, {0x3c,0x49,0x8b,0x28}, {0x0d,0x95,0x41,0xff},
|
||||
{0xa8,0x01,0x71,0x39}, {0x0c,0xb3,0xde,0x08}, {0xb4,0xe4,0x9c,0xd8}, {0x56,0xc1,0x90,0x64},
|
||||
{0xcb,0x84,0x61,0x7b}, {0x32,0xb6,0x70,0xd5}, {0x6c,0x5c,0x74,0x48}, {0xb8,0x57,0x42,0xd0}
|
||||
}
|
||||
};
|
||||
#define T8 xT8.xt8
|
||||
|
||||
static const word8 S5[256] = {
|
||||
0x52,0x09,0x6a,0xd5,
|
||||
|
@ -644,7 +673,8 @@ static const word8 S5[256] = {
|
|||
0x55,0x21,0x0c,0x7d
|
||||
};
|
||||
|
||||
static const word8 U1[256][4] = {
|
||||
static const union xtab xU1 = {
|
||||
.xt8 = {
|
||||
{0x00,0x00,0x00,0x00}, {0x0e,0x09,0x0d,0x0b}, {0x1c,0x12,0x1a,0x16}, {0x12,0x1b,0x17,0x1d},
|
||||
{0x38,0x24,0x34,0x2c}, {0x36,0x2d,0x39,0x27}, {0x24,0x36,0x2e,0x3a}, {0x2a,0x3f,0x23,0x31},
|
||||
{0x70,0x48,0x68,0x58}, {0x7e,0x41,0x65,0x53}, {0x6c,0x5a,0x72,0x4e}, {0x62,0x53,0x7f,0x45},
|
||||
|
@ -709,9 +739,12 @@ static const word8 U1[256][4] = {
|
|||
{0xef,0x15,0xe8,0xe6}, {0xe1,0x1c,0xe5,0xed}, {0xf3,0x07,0xf2,0xf0}, {0xfd,0x0e,0xff,0xfb},
|
||||
{0xa7,0x79,0xb4,0x92}, {0xa9,0x70,0xb9,0x99}, {0xbb,0x6b,0xae,0x84}, {0xb5,0x62,0xa3,0x8f},
|
||||
{0x9f,0x5d,0x80,0xbe}, {0x91,0x54,0x8d,0xb5}, {0x83,0x4f,0x9a,0xa8}, {0x8d,0x46,0x97,0xa3}
|
||||
}
|
||||
};
|
||||
#define U1 xU1.xt8
|
||||
|
||||
static const word8 U2[256][4] = {
|
||||
static const union xtab xU2 = {
|
||||
.xt8 = {
|
||||
{0x00,0x00,0x00,0x00}, {0x0b,0x0e,0x09,0x0d}, {0x16,0x1c,0x12,0x1a}, {0x1d,0x12,0x1b,0x17},
|
||||
{0x2c,0x38,0x24,0x34}, {0x27,0x36,0x2d,0x39}, {0x3a,0x24,0x36,0x2e}, {0x31,0x2a,0x3f,0x23},
|
||||
{0x58,0x70,0x48,0x68}, {0x53,0x7e,0x41,0x65}, {0x4e,0x6c,0x5a,0x72}, {0x45,0x62,0x53,0x7f},
|
||||
|
@ -776,9 +809,12 @@ static const word8 U2[256][4] = {
|
|||
{0xe6,0xef,0x15,0xe8}, {0xed,0xe1,0x1c,0xe5}, {0xf0,0xf3,0x07,0xf2}, {0xfb,0xfd,0x0e,0xff},
|
||||
{0x92,0xa7,0x79,0xb4}, {0x99,0xa9,0x70,0xb9}, {0x84,0xbb,0x6b,0xae}, {0x8f,0xb5,0x62,0xa3},
|
||||
{0xbe,0x9f,0x5d,0x80}, {0xb5,0x91,0x54,0x8d}, {0xa8,0x83,0x4f,0x9a}, {0xa3,0x8d,0x46,0x97}
|
||||
}
|
||||
};
|
||||
#define U2 xU2.xt8
|
||||
|
||||
static const word8 U3[256][4] = {
|
||||
static const union xtab xU3 = {
|
||||
.xt8 = {
|
||||
{0x00,0x00,0x00,0x00}, {0x0d,0x0b,0x0e,0x09}, {0x1a,0x16,0x1c,0x12}, {0x17,0x1d,0x12,0x1b},
|
||||
{0x34,0x2c,0x38,0x24}, {0x39,0x27,0x36,0x2d}, {0x2e,0x3a,0x24,0x36}, {0x23,0x31,0x2a,0x3f},
|
||||
{0x68,0x58,0x70,0x48}, {0x65,0x53,0x7e,0x41}, {0x72,0x4e,0x6c,0x5a}, {0x7f,0x45,0x62,0x53},
|
||||
|
@ -843,9 +879,12 @@ static const word8 U3[256][4] = {
|
|||
{0xe8,0xe6,0xef,0x15}, {0xe5,0xed,0xe1,0x1c}, {0xf2,0xf0,0xf3,0x07}, {0xff,0xfb,0xfd,0x0e},
|
||||
{0xb4,0x92,0xa7,0x79}, {0xb9,0x99,0xa9,0x70}, {0xae,0x84,0xbb,0x6b}, {0xa3,0x8f,0xb5,0x62},
|
||||
{0x80,0xbe,0x9f,0x5d}, {0x8d,0xb5,0x91,0x54}, {0x9a,0xa8,0x83,0x4f}, {0x97,0xa3,0x8d,0x46}
|
||||
}
|
||||
};
|
||||
#define U3 xU3.xt8
|
||||
|
||||
static const word8 U4[256][4] = {
|
||||
static const union xtab xU4 = {
|
||||
.xt8 = {
|
||||
{0x00,0x00,0x00,0x00}, {0x09,0x0d,0x0b,0x0e}, {0x12,0x1a,0x16,0x1c}, {0x1b,0x17,0x1d,0x12},
|
||||
{0x24,0x34,0x2c,0x38}, {0x2d,0x39,0x27,0x36}, {0x36,0x2e,0x3a,0x24}, {0x3f,0x23,0x31,0x2a},
|
||||
{0x48,0x68,0x58,0x70}, {0x41,0x65,0x53,0x7e}, {0x5a,0x72,0x4e,0x6c}, {0x53,0x7f,0x45,0x62},
|
||||
|
@ -910,7 +949,9 @@ static const word8 U4[256][4] = {
|
|||
{0x15,0xe8,0xe6,0xef}, {0x1c,0xe5,0xed,0xe1}, {0x07,0xf2,0xf0,0xf3}, {0x0e,0xff,0xfb,0xfd},
|
||||
{0x79,0xb4,0x92,0xa7}, {0x70,0xb9,0x99,0xa9}, {0x6b,0xae,0x84,0xbb}, {0x62,0xa3,0x8f,0xb5},
|
||||
{0x5d,0x80,0xbe,0x9f}, {0x54,0x8d,0xb5,0x91}, {0x4f,0x9a,0xa8,0x83}, {0x46,0x97,0xa3,0x8d}
|
||||
}
|
||||
};
|
||||
#define U4 xU4.xt8
|
||||
|
||||
static const word32 rcon[30] = {
|
||||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rijndael-alg-fst.c,v 1.2 2000/10/02 17:19:15 itojun Exp $ */
|
||||
/* $NetBSD: rijndael-alg-fst.c,v 1.3 2001/05/22 23:45:41 kleink Exp $ */
|
||||
/* $KAME: rijndael-alg-fst.c,v 1.6 2000/10/02 17:14:26 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -25,7 +25,11 @@ int rijndaelKeySched(word8 k[MAXKC][4], word8 W[MAXROUNDS+1][4][4], int ROUNDS)
|
|||
* The number of calculations depends on keyBits and blockBits
|
||||
*/
|
||||
int j, r, t, rconpointer = 0;
|
||||
word8 tk[MAXKC][4];
|
||||
union {
|
||||
word8 x8[MAXKC][4];
|
||||
word32 x32[MAXKC];
|
||||
} xtk;
|
||||
#define tk xtk.x8
|
||||
int KC = ROUNDS - 6;
|
||||
|
||||
for (j = KC-1; j >= 0; j--) {
|
||||
|
@ -80,6 +84,7 @@ int rijndaelKeySched(word8 k[MAXKC][4], word8 W[MAXROUNDS+1][4][4], int ROUNDS)
|
|||
}
|
||||
}
|
||||
return 0;
|
||||
#undef tk
|
||||
}
|
||||
|
||||
int rijndaelKeyEncToDec(word8 W[MAXROUNDS+1][4][4], int ROUNDS) {
|
||||
|
@ -121,9 +126,21 @@ int rijndaelKeyEncToDec(word8 W[MAXROUNDS+1][4][4], int ROUNDS) {
|
|||
/**
|
||||
* Encrypt a single block.
|
||||
*/
|
||||
int rijndaelEncrypt(word8 a[16], word8 b[16], word8 rk[MAXROUNDS+1][4][4], int ROUNDS) {
|
||||
int rijndaelEncrypt(word8 in[16], word8 out[16], word8 rk[MAXROUNDS+1][4][4], int ROUNDS) {
|
||||
int r;
|
||||
word8 temp[4][4];
|
||||
union {
|
||||
word8 x8[16];
|
||||
word32 x32[4];
|
||||
} xa, xb;
|
||||
#define a xa.x8
|
||||
#define b xb.x8
|
||||
union {
|
||||
word8 x8[4][4];
|
||||
word32 x32[4];
|
||||
} xtemp;
|
||||
#define temp xtemp.x8
|
||||
|
||||
memcpy(a, in, sizeof a);
|
||||
|
||||
*((word32*)temp[0]) = *((word32*)(a )) ^ *((word32*)rk[0][0]);
|
||||
*((word32*)temp[1]) = *((word32*)(a+ 4)) ^ *((word32*)rk[0][1]);
|
||||
|
@ -194,7 +211,12 @@ int rijndaelEncrypt(word8 a[16], word8 b[16], word8 rk[MAXROUNDS+1][4][4], int R
|
|||
*((word32*)(b+ 8)) ^= *((word32*)rk[ROUNDS][2]);
|
||||
*((word32*)(b+12)) ^= *((word32*)rk[ROUNDS][3]);
|
||||
|
||||
memcpy(out, b, sizeof b /* XXX out */);
|
||||
|
||||
return 0;
|
||||
#undef a
|
||||
#undef b
|
||||
#undef temp
|
||||
}
|
||||
|
||||
#ifdef INTERMEDIATE_VALUE_KAT
|
||||
|
@ -269,10 +291,22 @@ int rijndaelEncryptRound(word8 a[4][4], word8 rk[MAXROUNDS+1][4][4], int ROUNDS,
|
|||
/**
|
||||
* Decrypt a single block.
|
||||
*/
|
||||
int rijndaelDecrypt(word8 a[16], word8 b[16], word8 rk[MAXROUNDS+1][4][4], int ROUNDS) {
|
||||
int rijndaelDecrypt(word8 in[16], word8 out[16], word8 rk[MAXROUNDS+1][4][4], int ROUNDS) {
|
||||
int r;
|
||||
word8 temp[4][4];
|
||||
union {
|
||||
word8 x8[16];
|
||||
word32 x32[4];
|
||||
} xa, xb;
|
||||
#define a xa.x8
|
||||
#define b xb.x8
|
||||
union {
|
||||
word8 x8[4][4];
|
||||
word32 x32[4];
|
||||
} xtemp;
|
||||
#define temp xtemp.x8
|
||||
|
||||
memcpy(a, in, sizeof a);
|
||||
|
||||
*((word32*)temp[0]) = *((word32*)(a )) ^ *((word32*)rk[ROUNDS][0]);
|
||||
*((word32*)temp[1]) = *((word32*)(a+ 4)) ^ *((word32*)rk[ROUNDS][1]);
|
||||
*((word32*)temp[2]) = *((word32*)(a+ 8)) ^ *((word32*)rk[ROUNDS][2]);
|
||||
|
@ -342,7 +376,12 @@ int rijndaelDecrypt(word8 a[16], word8 b[16], word8 rk[MAXROUNDS+1][4][4], int R
|
|||
*((word32*)(b+ 8)) ^= *((word32*)rk[0][2]);
|
||||
*((word32*)(b+12)) ^= *((word32*)rk[0][3]);
|
||||
|
||||
memcpy(out, b, sizeof b /* XXX out */);
|
||||
|
||||
return 0;
|
||||
#undef a
|
||||
#undef b
|
||||
#undef temp
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rijndael-api-fst.h,v 1.2 2000/10/02 17:19:15 itojun Exp $ */
|
||||
/* $NetBSD: rijndael-api-fst.h,v 1.3 2001/05/22 23:45:41 kleink Exp $ */
|
||||
/* $KAME: rijndael-api-fst.h,v 1.5 2000/10/02 17:14:27 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -56,7 +56,11 @@ typedef struct {
|
|||
/* The following parameters are algorithm dependent, replace or add as necessary */
|
||||
int ROUNDS; /* key-length-dependent number of rounds */
|
||||
int blockLen; /* block length */
|
||||
u_int8_t keySched[RIJNDAEL_MAXROUNDS+1][4][4]; /* key schedule */
|
||||
union {
|
||||
u_int8_t xkS8[RIJNDAEL_MAXROUNDS+1][4][4]; /* key schedule */
|
||||
u_int32_t xkS32[RIJNDAEL_MAXROUNDS+1][4]; /* key schedule */
|
||||
} xKeySched;
|
||||
#define keySched xKeySched.xkS8
|
||||
} keyInstance;
|
||||
|
||||
/* The structure for cipher information */
|
||||
|
|
Loading…
Reference in New Issue