39 static const char* tsig_str =
"tsig-ssl";
44 static void init_context(
void *context,
47 static void update(
void *context,
const void *data,
size_t size);
48 static void final(
void *context, uint8_t *digest,
size_t *size);
50 typedef struct tsig_cleanup_table_struct tsig_cleanup_table_type;
51 struct tsig_cleanup_table_struct {
52 tsig_cleanup_table_type* next;
55 static tsig_cleanup_table_type* tsig_cleanup_table = NULL;
64 const char* digest,
const char* name,
const char* wireformat)
67 const EVP_MD *hmac_algorithm = NULL;
72 hmac_algorithm = EVP_get_digestbyname(digest);
73 if (!hmac_algorithm) {
74 ods_log_error(
"[%s] %s digest not available", tsig_str, digest);
80 algorithm->
wf_name = ldns_dname_new_frm_str(wireformat);
87 algorithm->
data = hmac_algorithm;
104 tsig_cleanup_table = NULL;
105 tsig_allocator = allocator;
106 OpenSSL_add_all_digests();
108 if (!tsig_openssl_init_algorithm(allocator,
"md5",
"hmac-md5",
109 "hmac-md5.sig-alg.reg.int.")) {
114 if (!tsig_openssl_init_algorithm(allocator,
"sha1",
"hmac-sha1",
120 #ifdef HAVE_EVP_SHA256
122 if (!tsig_openssl_init_algorithm(allocator,
"sha256",
"hmac-sha256",
131 cleanup_context(
void *data)
133 HMAC_CTX* context = (HMAC_CTX*) data;
134 HMAC_CTX_cleanup(context);
139 context_add_cleanup(
void* context)
141 tsig_cleanup_table_type* entry = NULL;
146 sizeof(tsig_cleanup_table_type));
148 entry->cleanup = context;
149 entry->next = tsig_cleanup_table;
150 tsig_cleanup_table = entry;
160 HMAC_CTX_init(context);
161 context_add_cleanup(context);
168 HMAC_CTX* ctx = (HMAC_CTX*) context;
169 const EVP_MD* md = (
const EVP_MD*) algorithm->
data;
170 HMAC_Init_ex(ctx, key->
data, key->
size, md, NULL);
175 update(
void* context,
const void* data,
size_t size)
177 HMAC_CTX* ctx = (HMAC_CTX*) context;
178 HMAC_Update(ctx, (
unsigned char*) data, (
int) size);
183 final(
void* context, uint8_t* digest,
size_t* size)
185 HMAC_CTX* ctx = (HMAC_CTX*) context;
186 unsigned len = (unsigned) *size;
187 HMAC_Final(ctx, digest, &len);
188 *size = (size_t) len;
198 tsig_handler_openssl_finalize(
void)
200 tsig_cleanup_table_type* entry = tsig_cleanup_table;
203 cleanup_context(entry->cleanup);
void *(* hmac_create)(allocator_type *allocator)
void ods_log_debug(const char *format,...)
void * allocator_alloc(allocator_type *allocator, size_t size)
enum ods_enum_status ods_status
void ods_log_error(const char *format,...)
void(* hmac_update)(void *context, const void *data, size_t size)
void(* hmac_final)(void *context, uint8_t *digest, size_t *size)
void(* hmac_init)(void *context, tsig_algo_type *algo, tsig_key_type *key)
#define ods_log_assert(x)
void tsig_handler_add_algo(tsig_algo_type *algo)