[gnutls-help] gnutls_mac_algorithm_t and gnutls_digest_algorithm_t 1:1 compatible?

Nikos Mavrogiannopoulos nmav at gnutls.org
Thu Jul 4 23:00:29 CEST 2013

On 07/03/2013 03:00 PM, Daniel Vassdal wrote:
> Is it reliable to cast from gnutls_mac_algorithm_t to gnutls_digest_algorithm_t?
> I want to let the user dynamically select hashing algorithm from what their gnutls installation supports, so what I'm doing is:
> gnutls_digest_algorithm_t selected_hash = (gnutls_digest_algorithm_t)gnutls_mac_get_id(hash_name);
> Is this prone to failure? I see the enums have a comment in them telling to align them. Could this change?
> Is there a better way to do what I want to do?

In general yes, but note that gnutls_mac_algorithm_t is a superset of
gnutls_digest_algorithm_t, i.e., a MAC algorithm may not always be a
digest algorithm (e.g. UMAC).

I'll try to add similar functions for the digest algorithms to avoid
such issues.


More information about the Gnutls-help mailing list