diff --git a/crypto/cpu-intel.c b/crypto/cpu-intel.c index 062556047..381199198 100644 --- a/crypto/cpu-intel.c +++ b/crypto/cpu-intel.c @@ -199,4 +199,4 @@ void OPENSSL_cpuid_setup(void) { OPENSSL_ia32cap_P[3] = extended_features[1]; } -#endif // !OPENSSL_NO_ASM && (OPENSSL_X86 || OPENSSL_X86_64) \ No newline at end of file +#endif // !OPENSSL_NO_ASM && (OPENSSL_X86 || OPENSSL_X86_64) diff --git a/crypto/crypto.c b/crypto/crypto.c index 7caecc515..c4907ee84 100644 --- a/crypto/crypto.c +++ b/crypto/crypto.c @@ -12,9 +12,9 @@ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include "internal.h" +#include +#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) // Our assembly does not use the GOT to reference symbols, which means // references to visible symbols will often require a TEXTREL. This is // undesirable, so all assembly-referenced symbols should be hidden. CPU @@ -26,7 +26,6 @@ #define HIDDEN __attribute__((visibility("hidden"))) #endif -#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) // This value must be explicitly initialised to zero in order to work around a // bug in libtool or the linker on OS X. // diff --git a/crypto/internal.h b/crypto/internal.h index b975c0b53..95be164eb 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -109,16 +109,22 @@ #ifndef OPENSSL_HEADER_CRYPTO_INTERNAL_H #define OPENSSL_HEADER_CRYPTO_INTERNAL_H -#include // Must be first. +#include // Must be first. #include "ring-core/check.h" +#if defined(__clang__) +// Don't require prototypes for functions defined in C that are only +// used from Rust. +#pragma GCC diagnostic ignored "-Wmissing-prototypes" +#endif + #if defined(__GNUC__) && \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 // |alignas| and |alignof| were added in C11. GCC added support in version 4.8. // Testing for __STDC_VERSION__/__cplusplus doesn't work because 4.7 already // reports support for C11. -#define alignas(x) __attribute__ ((aligned (x))) +#define alignas(x) __attribute__((aligned(x))) #elif defined(_MSC_VER) && !defined(__clang__) #define alignas(x) __declspec(align(x)) #else @@ -221,9 +227,8 @@ static inline crypto_word constant_time_is_zero_w(crypto_word a) { // // (declare-fun a () (_ BitVec 32)) // - // (assert (not (= (= #x00000001 (bvlshr (is_zero a) #x0000001f)) (= a #x00000000)))) - // (check-sat) - // (get-model) + // (assert (not (= (= #x00000001 (bvlshr (is_zero a) #x0000001f)) (= a + // #x00000000)))) (check-sat) (get-model) return constant_time_msb_w(~a & (a - 1)); } @@ -232,8 +237,7 @@ static inline crypto_word constant_time_is_nonzero_w(crypto_word a) { } // constant_time_eq_w returns 0xff..f if a == b and 0 otherwise. -static inline crypto_word constant_time_eq_w(crypto_word a, - crypto_word b) { +static inline crypto_word constant_time_eq_w(crypto_word a, crypto_word b) { return constant_time_is_zero_w(a ^ b); } @@ -241,8 +245,7 @@ static inline crypto_word constant_time_eq_w(crypto_word a, // 1s or all 0s (as returned by the methods above), the select methods return // either |a| (if |mask| is nonzero) or |b| (if |mask| is zero). static inline crypto_word constant_time_select_w(crypto_word mask, - crypto_word a, - crypto_word b) { + crypto_word a, crypto_word b) { // Clang recognizes this pattern as a select. While it usually transforms it // to a cmov, it sometimes further transforms it into a branch, which we do // not want. @@ -263,9 +266,7 @@ static inline uint32_t CRYPTO_bswap4(uint32_t x) { #include #pragma warning(pop) #pragma intrinsic(_byteswap_uint64, _byteswap_ulong) -static inline uint32_t CRYPTO_bswap4(uint32_t x) { - return _byteswap_ulong(x); -} +static inline uint32_t CRYPTO_bswap4(uint32_t x) { return _byteswap_ulong(x); } #endif #if !defined(RING_CORE_NOSTDLIBINC) @@ -303,4 +304,30 @@ static inline void *OPENSSL_memset(void *dst, int c, size_t n) { #endif } + +// Runtime CPU feature support + +#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) +// OPENSSL_ia32cap_P contains the Intel CPUID bits when running on an x86 or +// x86-64 system. +// +// Index 0: +// EDX for CPUID where EAX = 1 +// Bit 20 is always zero +// Bit 28 is adjusted to reflect whether the data cache is shared between +// multiple logical cores +// Bit 30 is used to indicate an Intel CPU +// Index 1: +// ECX for CPUID where EAX = 1 +// Bit 11 is used to indicate AMD XOP support, not SDBG +// Index 2: +// EBX for CPUID where EAX = 7 +// Index 3: +// ECX for CPUID where EAX = 7 +// +// Note: the CPUID bits are pre-adjusted for the OSXSAVE bit and the YMM and XMM +// bits in XCR0, so it is not necessary to check those. +extern uint32_t OPENSSL_ia32cap_P[4]; +#endif + #endif // OPENSSL_HEADER_CRYPTO_INTERNAL_H diff --git a/include/ring-core/cpu.h b/include/ring-core/cpu.h deleted file mode 100644 index e83ab355a..000000000 --- a/include/ring-core/cpu.h +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). */ - -#ifndef OPENSSL_HEADER_CPU_H -#define OPENSSL_HEADER_CPU_H - -#include -#include - -// Runtime CPU feature support - - -#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) -// OPENSSL_ia32cap_P contains the Intel CPUID bits when running on an x86 or -// x86-64 system. -// -// Index 0: -// EDX for CPUID where EAX = 1 -// Bit 20 is always zero -// Bit 28 is adjusted to reflect whether the data cache is shared between -// multiple logical cores -// Bit 30 is used to indicate an Intel CPU -// Index 1: -// ECX for CPUID where EAX = 1 -// Bit 11 is used to indicate AMD XOP support, not SDBG -// Index 2: -// EBX for CPUID where EAX = 7 -// Index 3: -// ECX for CPUID where EAX = 7 -// -// Note: the CPUID bits are pre-adjusted for the OSXSAVE bit and the YMM and XMM -// bits in XCR0, so it is not necessary to check those. -extern uint32_t OPENSSL_ia32cap_P[4]; -#endif - -#endif // OPENSSL_HEADER_CPU_H