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