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 #include "tomcrypt.h"
10
11 /**
12 @file cfb_start.c
13 CFB implementation, start chain, Tom St Denis
14 */
15
16
17 #ifdef LTC_CFB_MODE
18
19 /**
20 Initialize a CFB context
21 @param cipher The index of the cipher desired
22 @param IV The initialization vector
23 @param key The secret key
24 @param keylen The length of the secret key (octets)
25 @param num_rounds Number of rounds in the cipher desired (0 for default)
26 @param cfb The CFB state to initialize
27 @return CRYPT_OK if successful
28 */
cfb_start(int cipher,const unsigned char * IV,const unsigned char * key,int keylen,int num_rounds,symmetric_CFB * cfb)29 int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
30 int keylen, int num_rounds, symmetric_CFB *cfb)
31 {
32 int x, err;
33
34 LTC_ARGCHK(IV != NULL);
35 LTC_ARGCHK(key != NULL);
36 LTC_ARGCHK(cfb != NULL);
37
38 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
39 return err;
40 }
41
42
43 /* copy data */
44 cfb->cipher = cipher;
45 cfb->blocklen = cipher_descriptor[cipher].block_length;
46 for (x = 0; x < cfb->blocklen; x++)
47 cfb->IV[x] = IV[x];
48
49 /* init the cipher */
50 if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {
51 return err;
52 }
53
54 /* encrypt the IV */
55 cfb->padlen = 0;
56 return cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->IV, cfb->IV, &cfb->key);
57 }
58
59 #endif
60
61 /* ref: $Format:%D$ */
62 /* git commit: $Format:%H$ */
63 /* commit time: $Format:%ai$ */
64