Example #1
0
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
}
Example #2
0
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;
}
Example #3
0
void PRESENT80_enc(dqword *input, const unsigned char* userkey){
	format_input(input);
	for(int i=0; i<31; i++){
		addRoundKey(input, &rks[i]);
		sBoxLayer(input);
		pLayer(input);
	}
	addRoundKey(input, &rks[31]);
	format_output(input);
}
Example #4
0
void FastRijndael::decryptOneRound(unsigned char** block){
	if (!_initd){
		return;
	}
	_round = 1;
	addRoundKey(block);
	invMixColumns(block);
	invShiftRows(block);
	invSubBytes(block);
	_round--;
	addRoundKey(block);
}
Example #5
0
File: AES.cpp Project: ebakan/AES
//Decrypts one 16-byte array of data
void AES::decryptBlock(int keySize, uint8_t* state, uint8_t* key) {
    int rounds=6+keySize/32;

    addRoundKey(state,key+rounds*16);

    for(int i=rounds-1;i>=0;i--) {

        inv_shiftRows(state);
        inv_subBytes(state);
        addRoundKey(state,key+16*i);
        if(i!=0) //don't mix columns on last round
            inv_mixColumns(state);
    }
}
Example #6
0
File: AES.cpp Project: ebakan/AES
//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);
    }
}
Example #7
0
void FastRijndael::decrypt(unsigned char** block){
	if (!_initd){
		return;
	}
	_round = _nr;
	addRoundKey(block);
	_round--;
	for (; _round > 0; _round--){
		invShiftRows(block);
		invSubBytes(block);
		addRoundKey(block);
		invMixColumns(block);
	}		
	invShiftRows(block);
	invSubBytes(block);
	addRoundKey(block);
}
Example #8
0
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);		
}
Example #9
0
File: aes.c Project: Gunga/adesso
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);
}
Example #10
0
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);
	}
}
Example #11
0
 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);
	

 }
Example #12
0
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;
}
Example #13
0
void AES128::inv_addRoundKey(int i) {
	computeKeyRound(i);
	addRoundKey();
}