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_register_prng.c 14 Register a PRNG, Tom St Denis 15 */ 16 17 /** 18 Register a PRNG with the descriptor table 19 @param prng The PRNG you wish to register 20 @return value >= 0 if successfully added (or already present), -1 if unsuccessful 21 */ register_prng(const struct ltc_prng_descriptor * prng)22int register_prng(const struct ltc_prng_descriptor *prng) 23 { 24 int x; 25 26 LTC_ARGCHK(prng != NULL); 27 28 /* is it already registered? */ 29 LTC_MUTEX_LOCK(<c_prng_mutex); 30 for (x = 0; x < TAB_SIZE; x++) { 31 if (prng_descriptor[x] == prng) { 32 LTC_MUTEX_UNLOCK(<c_prng_mutex); 33 return x; 34 } 35 } 36 37 /* find a blank spot */ 38 for (x = 0; x < TAB_SIZE; x++) { 39 if (prng_descriptor[x] == NULL) { 40 prng_descriptor[x] = prng; 41 LTC_MUTEX_UNLOCK(<c_prng_mutex); 42 return x; 43 } 44 } 45 46 /* no spot */ 47 LTC_MUTEX_UNLOCK(<c_prng_mutex); 48 return -1; 49 } 50 51 /* ref: $Format:%D$ */ 52 /* git commit: $Format:%H$ */ 53 /* commit time: $Format:%ai$ */ 54