1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 * 3 * LibTomCrypt is a library that provides various cryptographic 4 * algorithms in a highly modular and flexible manner. 5 * 6 * The library is free for all purposes without any express 7 * guarantee it works. 8 */ 9 #include "tomcrypt.h" 10 11 /** 12 @file crypt_register_hash.c 13 Register a HASH, Tom St Denis 14 */ 15 16 /** 17 Register a hash with the descriptor table 18 @param hash The hash you wish to register 19 @return value >= 0 if successfully added (or already present), -1 if unsuccessful 20 */ register_hash(const struct ltc_hash_descriptor * hash)21int register_hash(const struct ltc_hash_descriptor *hash) 22 { 23 int x; 24 25 LTC_ARGCHK(hash != NULL); 26 27 /* is it already registered? */ 28 LTC_MUTEX_LOCK(<c_hash_mutex); 29 for (x = 0; x < TAB_SIZE; x++) { 30 if (XMEMCMP(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) { 31 LTC_MUTEX_UNLOCK(<c_hash_mutex); 32 return x; 33 } 34 } 35 36 /* find a blank spot */ 37 for (x = 0; x < TAB_SIZE; x++) { 38 if (hash_descriptor[x].name == NULL) { 39 XMEMCPY(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)); 40 LTC_MUTEX_UNLOCK(<c_hash_mutex); 41 return x; 42 } 43 } 44 45 /* no spot */ 46 LTC_MUTEX_UNLOCK(<c_hash_mutex); 47 return -1; 48 } 49 50 /* ref: HEAD -> master, tag: v1.18.2 */ 51 /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */ 52 /* commit time: 2018-07-01 22:49:01 +0200 */ 53