1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6    @file f8_setiv.c
7    F8 implementation, set IV, Tom St Denis
8 */
9 
10 #ifdef LTC_F8_MODE
11 
12 /**
13    Set an initialization vector
14    @param IV   The initialization vector
15    @param len  The length of the vector (in octets)
16    @param f8   The F8 state
17    @return CRYPT_OK if successful
18 */
f8_setiv(const unsigned char * IV,unsigned long len,symmetric_F8 * f8)19 int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8)
20 {
21    int err;
22 
23    LTC_ARGCHK(IV != NULL);
24    LTC_ARGCHK(f8 != NULL);
25 
26    if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
27        return err;
28    }
29 
30    if (len != (unsigned long)f8->blocklen) {
31       return CRYPT_INVALID_ARG;
32    }
33 
34    /* force next block */
35    f8->padlen = 0;
36    return cipher_descriptor[f8->cipher]->ecb_encrypt(IV, f8->IV, &f8->key);
37 }
38 
39 #endif
40 
41