tomcrypt/src/modes/ofb/ofb_encrypt.c

59 lines
1.4 KiB
C
Raw Normal View History

2004-01-25 17:40:34 +00:00
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
2004-05-12 20:42:16 +00:00
* guarantee it works.
2004-01-25 17:40:34 +00:00
*
2005-04-17 11:37:13 +00:00
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
2004-01-25 17:40:34 +00:00
*/
2004-12-30 23:55:53 +00:00
#include "tomcrypt.h"
/**
@file ofb_encrypt.c
OFB implementation, encrypt data, Tom St Denis
*/
2003-03-03 00:59:24 +00:00
#ifdef OFB
2004-12-30 23:55:53 +00:00
/**
OFB encrypt
@param pt Plaintext
@param ct [out] Ciphertext
@param len Length of plaintext (octets)
@param ofb OFB state
@return CRYPT_OK if successful
*/
2003-03-03 00:59:24 +00:00
int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb)
{
2003-03-03 01:02:42 +00:00
int err;
2004-12-30 23:55:53 +00:00
LTC_ARGCHK(pt != NULL);
LTC_ARGCHK(ct != NULL);
LTC_ARGCHK(ofb != NULL);
2003-03-03 01:02:42 +00:00
if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
return err;
2003-03-03 00:59:24 +00:00
}
2003-03-13 02:12:16 +00:00
/* is blocklen/padlen valid? */
if (ofb->blocklen < 0 || ofb->blocklen > (int)sizeof(ofb->IV) ||
ofb->padlen < 0 || ofb->padlen > (int)sizeof(ofb->IV)) {
return CRYPT_INVALID_ARG;
}
2003-03-03 01:02:42 +00:00
while (len-- > 0) {
2003-03-03 00:59:24 +00:00
if (ofb->padlen == ofb->blocklen) {
cipher_descriptor[ofb->cipher].ecb_encrypt(ofb->IV, ofb->IV, &ofb->key);
ofb->padlen = 0;
}
*ct++ = *pt++ ^ ofb->IV[ofb->padlen++];
}
return CRYPT_OK;
}
#endif
2005-06-09 00:08:13 +00:00
/* $Source$ */
/* $Revision$ */
/* $Date$ */