byte * aes(byte *in, byte *skey) { int i; for(i=0; i < 16; i++) { state[i] = in[i]; key[i] = skey[i]; } addRoundKey(); for(i = 0; i < 9; i++) { subBytes(); shiftRows(); mixColumns(); computeKey(rcon[i]); addRoundKey(); } subBytes(); shiftRows(); computeKey(rcon[i]); addRoundKey(); return state; }
void FastRijndael::encryptOneRound(unsigned char** block){ if (!_initd){ return; } _round = 0; #if DEBUG fprintf(STDOUT, "Round %i\n", _round-1); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++){ fprintf(STDOUT, "%x ", block[i][j]); } fprintf(STDOUT, "\n"); } #endif addRoundKey(block); #if DEBUG fprintf(STDOUT, "Round %i after whitening ARK\n", _round-1); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++){ fprintf(STDOUT, "%x ", block[i][j]); } fprintf(STDOUT, "\n"); } #endif _round++; subBytes(block); #if DEBUG fprintf(STDOUT, "Round %i after SB\n", _round-1); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++){ fprintf(STDOUT, "%x ", block[i][j]); } fprintf(STDOUT, "\n"); } #endif shiftRows(block); #if DEBUG fprintf(STDOUT, "Round %i after SR\n", _round-1); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++){ fprintf(STDOUT, "%x ", block[i][j]); } fprintf(STDOUT, "\n"); } #endif mixColumns(block); #if DEBUG fprintf(STDOUT, "Round %i after MC\n", _round-1); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++){ fprintf(STDOUT, "%x ", block[i][j]); } fprintf(STDOUT, "\n"); } #endif addRoundKey(block); #if DEBUG fprintf(STDOUT, "Round %i after ARK\n", _round-1); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++){ fprintf(STDOUT, "%x ", block[i][j]); } fprintf(STDOUT, "\n"); } #endif }
void RND512Q(uint32_t *x32, uint32_t r) { uint32_t i; uint32_t j; for(i=0;i<14;i++) { x32[i] = ~x32[i]; } x32[14] ^= 0xcfdfefff^r; x32[15] ^= 0x8f9fafbf^r; subBytes((uint8_t*)x32); j=1; for(i=0;i<4;i++) { rotate_line_left(x32,i, j); j+=2; } j=2; for(i=5;i<8;i++) { rotate_line_left(x32,i, j); j+=2; } mixBytes(x32); }
void FastRijndael::encrypt(unsigned char** block){ if (!_initd){ return; } _round = 0; addRoundKey(block); _round++; for (; _round < _nr; _round++){ subBytes(block); shiftRows(block); mixColumns(block); addRoundKey(block); } subBytes(block); shiftRows(block); addRoundKey(block); }
void AES::verboseEncryptNoReset() { if (round == 0) { std::cout << "Round " << round << " plaintext:" << std::endl; printData(); keyAdd(); std::cout << std::endl << "Round " << round << " keyAdd:" << std::endl; printData(); round++; } for (; round < 10; round++) { std::cout << std::endl << "Round " << round << " plaintext:" << std::endl; printData(); subBytes(); std::cout << std::endl << "Round " << round << " subBytes:" << std::endl; printData(); shiftRows(); std::cout << std::endl << "Round " << round << " shiftRows:" << std::endl; printData(); mixColumns(); std::cout << std::endl << "Round " << round << " mixColumns:" << std::endl; printData(); keyAdd(); std::cout << std::endl << "Round " << round << " keyAdd:" << std::endl; printData(); } subBytes(); std::cout << std::endl << "Round " << round << " subBytes:" << std::endl; printData(); shiftRows(); std::cout << std::endl << "Round " << round << " shiftRows:" << std::endl; printData(); keyAdd(); std::cout << std::endl << "Round " << round << " keyAdd / ciphertext:" << std::endl; printData(); }
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); }
void Rijndael::encryptNRounds(unsigned char** block, int rounds){ if (!_initd){ return; } _round = 0; addRoundKey(block); _round++; for (; _round <= rounds; _round++){ if (_round == _nr) break; subBytes(block); shiftRows(block); mixColumns(block); addRoundKey(block); } if (_round == _nr && rounds != _nr-1){ subBytes(block); shiftRows(block); addRoundKey(block); } }
void decipher_block(unsigned char * state,uint32 * word,uint32 nb,uint32 nr){ addRoundKey(state,word,nr,nb); int round; for(round = nr-1;round >= 1 ;round--){ shiftRows(state,nb,1); subBytes(state,nb,inv_s_box); addRoundKey(state,word,round,nb); mixColumns(state,nb,invGmix_columnTable); } shiftRows(state,nb,1); subBytes(state,nb,inv_s_box); addRoundKey(state,word,round,nb); printState(state,nb); }
void test_subBytes_given_ABCDEFGHIJKLMNOP(void){ printf("No1.0 - subBytes\n"); uint8_t exState[4][4] = {{0x83,0x6e,0x3b,0xe3}, \ {0x2c,0x5a,0xd6,0x2f}, \ {0x1a,0xa0,0xb3,0x84}, \ {0x1b,0x52,0x29,0x53} }; char* str = "ABCDEFGHIJKLMNOP"; uint8_t state[4][4]; convStrToState(str,state); subBytes(state); // printfState(state); TEST_ASSERT_EQUAL_STATE(exState,state); }
void RND512P(uint32_t *x32, uint32_t r) { uint32_t i; x32[ 0] ^= 0x30201000^r; x32[ 1] ^= 0x70605040^r; subBytes((uint8_t*)x32); for(i=1;i<8;i++) { rotate_line_left(x32,i, i); } mixBytes(x32); }
//Encrypts one 16-byte array of data void AES::encryptBlock(int keySize, uint8_t* state, uint8_t* key) { int rounds=6+keySize/32; addRoundKey(state,key); for(int i=1;i<=rounds;i++) { subBytes(state); shiftRows(state); if(i!=rounds) //don't mix columns on last round mixColumns(state); addRoundKey(state,key+16*i); } }
byte * AES128::encrypt(byte *message) { int i; memcpy((void*)state, (const void*)message,16); initKey(); addRoundKey(); for(i = 0; i < 9; i++) { subBytes(); shiftRows(); mixColumns(); computeKey(pgm_read_byte(rcon + i)); addRoundKey(); } subBytes(); shiftRows(); computeKey(pgm_read_byte(rcon + i)); addRoundKey(); memcpy((void*)message,(const void*)state, 16); return message; }
void AES::encrypt() { round = 0; keyAdd(); round++; for (; round < 10; round++) runRound(); subBytes(); shiftRows(); keyAdd(); printData(); }