1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3  *
4  * LibTomCrypt is a library that provides various cryptographic
5  * algorithms in a highly modular and flexible manner.
6  *
7  * The library is free for all purposes without any express
8  * guarantee it works.
9  */
10 #include "tomcrypt_private.h"
11 
12 /**
13    @file ofb_start.c
14    OFB implementation, start chain, Tom St Denis
15 */
16 
17 
18 #ifdef LTC_OFB_MODE
19 
20 /**
21    Initialize a OFB context
22    @param cipher      The index of the cipher desired
23    @param IV          The initialization vector
24    @param key         The secret key
25    @param keylen      The length of the secret key (octets)
26    @param num_rounds  Number of rounds in the cipher desired (0 for default)
27    @param ofb         The OFB state to initialize
28    @return CRYPT_OK if successful
29 */
ofb_start(int cipher,const unsigned char * IV,const unsigned char * key,int keylen,int num_rounds,symmetric_OFB * ofb)30 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
31               int keylen, int num_rounds, symmetric_OFB *ofb)
32 {
33    int x, err;
34 
35    LTC_ARGCHK(IV != NULL);
36    LTC_ARGCHK(key != NULL);
37    LTC_ARGCHK(ofb != NULL);
38 
39    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
40       return err;
41    }
42 
43    /* copy details */
44    ofb->cipher = cipher;
45    ofb->blocklen = cipher_descriptor[cipher]->block_length;
46    for (x = 0; x < ofb->blocklen; x++) {
47        ofb->IV[x] = IV[x];
48    }
49 
50    /* init the cipher */
51    ofb->padlen = ofb->blocklen;
52    return cipher_descriptor[cipher]->setup(key, keylen, num_rounds, &ofb->key);
53 }
54 
55 #endif
56 
57 /* ref:         $Format:%D$ */
58 /* git commit:  $Format:%H$ */
59 /* commit time: $Format:%ai$ */
60