@@ -105,7 +105,7 @@ rhash_info info_sha3_512 = { RHASH_SHA3_512, F_LE64, 64, "SHA3-512", "sha3-512"
105105#define iuf (name ) ini(name), upd(name), fin(name)
106106#define diuf (name ) dgshft(name), ini(name), upd(name), fin(name)
107107
108- /* information about all hashes */
108+ /* information about all supported hash functions */
109109rhash_hash_info rhash_hash_info_default [RHASH_HASH_COUNT ] =
110110{
111111 { & info_crc32 , sizeof (uint32_t ), 0 , iuf (rhash_crc32 ), 0 }, /* 32 bit */
@@ -139,6 +139,8 @@ rhash_hash_info rhash_hash_info_default[RHASH_HASH_COUNT] =
139139
140140/**
141141 * Initialize requested algorithms.
142+ *
143+ * @param mask ids of hash sums to initialize
142144 */
143145void rhash_init_algorithms (unsigned mask )
144146{
@@ -153,6 +155,21 @@ void rhash_init_algorithms(unsigned mask)
153155 rhash_uninitialized_algorithms = 0 ;
154156}
155157
158+ /**
159+ * Returns information about a hash function by its hash_id.
160+ *
161+ * @param hash_id the id of hash algorithm
162+ * @return pointer to the rhash_info structure containing the information
163+ */
164+ const rhash_info * rhash_info_by_id (unsigned hash_id )
165+ {
166+ hash_id &= RHASH_ALL_HASHES ;
167+ /* check that only one bit is set */
168+ if (hash_id != (hash_id & - (int )hash_id )) return NULL ;
169+ /* note: alternative condition is (hash_id == 0 || (hash_id & (hash_id - 1)) != 0) */
170+ return rhash_info_table [rhash_ctz (hash_id )].info ;
171+ }
172+
156173/* CRC32 helper functions */
157174
158175/**
0 commit comments