Previous 199869 Revisions Next

r34514 Tuesday 20th January, 2015 at 22:30:53 UTC by Andreas Naive
Two new key bits for SEGA's 315-5881 encryption
[src/mame/machine]315-5881_crypt.c 315-5881_crypt.h

trunk/src/mame/machine/315-5881_crypt.c
r243025r243026
134134given plaintext word, and the remaining 2 to the next plaintext word.
135135
136136The underlying block cipher consists of two 4-round Feistel Networks (FN): the first one takes the counter (16 bits),
137the game-key (>=27 bits) and the sequence-key (16 bits) and output a middle result (16 bits) which will act as another key
137the game-key (>=29 bits) and the sequence-key (16 bits) and output a middle result (16 bits) which will act as another key
138138for the second one. The second FN will take the encrypted word (16 bits), the game-key, the sequence-key and the result
139139from the first FN and will output the decrypted word (16 bits).
140140
r243025r243026
470470   },
471471};
472472
473const int sega_315_5881_crypt_device::fn1_game_key_scheduling[38][2] = {
474   {1,29},  {1,71},  {2,4},   {2,54},  {3,8},   {4,56},  {4,73},  {5,11},
475   {6,51},  {7,92},  {8,89},  {9,9},   {9,10},  {9,39},  {9,41},  {9,58},
476   {9,59},  {9,86},  {10,90}, {11,6},  {12,64}, {13,49}, {14,44}, {15,40},
477    {16,69}, {17,15}, {18,23}, {18,43}, {19,82}, {20,81}, {21,32}, {22,5},
478   {23,66}, {24,13}, {24,45}, {25,12}, {25,35}, {26,61},
473const int sega_315_5881_crypt_device::fn1_game_key_scheduling[FN1GK][2] = {
474    {1,29},  {1,71},  {2,4},   {2,54},  {3,8},   {4,56},  {4,73},  {5,11},
475    {6,51},  {7,92},  {8,89},  {9,9},   {9,39},  {9,41},  {9,58},  {9,86},
476    {10,90}, {11,6},  {12,64}, {13,49}, {14,44}, {15,40}, {16,69}, {17,15},
477    {18,23}, {18,43}, {19,82}, {20,81}, {21,32}, {22,5},  {23,66}, {24,13},
478   {24,45}, {25,12}, {25,35}, {26,61}, {27,10}, {27,59}, {28,25}
479479};
480480
481const int sega_315_5881_crypt_device::fn2_game_key_scheduling[34][2] = {
482   {0,0},   {1,3},   {2,11},  {3,20},  {4,22},  {5,23},  {6,29},  {7,38},
483   {8,39},  {9,47},  {9,55},  {9,86},  {9,87},  {9,90},  {10,50}, {10,53},
484   {11,57}, {12,59}, {13,61}, {13,64}, {14,63}, {15,67}, {16,72}, {17,83},
485    {18,88}, {19,94}, {20,35}, {21,17}, {22,6},  {22,11}, {23,85}, {24,16},
486   {25,25}, {26,92}
481const int sega_315_5881_crypt_device::fn2_game_key_scheduling[FN2GK][2] = {
482    {0,0},   {1,3},   {2,11},  {3,20},  {4,22},  {5,23},  {6,29},  {7,38},
483    {8,39},  {9,55},  {9,86},  {9,87},  {9,90},  {10,50}, {10,53}, {11,57},
484    {12,59}, {13,61}, {13,64}, {14,63}, {15,67}, {16,72}, {17,83}, {18,88},
485    {19,94}, {20,35}, {21,17}, {22,6},  {22,11}, {23,85}, {24,16}, {25,25},
486   {26,92}, {27,47}, {28,28}
487487};
488488
489489const int sega_315_5881_crypt_device::fn1_sequence_key_scheduling[20][2] = {
r243025r243026
539539   memset(fn1_subkeys, 0, sizeof(UINT32) * 4);
540540   memset(fn2_subkeys, 0, sizeof(UINT32) * 4);
541541
542   for (j = 0; j < 38; ++j) {
542   for (j = 0; j < FN1GK; ++j) {
543543      if (BIT(game_key, fn1_game_key_scheduling[j][0]) != 0) {
544544         aux = fn1_game_key_scheduling[j][1] % 24;
545545         aux2 = fn1_game_key_scheduling[j][1] / 24;
r243025r243026
547547      }
548548   }
549549
550   for (j = 0; j < 34; ++j) {
550   for (j = 0; j < FN2GK; ++j) {
551551      if (BIT(game_key, fn2_game_key_scheduling[j][0]) != 0) {
552552         aux = fn2_game_key_scheduling[j][1] % 24;
553553         aux2 = fn2_game_key_scheduling[j][1] / 24;
r243025r243026
587587   A = (aux & 0xff) ^ feistel_function(B, fn1_sboxes[0], fn1_subkeys[0]);
588588
589589   // 2nd round
590   B = B ^ feistel_function(A, fn1_sboxes[1], fn1_subkeys[1]);
590   B ^= feistel_function(A, fn1_sboxes[1], fn1_subkeys[1]);
591591
592592   // 3rd round
593   A = A ^ feistel_function(B, fn1_sboxes[2], fn1_subkeys[2]);
593   A ^= feistel_function(B, fn1_sboxes[2], fn1_subkeys[2]);
594594
595595   // 4th round
596   B = B ^ feistel_function(A, fn1_sboxes[3], fn1_subkeys[3]);
596   B ^= feistel_function(A, fn1_sboxes[3], fn1_subkeys[3]);
597597
598598   middle_result = (B << 8) | A;
599599
r243025r243026
617617   A = (aux & 0xff) ^ feistel_function(B, fn2_sboxes[0], fn2_subkeys[0]);
618618
619619   // 2nd round
620   B = B ^ feistel_function(A, fn2_sboxes[1], fn2_subkeys[1]);
620   B ^= feistel_function(A, fn2_sboxes[1], fn2_subkeys[1]);
621621
622622   // 3rd round
623   A = A ^ feistel_function(B, fn2_sboxes[2], fn2_subkeys[2]);
623   A ^= feistel_function(B, fn2_sboxes[2], fn2_subkeys[2]);
624624
625625   // 4th round
626   B = B ^ feistel_function(A, fn2_sboxes[3], fn2_subkeys[3]);
626   B ^= feistel_function(A, fn2_sboxes[3], fn2_subkeys[3]);
627627
628628   aux = (B << 8) | A;
629629
trunk/src/mame/machine/315-5881_crypt.h
r243025r243026
6666   static const sbox fn1_sboxes[4][4];
6767   static const sbox fn2_sboxes[4][4];
6868
69   static const int fn1_game_key_scheduling[38][2];
70   static const int fn2_game_key_scheduling[34][2];
69   static const int FN1GK = 39;
70   static const int FN2GK = 35;
71   static const int fn1_game_key_scheduling[FN1GK][2];
72   static const int fn2_game_key_scheduling[FN2GK][2];
7173   static const int fn1_sequence_key_scheduling[20][2];
7274   static const int fn2_sequence_key_scheduling[16];
7375   static const int fn2_middle_result_scheduling[16];


Previous 199869 Revisions Next


© 1997-2024 The MAME Team