comparison cfb_decrypt.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 CFB
14
15 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb)
16 {
17 int err;
18
19 _ARGCHK(pt != NULL);
20 _ARGCHK(ct != NULL);
21 _ARGCHK(cfb != NULL);
22
23 if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
24 return err;
25 }
26
27 /* is blocklen/padlen valid? */
28 if (cfb->blocklen < 0 || cfb->blocklen > (int)sizeof(cfb->IV) ||
29 cfb->padlen < 0 || cfb->padlen > (int)sizeof(cfb->pad)) {
30 return CRYPT_INVALID_ARG;
31 }
32
33 while (len-- > 0) {
34 if (cfb->padlen == cfb->blocklen) {
35 cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->pad, cfb->IV, &cfb->key);
36 cfb->padlen = 0;
37 }
38 cfb->pad[cfb->padlen] = *ct;
39 *pt = *ct ^ cfb->IV[cfb->padlen];
40 ++pt;
41 ++ct;
42 ++cfb->padlen;
43 }
44 return CRYPT_OK;
45 }
46
47 #endif
48