5c7382c
diff -up openssl-1.1.1b/apps/asn1pars.c.sync openssl-1.1.1b/apps/asn1pars.c
5c7382c
--- openssl-1.1.1b/apps/asn1pars.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/apps/asn1pars.c	2019-05-03 08:55:51.532407003 +0200
5c7382c
@@ -170,17 +170,17 @@ int asn1parse_main(int argc, char **argv
5c7382c
     if (derfile && (derout = bio_open_default(derfile, 'w', FORMAT_ASN1)) == NULL)
5c7382c
         goto end;
5c7382c
 
5c7382c
+    if ((buf = BUF_MEM_new()) == NULL)
5c7382c
+        goto end;
5c7382c
     if (strictpem) {
5c7382c
-        if (PEM_read_bio(in, &name, &header, &str, &num) !=
5c7382c
-            1) {
5c7382c
+        if (PEM_read_bio(in, &name, &header, &str, &num) != 1) {
5c7382c
             BIO_printf(bio_err, "Error reading PEM file\n");
5c7382c
             ERR_print_errors(bio_err);
5c7382c
             goto end;
5c7382c
         }
5c7382c
+        buf->data = (char *)str;
5c7382c
+        buf->length = buf->max = num;
5c7382c
     } else {
5c7382c
-
5c7382c
-        if ((buf = BUF_MEM_new()) == NULL)
5c7382c
-            goto end;
5c7382c
         if (!BUF_MEM_grow(buf, BUFSIZ * 8))
5c7382c
             goto end;           /* Pre-allocate :-) */
5c7382c
 
5c7382c
@@ -303,8 +303,6 @@ int asn1parse_main(int argc, char **argv
5c7382c
     BUF_MEM_free(buf);
5c7382c
     OPENSSL_free(name);
5c7382c
     OPENSSL_free(header);
5c7382c
-    if (strictpem)
5c7382c
-        OPENSSL_free(str);
5c7382c
     ASN1_TYPE_free(at);
5c7382c
     sk_OPENSSL_STRING_free(osk);
5c7382c
     return ret;
5c7382c
diff -up openssl-1.1.1b/crypto/aes/asm/aesp8-ppc.pl.sync openssl-1.1.1b/crypto/aes/asm/aesp8-ppc.pl
5c7382c
--- openssl-1.1.1b/crypto/aes/asm/aesp8-ppc.pl.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/aes/asm/aesp8-ppc.pl	2019-05-03 08:55:51.551406676 +0200
5c7382c
@@ -1829,7 +1829,7 @@ Lctr32_enc8x_three:
5c7382c
 	stvx_u		$out1,$x10,$out
5c7382c
 	stvx_u		$out2,$x20,$out
5c7382c
 	addi		$out,$out,0x30
5c7382c
-	b		Lcbc_dec8x_done
5c7382c
+	b		Lctr32_enc8x_done
5c7382c
 
5c7382c
 .align	5
5c7382c
 Lctr32_enc8x_two:
5c7382c
@@ -1841,7 +1841,7 @@ Lctr32_enc8x_two:
5c7382c
 	stvx_u		$out0,$x00,$out
5c7382c
 	stvx_u		$out1,$x10,$out
5c7382c
 	addi		$out,$out,0x20
5c7382c
-	b		Lcbc_dec8x_done
5c7382c
+	b		Lctr32_enc8x_done
5c7382c
 
5c7382c
 .align	5
5c7382c
 Lctr32_enc8x_one:
5c7382c
diff -up openssl-1.1.1b/crypto/bio/b_addr.c.sync openssl-1.1.1b/crypto/bio/b_addr.c
5c7382c
--- openssl-1.1.1b/crypto/bio/b_addr.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/bio/b_addr.c	2019-05-03 08:55:51.555406608 +0200
5c7382c
@@ -683,6 +683,12 @@ int BIO_lookup_ex(const char *host, cons
5c7382c
         hints.ai_family = family;
5c7382c
         hints.ai_socktype = socktype;
5c7382c
         hints.ai_protocol = protocol;
5c7382c
+#ifdef AI_ADDRCONFIG
5c7382c
+#ifdef AF_UNSPEC
5c7382c
+        if (family == AF_UNSPEC)
5c7382c
+#endif
5c7382c
+            hints.ai_flags |= AI_ADDRCONFIG;
5c7382c
+#endif
5c7382c
 
5c7382c
         if (lookup_type == BIO_LOOKUP_SERVER)
5c7382c
             hints.ai_flags |= AI_PASSIVE;
5c7382c
diff -up openssl-1.1.1b/crypto/bio/bss_mem.c.sync openssl-1.1.1b/crypto/bio/bss_mem.c
5c7382c
--- openssl-1.1.1b/crypto/bio/bss_mem.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/bio/bss_mem.c	2019-05-03 08:55:51.556406591 +0200
5c7382c
@@ -57,7 +57,12 @@ static const BIO_METHOD secmem_method =
5c7382c
     NULL,                      /* mem_callback_ctrl */
5c7382c
 };
5c7382c
 
5c7382c
-/* BIO memory stores buffer and read pointer  */
5c7382c
+/*
5c7382c
+ * BIO memory stores buffer and read pointer
5c7382c
+ * however the roles are different for read only BIOs.
5c7382c
+ * In that case the readp just stores the original state
5c7382c
+ * to be used for reset.
5c7382c
+ */
5c7382c
 typedef struct bio_buf_mem_st {
5c7382c
     struct buf_mem_st *buf;   /* allocated buffer */
5c7382c
     struct buf_mem_st *readp; /* read pointer */
5c7382c
@@ -192,11 +197,14 @@ static int mem_read(BIO *b, char *out, i
5c7382c
     BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
5c7382c
     BUF_MEM *bm = bbm->readp;
5c7382c
 
5c7382c
+    if (b->flags & BIO_FLAGS_MEM_RDONLY)
5c7382c
+        bm = bbm->buf;
5c7382c
     BIO_clear_retry_flags(b);
5c7382c
     ret = (outl >= 0 && (size_t)outl > bm->length) ? (int)bm->length : outl;
5c7382c
     if ((out != NULL) && (ret > 0)) {
5c7382c
         memcpy(out, bm->data, ret);
5c7382c
         bm->length -= ret;
5c7382c
+        bm->max -= ret;
5c7382c
         bm->data += ret;
5c7382c
     } else if (bm->length == 0) {
5c7382c
         ret = b->num;
5c7382c
@@ -241,29 +249,36 @@ static long mem_ctrl(BIO *b, int cmd, lo
5c7382c
     BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
5c7382c
     BUF_MEM *bm;
5c7382c
 
5c7382c
+    if (b->flags & BIO_FLAGS_MEM_RDONLY)
5c7382c
+        bm = bbm->buf;
5c7382c
+    else
5c7382c
+        bm = bbm->readp;
5c7382c
+
5c7382c
     switch (cmd) {
5c7382c
     case BIO_CTRL_RESET:
5c7382c
         bm = bbm->buf;
5c7382c
         if (bm->data != NULL) {
5c7382c
-            /* For read only case reset to the start again */
5c7382c
-            if ((b->flags & BIO_FLAGS_MEM_RDONLY) || (b->flags & BIO_FLAGS_NONCLEAR_RST)) {
5c7382c
-                bm->length = bm->max;
5c7382c
+            if (!(b->flags & BIO_FLAGS_MEM_RDONLY)) {
5c7382c
+                if (b->flags & BIO_FLAGS_NONCLEAR_RST) {
5c7382c
+                    bm->length = bm->max;
5c7382c
+                } else {
5c7382c
+                    memset(bm->data, 0, bm->max);
5c7382c
+                    bm->length = 0;
5c7382c
+                }
5c7382c
+                *bbm->readp = *bbm->buf;
5c7382c
             } else {
5c7382c
-                memset(bm->data, 0, bm->max);
5c7382c
-                bm->length = 0;
5c7382c
+                /* For read only case just reset to the start again */
5c7382c
+                *bbm->buf = *bbm->readp;
5c7382c
             }
5c7382c
-            *bbm->readp = *bbm->buf;
5c7382c
         }
5c7382c
         break;
5c7382c
     case BIO_CTRL_EOF:
5c7382c
-        bm = bbm->readp;
5c7382c
         ret = (long)(bm->length == 0);
5c7382c
         break;
5c7382c
     case BIO_C_SET_BUF_MEM_EOF_RETURN:
5c7382c
         b->num = (int)num;
5c7382c
         break;
5c7382c
     case BIO_CTRL_INFO:
5c7382c
-        bm = bbm->readp;
5c7382c
         ret = (long)bm->length;
5c7382c
         if (ptr != NULL) {
5c7382c
             pptr = (char **)ptr;
5c7382c
@@ -278,8 +293,9 @@ static long mem_ctrl(BIO *b, int cmd, lo
5c7382c
         break;
5c7382c
     case BIO_C_GET_BUF_MEM_PTR:
5c7382c
         if (ptr != NULL) {
5c7382c
-            mem_buf_sync(b);
5c7382c
-            bm = bbm->readp;
5c7382c
+            if (!(b->flags & BIO_FLAGS_MEM_RDONLY))
5c7382c
+                mem_buf_sync(b);
5c7382c
+            bm = bbm->buf;
5c7382c
             pptr = (char **)ptr;
5c7382c
             *pptr = (char *)bm;
5c7382c
         }
5c7382c
@@ -294,7 +310,6 @@ static long mem_ctrl(BIO *b, int cmd, lo
5c7382c
         ret = 0L;
5c7382c
         break;
5c7382c
     case BIO_CTRL_PENDING:
5c7382c
-        bm = bbm->readp;
5c7382c
         ret = (long)bm->length;
5c7382c
         break;
5c7382c
     case BIO_CTRL_DUP:
5c7382c
@@ -318,6 +333,8 @@ static int mem_gets(BIO *bp, char *buf,
5c7382c
     BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)bp->ptr;
5c7382c
     BUF_MEM *bm = bbm->readp;
5c7382c
 
5c7382c
+    if (bp->flags & BIO_FLAGS_MEM_RDONLY)
5c7382c
+        bm = bbm->buf;
5c7382c
     BIO_clear_retry_flags(bp);
5c7382c
     j = bm->length;
5c7382c
     if ((size - 1) < j)
5c7382c
diff -up openssl-1.1.1b/crypto/bn/asm/ppc.pl.sync openssl-1.1.1b/crypto/bn/asm/ppc.pl
5c7382c
--- openssl-1.1.1b/crypto/bn/asm/ppc.pl.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/bn/asm/ppc.pl	2019-05-03 08:55:51.530407037 +0200
5c7382c
@@ -258,6 +258,7 @@ $data=<
5c7382c
 # .text section
5c7382c
 
5c7382c
 	.machine	"any"
5c7382c
+	.text
5c7382c
 
5c7382c
 #
5c7382c
 #	NOTE:	The following label name should be changed to
5c7382c
diff -up openssl-1.1.1b/crypto/bn/bn_ctx.c.sync openssl-1.1.1b/crypto/bn/bn_ctx.c
5c7382c
--- openssl-1.1.1b/crypto/bn/bn_ctx.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/bn/bn_ctx.c	2019-05-03 08:55:51.524407140 +0200
5c7382c
@@ -194,6 +194,8 @@ void BN_CTX_start(BN_CTX *ctx)
5c7382c
 
5c7382c
 void BN_CTX_end(BN_CTX *ctx)
5c7382c
 {
5c7382c
+    if (ctx == NULL)
5c7382c
+        return;
5c7382c
     CTXDBG_ENTRY("BN_CTX_end", ctx);
5c7382c
     if (ctx->err_stack)
5c7382c
         ctx->err_stack--;
5c7382c
diff -up openssl-1.1.1b/crypto/bn/bn_lib.c.sync openssl-1.1.1b/crypto/bn/bn_lib.c
5c7382c
--- openssl-1.1.1b/crypto/bn/bn_lib.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/bn/bn_lib.c	2019-05-03 08:55:51.525407123 +0200
5c7382c
@@ -338,6 +338,8 @@ void BN_swap(BIGNUM *a, BIGNUM *b)
5c7382c
 
5c7382c
 void BN_clear(BIGNUM *a)
5c7382c
 {
5c7382c
+    if (a == NULL)
5c7382c
+        return;
5c7382c
     bn_check_top(a);
5c7382c
     if (a->d != NULL)
5c7382c
         OPENSSL_cleanse(a->d, sizeof(*a->d) * a->dmax);
5c7382c
diff -up openssl-1.1.1b/crypto/bn/bn_prime.c.sync openssl-1.1.1b/crypto/bn/bn_prime.c
5c7382c
--- openssl-1.1.1b/crypto/bn/bn_prime.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/bn/bn_prime.c	2019-05-03 08:55:51.525407123 +0200
5c7382c
@@ -135,8 +135,7 @@ int BN_generate_prime_ex(BIGNUM *ret, in
5c7382c
     found = 1;
5c7382c
  err:
5c7382c
     OPENSSL_free(mods);
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     bn_check_top(ret);
5c7382c
     return found;
5c7382c
diff -up openssl-1.1.1b/crypto/chacha/build.info.sync openssl-1.1.1b/crypto/chacha/build.info
5c7382c
--- openssl-1.1.1b/crypto/chacha/build.info.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/chacha/build.info	2019-05-03 08:55:51.538406900 +0200
5c7382c
@@ -9,6 +9,8 @@ GENERATE[chacha-armv4.S]=asm/chacha-armv
5c7382c
 INCLUDE[chacha-armv4.o]=..
5c7382c
 GENERATE[chacha-armv8.S]=asm/chacha-armv8.pl $(PERLASM_SCHEME)
5c7382c
 INCLUDE[chacha-armv8.o]=..
5c7382c
+GENERATE[chacha-s390x.S]=asm/chacha-s390x.pl $(PERLASM_SCHEME)
5c7382c
+INCLUDE[chacha-s390x.o]=..
5c7382c
 
5c7382c
 BEGINRAW[Makefile(unix)]
5c7382c
 ##### CHACHA assembler implementations
5c7382c
diff -up openssl-1.1.1b/crypto/conf/conf_sap.c.sync openssl-1.1.1b/crypto/conf/conf_sap.c
5c7382c
--- openssl-1.1.1b/crypto/conf/conf_sap.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/conf/conf_sap.c	2019-05-03 08:55:51.550406694 +0200
5c7382c
@@ -35,6 +35,7 @@ void OPENSSL_config(const char *appname)
5c7382c
     memset(&settings, 0, sizeof(settings));
5c7382c
     if (appname != NULL)
5c7382c
         settings.appname = strdup(appname);
5c7382c
+    settings.flags = DEFAULT_CONF_MFLAGS;
5c7382c
     OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, &settings);
5c7382c
 }
5c7382c
 #endif
5c7382c
diff -up openssl-1.1.1b/crypto/dh/dh_check.c.sync openssl-1.1.1b/crypto/dh/dh_check.c
5c7382c
--- openssl-1.1.1b/crypto/dh/dh_check.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/dh/dh_check.c	2019-05-03 08:55:51.525407123 +0200
5c7382c
@@ -58,10 +58,8 @@ int DH_check_params(const DH *dh, int *r
5c7382c
 
5c7382c
     ok = 1;
5c7382c
  err:
5c7382c
-    if (ctx != NULL) {
5c7382c
-        BN_CTX_end(ctx);
5c7382c
-        BN_CTX_free(ctx);
5c7382c
-    }
5c7382c
+    BN_CTX_end(ctx);
5c7382c
+    BN_CTX_free(ctx);
5c7382c
     return ok;
5c7382c
 }
5c7382c
 
5c7382c
@@ -171,10 +169,8 @@ int DH_check(const DH *dh, int *ret)
5c7382c
     }
5c7382c
     ok = 1;
5c7382c
  err:
5c7382c
-    if (ctx != NULL) {
5c7382c
-        BN_CTX_end(ctx);
5c7382c
-        BN_CTX_free(ctx);
5c7382c
-    }
5c7382c
+    BN_CTX_end(ctx);
5c7382c
+    BN_CTX_free(ctx);
5c7382c
     return ok;
5c7382c
 }
5c7382c
 
5c7382c
@@ -225,9 +221,7 @@ int DH_check_pub_key(const DH *dh, const
5c7382c
 
5c7382c
     ok = 1;
5c7382c
  err:
5c7382c
-    if (ctx != NULL) {
5c7382c
-        BN_CTX_end(ctx);
5c7382c
-        BN_CTX_free(ctx);
5c7382c
-    }
5c7382c
+    BN_CTX_end(ctx);
5c7382c
+    BN_CTX_free(ctx);
5c7382c
     return ok;
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/dh/dh_gen.c.sync openssl-1.1.1b/crypto/dh/dh_gen.c
5c7382c
--- openssl-1.1.1b/crypto/dh/dh_gen.c.sync	2019-05-03 08:55:45.170516224 +0200
5c7382c
+++ openssl-1.1.1b/crypto/dh/dh_gen.c	2019-05-03 08:55:51.525407123 +0200
5c7382c
@@ -144,9 +144,7 @@ static int dh_builtin_genparams(DH *ret,
5c7382c
         ok = 0;
5c7382c
     }
5c7382c
 
5c7382c
-    if (ctx != NULL) {
5c7382c
-        BN_CTX_end(ctx);
5c7382c
-        BN_CTX_free(ctx);
5c7382c
-    }
5c7382c
+    BN_CTX_end(ctx);
5c7382c
+    BN_CTX_free(ctx);
5c7382c
     return ok;
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/dh/dh_key.c.sync openssl-1.1.1b/crypto/dh/dh_key.c
5c7382c
--- openssl-1.1.1b/crypto/dh/dh_key.c.sync	2019-05-03 08:55:45.170516224 +0200
5c7382c
+++ openssl-1.1.1b/crypto/dh/dh_key.c	2019-05-03 08:55:51.526407106 +0200
5c7382c
@@ -237,10 +237,8 @@ static int compute_key(unsigned char *ke
5c7382c
 
5c7382c
     ret = BN_bn2bin(tmp, key);
5c7382c
  err:
5c7382c
-    if (ctx != NULL) {
5c7382c
-        BN_CTX_end(ctx);
5c7382c
-        BN_CTX_free(ctx);
5c7382c
-    }
5c7382c
+    BN_CTX_end(ctx);
5c7382c
+    BN_CTX_free(ctx);
5c7382c
     return ret;
5c7382c
 }
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/crypto/dsa/dsa_gen.c.sync openssl-1.1.1b/crypto/dsa/dsa_gen.c
5c7382c
--- openssl-1.1.1b/crypto/dsa/dsa_gen.c.sync	2019-05-03 08:55:45.171516207 +0200
5c7382c
+++ openssl-1.1.1b/crypto/dsa/dsa_gen.c	2019-05-03 08:55:51.526407106 +0200
5c7382c
@@ -308,8 +308,7 @@ int dsa_builtin_paramgen(DSA *ret, size_
5c7382c
         if (seed_out)
5c7382c
             memcpy(seed_out, seed, qsize);
5c7382c
     }
5c7382c
-    if (ctx)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     BN_MONT_CTX_free(mont);
5c7382c
     return ok;
5c7382c
@@ -641,8 +640,7 @@ int dsa_builtin_paramgen2(DSA *ret, size
5c7382c
     OPENSSL_free(seed);
5c7382c
     if (seed_out != seed_tmp)
5c7382c
         OPENSSL_free(seed_tmp);
5c7382c
-    if (ctx)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     BN_MONT_CTX_free(mont);
5c7382c
     EVP_MD_CTX_free(mctx);
5c7382c
diff -up openssl-1.1.1b/crypto/ec/ecdh_ossl.c.sync openssl-1.1.1b/crypto/ec/ecdh_ossl.c
5c7382c
--- openssl-1.1.1b/crypto/ec/ecdh_ossl.c.sync	2019-05-03 08:55:45.171516207 +0200
5c7382c
+++ openssl-1.1.1b/crypto/ec/ecdh_ossl.c	2019-05-03 08:55:51.556406591 +0200
5c7382c
@@ -123,7 +123,7 @@ int ecdh_simple_compute_key(unsigned cha
5c7382c
     ret = 1;
5c7382c
 
5c7382c
  err:
5c7382c
-    EC_POINT_free(tmp);
5c7382c
+    EC_POINT_clear_free(tmp);
5c7382c
     if (ctx)
5c7382c
         BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
diff -up openssl-1.1.1b/crypto/ec/ec_lib.c.sync openssl-1.1.1b/crypto/ec/ec_lib.c
5c7382c
--- openssl-1.1.1b/crypto/ec/ec_lib.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/ec/ec_lib.c	2019-05-03 08:55:51.527407088 +0200
5c7382c
@@ -1074,8 +1074,7 @@ static int ec_field_inverse_mod_ord(cons
5c7382c
     ret = 1;
5c7382c
 
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(new_ctx);
5c7382c
     return ret;
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/ec/ec_mult.c.sync openssl-1.1.1b/crypto/ec/ec_mult.c
5c7382c
--- openssl-1.1.1b/crypto/ec/ec_mult.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/ec/ec_mult.c	2019-05-03 08:55:51.540406865 +0200
5c7382c
@@ -378,7 +378,7 @@ int ec_scalar_mul_ladder(const EC_GROUP
5c7382c
 
5c7382c
  err:
5c7382c
     EC_POINT_free(p);
5c7382c
-    EC_POINT_free(s);
5c7382c
+    EC_POINT_clear_free(s);
5c7382c
     BN_CTX_end(ctx);
5c7382c
 
5c7382c
     return ret;
5c7382c
@@ -441,7 +441,7 @@ int ec_wNAF_mul(const EC_GROUP *group, E
5c7382c
          * scalar multiplication implementation based on a Montgomery ladder,
5c7382c
          * with various timing attack defenses.
5c7382c
          */
5c7382c
-        if ((scalar != NULL) && (num == 0)) {
5c7382c
+        if ((scalar != group->order) && (scalar != NULL) && (num == 0)) {
5c7382c
             /*-
5c7382c
              * In this case we want to compute scalar * GeneratorPoint: this
5c7382c
              * codepath is reached most prominently by (ephemeral) key
5c7382c
@@ -452,7 +452,7 @@ int ec_wNAF_mul(const EC_GROUP *group, E
5c7382c
              */
5c7382c
             return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx);
5c7382c
         }
5c7382c
-        if ((scalar == NULL) && (num == 1)) {
5c7382c
+        if ((scalar == NULL) && (num == 1) && (scalars[0] != group->order)) {
5c7382c
             /*-
5c7382c
              * In this case we want to compute scalar * VariablePoint: this
5c7382c
              * codepath is reached most prominently by the second half of ECDH,
5c7382c
@@ -948,8 +948,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *gr
5c7382c
     ret = 1;
5c7382c
 
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(new_ctx);
5c7382c
     EC_ec_pre_comp_free(pre_comp);
5c7382c
     if (points) {
5c7382c
diff -up openssl-1.1.1b/crypto/ec/ecp_nistp521.c.sync openssl-1.1.1b/crypto/ec/ecp_nistp521.c
5c7382c
--- openssl-1.1.1b/crypto/ec/ecp_nistp521.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/ec/ecp_nistp521.c	2019-05-03 08:55:51.532407003 +0200
5c7382c
@@ -357,10 +357,15 @@ static void felem_diff64(felem out, cons
5c7382c
 static void felem_diff_128_64(largefelem out, const felem in)
5c7382c
 {
5c7382c
     /*
5c7382c
-     * In order to prevent underflow, we add 0 mod p before subtracting.
5c7382c
+     * In order to prevent underflow, we add 64p mod p (which is equivalent
5c7382c
+     * to 0 mod p) before subtracting. p is 2^521 - 1, i.e. in binary a 521
5c7382c
+     * digit number with all bits set to 1. See "The representation of field
5c7382c
+     * elements" comment above for a description of how limbs are used to
5c7382c
+     * represent a number. 64p is represented with 8 limbs containing a number
5c7382c
+     * with 58 bits set and one limb with a number with 57 bits set.
5c7382c
      */
5c7382c
-    static const limb two63m6 = (((limb) 1) << 62) - (((limb) 1) << 5);
5c7382c
-    static const limb two63m5 = (((limb) 1) << 62) - (((limb) 1) << 4);
5c7382c
+    static const limb two63m6 = (((limb) 1) << 63) - (((limb) 1) << 6);
5c7382c
+    static const limb two63m5 = (((limb) 1) << 63) - (((limb) 1) << 5);
5c7382c
 
5c7382c
     out[0] += two63m6 - in[0];
5c7382c
     out[1] += two63m5 - in[1];
5c7382c
diff -up openssl-1.1.1b/crypto/ec/ecp_nistz256.c.sync openssl-1.1.1b/crypto/ec/ecp_nistz256.c
5c7382c
--- openssl-1.1.1b/crypto/ec/ecp_nistz256.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/ec/ecp_nistz256.c	2019-05-03 08:55:51.528407071 +0200
5c7382c
@@ -888,8 +888,7 @@ __owur static int ecp_nistz256_mult_prec
5c7382c
     ret = 1;
5c7382c
 
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(new_ctx);
5c7382c
 
5c7382c
     EC_nistz256_pre_comp_free(pre_comp);
5c7382c
diff -up openssl-1.1.1b/crypto/ec/ecp_smpl.c.sync openssl-1.1.1b/crypto/ec/ecp_smpl.c
5c7382c
--- openssl-1.1.1b/crypto/ec/ecp_smpl.c.sync	2019-05-03 08:55:45.152516533 +0200
5c7382c
+++ openssl-1.1.1b/crypto/ec/ecp_smpl.c	2019-05-03 08:55:51.528407071 +0200
5c7382c
@@ -312,8 +312,7 @@ int ec_GFp_simple_group_check_discrimina
5c7382c
     ret = 1;
5c7382c
 
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(new_ctx);
5c7382c
     return ret;
5c7382c
 }
5c7382c
@@ -792,8 +791,7 @@ int ec_GFp_simple_add(const EC_GROUP *gr
5c7382c
     ret = 1;
5c7382c
 
5c7382c
  end:
5c7382c
-    if (ctx)                    /* otherwise we already called BN_CTX_end */
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(new_ctx);
5c7382c
     return ret;
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/err/err.c.sync openssl-1.1.1b/crypto/err/err.c
5c7382c
--- openssl-1.1.1b/crypto/err/err.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/err/err.c	2019-05-03 08:55:51.548406728 +0200
5c7382c
@@ -523,8 +523,24 @@ static unsigned long get_error_values(in
5c7382c
         return ERR_R_INTERNAL_ERROR;
5c7382c
     }
5c7382c
 
5c7382c
+    while (es->bottom != es->top) {
5c7382c
+        if (es->err_flags[es->top] & ERR_FLAG_CLEAR) {
5c7382c
+            err_clear(es, es->top);
5c7382c
+            es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
5c7382c
+            continue;
5c7382c
+        }
5c7382c
+        i = (es->bottom + 1) % ERR_NUM_ERRORS;
5c7382c
+        if (es->err_flags[i] & ERR_FLAG_CLEAR) {
5c7382c
+            es->bottom = i;
5c7382c
+            err_clear(es, es->bottom);
5c7382c
+            continue;
5c7382c
+        }
5c7382c
+        break;
5c7382c
+    }
5c7382c
+
5c7382c
     if (es->bottom == es->top)
5c7382c
         return 0;
5c7382c
+
5c7382c
     if (top)
5c7382c
         i = es->top;            /* last error */
5c7382c
     else
5c7382c
@@ -913,25 +929,6 @@ int ERR_clear_last_mark(void)
5c7382c
     return 1;
5c7382c
 }
5c7382c
 
5c7382c
-#ifdef UINTPTR_T
5c7382c
-# undef UINTPTR_T
5c7382c
-#endif
5c7382c
-/*
5c7382c
- * uintptr_t is the answer, but unfortunately C89, current "least common
5c7382c
- * denominator" doesn't define it. Most legacy platforms typedef it anyway,
5c7382c
- * so that attempt to fill the gaps means that one would have to identify
5c7382c
- * that track these gaps, which would be undesirable. Macro it is...
5c7382c
- */
5c7382c
-#if defined(__VMS) && __INITIAL_POINTER_SIZE==64
5c7382c
-/*
5c7382c
- * But we can't use size_t on VMS, because it adheres to sizeof(size_t)==4
5c7382c
- * even in 64-bit builds, which means that it won't work as mask.
5c7382c
- */
5c7382c
-# define UINTPTR_T unsigned long long
5c7382c
-#else
5c7382c
-# define UINTPTR_T size_t
5c7382c
-#endif
5c7382c
-
5c7382c
 void err_clear_last_constant_time(int clear)
5c7382c
 {
5c7382c
     ERR_STATE *es;
5c7382c
@@ -943,11 +940,11 @@ void err_clear_last_constant_time(int cl
5c7382c
 
5c7382c
     top = es->top;
5c7382c
 
5c7382c
-    es->err_flags[top] &= ~(0 - clear);
5c7382c
-    es->err_buffer[top] &= ~(0UL - clear);
5c7382c
-    es->err_file[top] = (const char *)((UINTPTR_T)es->err_file[top] &
5c7382c
-                                       ~((UINTPTR_T)0 - clear));
5c7382c
-    es->err_line[top] |= 0 - clear;
5c7382c
-
5c7382c
-    es->top = (top + ERR_NUM_ERRORS - clear) % ERR_NUM_ERRORS;
5c7382c
+    /*
5c7382c
+     * Flag error as cleared but remove it elsewhere to avoid two errors
5c7382c
+     * accessing the same error stack location, revealing timing information.
5c7382c
+     */
5c7382c
+    clear = constant_time_select_int(constant_time_eq_int(clear, 0),
5c7382c
+                                     0, ERR_FLAG_CLEAR);
5c7382c
+    es->err_flags[top] |= clear;
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/evp/digest.c.sync openssl-1.1.1b/crypto/evp/digest.c
5c7382c
--- openssl-1.1.1b/crypto/evp/digest.c.sync	2019-05-03 08:55:51.553406642 +0200
5c7382c
+++ openssl-1.1.1b/crypto/evp/digest.c	2019-05-03 08:56:40.800561168 +0200
5c7382c
@@ -171,6 +171,9 @@ int EVP_DigestUpdate(EVP_MD_CTX *ctx, co
5c7382c
 #ifdef OPENSSL_FIPS
5c7382c
     FIPS_selftest_check();
5c7382c
 #endif
5c7382c
+    if (count == 0)
5c7382c
+        return 1;
5c7382c
+
5c7382c
     return ctx->update(ctx, data, count);
5c7382c
 }
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/crypto/evp/e_aria.c.sync openssl-1.1.1b/crypto/evp/e_aria.c
5c7382c
--- openssl-1.1.1b/crypto/evp/e_aria.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/evp/e_aria.c	2019-05-03 08:55:51.545406779 +0200
5c7382c
@@ -486,6 +486,16 @@ static int aria_gcm_cipher(EVP_CIPHER_CT
5c7382c
     return 0;
5c7382c
 }
5c7382c
 
5c7382c
+static int aria_gcm_cleanup(EVP_CIPHER_CTX *ctx)
5c7382c
+{
5c7382c
+    EVP_ARIA_GCM_CTX *gctx = EVP_C_DATA(EVP_ARIA_GCM_CTX, ctx);
5c7382c
+
5c7382c
+    if (gctx->iv != EVP_CIPHER_CTX_iv_noconst(ctx))
5c7382c
+        OPENSSL_free(gctx->iv);
5c7382c
+
5c7382c
+    return 1;
5c7382c
+}
5c7382c
+
5c7382c
 static int aria_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
5c7382c
                             const unsigned char *iv, int enc)
5c7382c
 {
5c7382c
@@ -727,6 +737,8 @@ static int aria_ccm_cipher(EVP_CIPHER_CT
5c7382c
     }
5c7382c
 }
5c7382c
 
5c7382c
+#define aria_ccm_cleanup    NULL
5c7382c
+
5c7382c
 #define ARIA_AUTH_FLAGS  (EVP_CIPH_FLAG_DEFAULT_ASN1 \
5c7382c
                           | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \
5c7382c
                           | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT \
5c7382c
@@ -739,7 +751,7 @@ static const EVP_CIPHER aria_##keylen##_
5c7382c
         ARIA_AUTH_FLAGS|EVP_CIPH_##MODE##_MODE,    \
5c7382c
         aria_##mode##_init_key,                    \
5c7382c
         aria_##mode##_cipher,                      \
5c7382c
-        NULL,                                      \
5c7382c
+        aria_##mode##_cleanup,                     \
5c7382c
         sizeof(EVP_ARIA_##MODE##_CTX),             \
5c7382c
         NULL,NULL,aria_##mode##_ctrl,NULL };       \
5c7382c
 const EVP_CIPHER *EVP_aria_##keylen##_##mode(void) \
5c7382c
diff -up openssl-1.1.1b/crypto/evp/e_chacha20_poly1305.c.sync openssl-1.1.1b/crypto/evp/e_chacha20_poly1305.c
5c7382c
--- openssl-1.1.1b/crypto/evp/e_chacha20_poly1305.c.sync	2019-05-03 08:55:45.216515434 +0200
5c7382c
+++ openssl-1.1.1b/crypto/evp/e_chacha20_poly1305.c	2019-05-03 08:55:51.551406676 +0200
5c7382c
@@ -30,6 +30,8 @@ typedef struct {
5c7382c
 
5c7382c
 #define data(ctx)   ((EVP_CHACHA_KEY *)(ctx)->cipher_data)
5c7382c
 
5c7382c
+#define CHACHA20_POLY1305_MAX_IVLEN     12
5c7382c
+
5c7382c
 static int chacha_init_key(EVP_CIPHER_CTX *ctx,
5c7382c
                            const unsigned char user_key[CHACHA_KEY_SIZE],
5c7382c
                            const unsigned char iv[CHACHA_CTR_SIZE], int enc)
5c7382c
@@ -533,7 +535,7 @@ static int chacha20_poly1305_ctrl(EVP_CI
5c7382c
         return 1;
5c7382c
 
5c7382c
     case EVP_CTRL_AEAD_SET_IVLEN:
5c7382c
-        if (arg <= 0 || arg > CHACHA_CTR_SIZE)
5c7382c
+        if (arg <= 0 || arg > CHACHA20_POLY1305_MAX_IVLEN)
5c7382c
             return 0;
5c7382c
         actx->nonce_len = arg;
5c7382c
         return 1;
5c7382c
diff -up openssl-1.1.1b/crypto/evp/evp_enc.c.sync openssl-1.1.1b/crypto/evp/evp_enc.c
5c7382c
--- openssl-1.1.1b/crypto/evp/evp_enc.c.sync	2019-05-03 08:55:45.174516155 +0200
5c7382c
+++ openssl-1.1.1b/crypto/evp/evp_enc.c	2019-05-03 08:55:51.544406797 +0200
5c7382c
@@ -338,6 +338,11 @@ static int evp_EncryptDecryptUpdate(EVP_
5c7382c
 
5c7382c
     bl = ctx->cipher->block_size;
5c7382c
 
5c7382c
+    if (inl <= 0) {
5c7382c
+        *outl = 0;
5c7382c
+        return inl == 0;
5c7382c
+    }
5c7382c
+
5c7382c
     if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
5c7382c
         /* If block size > 1 then the cipher will have to do this check */
5c7382c
         if (bl == 1 && is_partially_overlapping(out, in, cmpl)) {
5c7382c
@@ -353,10 +358,6 @@ static int evp_EncryptDecryptUpdate(EVP_
5c7382c
         return 1;
5c7382c
     }
5c7382c
 
5c7382c
-    if (inl <= 0) {
5c7382c
-        *outl = 0;
5c7382c
-        return inl == 0;
5c7382c
-    }
5c7382c
     if (is_partially_overlapping(out + ctx->buf_len, in, cmpl)) {
5c7382c
         EVPerr(EVP_F_EVP_ENCRYPTDECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
5c7382c
         return 0;
5c7382c
@@ -490,6 +491,11 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ct
5c7382c
     if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
5c7382c
         cmpl = (cmpl + 7) / 8;
5c7382c
 
5c7382c
+    if (inl <= 0) {
5c7382c
+        *outl = 0;
5c7382c
+        return inl == 0;
5c7382c
+    }
5c7382c
+
5c7382c
     if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
5c7382c
         if (b == 1 && is_partially_overlapping(out, in, cmpl)) {
5c7382c
             EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
5c7382c
@@ -505,11 +511,6 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ct
5c7382c
         return 1;
5c7382c
     }
5c7382c
 
5c7382c
-    if (inl <= 0) {
5c7382c
-        *outl = 0;
5c7382c
-        return inl == 0;
5c7382c
-    }
5c7382c
-
5c7382c
     if (ctx->flags & EVP_CIPH_NO_PADDING)
5c7382c
         return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/crypto/hmac/hmac.c.sync openssl-1.1.1b/crypto/hmac/hmac.c
5c7382c
--- openssl-1.1.1b/crypto/hmac/hmac.c.sync	2019-05-03 08:55:45.189515898 +0200
5c7382c
+++ openssl-1.1.1b/crypto/hmac/hmac.c	2019-05-03 08:55:51.538406900 +0200
5c7382c
@@ -35,6 +35,13 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const vo
5c7382c
         return 0;
5c7382c
     }
5c7382c
 
5c7382c
+    /*
5c7382c
+     * The HMAC construction is not allowed  to be used with the
5c7382c
+     * extendable-output functions (XOF) shake128 and shake256.
5c7382c
+     */
5c7382c
+    if ((EVP_MD_meth_get_flags(md) & EVP_MD_FLAG_XOF) != 0)
5c7382c
+        return 0;
5c7382c
+
5c7382c
     if (key != NULL) {
5c7382c
 #ifdef OPENSSL_FIPS
5c7382c
         if (FIPS_mode() && !(EVP_MD_flags(md) & EVP_MD_FLAG_FIPS)
5c7382c
diff -up openssl-1.1.1b/crypto/init.c.sync openssl-1.1.1b/crypto/init.c
5c7382c
--- openssl-1.1.1b/crypto/init.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/init.c	2019-05-03 08:55:51.550406694 +0200
5c7382c
@@ -702,7 +702,7 @@ int OPENSSL_init_crypto(uint64_t opts, c
5c7382c
         ret = RUN_ONCE(&config, ossl_init_config);
5c7382c
         conf_settings = NULL;
5c7382c
         CRYPTO_THREAD_unlock(init_lock);
5c7382c
-        if (!ret)
5c7382c
+        if (ret <= 0)
5c7382c
             return 0;
5c7382c
     }
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/crypto/modes/asm/ghash-x86_64.pl.sync openssl-1.1.1b/crypto/modes/asm/ghash-x86_64.pl
5c7382c
--- openssl-1.1.1b/crypto/modes/asm/ghash-x86_64.pl.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/modes/asm/ghash-x86_64.pl	2019-05-03 08:55:51.534406969 +0200
5c7382c
@@ -1155,6 +1155,7 @@ ___
5c7382c
 } else {
5c7382c
 $code.=<<___;
5c7382c
 	jmp	.L_init_clmul
5c7382c
+.cfi_endproc
5c7382c
 .size	gcm_init_avx,.-gcm_init_avx
5c7382c
 ___
5c7382c
 }
5c7382c
@@ -1594,6 +1595,7 @@ ___
5c7382c
 } else {
5c7382c
 $code.=<<___;
5c7382c
 	jmp	.L_ghash_clmul
5c7382c
+.cfi_endproc
5c7382c
 .size	gcm_ghash_avx,.-gcm_ghash_avx
5c7382c
 ___
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/modes/ccm128.c.sync openssl-1.1.1b/crypto/modes/ccm128.c
5c7382c
--- openssl-1.1.1b/crypto/modes/ccm128.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/modes/ccm128.c	2019-05-03 08:55:51.543406814 +0200
5c7382c
@@ -425,7 +425,7 @@ size_t CRYPTO_ccm128_tag(CCM128_CONTEXT
5c7382c
 
5c7382c
     M *= 2;
5c7382c
     M += 2;
5c7382c
-    if (len < M)
5c7382c
+    if (len != M)
5c7382c
         return 0;
5c7382c
     memcpy(tag, ctx->cmac.c, M);
5c7382c
     return M;
5c7382c
diff -up openssl-1.1.1b/crypto/o_str.c.sync openssl-1.1.1b/crypto/o_str.c
5c7382c
--- openssl-1.1.1b/crypto/o_str.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/o_str.c	2019-05-03 08:55:51.550406694 +0200
5c7382c
@@ -223,7 +223,26 @@ int openssl_strerror_r(int errnum, char
5c7382c
 #if defined(_MSC_VER) && _MSC_VER>=1400
5c7382c
     return !strerror_s(buf, buflen, errnum);
5c7382c
 #elif defined(_GNU_SOURCE)
5c7382c
-    return strerror_r(errnum, buf, buflen) != NULL;
5c7382c
+    char *err;
5c7382c
+
5c7382c
+    /*
5c7382c
+     * GNU strerror_r may not actually set buf.
5c7382c
+     * It can return a pointer to some (immutable) static string in which case
5c7382c
+     * buf is left unused.
5c7382c
+     */
5c7382c
+    err = strerror_r(errnum, buf, buflen);
5c7382c
+    if (err == NULL)
5c7382c
+        return 0;
5c7382c
+    /*
5c7382c
+     * If err is statically allocated, err != buf and we need to copy the data.
5c7382c
+     * If err points somewhere inside buf, OPENSSL_strlcpy can handle this,
5c7382c
+     * since src and dest are not annotated with __restrict and the function
5c7382c
+     * reads src byte for byte and writes to dest.
5c7382c
+     * If err == buf we do not have to copy anything.
5c7382c
+     */
5c7382c
+    if (err != buf)
5c7382c
+        OPENSSL_strlcpy(buf, err, buflen);
5c7382c
+    return 1;
5c7382c
 #elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
5c7382c
       (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
5c7382c
     /*
5c7382c
@@ -234,6 +253,7 @@ int openssl_strerror_r(int errnum, char
5c7382c
     return !strerror_r(errnum, buf, buflen);
5c7382c
 #else
5c7382c
     char *err;
5c7382c
+
5c7382c
     /* Fall back to non-thread safe strerror()...its all we can do */
5c7382c
     if (buflen < 2)
5c7382c
         return 0;
5c7382c
@@ -241,8 +261,7 @@ int openssl_strerror_r(int errnum, char
5c7382c
     /* Can this ever happen? */
5c7382c
     if (err == NULL)
5c7382c
         return 0;
5c7382c
-    strncpy(buf, err, buflen - 1);
5c7382c
-    buf[buflen - 1] = '\0';
5c7382c
+    OPENSSL_strlcpy(buf, err, buflen);
5c7382c
     return 1;
5c7382c
 #endif
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/poly1305/build.info.sync openssl-1.1.1b/crypto/poly1305/build.info
5c7382c
--- openssl-1.1.1b/crypto/poly1305/build.info.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/poly1305/build.info	2019-05-03 08:55:51.538406900 +0200
5c7382c
@@ -17,6 +17,7 @@ GENERATE[poly1305-armv8.S]=asm/poly1305-
5c7382c
 INCLUDE[poly1305-armv8.o]=..
5c7382c
 GENERATE[poly1305-mips.S]=asm/poly1305-mips.pl $(PERLASM_SCHEME)
5c7382c
 INCLUDE[poly1305-mips.o]=..
5c7382c
+GENERATE[poly1305-s390x.S]=asm/poly1305-s390x.pl $(PERLASM_SCHEME)
5c7382c
 
5c7382c
 BEGINRAW[Makefile(unix)]
5c7382c
 {- $builddir -}/poly1305-%.S:	{- $sourcedir -}/asm/poly1305-%.pl
5c7382c
diff -up openssl-1.1.1b/crypto/rc4/build.info.sync openssl-1.1.1b/crypto/rc4/build.info
5c7382c
--- openssl-1.1.1b/crypto/rc4/build.info.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/rc4/build.info	2019-05-03 08:55:51.538406900 +0200
5c7382c
@@ -11,6 +11,8 @@ GENERATE[rc4-md5-x86_64.s]=asm/rc4-md5-x
5c7382c
 
5c7382c
 GENERATE[rc4-parisc.s]=asm/rc4-parisc.pl $(PERLASM_SCHEME)
5c7382c
 
5c7382c
+GENERATE[rc4-s390x.s]=asm/rc4-s390x.pl $(PERLASM_SCHEME)
5c7382c
+
5c7382c
 BEGINRAW[Makefile]
5c7382c
 # GNU make "catch all"
5c7382c
 {- $builddir -}/rc4-%.s:	{- $sourcedir -}/asm/rc4-%.pl
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_ameth.c.sync openssl-1.1.1b/crypto/rsa/rsa_ameth.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_ameth.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_ameth.c	2019-05-03 08:55:51.533406986 +0200
5c7382c
@@ -583,10 +583,12 @@ static RSA_PSS_PARAMS *rsa_ctx_to_pss(EV
5c7382c
         return NULL;
5c7382c
     if (saltlen == -1) {
5c7382c
         saltlen = EVP_MD_size(sigmd);
5c7382c
-    } else if (saltlen == -2) {
5c7382c
+    } else if (saltlen == -2 || saltlen == -3) {
5c7382c
         saltlen = EVP_PKEY_size(pk) - EVP_MD_size(sigmd) - 2;
5c7382c
         if ((EVP_PKEY_bits(pk) & 0x7) == 1)
5c7382c
             saltlen--;
5c7382c
+        if (saltlen < 0)
5c7382c
+            return NULL;
5c7382c
     }
5c7382c
 
5c7382c
     return rsa_pss_params_create(sigmd, mgf1md, saltlen);
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_gen.c.sync openssl-1.1.1b/crypto/rsa/rsa_gen.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_gen.c.sync	2019-05-03 08:55:45.191515864 +0200
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_gen.c	2019-05-03 08:55:51.528407071 +0200
5c7382c
@@ -746,8 +746,7 @@ static int rsa_builtin_keygen(RSA *rsa,
5c7382c
         RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);
5c7382c
         ok = 0;
5c7382c
     }
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     return ok;
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_oaep.c.sync openssl-1.1.1b/crypto/rsa/rsa_oaep.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_oaep.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_oaep.c	2019-05-03 08:55:51.549406711 +0200
5c7382c
@@ -1,5 +1,5 @@
5c7382c
 /*
5c7382c
- * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
+ * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
  *
5c7382c
  * Licensed under the OpenSSL license (the "License").  You may not use
5c7382c
  * this file except in compliance with the License.  You can obtain a copy
5c7382c
@@ -143,7 +143,7 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(un
5c7382c
      * |num| is the length of the modulus; |flen| is the length of the
5c7382c
      * encoded message. Therefore, for any |from| that was obtained by
5c7382c
      * decrypting a ciphertext, we must have |flen| <= |num|. Similarly,
5c7382c
-     * num < 2 * mdlen + 2 must hold for the modulus irrespective of
5c7382c
+     * |num| >= 2 * |mdlen| + 2 must hold for the modulus irrespective of
5c7382c
      * the ciphertext, see PKCS #1 v2.2, section 7.1.2.
5c7382c
      * This does not leak any side-channel information.
5c7382c
      */
5c7382c
@@ -179,17 +179,16 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(un
5c7382c
         from -= 1 & mask;
5c7382c
         *--em = *from & mask;
5c7382c
     }
5c7382c
-    from = em;
5c7382c
 
5c7382c
     /*
5c7382c
      * The first byte must be zero, however we must not leak if this is
5c7382c
      * true. See James H. Manger, "A Chosen Ciphertext  Attack on RSA
5c7382c
      * Optimal Asymmetric Encryption Padding (OAEP) [...]", CRYPTO 2001).
5c7382c
      */
5c7382c
-    good = constant_time_is_zero(from[0]);
5c7382c
+    good = constant_time_is_zero(em[0]);
5c7382c
 
5c7382c
-    maskedseed = from + 1;
5c7382c
-    maskeddb = from + 1 + mdlen;
5c7382c
+    maskedseed = em + 1;
5c7382c
+    maskeddb = em + 1 + mdlen;
5c7382c
 
5c7382c
     if (PKCS1_MGF1(seed, mdlen, maskeddb, dblen, mgf1md))
5c7382c
         goto cleanup;
5c7382c
@@ -230,29 +229,30 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(un
5c7382c
     mlen = dblen - msg_index;
5c7382c
 
5c7382c
     /*
5c7382c
-     * For good measure, do this check in constant tine as well.
5c7382c
+     * For good measure, do this check in constant time as well.
5c7382c
      */
5c7382c
     good &= constant_time_ge(tlen, mlen);
5c7382c
 
5c7382c
     /*
5c7382c
-     * Even though we can't fake result's length, we can pretend copying
5c7382c
-     * |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |dblen|
5c7382c
-     * bytes are viewed as circular buffer with start at |tlen|-|mlen'|,
5c7382c
-     * where |mlen'| is "saturated" |mlen| value. Deducing information
5c7382c
-     * about failure or |mlen| would take attacker's ability to observe
5c7382c
-     * memory access pattern with byte granularity *as it occurs*. It
5c7382c
-     * should be noted that failure is indistinguishable from normal
5c7382c
-     * operation if |tlen| is fixed by protocol.
5c7382c
+     * Move the result in-place by |dblen|-|mdlen|-1-|mlen| bytes to the left.
5c7382c
+     * Then if |good| move |mlen| bytes from |db|+|mdlen|+1 to |to|.
5c7382c
+     * Otherwise leave |to| unchanged.
5c7382c
+     * Copy the memory back in a way that does not reveal the size of
5c7382c
+     * the data being copied via a timing side channel. This requires copying
5c7382c
+     * parts of the buffer multiple times based on the bits set in the real
5c7382c
+     * length. Clear bits do a non-copy with identical access pattern.
5c7382c
+     * The loop below has overall complexity of O(N*log(N)).
5c7382c
      */
5c7382c
-    tlen = constant_time_select_int(constant_time_lt(dblen, tlen), dblen, tlen);
5c7382c
-    msg_index = constant_time_select_int(good, msg_index, dblen - tlen);
5c7382c
-    mlen = dblen - msg_index;
5c7382c
-    for (from = db + msg_index, mask = good, i = 0; i < tlen; i++) {
5c7382c
-        unsigned int equals = constant_time_eq(i, mlen);
5c7382c
-
5c7382c
-        from -= dblen & equals; /* if (i == dblen) rewind   */
5c7382c
-        mask &= mask ^ equals;  /* if (i == dblen) mask = 0 */
5c7382c
-        to[i] = constant_time_select_8(mask, from[i], to[i]);
5c7382c
+    tlen = constant_time_select_int(constant_time_lt(dblen - mdlen - 1, tlen),
5c7382c
+                                    dblen - mdlen - 1, tlen);
5c7382c
+    for (msg_index = 1; msg_index < dblen - mdlen - 1; msg_index <<= 1) {
5c7382c
+        mask = ~constant_time_eq(msg_index & (dblen - mdlen - 1 - mlen), 0);
5c7382c
+        for (i = mdlen + 1; i < dblen - msg_index; i++)
5c7382c
+            db[i] = constant_time_select_8(mask, db[i + msg_index], db[i]);
5c7382c
+    }
5c7382c
+    for (i = 0; i < tlen; i++) {
5c7382c
+        mask = good & constant_time_lt(i, mlen);
5c7382c
+        to[i] = constant_time_select_8(mask, db[i + mdlen + 1], to[i]);
5c7382c
     }
5c7382c
 
5c7382c
     /*
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_ossl.c.sync openssl-1.1.1b/crypto/rsa/rsa_ossl.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_ossl.c.sync	2019-05-03 08:55:45.191515864 +0200
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_ossl.c	2019-05-03 08:55:51.548406728 +0200
5c7382c
@@ -174,8 +174,7 @@ static int rsa_ossl_public_encrypt(int f
5c7382c
      */
5c7382c
     r = BN_bn2binpad(ret, to, num);
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     OPENSSL_clear_free(buf, num);
5c7382c
     return r;
5c7382c
@@ -396,8 +395,7 @@ static int rsa_ossl_private_encrypt(int
5c7382c
      */
5c7382c
     r = BN_bn2binpad(res, to, num);
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     OPENSSL_clear_free(buf, num);
5c7382c
     return r;
5c7382c
@@ -539,11 +537,10 @@ static int rsa_ossl_private_decrypt(int
5c7382c
         goto err;
5c7382c
     }
5c7382c
     RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
5c7382c
-    err_clear_last_constant_time(r >= 0);
5c7382c
+    err_clear_last_constant_time(1 & ~constant_time_msb(r));
5c7382c
 
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     OPENSSL_clear_free(buf, num);
5c7382c
     return r;
5c7382c
@@ -655,8 +652,7 @@ static int rsa_ossl_public_decrypt(int f
5c7382c
         RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
5c7382c
 
5c7382c
  err:
5c7382c
-    if (ctx != NULL)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     OPENSSL_clear_free(buf, num);
5c7382c
     return r;
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_pk1.c.sync openssl-1.1.1b/crypto/rsa/rsa_pk1.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_pk1.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_pk1.c	2019-05-03 08:55:51.549406711 +0200
5c7382c
@@ -1,5 +1,5 @@
5c7382c
 /*
5c7382c
- * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
+ * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
  *
5c7382c
  * Licensed under the OpenSSL license (the "License").  You may not use
5c7382c
  * this file except in compliance with the License.  You can obtain a copy
5c7382c
@@ -192,15 +192,14 @@ int RSA_padding_check_PKCS1_type_2(unsig
5c7382c
         from -= 1 & mask;
5c7382c
         *--em = *from & mask;
5c7382c
     }
5c7382c
-    from = em;
5c7382c
 
5c7382c
-    good = constant_time_is_zero(from[0]);
5c7382c
-    good &= constant_time_eq(from[1], 2);
5c7382c
+    good = constant_time_is_zero(em[0]);
5c7382c
+    good &= constant_time_eq(em[1], 2);
5c7382c
 
5c7382c
     /* scan over padding data */
5c7382c
     found_zero_byte = 0;
5c7382c
     for (i = 2; i < num; i++) {
5c7382c
-        unsigned int equals0 = constant_time_is_zero(from[i]);
5c7382c
+        unsigned int equals0 = constant_time_is_zero(em[i]);
5c7382c
 
5c7382c
         zero_index = constant_time_select_int(~found_zero_byte & equals0,
5c7382c
                                               i, zero_index);
5c7382c
@@ -208,7 +207,7 @@ int RSA_padding_check_PKCS1_type_2(unsig
5c7382c
     }
5c7382c
 
5c7382c
     /*
5c7382c
-     * PS must be at least 8 bytes long, and it starts two bytes into |from|.
5c7382c
+     * PS must be at least 8 bytes long, and it starts two bytes into |em|.
5c7382c
      * If we never found a 0-byte, then |zero_index| is 0 and the check
5c7382c
      * also fails.
5c7382c
      */
5c7382c
@@ -227,24 +226,25 @@ int RSA_padding_check_PKCS1_type_2(unsig
5c7382c
     good &= constant_time_ge(tlen, mlen);
5c7382c
 
5c7382c
     /*
5c7382c
-     * Even though we can't fake result's length, we can pretend copying
5c7382c
-     * |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |num|
5c7382c
-     * bytes are viewed as circular buffer with start at |tlen|-|mlen'|,
5c7382c
-     * where |mlen'| is "saturated" |mlen| value. Deducing information
5c7382c
-     * about failure or |mlen| would take attacker's ability to observe
5c7382c
-     * memory access pattern with byte granularity *as it occurs*. It
5c7382c
-     * should be noted that failure is indistinguishable from normal
5c7382c
-     * operation if |tlen| is fixed by protocol.
5c7382c
-     */
5c7382c
-    tlen = constant_time_select_int(constant_time_lt(num, tlen), num, tlen);
5c7382c
-    msg_index = constant_time_select_int(good, msg_index, num - tlen);
5c7382c
-    mlen = num - msg_index;
5c7382c
-    for (from += msg_index, mask = good, i = 0; i < tlen; i++) {
5c7382c
-        unsigned int equals = constant_time_eq(i, mlen);
5c7382c
-
5c7382c
-        from -= tlen & equals;  /* if (i == mlen) rewind   */
5c7382c
-        mask &= mask ^ equals;  /* if (i == mlen) mask = 0 */
5c7382c
-        to[i] = constant_time_select_8(mask, from[i], to[i]);
5c7382c
+     * Move the result in-place by |num|-11-|mlen| bytes to the left.
5c7382c
+     * Then if |good| move |mlen| bytes from |em|+11 to |to|.
5c7382c
+     * Otherwise leave |to| unchanged.
5c7382c
+     * Copy the memory back in a way that does not reveal the size of
5c7382c
+     * the data being copied via a timing side channel. This requires copying
5c7382c
+     * parts of the buffer multiple times based on the bits set in the real
5c7382c
+     * length. Clear bits do a non-copy with identical access pattern.
5c7382c
+     * The loop below has overall complexity of O(N*log(N)).
5c7382c
+     */
5c7382c
+    tlen = constant_time_select_int(constant_time_lt(num - 11, tlen),
5c7382c
+                                    num - 11, tlen);
5c7382c
+    for (msg_index = 1; msg_index < num - 11; msg_index <<= 1) {
5c7382c
+        mask = ~constant_time_eq(msg_index & (num - 11 - mlen), 0);
5c7382c
+        for (i = 11; i < num - msg_index; i++)
5c7382c
+            em[i] = constant_time_select_8(mask, em[i + msg_index], em[i]);
5c7382c
+    }
5c7382c
+    for (i = 0; i < tlen; i++) {
5c7382c
+        mask = good & constant_time_lt(i, mlen);
5c7382c
+        to[i] = constant_time_select_8(mask, em[i + 11], to[i]);
5c7382c
     }
5c7382c
 
5c7382c
     OPENSSL_clear_free(em, num);
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_pmeth.c.sync openssl-1.1.1b/crypto/rsa/rsa_pmeth.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_pmeth.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_pmeth.c	2019-05-03 08:55:51.543406814 +0200
5c7382c
@@ -1,5 +1,5 @@
5c7382c
 /*
5c7382c
- * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
+ * Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
  *
5c7382c
  * Licensed under the OpenSSL license (the "License").  You may not use
5c7382c
  * this file except in compliance with the License.  You can obtain a copy
5c7382c
@@ -7,6 +7,8 @@
5c7382c
  * https://www.openssl.org/source/license.html
5c7382c
  */
5c7382c
 
5c7382c
+#include "internal/constant_time_locl.h"
5c7382c
+
5c7382c
 #include <stdio.h>
5c7382c
 #include "internal/cryptlib.h"
5c7382c
 #include <openssl/asn1t.h>
5c7382c
@@ -340,10 +342,9 @@ static int pkey_rsa_decrypt(EVP_PKEY_CTX
5c7382c
         ret = RSA_private_decrypt(inlen, in, out, ctx->pkey->pkey.rsa,
5c7382c
                                   rctx->pad_mode);
5c7382c
     }
5c7382c
-    if (ret < 0)
5c7382c
-        return ret;
5c7382c
-    *outlen = ret;
5c7382c
-    return 1;
5c7382c
+    *outlen = constant_time_select_s(constant_time_msb_s(ret), *outlen, ret);
5c7382c
+    ret = constant_time_select_int(constant_time_msb(ret), ret, 1);
5c7382c
+    return ret;
5c7382c
 }
5c7382c
 
5c7382c
 static int check_padding_md(const EVP_MD *md, int padding)
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_ssl.c.sync openssl-1.1.1b/crypto/rsa/rsa_ssl.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_ssl.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_ssl.c	2019-05-03 08:55:51.550406694 +0200
5c7382c
@@ -1,5 +1,5 @@
5c7382c
 /*
5c7382c
- * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
+ * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
  *
5c7382c
  * Licensed under the OpenSSL license (the "License").  You may not use
5c7382c
  * this file except in compliance with the License.  You can obtain a copy
5c7382c
@@ -55,7 +55,7 @@ int RSA_padding_add_SSLv23(unsigned char
5c7382c
 
5c7382c
 /*
5c7382c
  * Copy of RSA_padding_check_PKCS1_type_2 with a twist that rejects padding
5c7382c
- * if nul delimiter is preceded by 8 consecutive 0x03 bytes. It also
5c7382c
+ * if nul delimiter is not preceded by 8 consecutive 0x03 bytes. It also
5c7382c
  * preserves error code reporting for backward compatibility.
5c7382c
  */
5c7382c
 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
5c7382c
@@ -67,7 +67,10 @@ int RSA_padding_check_SSLv23(unsigned ch
5c7382c
     unsigned int good, found_zero_byte, mask, threes_in_row;
5c7382c
     int zero_index = 0, msg_index, mlen = -1, err;
5c7382c
 
5c7382c
-    if (flen < 10) {
5c7382c
+    if (tlen <= 0 || flen <= 0)
5c7382c
+        return -1;
5c7382c
+
5c7382c
+    if (flen > num || num < 11) {
5c7382c
         RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_SMALL);
5c7382c
         return -1;
5c7382c
     }
5c7382c
@@ -89,10 +92,9 @@ int RSA_padding_check_SSLv23(unsigned ch
5c7382c
         from -= 1 & mask;
5c7382c
         *--em = *from & mask;
5c7382c
     }
5c7382c
-    from = em;
5c7382c
 
5c7382c
-    good = constant_time_is_zero(from[0]);
5c7382c
-    good &= constant_time_eq(from[1], 2);
5c7382c
+    good = constant_time_is_zero(em[0]);
5c7382c
+    good &= constant_time_eq(em[1], 2);
5c7382c
     err = constant_time_select_int(good, 0, RSA_R_BLOCK_TYPE_IS_NOT_02);
5c7382c
     mask = ~good;
5c7382c
 
5c7382c
@@ -100,18 +102,18 @@ int RSA_padding_check_SSLv23(unsigned ch
5c7382c
     found_zero_byte = 0;
5c7382c
     threes_in_row = 0;
5c7382c
     for (i = 2; i < num; i++) {
5c7382c
-        unsigned int equals0 = constant_time_is_zero(from[i]);
5c7382c
+        unsigned int equals0 = constant_time_is_zero(em[i]);
5c7382c
 
5c7382c
         zero_index = constant_time_select_int(~found_zero_byte & equals0,
5c7382c
                                               i, zero_index);
5c7382c
         found_zero_byte |= equals0;
5c7382c
 
5c7382c
         threes_in_row += 1 & ~found_zero_byte;
5c7382c
-        threes_in_row &= found_zero_byte | constant_time_eq(from[i], 3);
5c7382c
+        threes_in_row &= found_zero_byte | constant_time_eq(em[i], 3);
5c7382c
     }
5c7382c
 
5c7382c
     /*
5c7382c
-     * PS must be at least 8 bytes long, and it starts two bytes into |from|.
5c7382c
+     * PS must be at least 8 bytes long, and it starts two bytes into |em|.
5c7382c
      * If we never found a 0-byte, then |zero_index| is 0 and the check
5c7382c
      * also fails.
5c7382c
      */
5c7382c
@@ -120,7 +122,7 @@ int RSA_padding_check_SSLv23(unsigned ch
5c7382c
                                    RSA_R_NULL_BEFORE_BLOCK_MISSING);
5c7382c
     mask = ~good;
5c7382c
 
5c7382c
-    good &= constant_time_lt(threes_in_row, 8);
5c7382c
+    good &= constant_time_ge(threes_in_row, 8);
5c7382c
     err = constant_time_select_int(mask | good, err,
5c7382c
                                    RSA_R_SSLV3_ROLLBACK_ATTACK);
5c7382c
     mask = ~good;
5c7382c
@@ -139,24 +141,25 @@ int RSA_padding_check_SSLv23(unsigned ch
5c7382c
     err = constant_time_select_int(mask | good, err, RSA_R_DATA_TOO_LARGE);
5c7382c
 
5c7382c
     /*
5c7382c
-     * Even though we can't fake result's length, we can pretend copying
5c7382c
-     * |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |num|
5c7382c
-     * bytes are viewed as circular buffer with start at |tlen|-|mlen'|,
5c7382c
-     * where |mlen'| is "saturated" |mlen| value. Deducing information
5c7382c
-     * about failure or |mlen| would take attacker's ability to observe
5c7382c
-     * memory access pattern with byte granularity *as it occurs*. It
5c7382c
-     * should be noted that failure is indistinguishable from normal
5c7382c
-     * operation if |tlen| is fixed by protocol.
5c7382c
+     * Move the result in-place by |num|-11-|mlen| bytes to the left.
5c7382c
+     * Then if |good| move |mlen| bytes from |em|+11 to |to|.
5c7382c
+     * Otherwise leave |to| unchanged.
5c7382c
+     * Copy the memory back in a way that does not reveal the size of
5c7382c
+     * the data being copied via a timing side channel. This requires copying
5c7382c
+     * parts of the buffer multiple times based on the bits set in the real
5c7382c
+     * length. Clear bits do a non-copy with identical access pattern.
5c7382c
+     * The loop below has overall complexity of O(N*log(N)).
5c7382c
      */
5c7382c
-    tlen = constant_time_select_int(constant_time_lt(num, tlen), num, tlen);
5c7382c
-    msg_index = constant_time_select_int(good, msg_index, num - tlen);
5c7382c
-    mlen = num - msg_index;
5c7382c
-    for (from += msg_index, mask = good, i = 0; i < tlen; i++) {
5c7382c
-        unsigned int equals = constant_time_eq(i, mlen);
5c7382c
-
5c7382c
-        from -= tlen & equals;  /* if (i == mlen) rewind   */
5c7382c
-        mask &= mask ^ equals;  /* if (i == mlen) mask = 0 */
5c7382c
-        to[i] = constant_time_select_8(mask, from[i], to[i]);
5c7382c
+    tlen = constant_time_select_int(constant_time_lt(num - 11, tlen),
5c7382c
+                                    num - 11, tlen);
5c7382c
+    for (msg_index = 1; msg_index < num - 11; msg_index <<= 1) {
5c7382c
+        mask = ~constant_time_eq(msg_index & (num - 11 - mlen), 0);
5c7382c
+        for (i = 11; i < num - msg_index; i++)
5c7382c
+            em[i] = constant_time_select_8(mask, em[i + msg_index], em[i]);
5c7382c
+    }
5c7382c
+    for (i = 0; i < tlen; i++) {
5c7382c
+        mask = good & constant_time_lt(i, mlen);
5c7382c
+        to[i] = constant_time_select_8(mask, em[i + 11], to[i]);
5c7382c
     }
5c7382c
 
5c7382c
     OPENSSL_clear_free(em, num);
5c7382c
diff -up openssl-1.1.1b/crypto/rsa/rsa_x931g.c.sync openssl-1.1.1b/crypto/rsa/rsa_x931g.c
5c7382c
--- openssl-1.1.1b/crypto/rsa/rsa_x931g.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/rsa/rsa_x931g.c	2019-05-03 08:55:51.530407037 +0200
5c7382c
@@ -133,8 +133,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM
5c7382c
 
5c7382c
     ret = 1;
5c7382c
  err:
5c7382c
-    if (ctx)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
     BN_CTX_free(ctx2);
5c7382c
 
5c7382c
@@ -188,8 +187,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, i
5c7382c
     ok = 1;
5c7382c
 
5c7382c
  error:
5c7382c
-    if (ctx)
5c7382c
-        BN_CTX_end(ctx);
5c7382c
+    BN_CTX_end(ctx);
5c7382c
     BN_CTX_free(ctx);
5c7382c
 
5c7382c
     if (ok)
5c7382c
diff -up openssl-1.1.1b/crypto/x509/x509_lu.c.sync openssl-1.1.1b/crypto/x509/x509_lu.c
5c7382c
--- openssl-1.1.1b/crypto/x509/x509_lu.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/crypto/x509/x509_lu.c	2019-05-03 08:55:51.546406762 +0200
5c7382c
@@ -297,6 +297,9 @@ int X509_STORE_CTX_get_by_subject(X509_S
5c7382c
     if (ctx == NULL)
5c7382c
         return 0;
5c7382c
 
5c7382c
+    stmp.type = X509_LU_NONE;
5c7382c
+    stmp.data.ptr = NULL;
5c7382c
+
5c7382c
     CRYPTO_THREAD_write_lock(ctx->lock);
5c7382c
     tmp = X509_OBJECT_retrieve_by_subject(ctx->objs, type, name);
5c7382c
     CRYPTO_THREAD_unlock(ctx->lock);
5c7382c
diff -up openssl-1.1.1b/doc/man1/pkeyutl.pod.sync openssl-1.1.1b/doc/man1/pkeyutl.pod
5c7382c
--- openssl-1.1.1b/doc/man1/pkeyutl.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man1/pkeyutl.pod	2019-05-03 08:55:51.555406608 +0200
5c7382c
@@ -272,20 +272,19 @@ value less than the minimum restriction.
5c7382c
 =head1 DSA ALGORITHM
5c7382c
 
5c7382c
 The DSA algorithm supports signing and verification operations only. Currently
5c7382c
-there are no additional options other than B<digest>. Only the SHA1
5c7382c
-digest can be used and this digest is assumed by default.
5c7382c
+there are no additional B<-pkeyopt> options other than B<digest>. The SHA1
5c7382c
+digest is assumed by default.
5c7382c
 
5c7382c
 =head1 DH ALGORITHM
5c7382c
 
5c7382c
 The DH algorithm only supports the derivation operation and no additional
5c7382c
-options.
5c7382c
+B<-pkeyopt> options.
5c7382c
 
5c7382c
 =head1 EC ALGORITHM
5c7382c
 
5c7382c
 The EC algorithm supports sign, verify and derive operations. The sign and
5c7382c
-verify operations use ECDSA and derive uses ECDH. Currently there are no
5c7382c
-additional options other than B<digest>. Only the SHA1 digest can be used and
5c7382c
-this digest is assumed by default.
5c7382c
+verify operations use ECDSA and derive uses ECDH. SHA1 is assumed by default for
5c7382c
+the B<-pkeyopt> B<digest> option.
5c7382c
 
5c7382c
 =head1 X25519 and X448 ALGORITHMS
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/doc/man1/ts.pod.sync openssl-1.1.1b/doc/man1/ts.pod
5c7382c
--- openssl-1.1.1b/doc/man1/ts.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man1/ts.pod	2019-05-03 08:55:51.554406625 +0200
5c7382c
@@ -262,7 +262,7 @@ specified, the argument is given to the
5c7382c
 =item B<-I<digest>>
5c7382c
 
5c7382c
 Signing digest to use. Overrides the B<signer_digest> config file
5c7382c
-option. (Optional)
5c7382c
+option. (Mandatory unless specified in the config file)
5c7382c
 
5c7382c
 =item B<-chain> certs_file.pem
5c7382c
 
5c7382c
@@ -460,7 +460,8 @@ command line option. (Optional)
5c7382c
 =item B<signer_digest>
5c7382c
 
5c7382c
 Signing digest to use. The same as the
5c7382c
-B<-I<digest>> command line option. (Optional)
5c7382c
+B<-I<digest>> command line option. (Mandatory unless specified on the command
5c7382c
+line)
5c7382c
 
5c7382c
 =item B<default_policy>
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/doc/man3/BIO_s_mem.pod.sync openssl-1.1.1b/doc/man3/BIO_s_mem.pod
5c7382c
--- openssl-1.1.1b/doc/man3/BIO_s_mem.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/BIO_s_mem.pod	2019-05-03 08:55:51.556406591 +0200
5c7382c
@@ -88,6 +88,22 @@ a buffering BIO to the chain will speed
5c7382c
 Calling BIO_set_mem_buf() on a BIO created with BIO_new_secmem() will
5c7382c
 give undefined results, including perhaps a program crash.
5c7382c
 
5c7382c
+Switching the memory BIO from read write to read only is not supported and
5c7382c
+can give undefined results including a program crash. There are two notable
5c7382c
+exceptions to the rule. The first one is to assign a static memory buffer
5c7382c
+immediately after BIO creation and set the BIO as read only.
5c7382c
+
5c7382c
+The other supported sequence is to start with read write BIO then temporarily
5c7382c
+switch it to read only and call BIO_reset() on the read only BIO immediately
5c7382c
+before switching it back to read write. Before the BIO is freed it must be
5c7382c
+switched back to the read write mode.
5c7382c
+
5c7382c
+Calling BIO_get_mem_ptr() on read only BIO will return a BUF_MEM that
5c7382c
+contains only the remaining data to be read. If the close status of the
5c7382c
+BIO is set to BIO_NOCLOSE, before freeing the BUF_MEM the data pointer
5c7382c
+in it must be set to NULL as the data pointer does not point to an
5c7382c
+allocated memory.
5c7382c
+
5c7382c
 =head1 BUGS
5c7382c
 
5c7382c
 There should be an option to set the maximum size of a memory BIO.
5c7382c
diff -up openssl-1.1.1b/doc/man3/BN_CTX_start.pod.sync openssl-1.1.1b/doc/man3/BN_CTX_start.pod
5c7382c
--- openssl-1.1.1b/doc/man3/BN_CTX_start.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/BN_CTX_start.pod	2019-05-03 08:55:51.554406625 +0200
5c7382c
@@ -27,6 +27,7 @@ calls must be made before calling any ot
5c7382c
 B<ctx> as an argument.
5c7382c
 
5c7382c
 Finally, BN_CTX_end() must be called before returning from the function.
5c7382c
+If B<ctx> is NULL, nothing is done.
5c7382c
 When BN_CTX_end() is called, the B<BIGNUM> pointers obtained from
5c7382c
 BN_CTX_get() become invalid.
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/doc/man3/BN_new.pod.sync openssl-1.1.1b/doc/man3/BN_new.pod
5c7382c
--- openssl-1.1.1b/doc/man3/BN_new.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/BN_new.pod	2019-05-03 08:55:51.554406625 +0200
5c7382c
@@ -27,6 +27,7 @@ OPENSSL_secure_malloc(3) is used to stor
5c7382c
 BN_clear() is used to destroy sensitive data such as keys when they
5c7382c
 are no longer needed. It erases the memory used by B and sets it
5c7382c
 to the value 0.
5c7382c
+If B is NULL, nothing is done.
5c7382c
 
5c7382c
 BN_free() frees the components of the B<BIGNUM>, and if it was created
5c7382c
 by BN_new(), also the structure itself. BN_clear_free() additionally
5c7382c
diff -up openssl-1.1.1b/doc/man3/EVP_chacha20.pod.sync openssl-1.1.1b/doc/man3/EVP_chacha20.pod
5c7382c
--- openssl-1.1.1b/doc/man3/EVP_chacha20.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/EVP_chacha20.pod	2019-05-03 08:55:51.536406934 +0200
5c7382c
@@ -21,7 +21,15 @@ The ChaCha20 stream cipher for EVP.
5c7382c
 
5c7382c
 =item EVP_chacha20()
5c7382c
 
5c7382c
-The ChaCha20 stream cipher. The key length is 256 bits, the IV is 96 bits long.
5c7382c
+The ChaCha20 stream cipher. The key length is 256 bits, the IV is 128 bits long.
5c7382c
+The first 32 bits consists of a counter in little-endian order followed by a 96
5c7382c
+bit nonce. For example a nonce of:
5c7382c
+
5c7382c
+000000000000000000000002
5c7382c
+
5c7382c
+With an initial counter of 42 (2a in hex) would be expressed as:
5c7382c
+
5c7382c
+2a000000000000000000000000000002
5c7382c
 
5c7382c
 =item EVP_chacha20_poly1305()
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/doc/man3/EVP_EncryptInit.pod.sync openssl-1.1.1b/doc/man3/EVP_EncryptInit.pod
5c7382c
--- openssl-1.1.1b/doc/man3/EVP_EncryptInit.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/EVP_EncryptInit.pod	2019-05-03 08:55:51.554406625 +0200
5c7382c
@@ -436,7 +436,9 @@ The following I<ctrl>s are supported for
5c7382c
 
5c7382c
 Sets the nonce length. This call can only be made before specifying the nonce.
5c7382c
 If not called a default nonce length of 12 (i.e. 96 bits) is used. The maximum
5c7382c
-nonce length is 16 (B<CHACHA_CTR_SIZE>, i.e. 128-bits).
5c7382c
+nonce length is 12 bytes (i.e. 96-bits). If a nonce of less than 12 bytes is set
5c7382c
+then the nonce is automatically padded with leading 0 bytes to make it 12 bytes
5c7382c
+in length.
5c7382c
 
5c7382c
 =item EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag)
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/doc/man3/HMAC.pod.sync openssl-1.1.1b/doc/man3/HMAC.pod
5c7382c
--- openssl-1.1.1b/doc/man3/HMAC.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/HMAC.pod	2019-05-03 08:55:51.539406883 +0200
5c7382c
@@ -63,7 +63,9 @@ If B<md> is NULL, the digest is placed i
5c7382c
 the output is placed in B<md_len>, unless it is B<NULL>. Note: passing a NULL
5c7382c
 value for B<md>  to use the static array is not thread safe.
5c7382c
 
5c7382c
-B<evp_md> can be EVP_sha1(), EVP_ripemd160() etc.
5c7382c
+B<evp_md> is a message digest such as EVP_sha1(), EVP_ripemd160() etc. HMAC does
5c7382c
+not support variable output length digests such as EVP_shake128() and
5c7382c
+EVP_shake256().
5c7382c
 
5c7382c
 HMAC_CTX_new() creates a new HMAC_CTX in heap memory.
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/doc/man3/RSA_padding_add_PKCS1_type_1.pod.sync openssl-1.1.1b/doc/man3/RSA_padding_add_PKCS1_type_1.pod
5c7382c
--- openssl-1.1.1b/doc/man3/RSA_padding_add_PKCS1_type_1.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/RSA_padding_add_PKCS1_type_1.pod	2019-05-03 08:55:51.555406608 +0200
5c7382c
@@ -5,6 +5,7 @@
5c7382c
 RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1,
5c7382c
 RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2,
5c7382c
 RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP,
5c7382c
+RSA_padding_add_PKCS1_OAEP_mgf1, RSA_padding_check_PKCS1_OAEP_mgf1,
5c7382c
 RSA_padding_add_SSLv23, RSA_padding_check_SSLv23,
5c7382c
 RSA_padding_add_none, RSA_padding_check_none - asymmetric encryption
5c7382c
 padding
5c7382c
@@ -14,35 +15,46 @@ padding
5c7382c
  #include <openssl/rsa.h>
5c7382c
 
5c7382c
  int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
5c7382c
-                                  unsigned char *f, int fl);
5c7382c
+                                  const unsigned char *f, int fl);
5c7382c
 
5c7382c
  int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
5c7382c
-                                    unsigned char *f, int fl, int rsa_len);
5c7382c
+                                    const unsigned char *f, int fl, int rsa_len);
5c7382c
 
5c7382c
  int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
5c7382c
-                                  unsigned char *f, int fl);
5c7382c
+                                  const unsigned char *f, int fl);
5c7382c
 
5c7382c
  int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
5c7382c
-                                    unsigned char *f, int fl, int rsa_len);
5c7382c
+                                    const unsigned char *f, int fl, int rsa_len);
5c7382c
 
5c7382c
  int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
5c7382c
-                                unsigned char *f, int fl, unsigned char *p, int pl);
5c7382c
+                                const unsigned char *f, int fl,
5c7382c
+                                const unsigned char *p, int pl);
5c7382c
 
5c7382c
  int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
5c7382c
-                                  unsigned char *f, int fl, int rsa_len,
5c7382c
-                                  unsigned char *p, int pl);
5c7382c
+                                  const unsigned char *f, int fl, int rsa_len,
5c7382c
+                                  const unsigned char *p, int pl);
5c7382c
+
5c7382c
+ int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
5c7382c
+                                     const unsigned char *f, int fl,
5c7382c
+                                     const unsigned char *p, int pl,
5c7382c
+                                     const EVP_MD *md, const EVP_MD *mgf1md);
5c7382c
+
5c7382c
+ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
5c7382c
+                                       const unsigned char *f, int fl, int rsa_len,
5c7382c
+                                       const unsigned char *p, int pl,
5c7382c
+                                       const EVP_MD *md, const EVP_MD *mgf1md);
5c7382c
 
5c7382c
  int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
5c7382c
-                            unsigned char *f, int fl);
5c7382c
+                            const unsigned char *f, int fl);
5c7382c
 
5c7382c
  int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
5c7382c
-                              unsigned char *f, int fl, int rsa_len);
5c7382c
+                              const unsigned char *f, int fl, int rsa_len);
5c7382c
 
5c7382c
  int RSA_padding_add_none(unsigned char *to, int tlen,
5c7382c
-                          unsigned char *f, int fl);
5c7382c
+                          const unsigned char *f, int fl);
5c7382c
 
5c7382c
  int RSA_padding_check_none(unsigned char *to, int tlen,
5c7382c
-                            unsigned char *f, int fl, int rsa_len);
5c7382c
+                            const unsigned char *f, int fl, int rsa_len);
5c7382c
 
5c7382c
 =head1 DESCRIPTION
5c7382c
 
5c7382c
@@ -98,6 +110,10 @@ at B<to>.
5c7382c
 For RSA_padding_xxx_OAEP(), B

points to the encoding parameter

5c7382c
 of length B<pl>. B

may be B<NULL> if B<pl> is 0.

5c7382c
 
5c7382c
+For RSA_padding_xxx_OAEP_mgf1(), B<md> points to the md hash,
5c7382c
+if B<md> is B<NULL> that means md=sha1, and B<mgf1md> points to
5c7382c
+the mgf1 hash, if B<mgf1md> is B<NULL> that means mgf1md=md.
5c7382c
+
5c7382c
 =head1 RETURN VALUES
5c7382c
 
5c7382c
 The RSA_padding_add_xxx() functions return 1 on success, 0 on error.
5c7382c
@@ -107,15 +123,21 @@ L<ERR_get_error(3)>.
5c7382c
 
5c7382c
 =head1 WARNING
5c7382c
 
5c7382c
-The RSA_padding_check_PKCS1_type_2() padding check leaks timing
5c7382c
+The result of RSA_padding_check_PKCS1_type_2() is a very sensitive
5c7382c
 information which can potentially be used to mount a Bleichenbacher
5c7382c
 padding oracle attack. This is an inherent weakness in the PKCS #1
5c7382c
-v1.5 padding design. Prefer PKCS1_OAEP padding. Otherwise it can
5c7382c
-be recommended to pass zero-padded B<f>, so that B<fl> equals to
5c7382c
-B<rsa_len>, and if fixed by protocol, B<tlen> being set to the
5c7382c
-expected length. In such case leakage would be minimal, it would
5c7382c
-take attacker's ability to observe memory access pattern with byte
5c7382c
-granilarity as it occurs, post-factum timing analysis won't do.
5c7382c
+v1.5 padding design. Prefer PKCS1_OAEP padding. If that is not
5c7382c
+possible, the result of RSA_padding_check_PKCS1_type_2() should be
5c7382c
+checked in constant time if it matches the expected length of the
5c7382c
+plaintext and additionally some application specific consistency
5c7382c
+checks on the plaintext need to be performed in constant time.
5c7382c
+If the plaintext is rejected it must be kept secret which of the
5c7382c
+checks caused the application to reject the message.
5c7382c
+Do not remove the zero-padding from the decrypted raw RSA data
5c7382c
+which was computed by RSA_private_decrypt() with B<RSA_NO_PADDING>,
5c7382c
+as this would create a small timing side channel which could be
5c7382c
+used to mount a Bleichenbacher attack against any padding mode
5c7382c
+including PKCS1_OAEP.
5c7382c
 
5c7382c
 =head1 SEE ALSO
5c7382c
 
5c7382c
@@ -125,7 +147,7 @@ L<RSA_sign(3)>, L<RSA_verify(3)>
5c7382c
 
5c7382c
 =head1 COPYRIGHT
5c7382c
 
5c7382c
-Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
+Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
 
5c7382c
 Licensed under the OpenSSL license (the "License").  You may not use
5c7382c
 this file except in compliance with the License.  You can obtain a copy
5c7382c
diff -up openssl-1.1.1b/doc/man3/RSA_public_encrypt.pod.sync openssl-1.1.1b/doc/man3/RSA_public_encrypt.pod
5c7382c
--- openssl-1.1.1b/doc/man3/RSA_public_encrypt.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/RSA_public_encrypt.pod	2019-05-03 08:55:51.555406608 +0200
5c7382c
@@ -8,10 +8,10 @@ RSA_public_encrypt, RSA_private_decrypt
5c7382c
 
5c7382c
  #include <openssl/rsa.h>
5c7382c
 
5c7382c
- int RSA_public_encrypt(int flen, unsigned char *from,
5c7382c
+ int RSA_public_encrypt(int flen, const unsigned char *from,
5c7382c
                         unsigned char *to, RSA *rsa, int padding);
5c7382c
 
5c7382c
- int RSA_private_decrypt(int flen, unsigned char *from,
5c7382c
+ int RSA_private_decrypt(int flen, const unsigned char *from,
5c7382c
                          unsigned char *to, RSA *rsa, int padding);
5c7382c
 
5c7382c
 =head1 DESCRIPTION
5c7382c
@@ -27,6 +27,8 @@ B<padding> denotes one of the following
5c7382c
 =item RSA_PKCS1_PADDING
5c7382c
 
5c7382c
 PKCS #1 v1.5 padding. This currently is the most widely used mode.
5c7382c
+However, it is highly recommended to use RSA_PKCS1_OAEP_PADDING in
5c7382c
+new applications. SEE WARNING BELOW.
5c7382c
 
5c7382c
 =item RSA_PKCS1_OAEP_PADDING
5c7382c
 
5c7382c
@@ -46,23 +48,35 @@ Encrypting user data directly with RSA i
5c7382c
 
5c7382c
 =back
5c7382c
 
5c7382c
-B<flen> must be less than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
5c7382c
-based padding modes, less than RSA_size(B<rsa>) - 41 for
5c7382c
+B<flen> must not be more than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
5c7382c
+based padding modes, not more than RSA_size(B<rsa>) - 42 for
5c7382c
 RSA_PKCS1_OAEP_PADDING and exactly RSA_size(B<rsa>) for RSA_NO_PADDING.
5c7382c
-The random number generator must be seeded prior to calling
5c7382c
-RSA_public_encrypt().
5c7382c
+When a padding mode other than RSA_NO_PADDING is in use, then
5c7382c
+RSA_public_encrypt() will include some random bytes into the ciphertext
5c7382c
+and therefore the ciphertext will be different each time, even if the
5c7382c
+plaintext and the public key are exactly identical.
5c7382c
+The returned ciphertext in B<to> will always be zero padded to exactly
5c7382c
+RSA_size(B<rsa>) bytes.
5c7382c
+B<to> and B<from> may overlap.
5c7382c
 
5c7382c
 RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
5c7382c
-private key B<rsa> and stores the plaintext in B<to>. B<to> must point
5c7382c
-to a memory section large enough to hold the decrypted data (which is
5c7382c
-smaller than RSA_size(B<rsa>)). B<padding> is the padding mode that
5c7382c
-was used to encrypt the data.
5c7382c
+private key B<rsa> and stores the plaintext in B<to>. B<flen> should
5c7382c
+be equal to RSA_size(B<rsa>) but may be smaller, when leading zero
5c7382c
+bytes are in the ciphertext. Those are not important and may be removed,
5c7382c
+but RSA_public_encrypt() does not do that. B<to> must point
5c7382c
+to a memory section large enough to hold the maximal possible decrypted
5c7382c
+data (which is equal to RSA_size(B<rsa>) for RSA_NO_PADDING,
5c7382c
+RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5 based padding modes and
5c7382c
+RSA_size(B<rsa>) - 42 for RSA_PKCS1_OAEP_PADDING).
5c7382c
+B<padding> is the padding mode that was used to encrypt the data.
5c7382c
+B<to> and B<from> may overlap.
5c7382c
 
5c7382c
 =head1 RETURN VALUES
5c7382c
 
5c7382c
 RSA_public_encrypt() returns the size of the encrypted data (i.e.,
5c7382c
 RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
5c7382c
-recovered plaintext.
5c7382c
+recovered plaintext. A return value of 0 is not an error and
5c7382c
+means only that the plaintext was empty.
5c7382c
 
5c7382c
 On error, -1 is returned; the error codes can be
5c7382c
 obtained by L<ERR_get_error(3)>.
5c7382c
@@ -85,7 +99,7 @@ L<RSA_size(3)>
5c7382c
 
5c7382c
 =head1 COPYRIGHT
5c7382c
 
5c7382c
-Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
+Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
 
5c7382c
 Licensed under the OpenSSL license (the "License").  You may not use
5c7382c
 this file except in compliance with the License.  You can obtain a copy
5c7382c
diff -up openssl-1.1.1b/doc/man3/SSL_CIPHER_get_name.pod.sync openssl-1.1.1b/doc/man3/SSL_CIPHER_get_name.pod
5c7382c
--- openssl-1.1.1b/doc/man3/SSL_CIPHER_get_name.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/SSL_CIPHER_get_name.pod	2019-05-03 08:55:51.537406917 +0200
5c7382c
@@ -124,7 +124,10 @@ Textual representation of the cipher nam
5c7382c
 
5c7382c
 =item <protocol version>
5c7382c
 
5c7382c
-Protocol version, such as B<TLSv1.2>, when the cipher was first defined.
5c7382c
+The minimum protocol version that the ciphersuite supports, such as B<TLSv1.2>.
5c7382c
+Note that this is not always the same as the protocol version in which the
5c7382c
+ciphersuite was first defined because some ciphersuites are backwards compatible
5c7382c
+with earlier protocol versions.
5c7382c
 
5c7382c
 =item Kx=<key exchange>
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/doc/man3/SSL_CTX_set_client_hello_cb.pod.sync openssl-1.1.1b/doc/man3/SSL_CTX_set_client_hello_cb.pod
5c7382c
--- openssl-1.1.1b/doc/man3/SSL_CTX_set_client_hello_cb.pod.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/doc/man3/SSL_CTX_set_client_hello_cb.pod	2019-05-03 08:55:51.534406969 +0200
5c7382c
@@ -65,6 +65,8 @@ both required, and on success the caller
5c7382c
 B<*out> using OPENSSL_free().  The contents of B<*out> is an array of integers
5c7382c
 holding the numerical value of the TLS extension types in the order they appear
5c7382c
 in the ClientHello.  B<*outlen> contains the number of elements in the array.
5c7382c
+In situations when the ClientHello has no extensions, the function will return
5c7382c
+success with B<*out> set to NULL and B<*outlen> set to 0.
5c7382c
 
5c7382c
 =head1 NOTES
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/include/openssl/err.h.sync openssl-1.1.1b/include/openssl/err.h
5c7382c
--- openssl-1.1.1b/include/openssl/err.h.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/include/openssl/err.h	2019-05-03 08:55:51.548406728 +0200
5c7382c
@@ -37,6 +37,7 @@ extern "C" {
5c7382c
 # define ERR_TXT_STRING          0x02
5c7382c
 
5c7382c
 # define ERR_FLAG_MARK           0x01
5c7382c
+# define ERR_FLAG_CLEAR          0x02
5c7382c
 
5c7382c
 # define ERR_NUM_ERRORS  16
5c7382c
 typedef struct err_state_st {
5c7382c
diff -up openssl-1.1.1b/ssl/ssl_lib.c.sync openssl-1.1.1b/ssl/ssl_lib.c
5c7382c
--- openssl-1.1.1b/ssl/ssl_lib.c.sync	2019-05-03 08:55:45.196515778 +0200
5c7382c
+++ openssl-1.1.1b/ssl/ssl_lib.c	2019-05-03 08:55:51.535406951 +0200
5c7382c
@@ -5089,6 +5089,11 @@ int SSL_client_hello_get1_extensions_pre
5c7382c
         if (ext->present)
5c7382c
             num++;
5c7382c
     }
5c7382c
+    if (num == 0) {
5c7382c
+        *out = NULL;
5c7382c
+        *outlen = 0;
5c7382c
+        return 1;
5c7382c
+    }
5c7382c
     if ((present = OPENSSL_malloc(sizeof(*present) * num)) == NULL) {
5c7382c
         SSLerr(SSL_F_SSL_CLIENT_HELLO_GET1_EXTENSIONS_PRESENT,
5c7382c
                ERR_R_MALLOC_FAILURE);
5c7382c
diff -up openssl-1.1.1b/ssl/ssl_locl.h.sync openssl-1.1.1b/ssl/ssl_locl.h
5c7382c
--- openssl-1.1.1b/ssl/ssl_locl.h.sync	2019-05-03 08:55:45.011518954 +0200
5c7382c
+++ openssl-1.1.1b/ssl/ssl_locl.h	2019-05-03 08:55:51.541406848 +0200
5c7382c
@@ -574,7 +574,6 @@ struct ssl_session_st {
5c7382c
         /* Session lifetime hint in seconds */
5c7382c
         unsigned long tick_lifetime_hint;
5c7382c
         uint32_t tick_age_add;
5c7382c
-        int tick_identity;
5c7382c
         /* Max number of bytes that can be sent as early data */
5c7382c
         uint32_t max_early_data;
5c7382c
         /* The ALPN protocol selected for this session */
5c7382c
@@ -1356,6 +1355,13 @@ struct ssl_st {
5c7382c
          * as this extension is optional on server side.
5c7382c
          */
5c7382c
         uint8_t max_fragment_len_mode;
5c7382c
+
5c7382c
+        /*
5c7382c
+         * On the client side the number of ticket identities we sent in the
5c7382c
+         * ClientHello. On the server side the identity of the ticket we
5c7382c
+         * selected.
5c7382c
+         */
5c7382c
+        int tick_identity;
5c7382c
     } ext;
5c7382c
 
5c7382c
     /*
5c7382c
@@ -2052,9 +2058,6 @@ typedef enum downgrade_en {
5c7382c
 #define TLSEXT_KEX_MODE_FLAG_KE                                 1
5c7382c
 #define TLSEXT_KEX_MODE_FLAG_KE_DHE                             2
5c7382c
 
5c7382c
-/* An invalid index into the TLSv1.3 PSK identities */
5c7382c
-#define TLSEXT_PSK_BAD_IDENTITY                                 -1
5c7382c
-
5c7382c
 #define SSL_USE_PSS(s) (s->s3->tmp.peer_sigalg != NULL && \
5c7382c
                         s->s3->tmp.peer_sigalg->sig == EVP_PKEY_RSA_PSS)
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/ssl/statem/extensions_clnt.c.sync openssl-1.1.1b/ssl/statem/extensions_clnt.c
5c7382c
--- openssl-1.1.1b/ssl/statem/extensions_clnt.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/ssl/statem/extensions_clnt.c	2019-05-03 08:55:51.542406831 +0200
5c7382c
@@ -993,7 +993,7 @@ EXT_RETURN tls_construct_ctos_psk(SSL *s
5c7382c
     const EVP_MD *handmd = NULL, *mdres = NULL, *mdpsk = NULL;
5c7382c
     int dores = 0;
5c7382c
 
5c7382c
-    s->session->ext.tick_identity = TLSEXT_PSK_BAD_IDENTITY;
5c7382c
+    s->ext.tick_identity = 0;
5c7382c
 
5c7382c
     /*
5c7382c
      * Note: At this stage of the code we only support adding a single
5c7382c
@@ -1083,6 +1083,7 @@ EXT_RETURN tls_construct_ctos_psk(SSL *s
5c7382c
         agems += s->session->ext.tick_age_add;
5c7382c
 
5c7382c
         reshashsize = EVP_MD_size(mdres);
5c7382c
+        s->ext.tick_identity++;
5c7382c
         dores = 1;
5c7382c
     }
5c7382c
 
5c7382c
@@ -1142,6 +1143,7 @@ EXT_RETURN tls_construct_ctos_psk(SSL *s
5c7382c
                      ERR_R_INTERNAL_ERROR);
5c7382c
             return EXT_RETURN_FAIL;
5c7382c
         }
5c7382c
+        s->ext.tick_identity++;
5c7382c
     }
5c7382c
 
5c7382c
     if (!WPACKET_close(pkt)
5c7382c
@@ -1180,11 +1182,6 @@ EXT_RETURN tls_construct_ctos_psk(SSL *s
5c7382c
         return EXT_RETURN_FAIL;
5c7382c
     }
5c7382c
 
5c7382c
-    if (dores)
5c7382c
-        s->session->ext.tick_identity = 0;
5c7382c
-    if (s->psksession != NULL)
5c7382c
-        s->psksession->ext.tick_identity = (dores ? 1 : 0);
5c7382c
-
5c7382c
     return EXT_RETURN_SENT;
5c7382c
 #else
5c7382c
     return EXT_RETURN_NOT_SENT;
5c7382c
@@ -1927,8 +1924,7 @@ int tls_parse_stoc_early_data(SSL *s, PA
5c7382c
     }
5c7382c
 
5c7382c
     if (!s->ext.early_data_ok
5c7382c
-            || !s->hit
5c7382c
-            || s->session->ext.tick_identity != 0) {
5c7382c
+            || !s->hit) {
5c7382c
         /*
5c7382c
          * If we get here then we didn't send early data, or we didn't resume
5c7382c
          * using the first identity, or the SNI/ALPN is not consistent so the
5c7382c
@@ -1956,17 +1952,28 @@ int tls_parse_stoc_psk(SSL *s, PACKET *p
5c7382c
         return 0;
5c7382c
     }
5c7382c
 
5c7382c
-    if (s->session->ext.tick_identity == (int)identity) {
5c7382c
+    if (identity >= (unsigned int)s->ext.tick_identity) {
5c7382c
+        SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_F_TLS_PARSE_STOC_PSK,
5c7382c
+                 SSL_R_BAD_PSK_IDENTITY);
5c7382c
+        return 0;
5c7382c
+    }
5c7382c
+
5c7382c
+    /*
5c7382c
+     * Session resumption tickets are always sent before PSK tickets. If the
5c7382c
+     * ticket index is 0 then it must be for a session resumption ticket if we
5c7382c
+     * sent two tickets, or if we didn't send a PSK ticket.
5c7382c
+     */
5c7382c
+    if (identity == 0 && (s->psksession == NULL || s->ext.tick_identity == 2)) {
5c7382c
         s->hit = 1;
5c7382c
         SSL_SESSION_free(s->psksession);
5c7382c
         s->psksession = NULL;
5c7382c
         return 1;
5c7382c
     }
5c7382c
 
5c7382c
-    if (s->psksession == NULL
5c7382c
-            || s->psksession->ext.tick_identity != (int)identity) {
5c7382c
-        SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_F_TLS_PARSE_STOC_PSK,
5c7382c
-                 SSL_R_BAD_PSK_IDENTITY);
5c7382c
+    if (s->psksession == NULL) {
5c7382c
+        /* Should never happen */
5c7382c
+        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PARSE_STOC_PSK,
5c7382c
+                 ERR_R_INTERNAL_ERROR);
5c7382c
         return 0;
5c7382c
     }
5c7382c
 
5c7382c
@@ -1985,6 +1992,9 @@ int tls_parse_stoc_psk(SSL *s, PACKET *p
5c7382c
     s->session = s->psksession;
5c7382c
     s->psksession = NULL;
5c7382c
     s->hit = 1;
5c7382c
+    /* Early data is only allowed if we used the first ticket */
5c7382c
+    if (identity != 0)
5c7382c
+        s->ext.early_data_ok = 0;
5c7382c
 #endif
5c7382c
 
5c7382c
     return 1;
5c7382c
diff -up openssl-1.1.1b/ssl/statem/extensions.c.sync openssl-1.1.1b/ssl/statem/extensions.c
5c7382c
--- openssl-1.1.1b/ssl/statem/extensions.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/ssl/statem/extensions.c	2019-05-03 08:55:51.541406848 +0200
5c7382c
@@ -989,7 +989,6 @@ static int final_server_name(SSL *s, uns
5c7382c
                 ss->ext.ticklen = 0;
5c7382c
                 ss->ext.tick_lifetime_hint = 0;
5c7382c
                 ss->ext.tick_age_add = 0;
5c7382c
-                ss->ext.tick_identity = 0;
5c7382c
                 if (!ssl_generate_session_id(s, ss)) {
5c7382c
                     SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_FINAL_SERVER_NAME,
5c7382c
                              ERR_R_INTERNAL_ERROR);
5c7382c
@@ -1646,7 +1645,6 @@ static int final_early_data(SSL *s, unsi
5c7382c
 
5c7382c
     if (s->max_early_data == 0
5c7382c
             || !s->hit
5c7382c
-            || s->session->ext.tick_identity != 0
5c7382c
             || s->early_data_state != SSL_EARLY_DATA_ACCEPTING
5c7382c
             || !s->ext.early_data_ok
5c7382c
             || s->hello_retry_request != SSL_HRR_NONE
5c7382c
diff -up openssl-1.1.1b/ssl/statem/extensions_srvr.c.sync openssl-1.1.1b/ssl/statem/extensions_srvr.c
5c7382c
--- openssl-1.1.1b/ssl/statem/extensions_srvr.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/ssl/statem/extensions_srvr.c	2019-05-03 08:55:51.542406831 +0200
5c7382c
@@ -1274,7 +1274,7 @@ int tls_parse_ctos_psk(SSL *s, PACKET *p
5c7382c
         goto err;
5c7382c
     }
5c7382c
 
5c7382c
-    sess->ext.tick_identity = id;
5c7382c
+    s->ext.tick_identity = id;
5c7382c
 
5c7382c
     SSL_SESSION_free(s->session);
5c7382c
     s->session = sess;
5c7382c
@@ -1948,7 +1948,7 @@ EXT_RETURN tls_construct_stoc_psk(SSL *s
5c7382c
 
5c7382c
     if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_psk)
5c7382c
             || !WPACKET_start_sub_packet_u16(pkt)
5c7382c
-            || !WPACKET_put_bytes_u16(pkt, s->session->ext.tick_identity)
5c7382c
+            || !WPACKET_put_bytes_u16(pkt, s->ext.tick_identity)
5c7382c
             || !WPACKET_close(pkt)) {
5c7382c
         SSLfatal(s, SSL_AD_INTERNAL_ERROR,
5c7382c
                  SSL_F_TLS_CONSTRUCT_STOC_PSK, ERR_R_INTERNAL_ERROR);
5c7382c
diff -up openssl-1.1.1b/ssl/statem/statem_clnt.c.sync openssl-1.1.1b/ssl/statem/statem_clnt.c
5c7382c
--- openssl-1.1.1b/ssl/statem/statem_clnt.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/ssl/statem/statem_clnt.c	2019-05-03 08:55:51.543406814 +0200
5c7382c
@@ -1613,10 +1613,7 @@ MSG_PROCESS_RETURN tls_process_server_he
5c7382c
          * so the PAC-based session secret is always preserved. It'll be
5c7382c
          * overwritten if the server refuses resumption.
5c7382c
          */
5c7382c
-        if (s->session->session_id_length > 0
5c7382c
-                || (SSL_IS_TLS13(s)
5c7382c
-                    && s->session->ext.tick_identity
5c7382c
-                       != TLSEXT_PSK_BAD_IDENTITY)) {
5c7382c
+        if (s->session->session_id_length > 0) {
5c7382c
             tsan_counter(&s->session_ctx->stats.sess_miss);
5c7382c
             if (!ssl_get_new_session(s, 0)) {
5c7382c
                 /* SSLfatal() already called */
5c7382c
diff -up openssl-1.1.1b/test/bio_memleak_test.c.sync openssl-1.1.1b/test/bio_memleak_test.c
5c7382c
--- openssl-1.1.1b/test/bio_memleak_test.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/test/bio_memleak_test.c	2019-05-03 08:55:51.556406591 +0200
5c7382c
@@ -18,28 +18,170 @@ static int test_bio_memleak(void)
5c7382c
     int ok = 0;
5c7382c
     BIO *bio;
5c7382c
     BUF_MEM bufmem;
5c7382c
-    const char *str = "BIO test\n";
5c7382c
+    static const char str[] = "BIO test\n";
5c7382c
     char buf[100];
5c7382c
 
5c7382c
     bio = BIO_new(BIO_s_mem());
5c7382c
-    if (bio == NULL)
5c7382c
+    if (!TEST_ptr(bio))
5c7382c
         goto finish;
5c7382c
-    bufmem.length = strlen(str) + 1;
5c7382c
+    bufmem.length = sizeof(str);
5c7382c
     bufmem.data = (char *) str;
5c7382c
     bufmem.max = bufmem.length;
5c7382c
     BIO_set_mem_buf(bio, &bufmem, BIO_NOCLOSE);
5c7382c
     BIO_set_flags(bio, BIO_FLAGS_MEM_RDONLY);
5c7382c
+    if (!TEST_int_eq(BIO_read(bio, buf, sizeof(buf)), sizeof(str)))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(buf, sizeof(str), str, sizeof(str)))
5c7382c
+        goto finish;
5c7382c
+    ok = 1;
5c7382c
 
5c7382c
-    if (BIO_read(bio, buf, sizeof(buf)) <= 0)
5c7382c
-	goto finish;
5c7382c
+finish:
5c7382c
+    BIO_free(bio);
5c7382c
+    return ok;
5c7382c
+}
5c7382c
 
5c7382c
-    ok = strcmp(buf, str) == 0;
5c7382c
+static int test_bio_get_mem(void)
5c7382c
+{
5c7382c
+    int ok = 0;
5c7382c
+    BIO *bio = NULL;
5c7382c
+    BUF_MEM *bufmem = NULL;
5c7382c
+
5c7382c
+    bio = BIO_new(BIO_s_mem());
5c7382c
+    if (!TEST_ptr(bio))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_puts(bio, "Hello World\n"), 12))
5c7382c
+        goto finish;
5c7382c
+    BIO_get_mem_ptr(bio, &bufmem);
5c7382c
+    if (!TEST_ptr(bufmem))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_gt(BIO_set_close(bio, BIO_NOCLOSE), 0))
5c7382c
+        goto finish;
5c7382c
+    BIO_free(bio);
5c7382c
+    bio = NULL;
5c7382c
+    if (!TEST_mem_eq(bufmem->data, bufmem->length, "Hello World\n", 12))
5c7382c
+        goto finish;
5c7382c
+    ok = 1;
5c7382c
 
5c7382c
 finish:
5c7382c
     BIO_free(bio);
5c7382c
+    BUF_MEM_free(bufmem);
5c7382c
     return ok;
5c7382c
 }
5c7382c
 
5c7382c
+static int test_bio_new_mem_buf(void)
5c7382c
+{
5c7382c
+    int ok = 0;
5c7382c
+    BIO *bio;
5c7382c
+    BUF_MEM *bufmem;
5c7382c
+    char data[16];
5c7382c
+
5c7382c
+    bio = BIO_new_mem_buf("Hello World\n", 12);
5c7382c
+    if (!TEST_ptr(bio))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_read(bio, data, 5), 5))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(data, 5, "Hello", 5))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_gt(BIO_get_mem_ptr(bio, &bufmem), 0))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_lt(BIO_write(bio, "test", 4), 0))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_read(bio, data, 16), 7))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(data, 7, " World\n", 7))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_gt(BIO_reset(bio), 0))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_read(bio, data, 16), 12))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(data, 12, "Hello World\n", 12))
5c7382c
+        goto finish;
5c7382c
+    ok = 1;
5c7382c
+
5c7382c
+finish:
5c7382c
+    BIO_free(bio);
5c7382c
+    return ok;
5c7382c
+}
5c7382c
+
5c7382c
+static int test_bio_rdonly_mem_buf(void)
5c7382c
+{
5c7382c
+    int ok = 0;
5c7382c
+    BIO *bio, *bio2 = NULL;
5c7382c
+    BUF_MEM *bufmem;
5c7382c
+    char data[16];
5c7382c
+
5c7382c
+    bio = BIO_new_mem_buf("Hello World\n", 12);
5c7382c
+    if (!TEST_ptr(bio))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_read(bio, data, 5), 5))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(data, 5, "Hello", 5))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_gt(BIO_get_mem_ptr(bio, &bufmem), 0))
5c7382c
+        goto finish;
5c7382c
+    (void)BIO_set_close(bio, BIO_NOCLOSE);
5c7382c
+
5c7382c
+    bio2 = BIO_new(BIO_s_mem());
5c7382c
+    if (!TEST_ptr(bio2))
5c7382c
+        goto finish;
5c7382c
+    BIO_set_mem_buf(bio2, bufmem, BIO_CLOSE);
5c7382c
+    BIO_set_flags(bio2, BIO_FLAGS_MEM_RDONLY);
5c7382c
+
5c7382c
+    if (!TEST_int_eq(BIO_read(bio2, data, 16), 7))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(data, 7, " World\n", 7))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_gt(BIO_reset(bio2), 0))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_read(bio2, data, 16), 7))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(data, 7, " World\n", 7))
5c7382c
+        goto finish;
5c7382c
+    ok = 1;
5c7382c
+
5c7382c
+finish:
5c7382c
+    BIO_free(bio);
5c7382c
+    BIO_free(bio2);
5c7382c
+    return ok;
5c7382c
+}
5c7382c
+
5c7382c
+static int test_bio_rdwr_rdonly(void)
5c7382c
+{
5c7382c
+    int ok = 0;
5c7382c
+    BIO *bio = NULL;
5c7382c
+    char data[16];
5c7382c
+
5c7382c
+    bio = BIO_new(BIO_s_mem());
5c7382c
+    if (!TEST_ptr(bio))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_puts(bio, "Hello World\n"), 12))
5c7382c
+        goto finish;
5c7382c
+
5c7382c
+    BIO_set_flags(bio, BIO_FLAGS_MEM_RDONLY);
5c7382c
+    if (!TEST_int_eq(BIO_read(bio, data, 16), 12))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_mem_eq(data, 12, "Hello World\n", 12))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_gt(BIO_reset(bio), 0))
5c7382c
+        goto finish;
5c7382c
+
5c7382c
+    BIO_clear_flags(bio, BIO_FLAGS_MEM_RDONLY);
5c7382c
+    if (!TEST_int_eq(BIO_puts(bio, "Hi!\n"), 4))
5c7382c
+        goto finish;
5c7382c
+    if (!TEST_int_eq(BIO_read(bio, data, 16), 16))
5c7382c
+        goto finish;
5c7382c
+
5c7382c
+    if (!TEST_mem_eq(data, 16, "Hello World\nHi!\n", 16))
5c7382c
+        goto finish;
5c7382c
+
5c7382c
+    ok = 1;
5c7382c
+
5c7382c
+finish:
5c7382c
+    BIO_free(bio);
5c7382c
+    return ok;
5c7382c
+}
5c7382c
+
5c7382c
+
5c7382c
 int global_init(void)
5c7382c
 {
5c7382c
     CRYPTO_set_mem_debug(1);
5c7382c
@@ -50,5 +192,9 @@ int global_init(void)
5c7382c
 int setup_tests(void)
5c7382c
 {
5c7382c
     ADD_TEST(test_bio_memleak);
5c7382c
+    ADD_TEST(test_bio_get_mem);
5c7382c
+    ADD_TEST(test_bio_new_mem_buf);
5c7382c
+    ADD_TEST(test_bio_rdonly_mem_buf);
5c7382c
+    ADD_TEST(test_bio_rdwr_rdonly);
5c7382c
     return 1;
5c7382c
 }
5c7382c
diff -up openssl-1.1.1b/test/ectest.c.sync openssl-1.1.1b/test/ectest.c
5c7382c
--- openssl-1.1.1b/test/ectest.c.sync	2019-05-03 08:55:45.127516962 +0200
5c7382c
+++ openssl-1.1.1b/test/ectest.c	2019-05-03 08:55:51.524407140 +0200
5c7382c
@@ -728,6 +728,74 @@ err:
5c7382c
     BN_CTX_free(ctx);
5c7382c
     return r;
5c7382c
 }
5c7382c
+
5c7382c
+/*
5c7382c
+ * Tests a point known to cause an incorrect underflow in an old version of
5c7382c
+ * ecp_nist521.c
5c7382c
+ */
5c7382c
+static int underflow_test(void)
5c7382c
+{
5c7382c
+    BN_CTX *ctx = NULL;
5c7382c
+    EC_GROUP *grp = NULL;
5c7382c
+    EC_POINT *P = NULL, *Q = NULL, *R = NULL;
5c7382c
+    BIGNUM *x1 = NULL, *y1 = NULL, *z1 = NULL, *x2 = NULL, *y2 = NULL;
5c7382c
+    BIGNUM *k = NULL;
5c7382c
+    int testresult = 0;
5c7382c
+    const char *x1str =
5c7382c
+        "1534f0077fffffe87e9adcfe000000000000000000003e05a21d2400002e031b1f4"
5c7382c
+        "b80000c6fafa4f3c1288798d624a247b5e2ffffffffffffffefe099241900004";
5c7382c
+    const char *p521m1 =
5c7382c
+        "1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
5c7382c
+        "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe";
5c7382c
+
5c7382c
+    ctx = BN_CTX_new();
5c7382c
+    if (!TEST_ptr(ctx))
5c7382c
+        return 0;
5c7382c
+
5c7382c
+    BN_CTX_start(ctx);
5c7382c
+    x1 = BN_CTX_get(ctx);
5c7382c
+    y1 = BN_CTX_get(ctx);
5c7382c
+    z1 = BN_CTX_get(ctx);
5c7382c
+    x2 = BN_CTX_get(ctx);
5c7382c
+    y2 = BN_CTX_get(ctx);
5c7382c
+    k = BN_CTX_get(ctx);
5c7382c
+    if (!TEST_ptr(k))
5c7382c
+        goto err;
5c7382c
+
5c7382c
+    grp = EC_GROUP_new_by_curve_name(NID_secp521r1);
5c7382c
+    P = EC_POINT_new(grp);
5c7382c
+    Q = EC_POINT_new(grp);
5c7382c
+    R = EC_POINT_new(grp);
5c7382c
+    if (!TEST_ptr(grp) || !TEST_ptr(P) || !TEST_ptr(Q) || !TEST_ptr(R))
5c7382c
+        goto err;
5c7382c
+
5c7382c
+    if (!TEST_int_gt(BN_hex2bn(&x1, x1str), 0)
5c7382c
+            || !TEST_int_gt(BN_hex2bn(&y1, p521m1), 0)
5c7382c
+            || !TEST_int_gt(BN_hex2bn(&z1, p521m1), 0)
5c7382c
+            || !TEST_int_gt(BN_hex2bn(&k, "02"), 0)
5c7382c
+            || !TEST_true(EC_POINT_set_Jprojective_coordinates_GFp(grp, P, x1,
5c7382c
+                                                                   y1, z1, ctx))
5c7382c
+            || !TEST_true(EC_POINT_mul(grp, Q, NULL, P, k, ctx))
5c7382c
+            || !TEST_true(EC_POINT_get_affine_coordinates(grp, Q, x1, y1, ctx))
5c7382c
+            || !TEST_true(EC_POINT_dbl(grp, R, P, ctx))
5c7382c
+            || !TEST_true(EC_POINT_get_affine_coordinates(grp, R, x2, y2, ctx)))
5c7382c
+        goto err;
5c7382c
+
5c7382c
+    if (!TEST_int_eq(BN_cmp(x1, x2), 0)
5c7382c
+            || !TEST_int_eq(BN_cmp(y1, y2), 0))
5c7382c
+        goto err;
5c7382c
+
5c7382c
+    testresult = 1;
5c7382c
+
5c7382c
+ err:
5c7382c
+    BN_CTX_end(ctx);
5c7382c
+    EC_POINT_free(P);
5c7382c
+    EC_POINT_free(Q);
5c7382c
+    EC_GROUP_free(grp);
5c7382c
+    BN_CTX_free(ctx);
5c7382c
+
5c7382c
+    return testresult;
5c7382c
+}
5c7382c
 # endif
5c7382c
 
5c7382c
 static const unsigned char p521_named[] = {
5c7382c
@@ -835,6 +903,7 @@ int setup_tests(void)
5c7382c
 # endif
5c7382c
 # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
5c7382c
     ADD_ALL_TESTS(nistp_single_test, OSSL_NELEM(nistp_tests_params));
5c7382c
+    ADD_TEST(underflow_test);
5c7382c
 # endif
5c7382c
     ADD_ALL_TESTS(internal_curve_test, crv_len);
5c7382c
     ADD_ALL_TESTS(internal_curve_test_method, crv_len);
5c7382c
diff -up openssl-1.1.1b/test/recipes/30-test_evp_data/evpciph.txt.sync openssl-1.1.1b/test/recipes/30-test_evp_data/evpciph.txt
5c7382c
--- openssl-1.1.1b/test/recipes/30-test_evp_data/evpciph.txt.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/test/recipes/30-test_evp_data/evpciph.txt	2019-05-03 08:55:51.552406659 +0200
5c7382c
@@ -2232,7 +2232,7 @@ IV = 00000000000000000000000000000000
5c7382c
 Plaintext = 11111111aaaaaaaa11111111bbbbbbbb11111111cccccccc11111111dddddddd22222222aaaaaaaa22222222bbbbbbbb22222222cccccccc22222222dddddddd33333333aaaaaaaa33333333bbbbbbbb33333333cccccccc33333333dddddddd44444444aaaaaaaa44444444bbbbbbbb44444444cccccccc44444444dddddddd55555555aaaaaaaa55555555bbbbbbbb55555555cccccccc55555555dddddddd
5c7382c
 Ciphertext = 30026c329666141721178b99c0a1f1b2f06940253f7b3089e2a30ea86aa3c88f5940f05ad7ee41d71347bb7261e348f18360473fdf7d4e7723bffb4411cc13f6cdd89f3bc7b9c768145022c7a74f14d7c305cd012a10f16050c23f1ae5c23f45998d13fbaa041e51619577e0772764896a5d4516d8ffceb3bf7e05f613edd9a60cdcedaff9cfcaf4e00d445a54334f73ab2cad944e51d266548e61c6eb0aa1cd
5c7382c
 
5c7382c
-Title = ARIA GCM test vectors from IETF draft-ietf-avtcore-aria-srtp-10
5c7382c
+Title = ARIA GCM test vectors from RFC8269
5c7382c
 
5c7382c
 Cipher = ARIA-128-GCM
5c7382c
 Key = e91e5e75da65554a48181f3846349562
5c7382c
@@ -2250,6 +2250,36 @@ Tag = e210d6ced2cf430ff841472915e7ef48
5c7382c
 Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5
5c7382c
 Ciphertext = 6f9e4bcbc8c85fc0128fb1e4a0a20cb9932ff74581f54fc013dd054b19f99371425b352d97d3f337b90b63d1b082adeeea9d2d7391897d591b985e55fb50cb5350cf7d38dc27dda127c078a149c8eb98083d66363a46e3726af217d3a00275ad5bf772c7610ea4c23006878f0ee69a8397703169a419303f40b72e4573714d19e2697df61e7c7252e5abc6bade876ac4961bfac4d5e867afca351a48aed52822
5c7382c
 
5c7382c
+Title = ARIA GCM self-generated test vectors
5c7382c
+
5c7382c
+Cipher = ARIA-128-GCM
5c7382c
+Key = e91e5e75da65554a48181f3846349562
5c7382c
+# Shorter than default IV
5c7382c
+IV = 0001020304
5c7382c
+AAD = 8008315ebf2e6fe020e8f5eb
5c7382c
+Tag = ebaa2645bb154542117ee46031aa176e
5c7382c
+Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5
5c7382c
+Ciphertext = 1723ccfc0ed44a12520473cfeb63bc933cd450a943f5f1cba78e19d72f80cc102acc51f2459a06cf6435182b8ddd451f83e13479efe5ec7dfbf16229f4017920fb41457a9b6fe1a401b30b2f332d827ae2f86e962326927c1ed8bfedac1f7a00ddde63bd392a8f28a488ba5974689f8d15b9b1739fb50aae0ff244026ec72064003c621b33ffc8086b0a97eefb70604a2826f6499f6eb12d67a0da03fc8e1482
5c7382c
+
5c7382c
+Cipher = ARIA-128-GCM
5c7382c
+Key = e91e5e75da65554a48181f3846349562
5c7382c
+# Longer than default IV
5c7382c
+IV = 000102030405060708090a0b0c0d0e0f
5c7382c
+AAD = 8008315ebf2e6fe020e8f5eb
5c7382c
+Tag = 61f7f44c7da3c60195b29ae0b46051a4
5c7382c
+Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5
5c7382c
+Ciphertext = 0d3e98fcaf7a2c4fe9198d66add90d113e5e0ff47598c40a4bf501960d935a4156c9a4d46c9358a608e10a16479a4247c9ab9bb4a02809e3eac3571b832590fe2ca3e2d545741e36282d96c041fc7d39a46ed60214c2c0ec70f27768dfea4f9563b5d5c2ac33b1368a78f2908f5daf942433fec6ab588f09e908e95cc8dfa85d1a0dfd5835dc14e148323230c63eedc99a9ce942214cb3768b97b821d613629f
5c7382c
+
5c7382c
+Cipher = ARIA-128-GCM
5c7382c
+Key = e91e5e75da65554a48181f3846349562
5c7382c
+# Extra long IV
5c7382c
+IV = 000102030405060708090a0b0c0d0e0f1011
5c7382c
+AAD = 8008315ebf2e6fe020e8f5eb
5c7382c
+Tag = c8b31ab6c2ddccab06b76af4e56e664e
5c7382c
+Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5
5c7382c
+Ciphertext = 616a7bce24206501082cef7267c09a4affa54f8f82eb7fb2cdebdcaab4b6ab05c37e891c2d0fc90d15c5fb684247625c8bc0befad86896ae1c8f5a8506954caba4e13df0a0eb23853d4474e7f3b2c57bb398456a24d198e14566bce8a5f8d3bcdb12994d2fdc0f5cf19aeff990c1fe119e01f9fcc86757b1d43a9accf7b2f913c2208a46c1967f403867f89b46ffe96864c63f042265806ea5270e0dddd0e8dd
5c7382c
+
5c7382c
+
5c7382c
 Title = ARIA CCM test vectors from IETF draft-ietf-avtcore-aria-srtp-02
5c7382c
 
5c7382c
 # 16-byte Tag
5c7382c
@@ -2357,14 +2387,41 @@ Operation = ENCRYPT
5c7382c
 Plaintext = B41E6BE2EBA84A148E2EED84593C5EC7
5c7382c
 Ciphertext = 9B9B7BFCD1813CB95D0B3618F40F5122
5c7382c
 
5c7382c
-Title = Chacha20
5c7382c
+Title = Chacha20 test vectors from RFC7539
5c7382c
 
5c7382c
+# A.1 Test Vector 1
5c7382c
 Cipher = chacha20
5c7382c
 Key = 0000000000000000000000000000000000000000000000000000000000000000
5c7382c
 IV = 00000000000000000000000000000000
5c7382c
 Plaintext = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
5c7382c
 Ciphertext = 76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586
5c7382c
 
5c7382c
+# A.1 Test Vector 2
5c7382c
+Cipher = chacha20
5c7382c
+Key = 0000000000000000000000000000000000000000000000000000000000000000
5c7382c
+IV = 01000000000000000000000000000000
5c7382c
+Plaintext = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
5c7382c
+Ciphertext = 9f07e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed29b721769ce64e43d57133b074d839d531ed1f28510afb45ace10a1f4b794d6f
5c7382c
+
5c7382c
+# A.2 Test Vector 1 is the same as A.1 Test Vector 1
5c7382c
+# A.2 Test Vector 2
5c7382c
+Cipher = chacha20
5c7382c
+Key = 0000000000000000000000000000000000000000000000000000000000000001
5c7382c
+#Counter (first 4 bytes) expressed in little-endian order
5c7382c
+IV = 01000000000000000000000000000002
5c7382c
+Plaintext = 416e79207375626d697373696f6e20746f20746865204945544620696e74656e6465642062792074686520436f6e7472696275746f7220666f72207075626c69636174696f6e20617320616c6c206f722070617274206f6620616e204945544620496e7465726e65742d4472616674206f722052464320616e6420616e792073746174656d656e74206d6164652077697468696e2074686520636f6e74657874206f6620616e204945544620616374697669747920697320636f6e7369646572656420616e20224945544620436f6e747269627574696f6e222e20537563682073746174656d656e747320696e636c756465206f72616c2073746174656d656e747320696e20494554462073657373696f6e732c2061732077656c6c206173207772697474656e20616e6420656c656374726f6e696320636f6d6d756e69636174696f6e73206d61646520617420616e792074696d65206f7220706c6163652c207768696368206172652061646472657373656420746f
5c7382c
+Ciphertext = a3fbf07df3fa2fde4f376ca23e82737041605d9f4f4f57bd8cff2c1d4b7955ec2a97948bd3722915c8f3d337f7d370050e9e96d647b7c39f56e031ca5eb6250d4042e02785ececfa4b4bb5e8ead0440e20b6e8db09d881a7c6132f420e52795042bdfa7773d8a9051447b3291ce1411c680465552aa6c405b7764d5e87bea85ad00f8449ed8f72d0d662ab052691ca66424bc86d2df80ea41f43abf937d3259dc4b2d0dfb48a6c9139ddd7f76966e928e635553ba76c5c879d7b35d49eb2e62b0871cdac638939e25e8a1e0ef9d5280fa8ca328b351c3c765989cbcf3daa8b6ccc3aaf9f3979c92b3720fc88dc95ed84a1be059c6499b9fda236e7e818b04b0bc39c1e876b193bfe5569753f88128cc08aaa9b63d1a16f80ef2554d7189c411f5869ca52c5b83fa36ff216b9c1d30062bebcfd2dc5bce0911934fda79a86f6e698ced759c3ff9b6477338f3da4f9cd8514ea9982ccafb341b2384dd902f3d1ab7ac61dd29c6f21ba5b862f3730e37cfdc4fd806c22f221
5c7382c
+
5c7382c
+# A.2 Test Vector 3
5c7382c
+Cipher = chacha20
5c7382c
+Key = 1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0
5c7382c
+#Counter (first 4 bytes) expressed in little-endian order
5c7382c
+IV = 2a000000000000000000000000000002
5c7382c
+Plaintext = 2754776173206272696c6c69672c20616e642074686520736c6974687920746f7665730a446964206779726520616e642067696d626c6520696e2074686520776162653a0a416c6c206d696d737920776572652074686520626f726f676f7665732c0a416e6420746865206d6f6d65207261746873206f757467726162652e
5c7382c
+Ciphertext = 62e6347f95ed87a45ffae7426f27a1df5fb69110044c0d73118effa95b01e5cf166d3df2d721caf9b21e5fb14c616871fd84c54f9d65b283196c7fe4f60553ebf39c6402c42234e32a356b3e764312a61a5532055716ead6962568f87d3f3f7704c6a8d1bcd1bf4d50d6154b6da731b187b58dfd728afa36757a797ac188d1
5c7382c
+
5c7382c
+Title = Chacha20
5c7382c
+
5c7382c
 Cipher = chacha20
5c7382c
 Key = 0000000000000000000000000000000000000000000000000000000000000001
5c7382c
 IV = 00000000000000000000000000000000
5c7382c
@@ -2506,3 +2563,12 @@ AAD = f33388860000000000004e91
5c7382c
 Tag = e0723bce23528ce6ccb10ff9627038bf
5c7382c
 Plaintext = 496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d
5c7382c
 Ciphertext = 64a0861575861af460f062c79be643bd5e805cfd345cf389f108670ac76c8cb24c6cfc18755d43eea09ee94e382d26b0bdb7b73c321b0100d4f03b7f355894cf332f830e710b97ce98c8a84abd0b948114ad176e008d33bd60f982b1ff37c8559797a06ef4f0ef61c186324e2b3506383606907b6a7c02b0f9f6157b53c867e4b9166c767b804d46a59b5216cde7a4e99040c5a40433225ee282a1b0a06c523eaf4534d7f83fa1155b0047718cbc546a0d072b04b3564eea1b422273f548271a0bb2316053fa76991955ebd63159434ecebb4e466dae5a1073a6727627097a1049e617d91d361094fa68f0ff77987130305beaba2eda04df997b714d6c6f2c299da65ba25e6a85842bf0440fd98a9a2266b061c4b3a13327c090f9a0789f58aad805275e4378a525f19232bfbfb749ede38480f405cf43ec2f1f8619ebcbc80a89e92a859c7911e674977ab17d4a7126a6b8a477358ff14a344d276ef6e504e10268ac3619fcf90c2d6c03fc2e3d1f290d9bf26c1fa1495dd8f97eec6229a55c2354e4524143551a5cc370a1c622c9390530cff21c3e1ed50c5e3daf97518ccce34156bdbd7eafab8bd417aef25c6c927301731bd319d247a1d5c3186ed10bfd9a7a24bac30e3e4503ed9204154d338b79ea276e7058e7f20f4d4fd1ac93d63f611af7b6d006c2a72add0eedc497b19cb30a198816664f0da00155f2e2d6ac61045b296d614301e0ad4983308028850dd4feffe3a8163970306e4047f5a165cb4befbc129729cd2e286e837e9b606486d402acc3dec5bf8b92387f6e486f2140
5c7382c
+
5c7382c
+Cipher = chacha20-poly1305
5c7382c
+Key = 1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0
5c7382c
+IV = ff000000000102030405060708
5c7382c
+AAD = f33388860000000000004e91
5c7382c
+Tag = e0723bce23528ce6ccb10ff9627038bf
5c7382c
+Plaintext = 496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d
5c7382c
+Ciphertext = 64a0861575861af460f062c79be643bd5e805cfd345cf389f108670ac76c8cb24c6cfc18755d43eea09ee94e382d26b0bdb7b73c321b0100d4f03b7f355894cf332f830e710b97ce98c8a84abd0b948114ad176e008d33bd60f982b1ff37c8559797a06ef4f0ef61c186324e2b3506383606907b6a7c02b0f9f6157b53c867e4b9166c767b804d46a59b5216cde7a4e99040c5a40433225ee282a1b0a06c523eaf4534d7f83fa1155b0047718cbc546a0d072b04b3564eea1b422273f548271a0bb2316053fa76991955ebd63159434ecebb4e466dae5a1073a6727627097a1049e617d91d361094fa68f0ff77987130305beaba2eda04df997b714d6c6f2c299da65ba25e6a85842bf0440fd98a9a2266b061c4b3a13327c090f9a0789f58aad805275e4378a525f19232bfbfb749ede38480f405cf43ec2f1f8619ebcbc80a89e92a859c7911e674977ab17d4a7126a6b8a477358ff14a344d276ef6e504e10268ac3619fcf90c2d6c03fc2e3d1f290d9bf26c1fa1495dd8f97eec6229a55c2354e4524143551a5cc370a1c622c9390530cff21c3e1ed50c5e3daf97518ccce34156bdbd7eafab8bd417aef25c6c927301731bd319d247a1d5c3186ed10bfd9a7a24bac30e3e4503ed9204154d338b79ea276e7058e7f20f4d4fd1ac93d63f611af7b6d006c2a72add0eedc497b19cb30a198816664f0da00155f2e2d6ac61045b296d614301e0ad4983308028850dd4feffe3a8163970306e4047f5a165cb4befbc129729cd2e286e837e9b606486d402acc3dec5bf8b92387f6e486f2140
5c7382c
+Result = INVALID_IV_LENGTH
5c7382c
diff -up openssl-1.1.1b/test/recipes/30-test_evp_data/evpmac.txt.sync openssl-1.1.1b/test/recipes/30-test_evp_data/evpmac.txt
5c7382c
--- openssl-1.1.1b/test/recipes/30-test_evp_data/evpmac.txt.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/test/recipes/30-test_evp_data/evpmac.txt	2019-05-03 08:55:51.539406883 +0200
5c7382c
@@ -351,6 +351,14 @@ Input = "Sample message for keylen>block
5c7382c
 Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384858687
5c7382c
 Output = 5f464f5e5b7848e3885e49b2c385f0694985d0e38966242dc4a5fe3fea4b37d46b65ceced5dcf59438dd840bab22269f0ba7febdb9fcf74602a35666b2a32915
5c7382c
 
5c7382c
+Title = HMAC self generated tests
5c7382c
+
5c7382c
+MAC = HMAC
5c7382c
+Algorithm = SHAKE128
5c7382c
+Input = "Test that SHAKE128 fails"
5c7382c
+Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
5c7382c
+Result = DIGESTSIGNINIT_ERROR
5c7382c
+
5c7382c
 
5c7382c
 Title = CMAC tests (from FIPS module)
5c7382c
 
5c7382c
diff -up openssl-1.1.1b/test/recipes/80-test_cms.t.sync openssl-1.1.1b/test/recipes/80-test_cms.t
5c7382c
--- openssl-1.1.1b/test/recipes/80-test_cms.t.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/test/recipes/80-test_cms.t	2019-05-03 08:55:51.533406986 +0200
5c7382c
@@ -308,6 +308,14 @@ my @smime_cms_param_tests = (
5c7382c
 	"-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
5c7382c
     ],
5c7382c
 
5c7382c
+    [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=-3",
5c7382c
+      [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
5c7382c
+	"-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
5c7382c
+	"-keyopt", "rsa_pss_saltlen:-3", "-out", "test.cms" ],
5c7382c
+      [ "-verify", "-in", "test.cms", "-inform", "PEM",
5c7382c
+	"-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
5c7382c
+    ],
5c7382c
+
5c7382c
     [ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
5c7382c
       [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach", "-noattr",
5c7382c
 	"-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
5c7382c
diff -up openssl-1.1.1b/test/rsa_test.c.sync openssl-1.1.1b/test/rsa_test.c
5c7382c
--- openssl-1.1.1b/test/rsa_test.c.sync	2019-02-26 15:15:30.000000000 +0100
5c7382c
+++ openssl-1.1.1b/test/rsa_test.c	2019-05-03 08:55:51.523407157 +0200
5c7382c
@@ -1,5 +1,5 @@
5c7382c
 /*
5c7382c
- * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
+ * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved.
5c7382c
  *
5c7382c
  * Licensed under the OpenSSL license (the "License").  You may not use
5c7382c
  * this file except in compliance with the License.  You can obtain a copy
5c7382c
@@ -268,6 +268,36 @@ err:
5c7382c
     return ret;
5c7382c
 }
5c7382c
 
5c7382c
+static int test_rsa_sslv23(int idx)
5c7382c
+{
5c7382c
+    int ret = 0;
5c7382c
+    RSA *key;
5c7382c
+    unsigned char ptext[256];
5c7382c
+    unsigned char ctext[256];
5c7382c
+    static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
5c7382c
+    unsigned char ctext_ex[256];
5c7382c
+    int plen;
5c7382c
+    int clen = 0;
5c7382c
+    int num;
5c7382c
+
5c7382c
+    plen = sizeof(ptext_ex) - 1;
5c7382c
+    clen = rsa_setkey(&key, ctext_ex, idx);
5c7382c
+
5c7382c
+    num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
5c7382c
+                             RSA_SSLV23_PADDING);
5c7382c
+    if (!TEST_int_eq(num, clen))
5c7382c
+        goto err;
5c7382c
+
5c7382c
+    num = RSA_private_decrypt(num, ctext, ptext, key, RSA_SSLV23_PADDING);
5c7382c
+    if (!TEST_mem_eq(ptext, num, ptext_ex, plen))
5c7382c
+        goto err;
5c7382c
+
5c7382c
+    ret = 1;
5c7382c
+err:
5c7382c
+    RSA_free(key);
5c7382c
+    return ret;
5c7382c
+}
5c7382c
+
5c7382c
 static int test_rsa_oaep(int idx)
5c7382c
 {
5c7382c
     int ret = 0;
5c7382c
@@ -332,6 +362,7 @@ err:
5c7382c
 int setup_tests(void)
5c7382c
 {
5c7382c
     ADD_ALL_TESTS(test_rsa_pkcs1, 3);
5c7382c
+    ADD_ALL_TESTS(test_rsa_sslv23, 3);
5c7382c
     ADD_ALL_TESTS(test_rsa_oaep, 3);
5c7382c
     return 1;
5c7382c
 }