-----Original Message-----
From: Muadzafri Makhtar [mailto:[EMAIL PROTECTED] 
Sent: den 10 november 2005 06:32
To: [email protected]
Subject: understandting keylength problem

hi guys,

i'm a newbie in cryptogrphy programming.  i got this code example in a
previous posting in the mailing list, but i could not find it back
anywhere by using the search tool in the archieve.   I'm currently
playing around with some symmeteric encryption like blowfish in trying to
understand how they work.  But the thing is this is part of the code that
i'm being tried to study but could no fully understand:

#define KEY_LENGTH 16

byte key[KEY_LENGTH]= //32bytes
{0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xA,0xB,0xC,0xD,0xF};

byte iv[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

CryptoPP::BlowfishEncryption enc(key, KEY_LENGTH);
CryptoPP::CBC_CTS_Encryptor cbcEnc(enc, iv);

first question is, the KEY_LENGTH.  Can i just put any number from
1-32 to define the key lenght?

second is what is the 0x0,0x1,0x2,0x3,0x4,0x5 or sometimes 0x48, 0x93, 0x46,
0x67, 0x98, 0x3D, 0xE6, 0x8D all about? is it specific to lenght of
KEY_LENGTH defined earlier? how to create those number for the KEY_LENGHT?

i did some timing function to the code that i'm running to see how fast
compared to other algoritm like DES, TWOFISH etc2.  But the problem is when
i changed the KEY_LENGHT from 32 to either 16, 8 or anynumber, the time
recorded is still the same. Either i used KEY_LENGHT 32,16,8 for blowfish it
just giving out the same timing results. Isnt it supposed to be if the
keylenght is extend, then the encrypting time should be extended to?

hope you guys can give some enligtment..

thanks in advance..

japp.
****************************************************************
Hello,
      Just a quick answer to some of your questions. I am also a newbie so
if anyone more experianced on the list see any bad or incorrect advice
please correct me.

KEY_LENGTH is the size of the key to use in bytes. Different algos support
different key sizes. There is a definition for standard key-length in the
cryptopp library for each algo. For example for AES it's called
AES::DEFAULT_KEYLENGTH, twofish Twofish::DEFAULT_KEYLENGTH and so on. These
are predefined so that you don't have to set them manually. You can of
course use other common key-lengths supported by the algo. For example
Blowfish uses key-lengths from minimum 32, maximum 448, and the default I
think is 128 bits [note bits not bytes] (all must be multiples of 8 bits). 

The 0x?? are hex values. So for example 0x37 would be equal to 55 decimal
(as 37 hex is 55 decimal). It is often used for example with memset to fill
a buffer with all zeroes 0x00. So for example to create a buffer to hold a
sha1 hash (which is 20 bytes) I could preinitialize it with all zeroes like
so:

byte hashOutputBuffer[ CryptoPP::SHA::DIGESTSIZE ];
memset( hashOutputBuffer, 0x00, CryptoPP::SHA::DIGESTSIZE );

Is the above example I use the SHA::DIGESTSIZE definition to set the length
value for the buffer. I first define the variable and then initialize it
with memset thus filling it with 0x00 (memset takes buffername, value to
set, number of bytes to copy). 

Look at my code I posted in a mail earlier on this list and you might get
some tips. Even though it deals with hashses and HMAC's the principals are
the same (HMAC also uses a key). Hope this was understandable and helped you
in some way. Have a nice day!

P.S. There are some errors in the code you posted: 

1. The keylength is defined to 16 bytes, the comment says 32 but it is
initialized to 15!?
2. Your IV is 16 bytes but also there is initialized with 15 values only.

// jpb
  

Reply via email to