comparison ofb_encrypt.c @ 3:7faae8f46238 libtomcrypt-orig

Branch renaming
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:25:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 3:7faae8f46238
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11 #include "mycrypt.h"
12
13 #ifdef OFB
14
15 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb)
16 {
17 int err;
18 _ARGCHK(pt != NULL);
19 _ARGCHK(ct != NULL);
20 _ARGCHK(ofb != NULL);
21 if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
22 return err;
23 }
24
25 /* is blocklen/padlen valid? */
26 if (ofb->blocklen < 0 || ofb->blocklen > (int)sizeof(ofb->IV) ||
27 ofb->padlen < 0 || ofb->padlen > (int)sizeof(ofb->IV)) {
28 return CRYPT_INVALID_ARG;
29 }
30
31 while (len-- > 0) {
32 if (ofb->padlen == ofb->blocklen) {
33 cipher_descriptor[ofb->cipher].ecb_encrypt(ofb->IV, ofb->IV, &ofb->key);
34 ofb->padlen = 0;
35 }
36 *ct++ = *pt++ ^ ofb->IV[ofb->padlen++];
37 }
38 return CRYPT_OK;
39 }
40
41 #endif