Path: blob/master/libs/tomcrypt/src/misc/crypt/crypt_register_prng.c
5972 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/8#include "tomcrypt.h"910/**11@file crypt_register_prng.c12Register a PRNG, Tom St Denis13*/1415/**16Register a PRNG with the descriptor table17@param prng The PRNG you wish to register18@return value >= 0 if successfully added (or already present), -1 if unsuccessful19*/20int register_prng(const struct ltc_prng_descriptor *prng)21{22int x;2324LTC_ARGCHK(prng != NULL);2526/* is it already registered? */27LTC_MUTEX_LOCK(<c_prng_mutex);28for (x = 0; x < TAB_SIZE; x++) {29if (XMEMCMP(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) == 0) {30LTC_MUTEX_UNLOCK(<c_prng_mutex);31return x;32}33}3435/* find a blank spot */36for (x = 0; x < TAB_SIZE; x++) {37if (prng_descriptor[x].name == NULL) {38XMEMCPY(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor));39LTC_MUTEX_UNLOCK(<c_prng_mutex);40return x;41}42}4344/* no spot */45LTC_MUTEX_UNLOCK(<c_prng_mutex);46return -1;47}484950