1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6   @file crypt_cipher_is_valid.c
7   Determine if cipher is valid, Tom St Denis
8 */
9 
10 /*
11    Test if a cipher index is valid
12    @param idx   The index of the cipher to search for
13    @return CRYPT_OK if valid
14 */
cipher_is_valid(int idx)15 int cipher_is_valid(int idx)
16 {
17    LTC_MUTEX_LOCK(&ltc_cipher_mutex);
18    if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx] == NULL) {
19       LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
20       return CRYPT_INVALID_CIPHER;
21    }
22    LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
23    return CRYPT_OK;
24 }
25