1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6    @file ofb_start.c
7    OFB implementation, start chain, Tom St Denis
8 */
9 
10 
11 #ifdef LTC_OFB_MODE
12 
13 /**
14    Initialize a OFB context
15    @param cipher      The index of the cipher desired
16    @param IV          The initialization vector
17    @param key         The secret key
18    @param keylen      The length of the secret key (octets)
19    @param num_rounds  Number of rounds in the cipher desired (0 for default)
20    @param ofb         The OFB state to initialize
21    @return CRYPT_OK if successful
22 */
ofb_start(int cipher,const unsigned char * IV,const unsigned char * key,int keylen,int num_rounds,symmetric_OFB * ofb)23 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
24               int keylen, int num_rounds, symmetric_OFB *ofb)
25 {
26    int x, err;
27 
28    LTC_ARGCHK(IV != NULL);
29    LTC_ARGCHK(key != NULL);
30    LTC_ARGCHK(ofb != NULL);
31 
32    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
33       return err;
34    }
35 
36    /* copy details */
37    ofb->cipher = cipher;
38    ofb->blocklen = cipher_descriptor[cipher]->block_length;
39    for (x = 0; x < ofb->blocklen; x++) {
40        ofb->IV[x] = IV[x];
41    }
42 
43    /* init the cipher */
44    ofb->padlen = ofb->blocklen;
45    return cipher_descriptor[cipher]->setup(key, keylen, num_rounds, &ofb->key);
46 }
47 
48 #endif
49