1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ 2 /* SPDX-License-Identifier: Unlicense */ 3 #include "tomcrypt_private.h" 4 5 /** 6 @file ctr_getiv.c 7 CTR implementation, get IV, Tom St Denis 8 */ 9 10 #ifdef LTC_CTR_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 ctr The CTR state 17 @return CRYPT_OK if successful 18 */ ctr_getiv(unsigned char * IV,unsigned long * len,const symmetric_CTR * ctr)19int ctr_getiv(unsigned char *IV, unsigned long *len, const symmetric_CTR *ctr) 20 { 21 LTC_ARGCHK(IV != NULL); 22 LTC_ARGCHK(len != NULL); 23 LTC_ARGCHK(ctr != NULL); 24 if ((unsigned long)ctr->blocklen > *len) { 25 *len = ctr->blocklen; 26 return CRYPT_BUFFER_OVERFLOW; 27 } 28 XMEMCPY(IV, ctr->ctr, ctr->blocklen); 29 *len = ctr->blocklen; 30 31 return CRYPT_OK; 32 } 33 34 #endif 35