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 ofb_start.c
13 OFB implementation, start chain, Tom St Denis
14 */
15
16
17 #ifdef LTC_OFB_MODE
18
19 /**
20 Initialize a OFB 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 ofb The OFB state to initialize
27 @return CRYPT_OK if successful
28 */
ofb_start(int cipher,const unsigned char * IV,const unsigned char * key,int keylen,int num_rounds,symmetric_OFB * ofb)29 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
30 int keylen, int num_rounds, symmetric_OFB *ofb)
31 {
32 int x, err;
33
34 LTC_ARGCHK(IV != NULL);
35 LTC_ARGCHK(key != NULL);
36 LTC_ARGCHK(ofb != NULL);
37
38 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
39 return err;
40 }
41
42 /* copy details */
43 ofb->cipher = cipher;
44 ofb->blocklen = cipher_descriptor[cipher].block_length;
45 for (x = 0; x < ofb->blocklen; x++) {
46 ofb->IV[x] = IV[x];
47 }
48
49 /* init the cipher */
50 ofb->padlen = ofb->blocklen;
51 return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ofb->key);
52 }
53
54 #endif
55
56 /* ref: $Format:%D$ */
57 /* git commit: $Format:%H$ */
58 /* commit time: $Format:%ai$ */
59