]> pd.if.org Git - zpackage/blob - libtomcrypt/src/misc/crypt/crypt_find_hash_any.c
commit files needed for zpm-fetchurl
[zpackage] / libtomcrypt / src / misc / crypt / crypt_find_hash_any.c
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_find_hash_any.c
13   Find a hash, Tom St Denis
14 */
15
16 /**
17    Find a hash flexibly.  First by name then if not present by digest size
18    @param name        The name of the hash desired
19    @param digestlen   The minimum length of the digest size (octets)
20    @return >= 0 if found, -1 if not present
21 */int find_hash_any(const char *name, int digestlen)
22 {
23    int x, y, z;
24    LTC_ARGCHK(name != NULL);
25
26    x = find_hash(name);
27    if (x != -1) return x;
28
29    LTC_MUTEX_LOCK(&ltc_hash_mutex);
30    y = MAXBLOCKSIZE+1;
31    z = -1;
32    for (x = 0; x < TAB_SIZE; x++) {
33        if (hash_descriptor[x].name == NULL) {
34           continue;
35        }
36        if ((int)hash_descriptor[x].hashsize >= digestlen && (int)hash_descriptor[x].hashsize < y) {
37           z = x;
38           y = hash_descriptor[x].hashsize;
39        }
40    }
41    LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
42    return z;
43 }
44
45 /* ref:         $Format:%D$ */
46 /* git commit:  $Format:%H$ */
47 /* commit time: $Format:%ai$ */