// hazuki0-sbox.cc - Don Yang (uguu.org) // // Output sboxes used by hazuki0.cc. This is used to verify that sboxes // used by hazuki8.cc still matched the original set. // // 06/22/12 #include typedef unsigned char Byte; // Global encryption states static Byte sbox[16][256]; // Initialize sboxes static void InitSbox(int group) { // Sbox parameters. See sbox_params.c static const char params[] = "h\32:,<$4~$HhVF+\16tz;Z}8^\1Mt|:0t;^OC|1h|||L|Av>jLt{H*J" "H*\nb9]zIcx3hp9n`Nm*?$F-\rzWdN{\4nC&^KEf\33;z0h\0~z25K25" "\13Tb{R7\2P8\t04KDNBZo|Lt427J27\n42KT\27\37n'Kb9\rb;\14*" "I~PzGPZ!PX\"jg\4.W\16XP;PV\r(ZeRU\16~/.(Xft\22\3h\2=$>BV" "aD&%9@.eD,e~u3&[6\10z\rr\32k(X6\n{\rzbmX\"e$J\16|t3&U1 o" "JR/9n\t\33,7\13PJ{^\21[Z\23[@\36[p^yB\37[D\32\\P$fj\rzx" "\\,\6Dj[if[;D~BjYj&?B`\16\rR1\5" "&1Af[j:_4FiDDhDF9DP>\6@\2aP\6\n4Zv@\0b^}7j\7Mh\4NTrhld"; for(int s = 0; s < 16; s++) { const int offset1 = params[(group * 16 + s) * 3] ^ 81; const int offset2 = params[(group * 16 + s) * 3 + 1] ^ 25; const int offset3 = params[(group * 16 + s) * 3 + 2] ^ 16; for(int i = 0; i < 256; i++) { int j = ((i + offset1) & 0x7f) | (i & 0x80); j = (((j >> 1) + offset2) & 0x7f) | ((j << 7) & 0x80); sbox[s][i] = (((j >> 1) + offset3) & 0x7f) | ((j << 7) & 0x80); } for(int iteration = 0; iteration < 2; iteration++) { for(int bit = 0; bit < 8; bit++) { for(int i = 0; i < 256; i++) { const Byte current = sbox[s][i]; const Byte neighbor = sbox[s][i ^ (1 << bit)]; const int difference = current ^ neighbor; if( (difference & (difference - 1)) == 0 ) { int j = i ^ (1 << ((bit + 1) % 8)); const Byte tmp = sbox[s][i]; sbox[s][i] = sbox[s][j]; sbox[s][j] = tmp; } } } } } } int main(int argc, char **argv) { for(int i = 0; i < 9; i++) { InitSbox(i); for(int j = 0; j < 16; j++) { for(int k = 0; k < 256; k++) printf("%02x", sbox[j][k]); putchar('\n'); } putchar('\n'); } return 0; }