I'm going to make a long story short. It's been a while that I want to implement my own AES encryption/decryption program. The encryption program went well and encrypting without any error or strange output (Since I have compared my program's output with a working commercial one and result was the same).

Wikipedia was (is) my guide in this implementation within which I read "A set of reverse rounds are applied to transform ciphertext back into the original plaintext using the same encryption key."

There are couple of modules that I implemented:

  1. Add round key
  2. Shift rows
  3. Sub bytes
  4. Mix Column

I also implemented couple of reverse implementation of the above modules:

  1. Reverse shift rows
  2. Reverse Sub Byte
  3. Reverse Mix Column

NOTE: I didn't implement reverse round key since, It's XOR ing the plaintext with the encryption key, and reverse of XOR is XOR itself (correct me if I am wrong)

So I putted this modules in the reverse order that I did encryption, but never I got my plain-text back:

expandkey128(key);
rev_subbytes(data);  
rev_shiftrows(data);
addroundkey(data,key,10);

for(int i = 9; i>= 1; i--) { 
    rev_subbytes(data); 
    rev_shiftrows(data);
    rev_mixColum(data);
    addroundkey(data,key,i);
}

addroundkey(data,key,0);

// Please note that I also did from 0 to 10 ,
// instead of 10 to 0 and didn't workout

And also I thought , maybe I should not implement reverse model of the modules, maybe I have to use those modules that I did encryption with, only in reverse order; well guess what? didn't work! :

expandkey128(key);
addroundkey(data,key,0);

for(int i = 1; i<= 9; i++) {
    subbytes(data); 
    shiftrows(data);
    mixColum(data);
    addroundkey(data,key,i);
}

subbytes(data);
shiftrows(data);
addroundkey(data,key,10);

So here is the question: what is wrong? |

Edit
Report