* information regarding copyright ownership.
*/
-#include <openssl/hmac.h>
+#include <openssl/evp.h>
#include <openssl/opensslv.h>
#include <isc/assertions.h>
isc_hmac_t *
isc_hmac_new(void) {
- HMAC_CTX *hmac = HMAC_CTX_new();
+ EVP_MD_CTX *hmac = EVP_MD_CTX_new();
RUNTIME_CHECK(hmac != NULL);
- return ((struct hmac *)hmac);
+ return ((isc_hmac_t *)hmac);
}
void
return;
}
- HMAC_CTX_free(hmac);
+ EVP_MD_CTX_free((EVP_MD_CTX *)hmac);
}
isc_result_t
-isc_hmac_init(isc_hmac_t *hmac, const void *key, size_t keylen,
+isc_hmac_init(isc_hmac_t *hmac, const void *key, const size_t keylen,
const isc_md_type_t *md_type) {
+ EVP_PKEY *pkey;
+
REQUIRE(hmac != NULL);
REQUIRE(key != NULL);
+ REQUIRE(keylen <= INT_MAX);
if (md_type == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
- if (HMAC_Init_ex(hmac, key, keylen, md_type, NULL) != 1) {
+ pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL, key, keylen);
+ if (pkey == NULL) {
+ return (ISC_R_CRYPTOFAILURE);
+ }
+
+ if (EVP_DigestSignInit(hmac, NULL, md_type, NULL, pkey) != 1) {
return (ISC_R_CRYPTOFAILURE);
}
+ EVP_PKEY_free(pkey);
+
return (ISC_R_SUCCESS);
}
isc_hmac_reset(isc_hmac_t *hmac) {
REQUIRE(hmac != NULL);
- if (HMAC_CTX_reset(hmac) != 1) {
+ if (EVP_MD_CTX_reset(hmac) != 1) {
return (ISC_R_CRYPTOFAILURE);
}
return (ISC_R_SUCCESS);
}
- if (HMAC_Update(hmac, buf, len) != 1) {
+ if (EVP_DigestSignUpdate(hmac, buf, len) != 1) {
return (ISC_R_CRYPTOFAILURE);
}
isc_result_t
isc_hmac_final(isc_hmac_t *hmac, unsigned char *digest,
unsigned int *digestlen) {
+ size_t len = 0;
+
REQUIRE(hmac != NULL);
REQUIRE(digest != NULL);
- if (HMAC_Final(hmac, digest, digestlen) != 1) {
+ if (EVP_DigestSignFinal(hmac, digest, &len) != 1) {
return (ISC_R_CRYPTOFAILURE);
}
+ if (digestlen != NULL) {
+ *digestlen = (unsigned int)len;
+ }
+
return (ISC_R_SUCCESS);
}
isc_hmac_get_md_type(isc_hmac_t *hmac) {
REQUIRE(hmac != NULL);
- return (HMAC_CTX_get_md(hmac));
+ return (EVP_MD_CTX_get0_md(hmac));
}
size_t
isc_hmac_get_size(isc_hmac_t *hmac) {
REQUIRE(hmac != NULL);
- return ((size_t)EVP_MD_size(HMAC_CTX_get_md(hmac)));
+ return ((size_t)EVP_MD_CTX_size(hmac));
}
int
isc_hmac_get_block_size(isc_hmac_t *hmac) {
REQUIRE(hmac != NULL);
- return (EVP_MD_block_size(HMAC_CTX_get_md(hmac)));
+ return (EVP_MD_CTX_block_size(hmac));
}
isc_result_t
-isc_hmac(const isc_md_type_t *type, const void *key, const int keylen,
+isc_hmac(const isc_md_type_t *type, const void *key, const size_t 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(const isc_md_type_t *type, const void *key, const int keylen,
+isc_hmac(const isc_md_type_t *type, const void *key, const size_t 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_hmac_init(isc_hmac_t *hmac, const void *key, const size_t keylen,
const isc_md_type_t *type);
/**
}
#endif /* if !HAVE_EVP_MD_CTX_RESET */
-#if !HAVE_HMAC_CTX_NEW
-HMAC_CTX *
-HMAC_CTX_new(void) {
- HMAC_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
- if (ctx != NULL) {
- if (!HMAC_CTX_reset(ctx)) {
- HMAC_CTX_free(ctx);
- return (NULL);
- }
- }
- return (ctx);
-}
-#endif /* if !HAVE_HMAC_CTX_NEW */
-
-#if !HAVE_HMAC_CTX_FREE
-void
-HMAC_CTX_free(HMAC_CTX *ctx) {
- if (ctx != NULL) {
- HMAC_CTX_cleanup(ctx);
- OPENSSL_free(ctx);
- }
-}
-#endif /* if !HAVE_HMAC_CTX_FREE */
-
-#if !HAVE_HMAC_CTX_RESET
-int
-HMAC_CTX_reset(HMAC_CTX *ctx) {
- HMAC_CTX_cleanup(ctx);
- return (1);
-}
-#endif /* if !HAVE_HMAC_CTX_RESET */
-
-#if !HAVE_HMAC_CTX_GET_MD
-const EVP_MD *
-HMAC_CTX_get_md(const HMAC_CTX *ctx) {
- return (ctx->md);
-}
-#endif /* if !HAVE_HMAC_CTX_GET_MD */
-
#if !HAVE_SSL_READ_EX
int
SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes) {
#define OPENSSL_zalloc(num) CRYPTO_zalloc(num, __FILE__, __LINE__)
#endif
+#if !HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
+#define EVP_PKEY_new_raw_private_key(type, e, key, keylen) \
+ EVP_PKEY_new_mac_key(type, e, key, (int)(keylen))
+#endif /* if !HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY */
+
#if !HAVE_EVP_CIPHER_CTX_NEW
EVP_CIPHER_CTX *
EVP_CIPHER_CTX_new(void);
#define EVP_MD_CTX_get0_md EVP_MD_CTX_md
#endif /* if !HAVE_EVP_MD_CTX_GET0_MD */
-#if !HAVE_HMAC_CTX_NEW
-HMAC_CTX *
-HMAC_CTX_new(void);
-#endif /* if !HAVE_HMAC_CTX_NEW */
-
-#if !HAVE_HMAC_CTX_FREE
-void
-HMAC_CTX_free(HMAC_CTX *ctx);
-#endif /* if !HAVE_HMAC_CTX_FREE */
-
-#if !HAVE_HMAC_CTX_RESET
-int
-HMAC_CTX_reset(HMAC_CTX *ctx);
-#endif /* if !HAVE_HMAC_CTX_RESET */
-
-#if !HAVE_HMAC_CTX_GET_MD
-const EVP_MD *
-HMAC_CTX_get_md(const HMAC_CTX *ctx);
-#endif /* if !HAVE_HMAC_CTX_GET_MD */
-
#if !HAVE_SSL_READ_EX
int
SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);