31 RCSID(
"$Id: 3432d82e70ccc491bbd10bf6cd63363adb638d4b $")
33 #include <freeradius-devel/util/atexit.h>
34 #include <freeradius-devel/util/md5.h>
35 #include <freeradius-devel/util/strerror.h>
37 #ifdef HAVE_OPENSSL_EVP_H
38 # include <freeradius-devel/tls/openssl_user_macros.h>
39 # include <openssl/hmac.h>
41 static _Thread_local EVP_MD_CTX *md5_hmac_ctx;
43 static int _hmac_md5_ctx_free_on_exit(
void *arg)
61 uint8_t const *key,
size_t key_len)
67 ctx = EVP_MD_CTX_new();
72 EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT);
78 pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, key_len);
84 if (
unlikely(EVP_DigestSignInit(ctx, NULL, EVP_md5(), NULL, pkey) != 1)) {
103 EVP_MD_CTX_reset(ctx);
120 uint8_t const *key,
size_t key_len)
153 memset(k_ipad, 0,
sizeof(k_ipad));
154 memset(k_opad, 0,
sizeof(k_opad));
155 memcpy(k_ipad, key, key_len);
156 memcpy(k_opad, key, key_len);
159 for (i = 0; i < 64; i++) {
#define fr_atexit_thread_local(_name, _free, _uctx)
int fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen, uint8_t const *key, size_t key_len)
Calculate HMAC using internal MD5 implementation.
fr_md5_update_t fr_md5_update
fr_md5_final_t fr_md5_final
fr_md5_ctx_reset_t fr_md5_ctx_reset
void fr_md5_ctx_free_from_list(fr_md5_ctx_t **ctx)
fr_md5_ctx_t * fr_md5_ctx_alloc_from_list(void)
#define MD5_DIGEST_LENGTH
#define fr_strerror_const(_msg)
static size_t char fr_sbuff_t size_t inlen