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