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
13 CFB implementation, decrypt data, Tom St Denis
21 @param pt [out] Plaintext
22 @param len Length of ciphertext (octets)
24 @return CRYPT_OK if successful
26 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb)
30 LTC_ARGCHK(pt != NULL);
31 LTC_ARGCHK(ct != NULL);
32 LTC_ARGCHK(cfb != NULL);
34 if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
38 /* is blocklen/padlen valid? */
39 if (cfb->blocklen < 0 || cfb->blocklen > (int)sizeof(cfb->IV) ||
40 cfb->padlen < 0 || cfb->padlen > (int)sizeof(cfb->pad)) {
41 return CRYPT_INVALID_ARG;
45 if (cfb->padlen == cfb->blocklen) {
46 if ((err = cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->pad, cfb->IV, &cfb->key)) != CRYPT_OK) {
51 cfb->pad[cfb->padlen] = *ct;
52 *pt = *ct ^ cfb->IV[cfb->padlen];
63 /* ref: $Format:%D$ */
64 /* git commit: $Format:%H$ */
65 /* commit time: $Format:%ai$ */