Пример #1
0
void Safe2Decrypt_RIJ128(const Ipp8u* in,
                               Ipp8u* out,
                               int Nr,
                               const Ipp8u* RoundKey,
                               const void* sbox)
{
   Ipp32u state[4];

   int round=0;

   UNREFERENCED_PARAMETER(sbox);

   // copy input to the state array
   TRANSPOSE((Ipp8u*)state, in);

   // add the round key to the state before starting the rounds.
   XorRoundKey((Ipp32u*)state, (Ipp32u*)(RoundKey+Nr*16));

   // there will be Nr rounds
   for(round=Nr-1;round>0;round--) {
      invShiftRows(state);
      invSubBytes((Ipp8u*)state);
      XorRoundKey(state,(Ipp32u*)(RoundKey+round*16));
      invMixColumns(state);
    }

   // last round
   invShiftRows(state);
   invSubBytes((Ipp8u*)state);
   XorRoundKey(state,(Ipp32u*)(RoundKey+0*16));

   // copy from the state to output
   TRANSPOSE(out, (Ipp8u*)state);
}
Пример #2
0
void FastRijndael::decryptTwoRounds(unsigned char** block){
	if (!_initd){
		return;
	}
	_round = 2;
	addRoundKey(block);
	invMixColumns(block);
	invShiftRows(block);
	invSubBytes(block);
	_round--;
	addRoundKey(block);
	invMixColumns(block);
	invShiftRows(block);
	invSubBytes(block);
	_round--;
	addRoundKey(block);
}
Пример #3
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);
}
/*

  'A'(41) 'E'(45) 'I'(49) 'M'(4d)   invS-BOX   f8 68 a4 65
  'B'(42) 'F'(46) 'J'(4a) 'N'(4e)  -------->   f6 98 5c b6
  'C'(43) 'G'(47) 'K'(4b) 'O'(4f)              64 16 cc 92
  'D'(44) 'H'(48) 'L'(4c) 'P'(50)              86 d4 5d 6c

*/
void test_invSubBytes_given_ABCDEFGHIJK(void){
  printf("No2.0 - invSubBytes\n");
   uint8_t exState[4][4] = {{0xf8,0x68,0xa4,0x65},    \
                           {0xf6,0x98,0x5c,0xb6},    \
                           {0x64,0x16,0xcc,0x92},    \
                           {0x86,0xd4,0x5d,0x6c} };  
  char* str = "ABCDEFGHIJKLMNOP";
  uint8_t state[4][4];
  convStrToState(str,state);
//  printfState(state);
  printf("\n");
  invSubBytes(state);
//  printfState(state);
  TEST_ASSERT_EQUAL_STATE(exState,state);
}