ietf-openpgp
[Top] [All Lists]

about cast cfb64

2002-11-20 21:00:13




  /*
 The data is encrypted in CFB mode, with a CFB shift size equal to the
   cipher's block size.  The Initial Vector (IV) is specified as all
   zeros.  Instead of using an IV, OpenPGP prefixes a 10-octet string to
   the data before it is encrypted.  The first eight octets are random,
   and the 9th and 10th octets are copies of the 7th and 8th octets,
   respectively. After encrypting the first 10 octets, the CFB state is
   resynchronized if the cipher block size is 8 octets or less.  The
   last 8 octets of ciphertext are passed through the cipher and the
   block boundary is reset.
*/

this paragraph is come from rfc2440, now if i have the session key and the
ciphertext, how can i decrypt it?
below is what i have tried, but it does not work.
after the first call CAST_cfb64_encrypt, i can get the right 10 octet,
but the second is not right, where do i make some mistakes?
my environment is win2k+vc6.0+openssl
thanks
regards

CAST_KEY castkey;
unsigned char out[128], ivec[8];
int num=0;
memset(out, '\0', 128);
memset(ivec, '\0', 8);
CAST_set_key(&castkey, 16, sessionkey);
CAST_cfb64_encrypt(cipher, out, 10, &castkey, ivec, &num, CAST_DECRYPT);
num = 0;
memset(out, '\0', 128);
CAST_cfb64_encrypt(cipher+10, out, len-10,&castkey, cipher+2, &num,
CAST_DECRYPT);



________________
USTC Alumni Email System, http://mail.ustc.edu,  FREE Signup.

<Prev in Thread] Current Thread [Next in Thread>