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, encrypt data, Tom St Denis
21 @param ct [out] Ciphertext
22 @param len Length of plaintext (octets)
24 @return CRYPT_OK if successful
26 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, 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 = *pt ^ cfb->IV[cfb->padlen]);
61 /* ref: $Format:%D$ */
62 /* git commit: $Format:%H$ */
63 /* commit time: $Format:%ai$ */