1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ 2 /* SPDX-License-Identifier: Unlicense */ 3 #include "tomcrypt_private.h" 4 5 /** 6 @file cbc_getiv.c 7 CBC implementation, get IV, Tom St Denis 8 */ 9 10 #ifdef LTC_CBC_MODE 11 12 /** 13 Get the current initialization vector 14 @param IV [out] The destination of the initialization vector 15 @param len [in/out] The max size and resulting size of the initialization vector 16 @param cbc The CBC state 17 @return CRYPT_OK if successful 18 */ cbc_getiv(unsigned char * IV,unsigned long * len,const symmetric_CBC * cbc)19int cbc_getiv(unsigned char *IV, unsigned long *len, const symmetric_CBC *cbc) 20 { 21 LTC_ARGCHK(IV != NULL); 22 LTC_ARGCHK(len != NULL); 23 LTC_ARGCHK(cbc != NULL); 24 if ((unsigned long)cbc->blocklen > *len) { 25 *len = cbc->blocklen; 26 return CRYPT_BUFFER_OVERFLOW; 27 } 28 XMEMCPY(IV, cbc->IV, cbc->blocklen); 29 *len = cbc->blocklen; 30 31 return CRYPT_OK; 32 } 33 34 #endif 35