xref: /optee_os/core/lib/libtomcrypt/src/modes/ofb/ofb_setiv.c (revision 8411e6ad673d20c4742ed30c785e3f5cdea54dfa)
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6    @file ofb_setiv.c
7    OFB implementation, set IV, Tom St Denis
8 */
9 
10 #ifdef LTC_OFB_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 ofb  The OFB state
17    @return CRYPT_OK if successful
18 */
ofb_setiv(const unsigned char * IV,unsigned long len,symmetric_OFB * ofb)19 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb)
20 {
21    int err;
22 
23    LTC_ARGCHK(IV  != NULL);
24    LTC_ARGCHK(ofb != NULL);
25 
26    if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
27        return err;
28    }
29 
30    if (len != (unsigned long)ofb->blocklen) {
31       return CRYPT_INVALID_ARG;
32    }
33 
34    /* force next block */
35    ofb->padlen = 0;
36    return cipher_descriptor[ofb->cipher]->ecb_encrypt(IV, ofb->IV, &ofb->key);
37 }
38 
39 #endif
40 
41