"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/openssl_shim.c" (4 Sep 2020, 2413 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "openssl_shim.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #include "openssl_shim.h"
   13 #include <stdlib.h>
   14 #include <string.h>
   15 
   16 #include <openssl/crypto.h>
   17 #include <openssl/engine.h>
   18 #include <openssl/evp.h>
   19 #include <openssl/hmac.h>
   20 #include <openssl/opensslv.h>
   21 
   22 #if !HAVE_CRYPTO_ZALLOC
   23 void *
   24 CRYPTO_zalloc(size_t size) {
   25     void *ret = OPENSSL_malloc(size);
   26     if (ret != NULL) {
   27         memset(ret, 0, size);
   28     }
   29     return (ret);
   30 }
   31 #endif /* if !HAVE_CRYPTO_ZALLOC */
   32 
   33 #if !HAVE_EVP_CIPHER_CTX_NEW
   34 EVP_CIPHER_CTX *
   35 EVP_CIPHER_CTX_new(void) {
   36     EVP_CIPHER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
   37     return (ctx);
   38 }
   39 #endif /* if !HAVE_EVP_CIPHER_CTX_NEW */
   40 
   41 #if !HAVE_EVP_CIPHER_CTX_FREE
   42 void
   43 EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) {
   44     if (ctx != NULL) {
   45         EVP_CIPHER_CTX_cleanup(ctx);
   46         OPENSSL_free(ctx);
   47     }
   48 }
   49 #endif /* if !HAVE_EVP_CIPHER_CTX_FREE */
   50 
   51 #if !HAVE_EVP_MD_CTX_NEW
   52 EVP_MD_CTX *
   53 EVP_MD_CTX_new(void) {
   54     EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
   55     if (ctx != NULL) {
   56         memset(ctx, 0, sizeof(*ctx));
   57     }
   58     return (ctx);
   59 }
   60 #endif /* if !HAVE_EVP_MD_CTX_NEW */
   61 
   62 #if !HAVE_EVP_MD_CTX_FREE
   63 void
   64 EVP_MD_CTX_free(EVP_MD_CTX *ctx) {
   65     if (ctx != NULL) {
   66         EVP_MD_CTX_cleanup(ctx);
   67         OPENSSL_free(ctx);
   68     }
   69 }
   70 #endif /* if !HAVE_EVP_MD_CTX_FREE */
   71 
   72 #if !HAVE_EVP_MD_CTX_RESET
   73 int
   74 EVP_MD_CTX_reset(EVP_MD_CTX *ctx) {
   75     return (EVP_MD_CTX_cleanup(ctx));
   76 }
   77 #endif /* if !HAVE_EVP_MD_CTX_RESET */
   78 
   79 #if !HAVE_HMAC_CTX_NEW
   80 HMAC_CTX *
   81 HMAC_CTX_new(void) {
   82     HMAC_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
   83     if (ctx != NULL) {
   84         if (!HMAC_CTX_reset(ctx)) {
   85             HMAC_CTX_free(ctx);
   86             return (NULL);
   87         }
   88     }
   89     return (ctx);
   90 }
   91 #endif /* if !HAVE_HMAC_CTX_NEW */
   92 
   93 #if !HAVE_HMAC_CTX_FREE
   94 void
   95 HMAC_CTX_free(HMAC_CTX *ctx) {
   96     if (ctx != NULL) {
   97         HMAC_CTX_cleanup(ctx);
   98         OPENSSL_free(ctx);
   99     }
  100 }
  101 #endif /* if !HAVE_HMAC_CTX_FREE */
  102 
  103 #if !HAVE_HMAC_CTX_RESET
  104 int
  105 HMAC_CTX_reset(HMAC_CTX *ctx) {
  106     HMAC_CTX_cleanup(ctx);
  107     return (1);
  108 }
  109 #endif /* if !HAVE_HMAC_CTX_RESET */
  110 
  111 #if !HAVE_HMAC_CTX_GET_MD
  112 const EVP_MD *
  113 HMAC_CTX_get_md(const HMAC_CTX *ctx) {
  114     return (ctx->md);
  115 }
  116 #endif /* if !HAVE_HMAC_CTX_GET_MD */