isaacpittman-hitachi / rpms / openssl

Forked from rpms/openssl 2 years ago
Clone

Blame SOURCES/openssl-1.1.1-upstream-sync.patch

3a273b
diff -up openssl-1.1.1c/crypto/dsa/dsa_ameth.c.sync openssl-1.1.1c/crypto/dsa/dsa_ameth.c
3a273b
--- openssl-1.1.1c/crypto/dsa/dsa_ameth.c.sync	2019-05-28 15:12:21.000000000 +0200
3a273b
+++ openssl-1.1.1c/crypto/dsa/dsa_ameth.c	2019-05-29 17:10:39.768187283 +0200
3a273b
@@ -503,7 +503,7 @@ static int dsa_pkey_ctrl(EVP_PKEY *pkey,
3a273b
 
3a273b
     case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
3a273b
         *(int *)arg2 = NID_sha256;
3a273b
-        return 2;
3a273b
+        return 1;
3a273b
 
3a273b
     default:
3a273b
         return -2;
3a273b
diff -up openssl-1.1.1c/crypto/err/err.c.sync openssl-1.1.1c/crypto/err/err.c
3a273b
--- openssl-1.1.1c/crypto/err/err.c.sync	2019-05-28 15:12:21.000000000 +0200
3a273b
+++ openssl-1.1.1c/crypto/err/err.c	2019-05-29 17:07:13.345793792 +0200
3a273b
@@ -184,8 +184,8 @@ static ERR_STRING_DATA *int_err_get_item
3a273b
 }
3a273b
 
3a273b
 #ifndef OPENSSL_NO_ERR
3a273b
-/* A measurement on Linux 2018-11-21 showed about 3.5kib */
3a273b
-# define SPACE_SYS_STR_REASONS 4 * 1024
3a273b
+/* 2019-05-21: Russian and Ukrainian locales on Linux require more than 6,5 kB */
3a273b
+# define SPACE_SYS_STR_REASONS 8 * 1024
3a273b
 # define NUM_SYS_STR_REASONS 127
3a273b
 
3a273b
 static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
3a273b
@@ -219,21 +219,23 @@ static void build_SYS_str_reasons(void)
3a273b
         ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
3a273b
 
3a273b
         str->error = ERR_PACK(ERR_LIB_SYS, 0, i);
3a273b
-        if (str->string == NULL) {
3a273b
+        /*
3a273b
+         * If we have used up all the space in strerror_pool,
3a273b
+         * there's no point in calling openssl_strerror_r()
3a273b
+         */
3a273b
+        if (str->string == NULL && cnt < sizeof(strerror_pool)) {
3a273b
             if (openssl_strerror_r(i, cur, sizeof(strerror_pool) - cnt)) {
3a273b
                 size_t l = strlen(cur);
3a273b
 
3a273b
                 str->string = cur;
3a273b
                 cnt += l;
3a273b
-                if (cnt > sizeof(strerror_pool))
3a273b
-                    cnt = sizeof(strerror_pool);
3a273b
                 cur += l;
3a273b
 
3a273b
                 /*
3a273b
                  * VMS has an unusual quirk of adding spaces at the end of
3a273b
-                 * some (most? all?) messages.  Lets trim them off.
3a273b
+                 * some (most? all?) messages. Lets trim them off.
3a273b
                  */
3a273b
-                while (ossl_isspace(cur[-1])) {
3a273b
+                while (cur > strerror_pool && ossl_isspace(cur[-1])) {
3a273b
                     cur--;
3a273b
                     cnt--;
3a273b
                 }
3a273b
diff -up openssl-1.1.1c/crypto/rand/rand_lib.c.sync openssl-1.1.1c/crypto/rand/rand_lib.c
3a273b
--- openssl-1.1.1c/crypto/rand/rand_lib.c.sync	2019-05-29 17:20:17.175099183 +0200
3a273b
+++ openssl-1.1.1c/crypto/rand/rand_lib.c	2019-05-30 11:51:20.784850208 +0200
3a273b
@@ -239,8 +239,9 @@ size_t rand_drbg_get_nonce(RAND_DRBG *dr
3a273b
     struct {
3a273b
         void * instance;
3a273b
         int count;
3a273b
-    } data = { NULL, 0 };
3a273b
+    } data;
3a273b
 
3a273b
+    memset(&data, 0, sizeof(data));
3a273b
     pool = rand_pool_new(0, min_len, max_len);
3a273b
     if (pool == NULL)
3a273b
         return 0;
3a273b
From 6c2f347c78a530407b5310497080810094427920 Mon Sep 17 00:00:00 2001
3a273b
From: Matt Caswell <matt@openssl.org>
3a273b
Date: Wed, 17 Apr 2019 11:09:05 +0100
3a273b
Subject: [PATCH 1/2] Defer sending a KeyUpdate until after pending writes are
3a273b
 complete
3a273b
3a273b
If we receive a KeyUpdate message (update requested) from the peer while
3a273b
we are in the middle of a write, we should defer sending the responding
3a273b
KeyUpdate message until after the current write is complete. We do this
3a273b
by waiting to send the KeyUpdate until the next time we write and there is
3a273b
no pending write data.
3a273b
3a273b
This does imply a subtle change in behaviour. Firstly the responding
3a273b
KeyUpdate message won't be sent straight away as it is now. Secondly if
3a273b
the peer sends multiple KeyUpdates without us doing any writing then we
3a273b
will only send one response, as opposed to previously where we sent a
3a273b
response for each KeyUpdate received.
3a273b
3a273b
Fixes #8677
3a273b
3a273b
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
3a273b
(Merged from https://github.com/openssl/openssl/pull/8773)
3a273b
3a273b
(cherry picked from commit feb9e31c40c49de6384dd0413685e9b5a15adc99)
3a273b
---
3a273b
 ssl/record/rec_layer_s3.c | 7 +++++++
3a273b
 ssl/statem/statem_clnt.c  | 6 ------
3a273b
 ssl/statem/statem_lib.c   | 7 ++-----
3a273b
 ssl/statem/statem_srvr.c  | 6 ------
3a273b
 4 files changed, 9 insertions(+), 17 deletions(-)
3a273b
3a273b
diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c
3a273b
index b2f97ef905..b65137c332 100644
3a273b
--- a/ssl/record/rec_layer_s3.c
3a273b
+++ b/ssl/record/rec_layer_s3.c
3a273b
@@ -373,6 +373,13 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, size_t len,
3a273b
 
3a273b
     s->rlayer.wnum = 0;
3a273b
 
3a273b
+    /*
3a273b
+     * If we are supposed to be sending a KeyUpdate then go into init unless we
3a273b
+     * have writes pending - in which case we should finish doing that first.
3a273b
+     */
3a273b
+    if (wb->left == 0 && s->key_update != SSL_KEY_UPDATE_NONE)
3a273b
+        ossl_statem_set_in_init(s, 1);
3a273b
+
3a273b
     /*
3a273b
      * When writing early data on the server side we could be "in_init" in
3a273b
      * between receiving the EoED and the CF - but we don't want to handle those
3a273b
diff --git a/ssl/statem/statem_clnt.c b/ssl/statem/statem_clnt.c
3a273b
index 87800cd835..6410414fb6 100644
3a273b
--- a/ssl/statem/statem_clnt.c
3a273b
+++ b/ssl/statem/statem_clnt.c
3a273b
@@ -473,12 +473,6 @@ static WRITE_TRAN ossl_statem_client13_write_transition(SSL *s)
3a273b
         return WRITE_TRAN_CONTINUE;
3a273b
 
3a273b
     case TLS_ST_CR_KEY_UPDATE:
3a273b
-        if (s->key_update != SSL_KEY_UPDATE_NONE) {
3a273b
-            st->hand_state = TLS_ST_CW_KEY_UPDATE;
3a273b
-            return WRITE_TRAN_CONTINUE;
3a273b
-        }
3a273b
-        /* Fall through */
3a273b
-
3a273b
     case TLS_ST_CW_KEY_UPDATE:
3a273b
     case TLS_ST_CR_SESSION_TICKET:
3a273b
     case TLS_ST_CW_FINISHED:
3a273b
diff --git a/ssl/statem/statem_lib.c b/ssl/statem/statem_lib.c
3a273b
index c0482b0a90..2960dafa52 100644
3a273b
--- a/ssl/statem/statem_lib.c
3a273b
+++ b/ssl/statem/statem_lib.c
3a273b
@@ -645,12 +645,9 @@ MSG_PROCESS_RETURN tls_process_key_update(SSL *s, PACKET *pkt)
3a273b
     /*
3a273b
      * If we get a request for us to update our sending keys too then, we need
3a273b
      * to additionally send a KeyUpdate message. However that message should
3a273b
-     * not also request an update (otherwise we get into an infinite loop). We
3a273b
-     * ignore a request for us to update our sending keys too if we already
3a273b
-     * sent close_notify.
3a273b
+     * not also request an update (otherwise we get into an infinite loop).
3a273b
      */
3a273b
-    if (updatetype == SSL_KEY_UPDATE_REQUESTED
3a273b
-            && (s->shutdown & SSL_SENT_SHUTDOWN) == 0)
3a273b
+    if (updatetype == SSL_KEY_UPDATE_REQUESTED)
3a273b
         s->key_update = SSL_KEY_UPDATE_NOT_REQUESTED;
3a273b
 
3a273b
     if (!tls13_update_key(s, 0)) {
3a273b
diff --git a/ssl/statem/statem_srvr.c b/ssl/statem/statem_srvr.c
3a273b
index d454326a99..04a23320fc 100644
3a273b
--- a/ssl/statem/statem_srvr.c
3a273b
+++ b/ssl/statem/statem_srvr.c
3a273b
@@ -502,12 +502,6 @@ static WRITE_TRAN ossl_statem_server13_write_transition(SSL *s)
3a273b
         return WRITE_TRAN_CONTINUE;
3a273b
 
3a273b
     case TLS_ST_SR_KEY_UPDATE:
3a273b
-        if (s->key_update != SSL_KEY_UPDATE_NONE) {
3a273b
-            st->hand_state = TLS_ST_SW_KEY_UPDATE;
3a273b
-            return WRITE_TRAN_CONTINUE;
3a273b
-        }
3a273b
-        /* Fall through */
3a273b
-
3a273b
     case TLS_ST_SW_KEY_UPDATE:
3a273b
         st->hand_state = TLS_ST_OK;
3a273b
         return WRITE_TRAN_CONTINUE;
3a273b
-- 
3a273b
2.20.1
3a273b
3a273b
From c8feb1039ccc4cd11e6db084df1446bf863bee1e Mon Sep 17 00:00:00 2001
3a273b
From: Matt Caswell <matt@openssl.org>
3a273b
Date: Wed, 17 Apr 2019 10:30:53 +0100
3a273b
Subject: [PATCH 2/2] Write a test for receiving a KeyUpdate (update requested)
3a273b
 while writing
3a273b
3a273b
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
3a273b
(Merged from https://github.com/openssl/openssl/pull/8773)
3a273b
3a273b
(cherry picked from commit a77b4dba237d001073d2d1c5d55c674a196c949f)
3a273b
---
3a273b
 test/sslapitest.c | 92 +++++++++++++++++++++++++++++++++++++++++++++
3a273b
 test/ssltestlib.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++
3a273b
 test/ssltestlib.h |  3 ++
3a273b
 3 files changed, 191 insertions(+)
3a273b
3a273b
diff --git a/test/sslapitest.c b/test/sslapitest.c
3a273b
index 2261fe4a7a..577342644d 100644
3a273b
--- a/test/sslapitest.c
3a273b
+++ b/test/sslapitest.c
3a273b
@@ -4290,6 +4290,11 @@ static int test_key_update(void)
3a273b
                 || !TEST_int_eq(SSL_read(serverssl, buf, sizeof(buf)),
3a273b
                                          strlen(mess)))
3a273b
             goto end;
3a273b
+
3a273b
+        if (!TEST_int_eq(SSL_write(serverssl, mess, strlen(mess)), strlen(mess))
3a273b
+                || !TEST_int_eq(SSL_read(clientssl, buf, sizeof(buf)),
3a273b
+                                         strlen(mess)))
3a273b
+            goto end;
3a273b
     }
3a273b
 
3a273b
     testresult = 1;
3a273b
@@ -4302,6 +4307,91 @@ static int test_key_update(void)
3a273b
 
3a273b
     return testresult;
3a273b
 }
3a273b
+
3a273b
+/*
3a273b
+ * Test we can handle a KeyUpdate (update requested) message while write data
3a273b
+ * is pending.
3a273b
+ * Test 0: Client sends KeyUpdate while Server is writing
3a273b
+ * Test 1: Server sends KeyUpdate while Client is writing
3a273b
+ */
3a273b
+static int test_key_update_in_write(int tst)
3a273b
+{
3a273b
+    SSL_CTX *cctx = NULL, *sctx = NULL;
3a273b
+    SSL *clientssl = NULL, *serverssl = NULL;
3a273b
+    int testresult = 0;
3a273b
+    char buf[20];
3a273b
+    static char *mess = "A test message";
3a273b
+    BIO *bretry = BIO_new(bio_s_always_retry());
3a273b
+    BIO *tmp = NULL;
3a273b
+    SSL *peerupdate = NULL, *peerwrite = NULL;
3a273b
+
3a273b
+    if (!TEST_ptr(bretry)
3a273b
+            || !TEST_true(create_ssl_ctx_pair(TLS_server_method(),
3a273b
+                                              TLS_client_method(),
3a273b
+                                              TLS1_3_VERSION,
3a273b
+                                              0,
3a273b
+                                              &sctx, &cctx, cert, privkey))
3a273b
+            || !TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
3a273b
+                                             NULL, NULL))
3a273b
+            || !TEST_true(create_ssl_connection(serverssl, clientssl,
3a273b
+                                                SSL_ERROR_NONE)))
3a273b
+        goto end;
3a273b
+
3a273b
+    peerupdate = tst == 0 ? clientssl : serverssl;
3a273b
+    peerwrite = tst == 0 ? serverssl : clientssl;
3a273b
+
3a273b
+    if (!TEST_true(SSL_key_update(peerupdate, SSL_KEY_UPDATE_REQUESTED))
3a273b
+            || !TEST_true(SSL_do_handshake(peerupdate)))
3a273b
+        goto end;
3a273b
+
3a273b
+    /* Swap the writing endpoint's write BIO to force a retry */
3a273b
+    tmp = SSL_get_wbio(peerwrite);
3a273b
+    if (!TEST_ptr(tmp) || !TEST_true(BIO_up_ref(tmp))) {
3a273b
+        tmp = NULL;
3a273b
+        goto end;
3a273b
+    }
3a273b
+    SSL_set0_wbio(peerwrite, bretry);
3a273b
+    bretry = NULL;
3a273b
+
3a273b
+    /* Write data that we know will fail with SSL_ERROR_WANT_WRITE */
3a273b
+    if (!TEST_int_eq(SSL_write(peerwrite, mess, strlen(mess)), -1)
3a273b
+            || !TEST_int_eq(SSL_get_error(peerwrite, 0), SSL_ERROR_WANT_WRITE))
3a273b
+        goto end;
3a273b
+
3a273b
+    /* Reinstate the original writing endpoint's write BIO */
3a273b
+    SSL_set0_wbio(peerwrite, tmp);
3a273b
+    tmp = NULL;
3a273b
+
3a273b
+    /* Now read some data - we will read the key update */
3a273b
+    if (!TEST_int_eq(SSL_read(peerwrite, buf, sizeof(buf)), -1)
3a273b
+            || !TEST_int_eq(SSL_get_error(peerwrite, 0), SSL_ERROR_WANT_READ))
3a273b
+        goto end;
3a273b
+
3a273b
+    /*
3a273b
+     * Complete the write we started previously and read it from the other
3a273b
+     * endpoint
3a273b
+     */
3a273b
+    if (!TEST_int_eq(SSL_write(peerwrite, mess, strlen(mess)), strlen(mess))
3a273b
+            || !TEST_int_eq(SSL_read(peerupdate, buf, sizeof(buf)), strlen(mess)))
3a273b
+        goto end;
3a273b
+
3a273b
+    /* Write more data to ensure we send the KeyUpdate message back */
3a273b
+    if (!TEST_int_eq(SSL_write(peerwrite, mess, strlen(mess)), strlen(mess))
3a273b
+            || !TEST_int_eq(SSL_read(peerupdate, buf, sizeof(buf)), strlen(mess)))
3a273b
+        goto end;
3a273b
+
3a273b
+    testresult = 1;
3a273b
+
3a273b
+ end:
3a273b
+    SSL_free(serverssl);
3a273b
+    SSL_free(clientssl);
3a273b
+    SSL_CTX_free(sctx);
3a273b
+    SSL_CTX_free(cctx);
3a273b
+    BIO_free(bretry);
3a273b
+    BIO_free(tmp);
3a273b
+
3a273b
+    return testresult;
3a273b
+}
3a273b
 #endif /* OPENSSL_NO_TLS1_3 */
3a273b
 
3a273b
 static int test_ssl_clear(int idx)
3a273b
@@ -5982,6 +6072,7 @@ int setup_tests(void)
3a273b
 #ifndef OPENSSL_NO_TLS1_3
3a273b
     ADD_ALL_TESTS(test_export_key_mat_early, 3);
3a273b
     ADD_TEST(test_key_update);
3a273b
+    ADD_ALL_TESTS(test_key_update_in_write, 2);
3a273b
 #endif
3a273b
     ADD_ALL_TESTS(test_ssl_clear, 2);
3a273b
     ADD_ALL_TESTS(test_max_fragment_len_ext, OSSL_NELEM(max_fragment_len_test));
3a273b
@@ -6002,4 +6093,5 @@ int setup_tests(void)
3a273b
 void cleanup_tests(void)
3a273b
 {
3a273b
     bio_s_mempacket_test_free();
3a273b
+    bio_s_always_retry_free();
3a273b
 }
3a273b
diff --git a/test/ssltestlib.c b/test/ssltestlib.c
3a273b
index 05139be750..e1038620ac 100644
3a273b
--- a/test/ssltestlib.c
3a273b
+++ b/test/ssltestlib.c
3a273b
@@ -62,9 +62,11 @@ static int tls_dump_puts(BIO *bp, const char *str);
3a273b
 /* Choose a sufficiently large type likely to be unused for this custom BIO */
3a273b
 #define BIO_TYPE_TLS_DUMP_FILTER  (0x80 | BIO_TYPE_FILTER)
3a273b
 #define BIO_TYPE_MEMPACKET_TEST    0x81
3a273b
+#define BIO_TYPE_ALWAYS_RETRY      0x82
3a273b
 
3a273b
 static BIO_METHOD *method_tls_dump = NULL;
3a273b
 static BIO_METHOD *meth_mem = NULL;
3a273b
+static BIO_METHOD *meth_always_retry = NULL;
3a273b
 
3a273b
 /* Note: Not thread safe! */
3a273b
 const BIO_METHOD *bio_f_tls_dump_filter(void)
3a273b
@@ -612,6 +614,100 @@ static int mempacket_test_puts(BIO *bio, const char *str)
3a273b
     return mempacket_test_write(bio, str, strlen(str));
3a273b
 }
3a273b
 
3a273b
+static int always_retry_new(BIO *bi);
3a273b
+static int always_retry_free(BIO *a);
3a273b
+static int always_retry_read(BIO *b, char *out, int outl);
3a273b
+static int always_retry_write(BIO *b, const char *in, int inl);
3a273b
+static long always_retry_ctrl(BIO *b, int cmd, long num, void *ptr);
3a273b
+static int always_retry_gets(BIO *bp, char *buf, int size);
3a273b
+static int always_retry_puts(BIO *bp, const char *str);
3a273b
+
3a273b
+const BIO_METHOD *bio_s_always_retry(void)
3a273b
+{
3a273b
+    if (meth_always_retry == NULL) {
3a273b
+        if (!TEST_ptr(meth_always_retry = BIO_meth_new(BIO_TYPE_ALWAYS_RETRY,
3a273b
+                                                       "Always Retry"))
3a273b
+            || !TEST_true(BIO_meth_set_write(meth_always_retry,
3a273b
+                                             always_retry_write))
3a273b
+            || !TEST_true(BIO_meth_set_read(meth_always_retry,
3a273b
+                                            always_retry_read))
3a273b
+            || !TEST_true(BIO_meth_set_puts(meth_always_retry,
3a273b
+                                            always_retry_puts))
3a273b
+            || !TEST_true(BIO_meth_set_gets(meth_always_retry,
3a273b
+                                            always_retry_gets))
3a273b
+            || !TEST_true(BIO_meth_set_ctrl(meth_always_retry,
3a273b
+                                            always_retry_ctrl))
3a273b
+            || !TEST_true(BIO_meth_set_create(meth_always_retry,
3a273b
+                                              always_retry_new))
3a273b
+            || !TEST_true(BIO_meth_set_destroy(meth_always_retry,
3a273b
+                                               always_retry_free)))
3a273b
+            return NULL;
3a273b
+    }
3a273b
+    return meth_always_retry;
3a273b
+}
3a273b
+
3a273b
+void bio_s_always_retry_free(void)
3a273b
+{
3a273b
+    BIO_meth_free(meth_always_retry);
3a273b
+}
3a273b
+
3a273b
+static int always_retry_new(BIO *bio)
3a273b
+{
3a273b
+    BIO_set_init(bio, 1);
3a273b
+    return 1;
3a273b
+}
3a273b
+
3a273b
+static int always_retry_free(BIO *bio)
3a273b
+{
3a273b
+    BIO_set_data(bio, NULL);
3a273b
+    BIO_set_init(bio, 0);
3a273b
+    return 1;
3a273b
+}
3a273b
+
3a273b
+static int always_retry_read(BIO *bio, char *out, int outl)
3a273b
+{
3a273b
+    BIO_set_retry_read(bio);
3a273b
+    return -1;
3a273b
+}
3a273b
+
3a273b
+static int always_retry_write(BIO *bio, const char *in, int inl)
3a273b
+{
3a273b
+    BIO_set_retry_write(bio);
3a273b
+    return -1;
3a273b
+}
3a273b
+
3a273b
+static long always_retry_ctrl(BIO *bio, int cmd, long num, void *ptr)
3a273b
+{
3a273b
+    long ret = 1;
3a273b
+
3a273b
+    switch (cmd) {
3a273b
+    case BIO_CTRL_FLUSH:
3a273b
+        BIO_set_retry_write(bio);
3a273b
+        /* fall through */
3a273b
+    case BIO_CTRL_EOF:
3a273b
+    case BIO_CTRL_RESET:
3a273b
+    case BIO_CTRL_DUP:
3a273b
+    case BIO_CTRL_PUSH:
3a273b
+    case BIO_CTRL_POP:
3a273b
+    default:
3a273b
+        ret = 0;
3a273b
+        break;
3a273b
+    }
3a273b
+    return ret;
3a273b
+}
3a273b
+
3a273b
+static int always_retry_gets(BIO *bio, char *buf, int size)
3a273b
+{
3a273b
+    BIO_set_retry_read(bio);
3a273b
+    return -1;
3a273b
+}
3a273b
+
3a273b
+static int always_retry_puts(BIO *bio, const char *str)
3a273b
+{
3a273b
+    BIO_set_retry_write(bio);
3a273b
+    return -1;
3a273b
+}
3a273b
+
3a273b
 int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
3a273b
                         int min_proto_version, int max_proto_version,
3a273b
                         SSL_CTX **sctx, SSL_CTX **cctx, char *certfile,
3a273b
diff --git a/test/ssltestlib.h b/test/ssltestlib.h
3a273b
index fa19e7d80d..56e323f5bc 100644
3a273b
--- a/test/ssltestlib.h
3a273b
+++ b/test/ssltestlib.h
3a273b
@@ -30,6 +30,9 @@ void bio_f_tls_dump_filter_free(void);
3a273b
 const BIO_METHOD *bio_s_mempacket_test(void);
3a273b
 void bio_s_mempacket_test_free(void);
3a273b
 
3a273b
+const BIO_METHOD *bio_s_always_retry(void);
3a273b
+void bio_s_always_retry_free(void);
3a273b
+
3a273b
 /* Packet types - value 0 is reserved */
3a273b
 #define INJECT_PACKET                   1
3a273b
 #define INJECT_PACKET_IGNORE_REC_SEQ    2
3a273b
-- 
3a273b
2.20.1
3a273b
3a273b
diff -up openssl-1.1.1c/include/internal/constant_time_locl.h.valgrind openssl-1.1.1c/include/internal/constant_time_locl.h
3a273b
--- openssl-1.1.1c/include/internal/constant_time_locl.h.valgrind	2019-05-28 15:12:21.000000000 +0200
3a273b
+++ openssl-1.1.1c/include/internal/constant_time_locl.h	2019-06-24 15:02:12.796053536 +0200
3a273b
@@ -213,18 +213,66 @@ static ossl_inline unsigned char constan
3a273b
     return constant_time_eq_8((unsigned)(a), (unsigned)(b));
3a273b
 }
3a273b
 
3a273b
+/* Returns the value unmodified, but avoids optimizations. */
3a273b
+static ossl_inline unsigned int value_barrier(unsigned int a)
3a273b
+{
3a273b
+#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
3a273b
+    unsigned int r;
3a273b
+    __asm__("" : "=r"(r) : "0"(a));
3a273b
+#else
3a273b
+    volatile unsigned int r = a;
3a273b
+#endif
3a273b
+    return r;
3a273b
+}
3a273b
+
3a273b
+/* Convenience method for uint32_t. */
3a273b
+static ossl_inline uint32_t value_barrier_32(uint32_t a)
3a273b
+{
3a273b
+#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
3a273b
+    uint32_t r;
3a273b
+    __asm__("" : "=r"(r) : "0"(a));
3a273b
+#else
3a273b
+    volatile uint32_t r = a;
3a273b
+#endif
3a273b
+    return r;
3a273b
+}
3a273b
+
3a273b
+/* Convenience method for uint64_t. */
3a273b
+static ossl_inline uint64_t value_barrier_64(uint64_t a)
3a273b
+{
3a273b
+#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
3a273b
+    uint64_t r;
3a273b
+    __asm__("" : "=r"(r) : "0"(a));
3a273b
+#else
3a273b
+    volatile uint64_t r = a;
3a273b
+#endif
3a273b
+    return r;
3a273b
+}
3a273b
+
3a273b
+/* Convenience method for size_t. */
3a273b
+static ossl_inline size_t value_barrier_s(size_t a)
3a273b
+{
3a273b
+#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
3a273b
+    size_t r;
3a273b
+    __asm__("" : "=r"(r) : "0"(a));
3a273b
+#else
3a273b
+    volatile size_t r = a;
3a273b
+#endif
3a273b
+    return r;
3a273b
+}
3a273b
+
3a273b
 static ossl_inline unsigned int constant_time_select(unsigned int mask,
3a273b
                                                      unsigned int a,
3a273b
                                                      unsigned int b)
3a273b
 {
3a273b
-    return (mask & a) | (~mask & b);
3a273b
+    return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
3a273b
 }
3a273b
 
3a273b
 static ossl_inline size_t constant_time_select_s(size_t mask,
3a273b
                                                  size_t a,
3a273b
                                                  size_t b)
3a273b
 {
3a273b
-    return (mask & a) | (~mask & b);
3a273b
+    return (value_barrier_s(mask) & a) | (value_barrier_s(~mask) & b);
3a273b
 }
3a273b
 
3a273b
 static ossl_inline unsigned char constant_time_select_8(unsigned char mask,
3a273b
@@ -249,13 +297,13 @@ static ossl_inline int constant_time_sel
3a273b
 static ossl_inline uint32_t constant_time_select_32(uint32_t mask, uint32_t a,
3a273b
                                                     uint32_t b)
3a273b
 {
3a273b
-    return (mask & a) | (~mask & b);
3a273b
+    return (value_barrier_32(mask) & a) | (value_barrier_32(~mask) & b);
3a273b
 }
3a273b
 
3a273b
 static ossl_inline uint64_t constant_time_select_64(uint64_t mask, uint64_t a,
3a273b
                                                     uint64_t b)
3a273b
 {
3a273b
-    return (mask & a) | (~mask & b);
3a273b
+    return (value_barrier_64(mask) & a) | (value_barrier_64(~mask) & b);
3a273b
 }
3a273b
 
3a273b
 /*