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 f8_setiv.c
14    F8 implementation, set IV, Tom St Denis
15 */
16 
17 #ifdef LTC_F8_MODE
18 
19 /**
20    Set an initialization vector
21    @param IV   The initialization vector
22    @param len  The length of the vector (in octets)
23    @param f8   The F8 state
24    @return CRYPT_OK if successful
25 */
f8_setiv(const unsigned char * IV,unsigned long len,symmetric_F8 * f8)26 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8)
27 {
28    int err;
29 
30    LTC_ARGCHK(IV != NULL);
31    LTC_ARGCHK(f8 != NULL);
32 
33    if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
34        return err;
35    }
36 
37    if (len != (unsigned long)f8->blocklen) {
38       return CRYPT_INVALID_ARG;
39    }
40 
41    /* force next block */
42    f8->padlen = 0;
43    return cipher_descriptor[f8->cipher]->ecb_encrypt(IV, f8->IV, &f8->key);
44 }
45 
46 #endif
47 
48 
49 /* ref:         $Format:%D$ */
50 /* git commit:  $Format:%H$ */
51 /* commit time: $Format:%ai$ */
52