unsigned int digestlen;
isc_region_t r;
isc_md_t *md;
- isc_md_type_t md_type = 0;
+ const isc_md_type_t *md_type = NULL;
REQUIRE(key != NULL);
REQUIRE(key->type == dns_rdatatype_dnskey ||
}
static isc_result_t
-hmac_fromdns(isc_md_type_t type, dst_key_t *key, isc_buffer_t *data);
+hmac_fromdns(const isc_md_type_t *type, dst_key_t *key, isc_buffer_t *data);
struct dst_hmac_key {
uint8_t key[ISC_MAX_BLOCK_SIZE];
}
static inline isc_result_t
-hmac_createctx(isc_md_type_t type, const dst_key_t *key, dst_context_t *dctx) {
+hmac_createctx(const isc_md_type_t *type, const dst_key_t *key,
+ dst_context_t *dctx) {
isc_result_t result;
const dst_hmac_key_t *hkey = key->keydata.hmac_key;
isc_hmac_t *ctx = isc_hmac_new(); /* Either returns or abort()s */
}
static inline bool
-hmac_compare(isc_md_type_t type, const dst_key_t *key1, const dst_key_t *key2) {
+hmac_compare(const isc_md_type_t *type, const dst_key_t *key1,
+ const dst_key_t *key2) {
dst_hmac_key_t *hkey1, *hkey2;
hkey1 = key1->keydata.hmac_key;
}
static inline isc_result_t
-hmac_generate(isc_md_type_t type, dst_key_t *key) {
+hmac_generate(const isc_md_type_t *type, dst_key_t *key) {
isc_buffer_t b;
isc_result_t ret;
unsigned int bytes, len;
static inline isc_result_t
hmac_todns(const dst_key_t *key, isc_buffer_t *data) {
+ REQUIRE(key != NULL && key->keydata.hmac_key != NULL);
dst_hmac_key_t *hkey = key->keydata.hmac_key;
unsigned int bytes;
- REQUIRE(hkey != NULL);
-
bytes = (key->key_size + 7) / 8;
if (isc_buffer_availablelength(data) < bytes) {
return (ISC_R_NOSPACE);
}
static inline isc_result_t
-hmac_fromdns(isc_md_type_t type, dst_key_t *key, isc_buffer_t *data) {
+hmac_fromdns(const isc_md_type_t *type, dst_key_t *key, isc_buffer_t *data) {
dst_hmac_key_t *hkey;
unsigned int keylen;
isc_region_t r;
}
static inline int
-hmac__get_tag_key(isc_md_type_t type) {
+hmac__get_tag_key(const isc_md_type_t *type) {
if (type == ISC_MD_MD5) {
return (TAG_HMACMD5_KEY);
} else if (type == ISC_MD_SHA1) {
}
static inline int
-hmac__get_tag_bits(isc_md_type_t type) {
+hmac__get_tag_bits(const isc_md_type_t *type) {
if (type == ISC_MD_MD5) {
return (TAG_HMACMD5_BITS);
} else if (type == ISC_MD_SHA1) {
}
static inline isc_result_t
-hmac_tofile(isc_md_type_t type, const dst_key_t *key, const char *directory) {
+hmac_tofile(const isc_md_type_t *type, const dst_key_t *key,
+ const char *directory) {
dst_hmac_key_t *hkey;
dst_private_t priv;
int bytes = (key->key_size + 7) / 8;
}
static inline int
-hmac__to_dst_alg(isc_md_type_t type) {
+hmac__to_dst_alg(const isc_md_type_t *type) {
if (type == ISC_MD_MD5) {
return (DST_ALG_HMACMD5);
} else if (type == ISC_MD_SHA1) {
}
static inline isc_result_t
-hmac_parse(isc_md_type_t type, dst_key_t *key, isc_lex_t *lexer,
+hmac_parse(const isc_md_type_t *type, dst_key_t *key, isc_lex_t *lexer,
dst_key_t *pub) {
dst_private_t priv;
isc_result_t result, tresult;
isc_result_t
isc_hmac_init(isc_hmac_t *hmac, const void *key, size_t keylen,
- isc_md_type_t md_type) {
+ const isc_md_type_t *md_type) {
REQUIRE(hmac != NULL);
REQUIRE(key != NULL);
return (ISC_R_SUCCESS);
}
-isc_md_type_t
+const isc_md_type_t *
isc_hmac_get_md_type(isc_hmac_t *hmac) {
REQUIRE(hmac != NULL);
}
isc_result_t
-isc_hmac(isc_md_type_t type, const void *key, const int keylen,
+isc_hmac(const isc_md_type_t *type, const void *key, const int keylen,
const unsigned char *buf, const size_t len, unsigned char *digest,
unsigned int *digestlen) {
isc_result_t res;
* (i.e. the length of the digest) will be written to the @digestlen.
*/
isc_result_t
-isc_hmac(isc_md_type_t type, const void *key, const int keylen,
+isc_hmac(const isc_md_type_t *type, const void *key, const int keylen,
const unsigned char *buf, const size_t len, unsigned char *digest,
unsigned int *digestlen);
isc_result_t
isc_hmac_init(isc_hmac_t *hmac, const void *key, size_t keylen,
- isc_md_type_t type);
+ const isc_md_type_t *type);
/**
* isc_hmac_reset:
* This function return the isc_md_type_t previously set for the supplied
* HMAC context or NULL if no isc_md_type_t has been set.
*/
-isc_md_type_t
+const isc_md_type_t *
isc_hmac_get_md_type(isc_hmac_t *hmac);
/**
#include <isc/result.h>
#include <isc/types.h>
-#include <openssl/evp.h>
-
-typedef EVP_MD_CTX isc_md_t;
+typedef void isc_md_t;
/**
* isc_md_type_t:
*
* Enumeration of supported message digest algorithms.
*/
-typedef const EVP_MD *isc_md_type_t;
-
-#define ISC_MD_MD5 EVP_md5()
-#define ISC_MD_SHA1 EVP_sha1()
-#define ISC_MD_SHA224 EVP_sha224()
-#define ISC_MD_SHA256 EVP_sha256()
-#define ISC_MD_SHA384 EVP_sha384()
-#define ISC_MD_SHA512 EVP_sha512()
+typedef void isc_md_type_t;
+
+#define ISC_MD_MD5 isc__md_md5()
+#define ISC_MD_SHA1 isc__md_sha1()
+#define ISC_MD_SHA224 isc__md_sha224()
+#define ISC_MD_SHA256 isc__md_sha256()
+#define ISC_MD_SHA384 isc__md_sha384()
+#define ISC_MD_SHA512 isc__md_sha512()
+
+const isc_md_type_t *
+isc__md_md5(void);
+const isc_md_type_t *
+isc__md_sha1(void);
+const isc_md_type_t *
+isc__md_sha224(void);
+const isc_md_type_t *
+isc__md_sha256(void);
+const isc_md_type_t *
+isc__md_sha384(void);
+const isc_md_type_t *
+isc__md_sha512(void);
#define ISC_MD5_DIGESTLENGTH isc_md_type_get_size(ISC_MD_MD5)
#define ISC_MD5_BLOCK_LENGTH isc_md_type_get_block_size(ISC_MD_MD5)
#define ISC_SHA512_DIGESTLENGTH isc_md_type_get_size(ISC_MD_SHA512)
#define ISC_SHA512_BLOCK_LENGTH isc_md_type_get_block_size(ISC_MD_SHA512)
-#define ISC_MAX_MD_SIZE EVP_MAX_MD_SIZE
+#define ISC_MAX_MD_SIZE 64U /* EVP_MAX_MD_SIZE */
#define ISC_MAX_BLOCK_SIZE 128U /* ISC_SHA512_BLOCK_LENGTH */
/**
* at @digestlen, at most ISC_MAX_MD_SIZE bytes will be written.
*/
isc_result_t
-isc_md(isc_md_type_t type, const unsigned char *buf, const size_t len,
+isc_md(const isc_md_type_t *type, const unsigned char *buf, const size_t len,
unsigned char *digest, unsigned int *digestlen);
/**
* initialized before calling this function.
*/
isc_result_t
-isc_md_init(isc_md_t *, const isc_md_type_t md_type);
+isc_md_init(isc_md_t *, const isc_md_type_t *md_type);
/**
* isc_md_reset:
* This function return the isc_md_type_t previously set for the supplied
* message digest context or NULL if no isc_md_type_t has been set.
*/
-isc_md_type_t
+const isc_md_type_t *
isc_md_get_md_type(isc_md_t *md);
/**
* isc_md_type_t , i.e. the size of the hash.
*/
size_t
-isc_md_type_get_size(isc_md_type_t md_type);
+isc_md_type_get_size(const isc_md_type_t *md_type);
/**
* isc_md_block_size:
* isc_md_type_t.
*/
size_t
-isc_md_type_get_block_size(isc_md_type_t md_type);
+isc_md_type_get_block_size(const isc_md_type_t *md_type);
}
isc_result_t
-isc_md_init(isc_md_t *md, const isc_md_type_t md_type) {
+isc_md_init(isc_md_t *md, const isc_md_type_t *md_type) {
REQUIRE(md != NULL);
if (md_type == NULL) {
return (ISC_R_SUCCESS);
}
-isc_md_type_t
+const isc_md_type_t *
isc_md_get_md_type(isc_md_t *md) {
REQUIRE(md != NULL);
}
size_t
-isc_md_type_get_size(isc_md_type_t md_type) {
+isc_md_type_get_size(const isc_md_type_t *md_type) {
+ STATIC_ASSERT(ISC_MAX_MD_SIZE >= EVP_MAX_MD_SIZE,
+ "Change ISC_MAX_MD_SIZE to be greater than or equal to "
+ "EVP_MAX_MD_SIZE");
if (md_type != NULL) {
return ((size_t)EVP_MD_size(md_type));
}
}
size_t
-isc_md_type_get_block_size(isc_md_type_t md_type) {
+isc_md_type_get_block_size(const isc_md_type_t *md_type) {
+ STATIC_ASSERT(ISC_MAX_MD_SIZE >= EVP_MAX_MD_SIZE,
+ "Change ISC_MAX_MD_SIZE to be greater than or equal to "
+ "EVP_MAX_MD_SIZE");
if (md_type != NULL) {
return ((size_t)EVP_MD_block_size(md_type));
}
}
isc_result_t
-isc_md(isc_md_type_t md_type, const unsigned char *buf, const size_t len,
+isc_md(const isc_md_type_t *md_type, const unsigned char *buf, const size_t len,
unsigned char *digest, unsigned int *digestlen) {
isc_md_t *md;
isc_result_t res;
return (res);
}
+
+#define md_register_algorithm(alg) \
+ const isc_md_type_t *isc__md_##alg(void) { return (EVP_##alg()); }
+
+md_register_algorithm(md5);
+md_register_algorithm(sha1);
+md_register_algorithm(sha224);
+md_register_algorithm(sha256);
+md_register_algorithm(sha384);
+md_register_algorithm(sha512);
static void
isc_hmac_test(isc_hmac_t *hmac, const void *key, size_t keylen,
- isc_md_type_t type, const char *buf, size_t buflen,
+ const isc_md_type_t *type, const char *buf, size_t buflen,
const char *result, const int repeats) {
assert_non_null(hmac);
assert_int_equal(isc_hmac_init(hmac, key, keylen, type), ISC_R_SUCCESS);
}
static void
-isc_md_test(isc_md_t *md, isc_md_type_t type, const char *buf, size_t buflen,
- const char *result, const int repeats) {
+isc_md_test(isc_md_t *md, const isc_md_type_t *type, const char *buf,
+ size_t buflen, const char *result, const int repeats) {
assert_non_null(md);
assert_int_equal(isc_md_init(md, type), ISC_R_SUCCESS);
isc__mem_strdup
isc__mempool_get
isc__mempool_put
+isc__md_md5
+isc__md_sha1
+isc__md_sha224
+isc__md_sha256
+isc__md_sha384
+isc__md_sha512
isc_socket_accept
isc_socket_attach
isc_socket_bind
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <isc/assertions.h>
static isc_result_t
sign(unsigned char *data, unsigned int length, unsigned char *hmac,
uint32_t algorithm, isccc_region_t *secret) {
- isc_md_type_t md_type;
+ const isc_md_type_t *md_type;
isc_result_t result;
isccc_region_t source, target;
unsigned char digest[ISC_MAX_MD_SIZE];
static isc_result_t
verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length,
uint32_t algorithm, isccc_region_t *secret) {
- isc_md_type_t md_type;
+ const isc_md_type_t *md_type;
isccc_region_t source;
isccc_region_t target;
isc_result_t result;