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 crypt_find_cipher_any.c 14 Find a cipher in the descriptor tables, Tom St Denis 15 */ 16 17 /** 18 Find a cipher flexibly. First by name then if not present by block and key size 19 @param name The name of the cipher desired 20 @param blocklen The minimum length of the block cipher desired (octets) 21 @param keylen The minimum length of the key size desired (octets) 22 @return >= 0 if found, -1 if not present 23 */ find_cipher_any(const char * name,int blocklen,int keylen)24int find_cipher_any(const char *name, int blocklen, int keylen) 25 { 26 int x; 27 28 if(name != NULL) { 29 x = find_cipher(name); 30 if (x != -1) return x; 31 } 32 33 LTC_MUTEX_LOCK(<c_cipher_mutex); 34 for (x = 0; x < TAB_SIZE; x++) { 35 if (cipher_descriptor[x] == NULL) { 36 continue; 37 } 38 if (blocklen <= (int)cipher_descriptor[x]->block_length && keylen <= (int)cipher_descriptor[x]->max_key_length) { 39 LTC_MUTEX_UNLOCK(<c_cipher_mutex); 40 return x; 41 } 42 } 43 LTC_MUTEX_UNLOCK(<c_cipher_mutex); 44 return -1; 45 } 46 47 /* ref: $Format:%D$ */ 48 /* git commit: $Format:%H$ */ 49 /* commit time: $Format:%ai$ */ 50