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
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <openssl/opensslv.h>
|
|
|
|
|
2018-06-14 23:54:48 +02:00
|
|
|
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
|
2018-06-13 13:42:25 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "openssl_shim.h"
|
|
|
|
#include <openssl/engine.h>
|
|
|
|
#include <openssl/hmac.h>
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
void *
|
|
|
|
OPENSSL_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
|
|
|
}
|
|
|
|
|
2018-10-26 10:01:14 +11:00
|
|
|
#if OPENSSL_VERSION_NUMBER < 0x10001000L || defined(LIBRESSL_VERSION_NUMBER)
|
2018-10-05 13:06:31 +02:00
|
|
|
EVP_CIPHER_CTX *
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
void
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 10:01:14 +11:00
|
|
|
#endif
|
2018-06-13 13:42:25 +02:00
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
EVP_MD_CTX *
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
void
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
int
|
|
|
|
EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
2018-06-13 13:42:25 +02:00
|
|
|
{
|
2018-10-05 13:06:31 +02:00
|
|
|
return (EVP_MD_CTX_cleanup(ctx));
|
2018-06-13 13:42:25 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
HMAC_CTX *
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
void
|
|
|
|
HMAC_CTX_free(HMAC_CTX *ctx)
|
2018-06-13 13:42:25 +02:00
|
|
|
{
|
|
|
|
if (ctx != NULL) {
|
|
|
|
HMAC_CTX_cleanup(ctx);
|
|
|
|
OPENSSL_free(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
int
|
|
|
|
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
|
|
|
}
|
2018-06-13 13:44:34 +02:00
|
|
|
|
2018-03-20 17:20:50 +00:00
|
|
|
const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx) {
|
|
|
|
return ctx->md;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:06:31 +02:00
|
|
|
#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L ||
|
|
|
|
* defined(LIBRESSL_VERSION_NUMBER) */
|