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); }
/** * @brief Decrypts 16 bytes of data. * * Based on Advanced Encryption Standard specification. * * @param dataToEncrypt Data to encrypt, must be at least 16 bytes in size. * @param result Destination to store encrypted data, must be at least 16 bytes in size. * @param numRounds Number of rounds. * @param roundKey Round key. */ void ThreadMessageItemEncrypt::InverseCipher(unsigned char * dataToEncrypt,unsigned char * result, unsigned char numRounds, unsigned char * roundKey) { // Copy data into state for manipulation for(size_t r = 0;r<EncryptKey::WORD_SIZE;r++) { for(size_t c = 0;c<EncryptKey::WORD_SIZE;c++) { state[r][c] = result[r+(c*EncryptKey::WORD_SIZE)]; } } // Perform decryption operations XorRoundKey(numRounds,roundKey); for(size_t r = numRounds-1; r>=1; r--) { ShiftRowsRight(); InverseSubBytes(); XorRoundKey(r,roundKey); InverseMixColumns(); } ShiftRowsRight(); InverseSubBytes(); XorRoundKey(0,roundKey); // Copy state into data now that we have finished for(int r = 0;r<EncryptKey::WORD_SIZE;r++) { for(int c = 0;c<EncryptKey::WORD_SIZE;c++) { result[r+(c*EncryptKey::WORD_SIZE)] = state[r][c]; } } }