void test_invCipher_given_192_bit_chiper_key(void) { printf("No2.0 - cipher 192-bit key Size \n"); uint8_t plainText[4][4] = { {0x00,0x44,0x88,0xcc}, {0x11,0x55,0x99,0xdd}, {0x22,0x66,0xaa,0xee}, {0x33,0x77,0xbb,0xff} }; uint8_t expOut[4][4] = { {0xdd,0x86,0x6e,0xec}, {0xa9,0x4c,0xaf,0x0d}, {0x7c,0xdf,0x70,0x71}, {0xa4,0xe0,0xa0,0x91} }; uint8_t cipcherkey[] = {0x00,0x01,0x02,0x03, 0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b, 0x0c,0x0d,0x0e,0x0f, 0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17 }; uint32_t word[52]; uint8_t encrypOut[4][4]; uint8_t decrypOut[4][4]; keyExpansion(cipcherkey,word,6,12); cipher(plainText,encrypOut,word,12); { customTestAssertEqualState(expOut,encrypOut,66); }; invCipher(encrypOut,decrypOut,word,12); { customTestAssertEqualState(plainText,decrypOut,70); }; }
int main(int argc, char* argv){ uint64_t text[2] = {8367809505449045871, 7883959205594428265 }; uint64_t key[T] = {2242261671028070680, 1663540288323457296, 1084818905618843912, 506097522914230528 }; printf("Key: %lx %lx %lx %lx\n", key[0], key[1], key[2], key[3]); printf("Plaintext: %lx %lx\n", text[0], text[1]); keyExpansion(key); encrypt(text, key, 2); printf("Encrypted: %lx %lx \n", text[0], text[1]); printf("Expected: 8d2b5579afc8a3a0 3bf72a87efe7b868 \n"); decrypt(text, key, 2); printf("Decrypted: %lx %lx \n", text[0], text[1]); }
bool chipher_test2() { std::cout << "\nchipher_test:\n"; BYTE key[4 * c_bKeySize] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; DWORD roundKeys[c_bBlockSize * (c_bRoundsCount + 1)] = {0}; keyExpansion(key, roundKeys, c_bKeySize); DWORD arrInput[c_bBlockSize] = { 0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff }; DWORD arrOutput[c_bBlockSize] = {0}; std::cout << "input:\n"; testUtils::printArray(arrInput, c_bBlockSize, c_bBlockSize); chipher(arrInput, arrOutput, roundKeys); std::cout << "\nencrypted:\n"; testUtils::printArray(arrOutput, c_bBlockSize, c_bBlockSize); invChipher(arrOutput, arrInput, roundKeys); std::cout << "\ndecrypted:\n"; testUtils::printArray(arrInput, c_bBlockSize, c_bBlockSize); return true; }
void test_invCipher_given_256_bit_chiper_key(void) { printf("No3.0 - cipher 256-bit key Size \n"); uint8_t plainText[4][4] = { {0x00,0x44,0x88,0xcc},\ {0x11,0x55,0x99,0xdd},\ {0x22,0x66,0xaa,0xee},\ {0x33,0x77,0xbb,0xff} }; uint8_t expOut[4][4] = { {0x8e,0x51,0xea,0x4b},\ {0xa2,0x67,0xfc,0x49},\ {0xb7,0x45,0x49,0x60},\ {0xca,0xbf,0x90,0x89} }; uint8_t cipcherkey[] = {0x00,0x01,0x02,0x03,\ 0x04,0x05,0x06,0x07,\ 0x08,0x09,0x0a,0x0b,\ 0x0c,0x0d,0x0e,0x0f,\ 0x10,0x11,0x12,0x13,\ 0x14,0x15,0x16,0x17,\ 0x18,0x19,0x1a,0x1b,\ 0x1c,0x1d,0x1e,0x1f }; uint32_t word[60]; uint8_t encrypOut[4][4]; uint8_t decrypOut[4][4]; keyExpansion(cipcherkey,word,8,14); cipher(plainText,encrypOut,word,14); TEST_ASSERT_EQUAL_STATE(expOut,encrypOut); invCipher(encrypOut,decrypOut,word,14); // printf("\n"); // printfState(decrypOut); TEST_ASSERT_EQUAL_STATE(plainText,decrypOut); }
bool chipher_test() { std::cout << "\nchipher_test:\n"; BYTE key[4 * c_bKeySize] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; DWORD roundKeys[c_bBlockSize * (c_bRoundsCount + 1)] = {0}; keyExpansion(key, roundKeys, c_bKeySize); DWORD arrInput[c_bBlockSize] = { 0x3243f6a8, 0x885a308d, 0x313198a2, 0xe0370734 }; DWORD arrOutput[c_bBlockSize] = {0}; std::cout << "input:\n"; testUtils::printArray(arrInput, c_bBlockSize, c_bBlockSize); chipher(arrInput, arrOutput, roundKeys); std::cout << "\nencrypted:\n"; testUtils::printArray(arrOutput, c_bBlockSize, c_bBlockSize); invChipher(arrOutput, arrInput, roundKeys); std::cout << "\ndecrypted:\n"; testUtils::printArray(arrInput, c_bBlockSize, c_bBlockSize); return true; }
void test_invCipher_given_192_bit_chiper_key(void) { printf("No2.0 - cipher 192-bit key Size \n"); uint8_t plainText[4][4] = { {0x00,0x44,0x88,0xcc},\ {0x11,0x55,0x99,0xdd},\ {0x22,0x66,0xaa,0xee},\ {0x33,0x77,0xbb,0xff} }; uint8_t expOut[4][4] = { {0xdd,0x86,0x6e,0xec},\ {0xa9,0x4c,0xaf,0x0d},\ {0x7c,0xdf,0x70,0x71},\ {0xa4,0xe0,0xa0,0x91} }; uint8_t cipcherkey[] = {0x00,0x01,0x02,0x03,\ 0x04,0x05,0x06,0x07,\ 0x08,0x09,0x0a,0x0b,\ 0x0c,0x0d,0x0e,0x0f,\ 0x10,0x11,0x12,0x13,\ 0x14,0x15,0x16,0x17 }; uint32_t word[52]; uint8_t encrypOut[4][4]; uint8_t decrypOut[4][4]; keyExpansion(cipcherkey,word,6,12); cipher(plainText,encrypOut,word,12); TEST_ASSERT_EQUAL_STATE(expOut,encrypOut); invCipher(encrypOut,decrypOut,word,12); // printf("\n"); // printfState(decrypOut); TEST_ASSERT_EQUAL_STATE(plainText,decrypOut); }
void test_invCipher_given_128_bit_chiper_key(void) { printf("No1.0 - cipher 128-bit key Size \n"); uint8_t plainText[4][4] = { {0x00,0x44,0x88,0xcc},\ {0x11,0x55,0x99,0xdd},\ {0x22,0x66,0xaa,0xee},\ {0x33,0x77,0xbb,0xff} }; uint8_t expOut[4][4] = { {0x69,0x6a,0xd8,0x70},\ {0xc4,0x7b,0xcd,0xb4},\ {0xe0,0x04,0xb7,0xc5},\ {0xd8,0x30,0x80,0x5a} }; uint8_t cipcherkey[] = { 0x00,0x01,0x02,0x03,\ 0x04,0x05,0x06,0x07,\ 0x08,0x09,0x0a,0x0b,\ 0x0c,0x0d,0x0e,0x0f }; uint32_t word[44]; uint8_t encrypOut[4][4]; uint8_t decrypOut[4][4]; keyExpansion(cipcherkey,word,4,10); cipher(plainText,encrypOut,word,10); TEST_ASSERT_EQUAL_STATE(expOut,encrypOut); invCipher(encrypOut,decrypOut,word,10); // printf("\n"); // printfState(decrypOut); TEST_ASSERT_EQUAL_STATE(plainText,decrypOut); }
void test_invCipher_given_128_bit_chiper_key(void) { printf("No1.0 - cipher 128-bit key Size \n"); uint8_t plainText[4][4] = { {0x00,0x44,0x88,0xcc}, {0x11,0x55,0x99,0xdd}, {0x22,0x66,0xaa,0xee}, {0x33,0x77,0xbb,0xff} }; uint8_t expOut[4][4] = { {0x69,0x6a,0xd8,0x70}, {0xc4,0x7b,0xcd,0xb4}, {0xe0,0x04,0xb7,0xc5}, {0xd8,0x30,0x80,0x5a} }; uint8_t cipcherkey[] = { 0x00,0x01,0x02,0x03, 0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b, 0x0c,0x0d,0x0e,0x0f }; uint32_t word[44]; uint8_t encrypOut[4][4]; uint8_t decrypOut[4][4]; keyExpansion(cipcherkey,word,4,10); cipher(plainText,encrypOut,word,10); { customTestAssertEqualState(expOut,encrypOut,38); }; invCipher(encrypOut,decrypOut,word,10); { customTestAssertEqualState(plainText,decrypOut,42); }; }
void test_keyExpansion_given_192_bit_cipher_key(void){ printf("No8.0 - keyExpansion 192-bit cipher key\n"); int i = 0; char* key = malloc(sizeof(char)*25); uint8_t cipcherkey[] = { 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,0xc8,0x10,0xf3,0x2b,\ 0x80,0x90,0x79,0xe5,0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b}; for(i = 0; i < 24 ; i++){ key[i] = cipcherkey[i]; } uint32_t word[52]; keyExpansion(key,word,6,12); TEST_ASSERT_EQUAL_UINT32(0xad07d753,word[43]); }
void test_keyExpansion_given_128_bit_cipher_key(void){ printf("No7.0 - keyExpansion 128-bit cipher key\n"); int i = 0; char* key = malloc(sizeof(char)*17); uint8_t cipcherkey[] = { 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c}; for(i = 0; i < 16 ; i++){ key[i] = cipcherkey[i]; } //printf("key = %.*x\n",8,key[i]); uint32_t word[44]; keyExpansion(key,word,4,10); TEST_ASSERT_EQUAL_UINT32(0xb6630ca6,word[43]); TEST_ASSERT_EQUAL_UINT32(0xac7766f3,word[36]); TEST_ASSERT_EQUAL_UINT32(0x110b3efd,word[25]); }
void test_keyExpansion_given_256_bit_cipher_key(void){ printf("No9.0 - keyExpansion 256-bit cipher key\n"); int i = 0; char* key = malloc(sizeof(char)*33); uint8_t cipcherkey[] = { 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,\ 0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,\ 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4}; for(i = 0; i < 32 ; i++){ key[i] = cipcherkey[i]; } uint32_t word[60]; keyExpansion(key,word,8,14); TEST_ASSERT_EQUAL_UINT32(0x9ba35411,word[8]); TEST_ASSERT_EQUAL_UINT32(0x98312229,word[22]); TEST_ASSERT_EQUAL_UINT32(0xde136967,word[40]); TEST_ASSERT_EQUAL_UINT32(0x706c631e,word[59]); }
void cipher(uint16_t state[]){ uint16_t expanded_key[nk*(nb*(nr+1))]; int round; keyExpansion(expanded_key); addRoundKey(state, expanded_key, 0); for (round = 1; round < nr; round++) { subBytes(state); shiftRows(state); mixColumns(state); addRoundKey(state, expanded_key, round); } subBytes(state); shiftRows(state); addRoundKey(state, expanded_key, round); }
int main(int argc, char *argv[]) { byte input[16] = {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}; byte output[176]; keyExpansion(input, output); int i; for(i=0;i<176;i++){ printf(" %02x ", output[i]); if((i + 1) % 16 == 0 && i != 0){ printf("\n"); } } return 0; }
bool keyExpansion_test() { std::cout << "\nkeyExpansion_test:\n"; BYTE key[4 * c_bKeySize] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; testUtils::printArray(key, 4 * c_bKeySize, c_bKeySize); DWORD roundKeys[c_bBlockSize * (c_bRoundsCount + 1)] = {0}; keyExpansion(key, roundKeys, c_bKeySize); std::cout << "\nkeyExpansion:\n"; testUtils::printArray(roundKeys, c_bBlockSize * (c_bRoundsCount + 1), 6); return true; }
int main(int argc, char *argv[]) { byte shortkey[16] = {0x2b, 0x7e, 0x15, 0x16, 0x028, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}; byte expandedkey[176]; keyExpansion(shortkey, expandedkey); byte state[16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a}; //correct cipher text is 3ad77bb40d7a3660a89ecaf32466ef97 encryptBlock(state, expandedkey); int i; printf("\n"); for(i = 0;i < 16;i++){ printf(" %02x ", state[i]); } return 0; }
int main(int argc, char *argv[]) { byte shortkey[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; byte expandedkey[176]; keyExpansion(shortkey, expandedkey); byte state[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; shiftRows(state); int i; for(i = 0;i < 16;i++){ printf(" %02x ", state[i]); if((i + 1) % 4 == 0){ printf("\n"); } } return 0; }
int main(void) { keyExpansion(); return 0; }