Debian Codegraph @

crt/s2n/crypto/s2n_evp.h

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #pragma once
17
18 #include <openssl/evp.h>
19 #include <openssl/hmac.h>
20
21 #include "crypto/s2n_openssl.h"
22 #include "utils/s2n_result.h"
23
24 struct s2n_evp_digest {
25 const EVP_MD *md;
26 EVP_MD_CTX *ctx;
27 };
28
29 /* Define API's that change based on the OpenSSL Major Version. */
30 #if S2N_OPENSSL_VERSION_AT_LEAST(1, 1, 0) && !defined(LIBRESSL_VERSION_NUMBER)
31 #define S2N_EVP_MD_CTX_NEW() (EVP_MD_CTX_new())
32 #define S2N_EVP_MD_CTX_RESET(md_ctx) (EVP_MD_CTX_reset(md_ctx))
33 #define S2N_EVP_MD_CTX_FREE(md_ctx) (EVP_MD_CTX_free(md_ctx))
34 #else
35 #define S2N_EVP_MD_CTX_NEW() (EVP_MD_CTX_create())
36 #define S2N_EVP_MD_CTX_RESET(md_ctx) (EVP_MD_CTX_cleanup(md_ctx))
37 #define S2N_EVP_MD_CTX_FREE(md_ctx) (EVP_MD_CTX_destroy(md_ctx))
38 #endif
39
40 /* On some versions of OpenSSL, "EVP_PKEY_CTX_set_signature_md()" is just a macro that casts digest_alg to "void*",
41 * which fails to compile when the "-Werror=cast-qual" compiler flag is enabled. So we work around this OpenSSL
42 * issue by turning off this compiler check for this one function with a cast through.
43 */
44 #define S2N_EVP_PKEY_CTX_set_signature_md(ctx, md) \
45 EVP_PKEY_CTX_set_signature_md(ctx, (EVP_MD *) (uintptr_t) md)