[openssl] OpenSSL_1_0_2-stable update

bernd.edlinger at hotmail.de bernd.edlinger at hotmail.de
Sun Jul 21 08:14:39 UTC 2019


The branch OpenSSL_1_0_2-stable has been updated
       via  aa8b244e5c22193078e3e80fad1f5b27bf62c73b (commit)
      from  7a7afc559ebc0ad88390cc62bfc34c221d595831 (commit)


- Log -----------------------------------------------------------------
commit aa8b244e5c22193078e3e80fad1f5b27bf62c73b
Author: Bernd Edlinger <bernd.edlinger at hotmail.de>
Date:   Fri Jun 21 21:26:19 2019 +0200

    Add value_barriers in constant time select functions
    
    The barriers prevent the compiler from narrowing down the
    possible value range of the mask and ~mask in the select
    statements, which avoids the recognition of the select
    and turning it into a conditional load or branch.
    
    Reviewed-by: Paul Dale <paul.dale at oracle.com>
    (Merged from https://github.com/openssl/openssl/pull/9419)

-----------------------------------------------------------------------

Summary of changes:
 crypto/constant_time_locl.h | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/crypto/constant_time_locl.h b/crypto/constant_time_locl.h
index a5734f2..94e20bc 100644
--- a/crypto/constant_time_locl.h
+++ b/crypto/constant_time_locl.h
@@ -185,11 +185,29 @@ static inline unsigned char constant_time_eq_int_8(int a, int b)
     return constant_time_eq_8((unsigned)(a), (unsigned)(b));
 }
 
+/*
+ * Returns the value unmodified, but avoids optimizations.
+ * The barriers prevent the compiler from narrowing down the
+ * possible value range of the mask and ~mask in the select
+ * statements, which avoids the recognition of the select
+ * and turning it into a conditional load or branch.
+ */
+static inline unsigned int value_barrier(unsigned int a)
+{
+#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
+    unsigned int r;
+    __asm__("" : "=r"(r) : "0"(a));
+#else
+    volatile unsigned int r = a;
+#endif
+    return r;
+}
+
 static inline unsigned int constant_time_select(unsigned int mask,
                                                 unsigned int a,
                                                 unsigned int b)
 {
-    return (mask & a) | (~mask & b);
+    return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
 }
 
 static inline unsigned char constant_time_select_8(unsigned char mask,


More information about the openssl-commits mailing list