|
I am
currently trying to developp an application using a Gemplus smart card (GPK
16000) and I am supposed to use what they call Secure Messaging to dialog with
the card. The
problem is my cryptographic background is very low and even with the examples my
mind is still confufed. So
everytime is send a command to the smart card I need to calculate a Crypto
checksum as shown below : Imagine the Cmd is 24 bytes long, the first step is to
divided it into blocks of 8 bytes : So in
my case with my command of 24 bytes I obtain 3 blocks : Block 1, Block and Block
3. And now here is how is calculated the checksum
: Kts
is a private key (16 bytes long) : R1 = 3DES(Block1, Kts) R2 = 3DES(Block2 XOR R1,
Kts) R3 = 3DES (Block3 XOR R2, Kts) And
my checksum is supposed to be the latest result
R3. Now
my question is how do I do that ? I
have another question when you do a 3DES with a private key of 16 bytes and a
text to cipher of 8 bytes what is the length of the ciphered text ? (8 or
16). After
having read some tutorial on 3DES, it seems that this kind of algorithm is
actually implemented in 3DES CBC mode but I am not sure of that. Anyway I tried
the following code : // 3DES in CBC mode with
Kats unsigned int
outputLength; const
byte iv[] =
{0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; byte*
ciphertext;
CBC_Mode<DES_EDE2>::Encryption
cbcEncryption(m_Kats,DES_EDE2::DEFAULT_KEYLENGTH,
iv); StreamTransformationFilter
encryptor(cbcEncryption,NULL,StreamTransformationFilter::NO_PADDING);
encryptor.Put(Cmd, 24);
encryptor.MessageEnd();
outputLength = encryptor.MaxRetrievable();
ciphertext = new byte[outputLength];
encryptor.Get(ciphertext, outputLength); I
don�t even know what is the IV tab but I finally obtain a 24 bytes long ciphered
text and I was more expected a 8 bytes result. To sum up I am lost. Please
Help |
<<clip_image002.jpg>>
