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 OFB 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 ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb)
29 LTC_ARGCHK(pt != NULL);
30 LTC_ARGCHK(ct != NULL);
31 LTC_ARGCHK(ofb != NULL);
32 if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
36 /* is blocklen/padlen valid? */
37 if (ofb->blocklen < 0 || ofb->blocklen > (int)sizeof(ofb->IV) ||
38 ofb->padlen < 0 || ofb->padlen > (int)sizeof(ofb->IV)) {
39 return CRYPT_INVALID_ARG;
43 if (ofb->padlen == ofb->blocklen) {
44 if ((err = cipher_descriptor[ofb->cipher].ecb_encrypt(ofb->IV, ofb->IV, &ofb->key)) != CRYPT_OK) {
49 *ct++ = *pt++ ^ ofb->IV[(ofb->padlen)++];
56 /* ref: $Format:%D$ */
57 /* git commit: $Format:%H$ */
58 /* commit time: $Format:%ai$ */