I am trying to implement MISTY1. It's RFC, RFC2994, contains psuedocode that I basically copy and pasted into Code::Blocks. However, I managed to mess that up somehow. After 2 days, I still have not figured out what i did wrong (Im probably being blinded by familiarity).

The RFC provides 2 test vectors, but only the key, plaintext and ciphertext. it does not provide internal values of any sort, and i cannot find other examples of calculations.

I can decrypt incorrectly encrypted data, so i suspect the error is in the key scheduling part, but I have no values to test with.

The full code is at http://ideone.com/RC8Z7 . the test vector (in the main function) provided contained 2 blocks of data. i just encrypted the first block. the second block is commented out. the functions not in class MISTY1 have been used for quite some time and are of no concern. They are there to tell you what they do

Edit: I have looked at other implementations, and I seem to be doing the same things they do, and yet I'm not getting correct outputs.

3 Answers
3

Your implementation of FI() looks suspect to me. I'm pretty sure d7 is supposed to be a 7-bit value, but you store it in a 16-bit value. This means that, after any operation that could set higher bits of d7, you need to clear all but the low 7 bits of d7. Your code doesn't do that. I suspect that's gonna screw things up.

You even have a statement d7 = d7 & 0x7f; at the critical point, but for some reason you put it in parentheses and commented it out. Fix that. Uncomment and unparenthesize it.

Given that you have other implementations that seem to be correct, here are some steps you can take:

Test each of the components of the cipher, by feeding some inputs and comparing the outputs your code gives to the output the other implementations give. Test FI(), FO(), and the tables; those are small enough you should be able to exhaustively test them (on all possible inputs). Test FL() and FLINV() on a large collection of random inputs. Then, test the full cipher on a large collection of random inputs.

Generate some test vectors from the other implementations that you believe you be correct. Extract the output after each round. Compare these testvectors to what your implementation produces.

I would expect that these methods should enable you to narrow down where the problem is.