int _tmain(int argc, _TCHAR* argv[]) { KeySchedule(Key, strlen(Key)); byte i = 0, j = 0; for (int n = 0; n < strlen(pt); n++) { byte val = pt[i] ^ Gen(i, j); printf("%02x ", val); } return 0; }
int main(void) { int i; u8 key[16] = { 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, }; u8 text[8] = { //0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, }; KeySchedule(key); /* for (i = 0; i < 8; i++) printf("%04x ", KLi1[i]); printf("\n"); for (i = 0; i < 8; i++) printf("%04x ", KLi2[i]); printf("\n"); for (i = 0; i < 8; i++) printf("%04x ", KOi1[i]); printf("\n"); for (i = 0; i < 8; i++) printf("%04x ", KOi2[i]); printf("\n"); for (i = 0; i < 8; i++) printf("%04x ", KOi3[i]); printf("\n"); for (i = 0; i < 8; i++) printf("%04x ", KIi1[i]); printf("\n"); for (i = 0; i < 8; i++) printf("%04x ", KIi2[i]); printf("\n"); for (i = 0; i < 8; i++) printf("%04x ", KIi3[i]); printf("\n"); */ Kasumi(text); //printf("\n"); for (i = 0; i < 8; i++) printf("%02x ", text[i]); printf("\n"); return 0; }
int main(int argc, char** argv){ print(state); KeySchedule(); AddRoundKey(); for(iteracja = 1; iteracja < ROUND_cnt; ++iteracja){ SubBytes(); ShiftRows(); MixColumns(); print(state); AddRoundKey(); } SubBytes(); ShiftRows() AddRoundKey(); print(state); /*encrypted*/ AddRoundKey(); InvShiftRows(); InvSubBytes(); for(iteracja = ROUND_cnt-1; iteracja > 0; --iteracja){ AddRoundKey(); InvMixColumns(); InvShiftRows(); InvSubBytes(); } AddRoundKey(); print(state); return 0; }
/* * Copyright (C) 2005 * Akira Iwata & Masayuki Sato * Akira Iwata Laboratory, * Nagoya Institute of Technology in Japan. * * All rights reserved. * * This software is written by Masayuki Sato. * And if you want to contact us, send an email to Kimitake Wakayama * ([email protected]) * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. All advertising materials mentioning features or use of this software must * display the following acknowledgment: * "This product includes software developed by Akira Iwata Laboratory, * Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)." * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by Akira Iwata Laboratory, * Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)." * * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. * AKIRA IWATA LABORATORY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, * IN NO EVENT SHALL AKIRA IWATA LABORATORY BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ int decrypt (int statemt[32], int key[32], int type) { int i; /* +--------------------------------------------------------------------------+ | * Test Vector (added for CHStone) | | out_enc_statemt : expected output data for "decrypt" | +--------------------------------------------------------------------------+ */ const int out_dec_statemt[16] = { 0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x7, 0x34 }; KeySchedule (type, key); switch (type) { case 128128: round = 10; nb = 4; break; case 128192: case 192192: round = 12; nb = 6; break; case 192128: round = 12; nb = 4; break; case 128256: case 192256: round = 14; nb = 8; break; case 256128: round = 14; nb = 4; break; case 256192: round = 14; nb = 6; break; case 256256: round = 14; nb = 8; break; } AddRoundKey (statemt, type, round); InversShiftRow_ByteSub (statemt, nb); for (i = round - 1; i >= 1; --i) { AddRoundKey_InversMixColumn (statemt, nb, i); InversShiftRow_ByteSub (statemt, nb); } AddRoundKey (statemt, type, 0); printf ("\ndecrypto message\t"); for (i = 0; i < ((type % 1000) / 8); ++i) { if (statemt[i] < 16) printf ("0"); printf ("%x", statemt[i]); } for (i = 0; i < 16; i++) main_result += (statemt[i] != out_dec_statemt[i]); return 0; }
/* ******* encrypto ************ */ int encrypt (int statemt[32], int key[32], int type) { int i; /* +--------------------------------------------------------------------------+ | * Test Vector (added for CHStone) | | out_enc_statemt : expected output data for "encrypt" | +--------------------------------------------------------------------------+ */ const int out_enc_statemt[16] = { 0x39, 0x25, 0x84, 0x1d, 0x2, 0xdc, 0x9, 0xfb, 0xdc, 0x11, 0x85, 0x97, 0x19, 0x6a, 0xb, 0x32 }; KeySchedule (type, key); switch (type) { case 128128: round = 0; nb = 4; break; case 192128: round = 2; nb = 4; break; case 256128: round = 4; nb = 4; break; case 128192: case 192192: round = 2; nb = 6; break; case 256192: round = 4; nb = 6; break; case 128256: case 192256: case 256256: round = 4; nb = 8; break; } AddRoundKey (statemt, type, 0); for (i = 1; i <= round + 9; ++i) { ByteSub_ShiftRow (statemt, nb); MixColumn_AddRoundKey (statemt, nb, i); } ByteSub_ShiftRow (statemt, nb); AddRoundKey (statemt, type, i); printf ("encrypted message \t"); for (i = 0; i < nb * 4; ++i) { if (statemt[i] < 16) printf ("0"); printf ("%x", statemt[i]); } for (i = 0; i < 16; i++) main_result += (statemt[i] != out_enc_statemt[i]); return 0; }