|
|
@ -39,7 +39,7 @@ u32 FSM_R3 = 0x00;
|
|
|
|
|
|
|
|
|
|
|
|
/* Rijndael S-box SR */
|
|
|
|
/* Rijndael S-box SR */
|
|
|
|
|
|
|
|
|
|
|
|
u8 SR[256] = {
|
|
|
|
static u8 snow_3g_SR[256] = {
|
|
|
|
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9,
|
|
|
|
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, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F,
|
|
|
|
0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F,
|
|
|
|
0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07,
|
|
|
|
0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07,
|
|
|
@ -57,7 +57,7 @@ u8 SR[256] = {
|
|
|
|
|
|
|
|
|
|
|
|
/* S-box SQ */
|
|
|
|
/* S-box SQ */
|
|
|
|
|
|
|
|
|
|
|
|
u8 SQ[256] = {
|
|
|
|
static u8 snow_3g_SQ[256] = {
|
|
|
|
0x25, 0x24, 0x73, 0x67, 0xD7, 0xAE, 0x5C, 0x30, 0xA4, 0xEE, 0x6E, 0xCB, 0x7D, 0xB5, 0x82, 0xDB, 0xE4, 0x8E, 0x48,
|
|
|
|
0x25, 0x24, 0x73, 0x67, 0xD7, 0xAE, 0x5C, 0x30, 0xA4, 0xEE, 0x6E, 0xCB, 0x7D, 0xB5, 0x82, 0xDB, 0xE4, 0x8E, 0x48,
|
|
|
|
0x49, 0x4F, 0x5D, 0x6A, 0x78, 0x70, 0x88, 0xE8, 0x5F, 0x5E, 0x84, 0x65, 0xE2, 0xD8, 0xE9, 0xCC, 0xED, 0x40, 0x2F,
|
|
|
|
0x49, 0x4F, 0x5D, 0x6A, 0x78, 0x70, 0x88, 0xE8, 0x5F, 0x5E, 0x84, 0x65, 0xE2, 0xD8, 0xE9, 0xCC, 0xED, 0x40, 0x2F,
|
|
|
|
0x11, 0x28, 0x57, 0xD2, 0xAC, 0xE3, 0x4A, 0x15, 0x1B, 0xB9, 0xB2, 0x80, 0x85, 0xA6, 0x2E, 0x02, 0x47, 0x29, 0x07,
|
|
|
|
0x11, 0x28, 0x57, 0xD2, 0xAC, 0xE3, 0x4A, 0x15, 0x1B, 0xB9, 0xB2, 0x80, 0x85, 0xA6, 0x2E, 0x02, 0x47, 0x29, 0x07,
|
|
|
@ -137,10 +137,10 @@ u32 DIValpha(u8 c)
|
|
|
|
u32 S1(u32 w)
|
|
|
|
u32 S1(u32 w)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
u8 r0 = 0, r1 = 0, r2 = 0, r3 = 0;
|
|
|
|
u8 r0 = 0, r1 = 0, r2 = 0, r3 = 0;
|
|
|
|
u8 srw0 = SR[(u8)((w >> 24) & 0xff)];
|
|
|
|
u8 srw0 = snow_3g_SR[(u8)((w >> 24) & 0xff)];
|
|
|
|
u8 srw1 = SR[(u8)((w >> 16) & 0xff)];
|
|
|
|
u8 srw1 = snow_3g_SR[(u8)((w >> 16) & 0xff)];
|
|
|
|
u8 srw2 = SR[(u8)((w >> 8) & 0xff)];
|
|
|
|
u8 srw2 = snow_3g_SR[(u8)((w >> 8) & 0xff)];
|
|
|
|
u8 srw3 = SR[(u8)((w)&0xff)];
|
|
|
|
u8 srw3 = snow_3g_SR[(u8)((w)&0xff)];
|
|
|
|
r0 = ((MULx(srw0, 0x1b)) ^ (srw1) ^ (srw2) ^ ((MULx(srw3, 0x1b)) ^ srw3));
|
|
|
|
r0 = ((MULx(srw0, 0x1b)) ^ (srw1) ^ (srw2) ^ ((MULx(srw3, 0x1b)) ^ srw3));
|
|
|
|
r1 = (((MULx(srw0, 0x1b)) ^ srw0) ^ (MULx(srw1, 0x1b)) ^ (srw2) ^ (srw3));
|
|
|
|
r1 = (((MULx(srw0, 0x1b)) ^ srw0) ^ (MULx(srw1, 0x1b)) ^ (srw2) ^ (srw3));
|
|
|
|
r2 = ((srw0) ^ ((MULx(srw1, 0x1b)) ^ srw1) ^ (MULx(srw2, 0x1b)) ^ (srw3));
|
|
|
|
r2 = ((srw0) ^ ((MULx(srw1, 0x1b)) ^ srw1) ^ (MULx(srw2, 0x1b)) ^ (srw3));
|
|
|
@ -158,10 +158,10 @@ u32 S1(u32 w)
|
|
|
|
u32 S2(u32 w)
|
|
|
|
u32 S2(u32 w)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
u8 r0 = 0, r1 = 0, r2 = 0, r3 = 0;
|
|
|
|
u8 r0 = 0, r1 = 0, r2 = 0, r3 = 0;
|
|
|
|
u8 sqw0 = SQ[(u8)((w >> 24) & 0xff)];
|
|
|
|
u8 sqw0 = snow_3g_SQ[(u8)((w >> 24) & 0xff)];
|
|
|
|
u8 sqw1 = SQ[(u8)((w >> 16) & 0xff)];
|
|
|
|
u8 sqw1 = snow_3g_SQ[(u8)((w >> 16) & 0xff)];
|
|
|
|
u8 sqw2 = SQ[(u8)((w >> 8) & 0xff)];
|
|
|
|
u8 sqw2 = snow_3g_SQ[(u8)((w >> 8) & 0xff)];
|
|
|
|
u8 sqw3 = SQ[(u8)((w)&0xff)];
|
|
|
|
u8 sqw3 = snow_3g_SQ[(u8)((w)&0xff)];
|
|
|
|
r0 = ((MULx(sqw0, 0x69)) ^ (sqw1) ^ (sqw2) ^ ((MULx(sqw3, 0x69)) ^ sqw3));
|
|
|
|
r0 = ((MULx(sqw0, 0x69)) ^ (sqw1) ^ (sqw2) ^ ((MULx(sqw3, 0x69)) ^ sqw3));
|
|
|
|
r1 = (((MULx(sqw0, 0x69)) ^ sqw0) ^ (MULx(sqw1, 0x69)) ^ (sqw2) ^ (sqw3));
|
|
|
|
r1 = (((MULx(sqw0, 0x69)) ^ sqw0) ^ (MULx(sqw1, 0x69)) ^ (sqw2) ^ (sqw3));
|
|
|
|
r2 = ((sqw0) ^ ((MULx(sqw1, 0x69)) ^ sqw1) ^ (MULx(sqw2, 0x69)) ^ (sqw3));
|
|
|
|
r2 = ((sqw0) ^ ((MULx(sqw1, 0x69)) ^ sqw1) ^ (MULx(sqw2, 0x69)) ^ (sqw3));
|
|
|
|