1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
15
int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb)
23
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
27
/* is blocklen/padlen valid? */
28
if (cfb->blocklen < 0 || cfb->blocklen > (int)sizeof(cfb->IV) ||
29
cfb->padlen < 0 || cfb->padlen > (int)sizeof(cfb->pad)) {
30
return CRYPT_INVALID_ARG;
34
if (cfb->padlen == cfb->blocklen) {
35
cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->pad, cfb->IV, &cfb->key);
38
cfb->pad[cfb->padlen] = *ct;
39
*pt = *ct ^ cfb->IV[cfb->padlen];