From 0541314f0c8ab0e6e4955e70cb31747732797a9c Mon Sep 17 00:00:00 2001 From: Andrew Hopkins Date: Mon, 29 Apr 2024 16:34:40 -0700 Subject: [PATCH] Cleanup remaing duplicate symbol definitions and turn Wredundant-decls on (#1561) ### Issues: Addresses https://github.com/aws/aws-lc/issues/1556 ### Description of changes: Fix a few other cases of duplicate definitions and turn this on so the CI can catch this in the future. ### Call-outs: We own this s2n-bignum header file. ### Testing: We have GCC CI for x86/ARM. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. --- CMakeLists.txt | 9 ++++++--- crypto/evp_extra/internal.h | 5 +++++ crypto/fipsmodule/cpucap/cpu_intel.c | 1 - crypto/fipsmodule/evp/evp.c | 5 ++--- crypto/fipsmodule/evp/evp_ctx.c | 4 +--- crypto/fipsmodule/sha/sha1-altivec.c | 2 -- third_party/s2n-bignum/include/s2n-bignum_aws-lc.h | 3 +++ 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbc2ae5895..d52e8fe34a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,10 +290,13 @@ if(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX) message(STATUS "MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX selected, removing AVX512 optimisations") endif() -# Detect if memcmp is wrongly stripped like strcmp. -# If exists, let CMake generate a warning. -# memcmp bug link https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189. if (GCC) + # All versions of GCC that AWS-LC supports has this warning + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls") + + # Detect if memcmp is wrongly stripped like strcmp. + # If exists, let CMake generate a warning. + # memcmp bug link https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189. # CMake try_run requires these variables must be preset. # https://cmake.org/cmake/help/latest/command/try_run.html set(MEMCMP_INVALID_STRIPPED "") diff --git a/crypto/evp_extra/internal.h b/crypto/evp_extra/internal.h index 895c14545b..d3103f38b3 100644 --- a/crypto/evp_extra/internal.h +++ b/crypto/evp_extra/internal.h @@ -1,6 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 OR ISC +#ifndef AWS_LC_EVP_EXTRA_INTERNAL_H +#define AWS_LC_EVP_EXTRA_INTERNAL_H + #include #include "../fipsmodule/evp/internal.h" @@ -60,3 +63,5 @@ const EVP_PKEY_METHOD *const *AWSLC_non_fips_pkey_evp_methods(void); // Returns a reference to the list |asn1_evp_pkey_methods|. The list has // size |ASN1_EVP_PKEY_METHODS|. const EVP_PKEY_ASN1_METHOD *const *AWSLC_non_fips_pkey_evp_asn1_methods(void); + +#endif diff --git a/crypto/fipsmodule/cpucap/cpu_intel.c b/crypto/fipsmodule/cpucap/cpu_intel.c index 9cce06dc72..5d5fa5eff6 100644 --- a/crypto/fipsmodule/cpucap/cpu_intel.c +++ b/crypto/fipsmodule/cpucap/cpu_intel.c @@ -158,7 +158,6 @@ static void handle_cpu_env(uint32_t *out, const char *in) { } } -extern uint32_t OPENSSL_ia32cap_P[4]; extern uint8_t OPENSSL_cpucap_initialized; void OPENSSL_cpuid_setup(void) { diff --git a/crypto/fipsmodule/evp/evp.c b/crypto/fipsmodule/evp/evp.c index 5685452dea..4587f8a36a 100644 --- a/crypto/fipsmodule/evp/evp.c +++ b/crypto/fipsmodule/evp/evp.c @@ -68,8 +68,9 @@ #include #include -#include "internal.h" +#include "../../evp_extra/internal.h" #include "../../internal.h" +#include "internal.h" // Node depends on |EVP_R_NOT_XOF_OR_INVALID_LENGTH|. @@ -234,8 +235,6 @@ const char *EVP_MD_name(const EVP_MD *md) { return EVP_MD_get0_name(md); } -extern const EVP_PKEY_ASN1_METHOD *const *AWSLC_non_fips_pkey_evp_asn1_methods(void); - // evp_pkey_asn1_find returns the ASN.1 method table for the given |nid|, which // should be one of the |EVP_PKEY_*| values. It returns NULL if |nid| is // unknown. diff --git a/crypto/fipsmodule/evp/evp_ctx.c b/crypto/fipsmodule/evp/evp_ctx.c index 1a8574f718..801fe0a12a 100644 --- a/crypto/fipsmodule/evp/evp_ctx.c +++ b/crypto/fipsmodule/evp/evp_ctx.c @@ -64,9 +64,7 @@ #include "../../internal.h" #include "internal.h" - -// Forward declaration of |AWSLC_non_fips_pkey_evp_methods| to learn return type. -extern const EVP_PKEY_METHOD *const *AWSLC_non_fips_pkey_evp_methods(void); +#include "../../evp_extra/internal.h" DEFINE_LOCAL_DATA(struct fips_evp_pkey_methods, AWSLC_fips_evp_pkey_methods) { out->methods[0] = EVP_PKEY_rsa_pkey_meth(); diff --git a/crypto/fipsmodule/sha/sha1-altivec.c b/crypto/fipsmodule/sha/sha1-altivec.c index 3152827a0c..ab3645ff91 100644 --- a/crypto/fipsmodule/sha/sha1-altivec.c +++ b/crypto/fipsmodule/sha/sha1-altivec.c @@ -69,8 +69,6 @@ #include -void sha1_block_data_order(uint32_t *state, const uint8_t *data, size_t num); - static uint32_t rotate(uint32_t a, int n) { return (a << n) | (a >> (32 - n)); } typedef vector unsigned int vec_uint32_t; diff --git a/third_party/s2n-bignum/include/s2n-bignum_aws-lc.h b/third_party/s2n-bignum/include/s2n-bignum_aws-lc.h index c8bd17da28..db7897a841 100644 --- a/third_party/s2n-bignum/include/s2n-bignum_aws-lc.h +++ b/third_party/s2n-bignum/include/s2n-bignum_aws-lc.h @@ -12,6 +12,8 @@ * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ +#ifndef S2N_BIGNUM_AWS_LC_H +#define S2N_BIGNUM_AWS_LC_H // ---------------------------------------------------------------------------- // C prototypes for s2n-bignum functions used in AWS-LC @@ -322,3 +324,4 @@ extern void edwards25519_scalarmuldouble(uint64_t res[static 8], uint64_t scalar uint64_t point[static 8], uint64_t bscalar[static 4]); extern void edwards25519_scalarmuldouble_alt(uint64_t res[static 8], uint64_t scalar[static 4], uint64_t point[static 8], uint64_t bscalar[static 4]); +#endif