From 94c51dd2c4557edf4a954f3d05088a13a496d954 Mon Sep 17 00:00:00 2001 From: Michael Hamburg Date: Tue, 5 Aug 2014 16:04:57 -0700 Subject: [PATCH] Better patch for the bug Samuel Neves described --- src/arch_x86_64/p448.h | 16 +++++++++++++--- src/scalarmul.c | 15 ++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/arch_x86_64/p448.h b/src/arch_x86_64/p448.h index 02acaf9..56c62a9 100644 --- a/src/arch_x86_64/p448.h +++ b/src/arch_x86_64/p448.h @@ -88,12 +88,22 @@ mask_t p448_is_zero ( const p448_t *in ); - -static __inline__ void + +static +#ifndef GCC_HAS_A_BUG_SO_DONT_INLINE_FIELD_BIAS + __inline__ +#endif +void p448_bias ( p448_t *inout, int amount -) __attribute__((unused,always_inline)); +) +#ifdef GCC_HAS_A_BUG_SO_DONT_INLINE_FIELD_BIAS + __attribute__((unused,noinline,optimize("O1"))) +#else + __attribute__((unused,always_inline)) +#endif +; void p448_mul ( diff --git a/src/scalarmul.c b/src/scalarmul.c index ce9b070..e5e3237 100644 --- a/src/scalarmul.c +++ b/src/scalarmul.c @@ -1,6 +1,11 @@ /* Copyright (c) 2014 Cryptography Research, Inc. * Released under the MIT License. See LICENSE.txt for license information. */ +#if (defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__)) + /* This works around an apparent compiler bug in GCC, thanks Samuel Neves */ + #define GCC_HAS_A_BUG_SO_DONT_INLINE_FIELD_BIAS +#endif + #include "word.h" #include @@ -63,15 +68,7 @@ cond_negate_tw_pniels ( cond_negate_tw_niels(&n->n, doNegate); } -#if (defined(__GNUC__) && !defined(__clang__) && defined(__x86_64__) && !defined(__AVX2__)) - /* This works around an apparent compiler bug in GCC, thanks Samuel Neves */ - static void __attribute__((optimize("O1"))) - #ifdef __OPTIMIZE_SIZE__ - #warning "There's a bug in here somewhere with GCC -Os on non-AVX2 platforms" - #endif -#else - static __inline__ void -#endif +static __inline__ void constant_time_lookup_tw_pniels ( struct tw_pniels_t *out, const struct tw_pniels_t *in,