PDA

View Full Version : Safer-K128


ramon
April 22nd, 2004, 05:55
Hi,

I have the following C# code <<attached>>, the class SaferKn encrypts and decrypts blocks bytes, it is Safer-K128 with 10 rounds.

if I do:
byte[] array1_crypted;
byte[] array1_decrypted;
byte[] array1 = new byte[] { (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o' };

SaferKn MyCipher = new SaferKn();
array1_crypted = MyCipher.EncryptBlock(array1);
array1_decrypted = MyCipher.DecryptBlock(array1_crypted);

then I can see that "array1_decrypted == array1 == Hello" as expected,
but if I use MyCipher.KeyScheduling(...) with my own userkey1 and userkey2
before encrypt/decrypt then "array1_decrypted != array1" will be different!!!

Sorry if I'm missing something basic here, but if the users keys are the same, why "array1_decrypted != array1", the userkey1 and userkey2 is not the same for encrypt and decrypt? If not how to retrieve decrypt user keys if I know the encrypt keys?

thank u for your attention,
Ramon

mike
April 23rd, 2004, 00:41
OK, the two user keys are there so you can have a 64-bit key or a 128-bit key. You're using 128-bit, so all 16 bytes should be generated randomly.

The way it's supposed to work, you call KeySchedule once and then can encrypt & decrypt blocks to your heart's content. If that doesn't work, there may be an error in the code.

http://citeseer.ist.psu.edu/massey95safer.html
has test vectors and the state in each round, so you can check your implementation.

ramon
April 23rd, 2004, 03:31
Yeah, thanks mike, I solved the problem, this code was ripped of from an app, I just used original code C code of safer and I got it to work.

cyas