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