2018-06-13 13:42:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-06-13 13:42:25 +02:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include "openssl_shim.h"
|
2018-06-13 13:42:25 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
|
|
|
|
#include <openssl/crypto.h>
|
2018-06-13 13:42:25 +02:00
|
|
|
#include <openssl/engine.h>
|
2018-10-26 05:29:56 +02:00
|
|
|
#include <openssl/evp.h>
|
2018-06-13 13:42:25 +02:00
|
|
|
#include <openssl/hmac.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <openssl/opensslv.h>
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_CRYPTO_ZALLOC
|
2018-10-05 13:06:31 +02:00
|
|
|
void *
|
2020-02-13 14:44:37 -08:00
|
|
|
CRYPTO_zalloc(size_t size) {
|
2018-06-13 13:42:25 +02:00
|
|
|
void *ret = OPENSSL_malloc(size);
|
|
|
|
if (ret != NULL) {
|
|
|
|
memset(ret, 0, size);
|
|
|
|
}
|
2018-10-05 13:06:31 +02:00
|
|
|
return (ret);
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_CRYPTO_ZALLOC */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_EVP_CIPHER_CTX_NEW
|
2018-10-05 13:06:31 +02:00
|
|
|
EVP_CIPHER_CTX *
|
2020-02-13 14:44:37 -08:00
|
|
|
EVP_CIPHER_CTX_new(void) {
|
2018-06-13 13:42:25 +02:00
|
|
|
EVP_CIPHER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
|
2018-10-05 13:06:31 +02:00
|
|
|
return (ctx);
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_EVP_CIPHER_CTX_NEW */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_EVP_CIPHER_CTX_FREE
|
2018-10-05 13:06:31 +02:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) {
|
2018-06-13 13:42:25 +02:00
|
|
|
if (ctx != NULL) {
|
|
|
|
EVP_CIPHER_CTX_cleanup(ctx);
|
|
|
|
OPENSSL_free(ctx);
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_EVP_CIPHER_CTX_FREE */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_EVP_MD_CTX_NEW
|
2018-10-05 13:06:31 +02:00
|
|
|
EVP_MD_CTX *
|
2020-02-13 14:44:37 -08:00
|
|
|
EVP_MD_CTX_new(void) {
|
2018-06-13 13:42:25 +02:00
|
|
|
EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
|
|
|
|
if (ctx != NULL) {
|
|
|
|
memset(ctx, 0, sizeof(*ctx));
|
|
|
|
}
|
2018-10-05 13:06:31 +02:00
|
|
|
return (ctx);
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_EVP_MD_CTX_NEW */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_EVP_MD_CTX_FREE
|
2018-10-05 13:06:31 +02:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
EVP_MD_CTX_free(EVP_MD_CTX *ctx) {
|
2018-06-13 13:42:25 +02:00
|
|
|
if (ctx != NULL) {
|
|
|
|
EVP_MD_CTX_cleanup(ctx);
|
|
|
|
OPENSSL_free(ctx);
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_EVP_MD_CTX_FREE */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_EVP_MD_CTX_RESET
|
2018-10-05 13:06:31 +02:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
EVP_MD_CTX_reset(EVP_MD_CTX *ctx) {
|
2018-10-05 13:06:31 +02:00
|
|
|
return (EVP_MD_CTX_cleanup(ctx));
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_EVP_MD_CTX_RESET */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_HMAC_CTX_NEW
|
2018-10-05 13:06:31 +02:00
|
|
|
HMAC_CTX *
|
2020-02-13 14:44:37 -08:00
|
|
|
HMAC_CTX_new(void) {
|
2018-06-13 13:42:25 +02:00
|
|
|
HMAC_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
|
|
|
|
if (ctx != NULL) {
|
|
|
|
if (!HMAC_CTX_reset(ctx)) {
|
|
|
|
HMAC_CTX_free(ctx);
|
2018-10-05 13:06:31 +02:00
|
|
|
return (NULL);
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-05 13:06:31 +02:00
|
|
|
return (ctx);
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_HMAC_CTX_NEW */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_HMAC_CTX_FREE
|
2018-10-05 13:06:31 +02:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
HMAC_CTX_free(HMAC_CTX *ctx) {
|
2018-06-13 13:42:25 +02:00
|
|
|
if (ctx != NULL) {
|
|
|
|
HMAC_CTX_cleanup(ctx);
|
|
|
|
OPENSSL_free(ctx);
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_HMAC_CTX_FREE */
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_HMAC_CTX_RESET
|
2018-10-05 13:06:31 +02:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
HMAC_CTX_reset(HMAC_CTX *ctx) {
|
2018-06-13 13:42:25 +02:00
|
|
|
HMAC_CTX_cleanup(ctx);
|
2018-10-05 13:06:31 +02:00
|
|
|
return (1);
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_HMAC_CTX_RESET */
|
2018-06-13 13:44:34 +02:00
|
|
|
|
2018-10-26 05:29:56 +02:00
|
|
|
#if !HAVE_HMAC_CTX_GET_MD
|
2020-02-12 13:59:18 +01:00
|
|
|
const EVP_MD *
|
2020-02-13 14:44:37 -08:00
|
|
|
HMAC_CTX_get_md(const HMAC_CTX *ctx) {
|
2020-02-13 21:48:23 +01:00
|
|
|
return (ctx->md);
|
2018-03-20 17:20:50 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if !HAVE_HMAC_CTX_GET_MD */
|