#12 Rebase to upstream version OpenSSL 3.0.0
Merged a year ago by saprasad. Opened 2 years ago by saprasad.
rpms/ saprasad/openssl rawhide  into  rawhide

file modified
+1
@@ -52,3 +52,4 @@ 

  /openssl-1.1.1i-hobbled.tar.xz

  /openssl-1.1.1j-hobbled.tar.xz

  /openssl-1.1.1k-hobbled.tar.xz

+ /openssl-3.0.0-hobbled.tar.xz

@@ -0,0 +1,33 @@ 

+ From 603a35802319c0459737e3f067369ceb990fe2e6 Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 24 Sep 2020 09:01:41 +0200

+ Subject: Aarch64 and ppc64le use lib64

+ 

+ (Was openssl-1.1.1-build.patch)

+ ---

+  Configurations/10-main.conf | 2 ++

+  1 file changed, 2 insertions(+)

+ 

+ diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf

+ index d7580bf3e1..a7dbfd7f40 100644

+ --- a/Configurations/10-main.conf

+ +++ b/Configurations/10-main.conf

+ @@ -723,6 +723,7 @@ my %targets = (

+          lib_cppflags     => add("-DL_ENDIAN"),

+          asm_arch         => 'ppc64',

+          perlasm_scheme   => "linux64le",

+ +        multilib         => "64",

+      },

+  

+      "linux-armv4" => {

+ @@ -765,6 +766,7 @@ my %targets = (

+          inherit_from     => [ "linux-generic64" ],

+          asm_arch         => 'aarch64',

+          perlasm_scheme   => "linux64",

+ +        multilib         => "64",

+      },

+      "linux-arm64ilp32" => {  # https://wiki.linaro.org/Platform/arm64-ilp32

+          inherit_from     => [ "linux-generic32" ],

+ -- 

+ 2.26.2

+ 

file renamed
+24 -7
@@ -1,7 +1,21 @@ 

- diff -up openssl-1.1.1a/apps/openssl.cnf.defaults openssl-1.1.1a/apps/openssl.cnf

- --- openssl-1.1.1a/apps/openssl.cnf.defaults	2018-11-20 14:35:37.000000000 +0100

- +++ openssl-1.1.1a/apps/openssl.cnf	2019-01-15 13:56:50.841719776 +0100

- @@ -74,7 +74,7 @@ cert_opt 	= ca_default		# Certificate fi

+ From 41df9ae215cee9574e17e6f887c96a7c97d588f5 Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 24 Sep 2020 09:03:40 +0200

+ Subject: Use more general default values in openssl.cnf

+ 

+ Also set sha256 as default hash, although that should not be

+ necessary anymore.

+ 

+ (was openssl-1.1.1-defaults.patch)

+ ---

+  apps/openssl.cnf | 12 +++++++-----

+  1 file changed, 7 insertions(+), 5 deletions(-)

+ 

+ diff --git a/apps/openssl.cnf b/apps/openssl.cnf

+ index 97567a67be..eb25a0ac48 100644

+ --- a/apps/openssl.cnf

+ +++ b/apps/openssl.cnf

+ @@ -104,7 +104,7 @@ cert_opt 	= ca_default		# Certificate field options

   

   default_days	= 365			# how long to certify for

   default_crl_days= 30			# how long before next CRL
@@ -10,7 +24,7 @@ 

   preserve	= no			# keep passed DN ordering

   

   # A few difference way of specifying how similar the request should look

- @@ -106,6 +106,7 @@ emailAddress		= optional

+ @@ -136,6 +136,7 @@ emailAddress		= optional

   ####################################################################

   [ req ]

   default_bits		= 2048
@@ -18,7 +32,7 @@ 

   default_keyfile 	= privkey.pem

   distinguished_name	= req_distinguished_name

   attributes		= req_attributes

- @@ -128,17 +129,18 @@ string_mask = utf8only

+ @@ -158,17 +159,18 @@ string_mask = utf8only

   

   [ req_distinguished_name ]

   countryName			= Country Name (2 letter code)
@@ -40,7 +54,7 @@ 

   

   # we can do this but it is not needed normally :-)

   #1.organizationName		= Second Organization Name (eg, company)

- @@ -147,7 +149,7 @@ localityName			= Locality Name (eg, city

+ @@ -177,7 +179,7 @@ localityName			= Locality Name (eg, city)

   organizationalUnitName		= Organizational Unit Name (eg, section)

   #organizationalUnitName_default	=

   
@@ -49,3 +63,6 @@ 

   commonName_max			= 64

   

   emailAddress			= Email Address

+ -- 

+ 2.26.2

+ 

@@ -0,0 +1,26 @@ 

+ From 3d5755df8d09ca841c0aca2d7344db060f6cc97f Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 24 Sep 2020 09:05:55 +0200

+ Subject: Do not install html docs

+ 

+ (was openssl-1.1.1-no-html.patch)

+ ---

+  Configurations/unix-Makefile.tmpl | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl

+ index 342e46d24d..9f369edf0e 100644

+ --- a/Configurations/unix-Makefile.tmpl

+ +++ b/Configurations/unix-Makefile.tmpl

+ @@ -554,7 +554,7 @@ install_sw: install_dev install_engines install_modules install_runtime

+  

+  uninstall_sw: uninstall_runtime uninstall_modules uninstall_engines uninstall_dev

+  

+ -install_docs: install_man_docs install_html_docs

+ +install_docs: install_man_docs

+  

+  uninstall_docs: uninstall_man_docs uninstall_html_docs

+  	$(RM) -r $(DESTDIR)$(DOCDIR)

+ -- 

+ 2.26.2

+ 

@@ -0,0 +1,73 @@ 

+ From 6790960076742a9053c624e26fbb87fcd5789e27 Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 24 Sep 2020 09:17:26 +0200

+ Subject: Override default paths for the CA directory tree

+ 

+ Also add default section to load crypto-policies configuration

+ for TLS.

+ 

+ It needs to be reverted before running tests.

+ 

+ (was openssl-1.1.1-conf-paths.patch)

+ ---

+  apps/CA.pl.in    |  2 +-

+  apps/openssl.cnf | 20 ++++++++++++++++++--

+  2 files changed, 19 insertions(+), 3 deletions(-)

+ 

+ diff --git a/apps/CA.pl.in b/apps/CA.pl.in

+ index c0afb96716..d6a5fabd16 100644

+ --- a/apps/CA.pl.in

+ +++ b/apps/CA.pl.in

+ @@ -29,7 +29,7 @@ my $X509 = "$openssl x509";

+  my $PKCS12 = "$openssl pkcs12";

+  

+  # Default values for various configuration settings.

+ -my $CATOP = "./demoCA";

+ +my $CATOP = "/etc/pki/CA";

+  my $CAKEY = "cakey.pem";

+  my $CAREQ = "careq.pem";

+  my $CACERT = "cacert.pem";

+ diff -up openssl-3.0.0-alpha16/apps/openssl.cnf.default-tls openssl-3.0.0-alpha16/apps/openssl.cnf

+ --- openssl-3.0.0-alpha16/apps/openssl.cnf.default-tls	2021-07-06 13:41:39.204978272 +0200

+ +++ openssl-3.0.0-alpha16/apps/openssl.cnf	2021-07-06 13:49:50.362857683 +0200

+ @@ -53,6 +53,8 @@ tsa_policy3 = 1.2.3.4.5.7

+  

+  [openssl_init]

+  providers = provider_sect

+ +# Load default TLS policy configuration

+ +ssl_conf = ssl_module

+  

+  # List of providers to load

+  [provider_sect]

+ @@ -64,6 +66,13 @@ default = default_sect

+  [default_sect]

+  # activate = 1

+  

+ +[ ssl_module ]

+ +

+ +system_default = crypto_policy

+ +

+ +[ crypto_policy ]

+ +

+ +.include = /etc/crypto-policies/back-ends/opensslcnf.config

+  

+  ####################################################################

+  [ ca ]

+ @@ -72,7 +81,7 @@ default_ca	= CA_default		# The default c

+  ####################################################################

+  [ CA_default ]

+  

+ -dir		= ./demoCA		# Where everything is kept

+ +dir		= /etc/pki/CA		# Where everything is kept

+  certs		= $dir/certs		# Where the issued certs are kept

+  crl_dir		= $dir/crl		# Where the issued crl are kept

+  database	= $dir/index.txt	# database index file.

+ @@ -304,7 +313,7 @@ default_tsa = tsa_config1	# the default

+  [ tsa_config1 ]

+  

+  # These are used by the TSA reply generation only.

+ -dir		= ./demoCA		# TSA root directory

+ +dir		= /etc/pki/CA		# TSA root directory

+  serial		= $dir/tsaserial	# The current serial number (mandatory)

+  crypto_device	= builtin		# OpenSSL engine to use for signing

+  signer_cert	= $dir/tsacert.pem 	# The TSA signing certificate

@@ -0,0 +1,28 @@ 

+ From 3d8fa9859501b07e02b76b5577e2915d5851e927 Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 24 Sep 2020 09:27:18 +0200

+ Subject: apps/ca: fix md option help text

+ 

+ upstreamable

+ 

+ (was openssl-1.1.1-apps-dgst.patch)

+ ---

+  apps/ca.c | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/apps/ca.c b/apps/ca.c

+ index 0f21b4fa1c..3d4b2c1673 100755

+ --- a/apps/ca.c

+ +++ b/apps/ca.c

+ @@ -209,7 +209,7 @@ const OPTIONS ca_options[] = {

+      {"noemailDN", OPT_NOEMAILDN, '-', "Don't add the EMAIL field to the DN"},

+  

+      OPT_SECTION("Signing"),

+ -    {"md", OPT_MD, 's', "Digest to use, such as sha256"},

+ +    {"md", OPT_MD, 's', "Digest to use, such as sha256; see openssl help for list"},

+      {"keyfile", OPT_KEYFILE, 's', "The CA private key"},

+      {"keyform", OPT_KEYFORM, 'f',

+       "Private key file format (ENGINE, other values ignored)"},

+ -- 

+ 2.26.2

+ 

@@ -0,0 +1,29 @@ 

+ From 3f9deff30ae6efbfe979043b00cdf649b39793c0 Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 24 Sep 2020 09:51:34 +0200

+ Subject: Disable signature verification with totally unsafe hash algorithms

+ 

+ (was openssl-1.1.1-no-weak-verify.patch)

+ ---

+  crypto/asn1/a_verify.c | 5 +++++

+  1 file changed, 5 insertions(+)

+ 

+ diff --git a/crypto/asn1/a_verify.c b/crypto/asn1/a_verify.c

+ index b7eed914b0..af62f0ef08 100644

+ --- a/crypto/asn1/a_verify.c

+ +++ b/crypto/asn1/a_verify.c

+ @@ -152,6 +152,11 @@ int ASN1_item_verify_ctx(const ASN1_ITEM *it, const X509_ALGOR *alg,

+              ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);

+          if (ret <= 1)

+              goto err;

+ +    } else if ((mdnid == NID_md5

+ +               && ossl_safe_getenv("OPENSSL_ENABLE_MD5_VERIFY") == NULL) ||

+ +               mdnid == NID_md4 || mdnid == NID_md2 || mdnid == NID_sha) {

+ +        ERR_raise(ERR_LIB_ASN1, ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);

+ +        goto err;

+      } else {

+          const EVP_MD *type = NULL;

+  

+ -- 

+ 2.26.2

+ 

@@ -0,0 +1,331 @@ 

+ From 736d709ec194b3a763e004696df22792c62a11fc Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 24 Sep 2020 10:16:46 +0200

+ Subject: Add support for PROFILE=SYSTEM system default cipherlist

+ 

+ (was openssl-1.1.1-system-cipherlist.patch)

+ ---

+  Configurations/unix-Makefile.tmpl |  5 ++

+  Configure                         | 10 +++-

+  doc/man1/openssl-ciphers.pod.in   |  9 ++++

+  include/openssl/ssl.h.in          |  5 ++

+  ssl/ssl_ciph.c                    | 88 +++++++++++++++++++++++++++----

+  ssl/ssl_lib.c                     |  4 +-

+  test/cipherlist_test.c            |  2 +

+  util/libcrypto.num                |  1 +

+  8 files changed, 110 insertions(+), 14 deletions(-)

+ 

+ diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl

+ index 9f369edf0e..c52389f831 100644

+ --- a/Configurations/unix-Makefile.tmpl

+ +++ b/Configurations/unix-Makefile.tmpl

+ @@ -269,6 +269,10 @@ MANDIR=$(INSTALLTOP)/share/man

+  DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)

+  HTMLDIR=$(DOCDIR)/html

+  

+ +{- output_off() if $config{system_ciphers_file} eq ""; "" -}

+ +SYSTEM_CIPHERS_FILE_DEFINE=-DSYSTEM_CIPHERS_FILE="\"{- $config{system_ciphers_file} -}\""

+ +{- output_on() if $config{system_ciphers_file} eq ""; "" -}

+ +

+  # MANSUFFIX is for the benefit of anyone who may want to have a suffix

+  # appended after the manpage file section number.  "ssl" is popular,

+  # resulting in files such as config.5ssl rather than config.5.

+ @@ -292,6 +296,7 @@ CC=$(CROSS_COMPILE){- $config{CC} -}

+  CXX={- $config{CXX} ? "\$(CROSS_COMPILE)$config{CXX}" : '' -}

+  CPPFLAGS={- our $cppflags1 = join(" ",

+                                    (map { "-D".$_} @{$config{CPPDEFINES}}),

+ +                                  "\$(SYSTEM_CIPHERS_FILE_DEFINE)",

+                                    (map { "-I".$_} @{$config{CPPINCLUDES}}),

+                                    @{$config{CPPFLAGS}}) -}

+  CFLAGS={- join(' ', @{$config{CFLAGS}}) -}

+ diff --git a/doc/man1/openssl-ciphers.pod.in b/doc/man1/openssl-ciphers.pod.in

+ index b4ed3e51d5..2122e6bdfd 100644

+ --- a/doc/man1/openssl-ciphers.pod.in

+ +++ b/doc/man1/openssl-ciphers.pod.in

+ @@ -187,6 +187,15 @@ As of OpenSSL 1.0.0, the B<ALL> cipher suites are sensibly ordered by default.

+  

+  The cipher suites not enabled by B<ALL>, currently B<eNULL>.

+  

+ +=item B<PROFILE=SYSTEM>

+ +

+ +The list of enabled cipher suites will be loaded from the system crypto policy

+ +configuration file B</etc/crypto-policies/back-ends/openssl.config>.

+ +See also L<update-crypto-policies(8)>.

+ +This is the default behavior unless an application explicitly sets a cipher

+ +list. If used in a cipher list configuration value this string must be at the

+ +beginning of the cipher list, otherwise it will not be recognized.

+ +

+  =item B<HIGH>

+  

+  "High" encryption cipher suites. This currently means those with key lengths

+ diff --git a/include/openssl/ssl.h.in b/include/openssl/ssl.h.in

+ index f9a61609e4..c6f95fed3f 100644

+ --- a/include/openssl/ssl.h.in

+ +++ b/include/openssl/ssl.h.in

+ @@ -209,6 +209,11 @@ extern "C" {

+   * throwing out anonymous and unencrypted ciphersuites! (The latter are not

+   * actually enabled by ALL, but "ALL:RSA" would enable some of them.)

+   */

+ +# ifdef SYSTEM_CIPHERS_FILE

+ +#  define SSL_SYSTEM_DEFAULT_CIPHER_LIST "PROFILE=SYSTEM"

+ +# else

+ +#  define SSL_SYSTEM_DEFAULT_CIPHER_LIST OSSL_default_cipher_list()

+ +# endif

+  

+  /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */

+  # define SSL_SENT_SHUTDOWN       1

+ diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c

+ index b1d3f7919e..f7cc7fed48 100644

+ --- a/ssl/ssl_ciph.c

+ +++ b/ssl/ssl_ciph.c

+ @@ -1411,6 +1411,53 @@ int SSL_set_ciphersuites(SSL *s, const char *str)

+      return ret;

+  }

+  

+ +#ifdef SYSTEM_CIPHERS_FILE

+ +static char *load_system_str(const char *suffix)

+ +{

+ +    FILE *fp;

+ +    char buf[1024];

+ +    char *new_rules;

+ +    const char *ciphers_path;

+ +    unsigned len, slen;

+ +

+ +    if ((ciphers_path = ossl_safe_getenv("OPENSSL_SYSTEM_CIPHERS_OVERRIDE")) == NULL)

+ +        ciphers_path = SYSTEM_CIPHERS_FILE;

+ +    fp = fopen(ciphers_path, "r");

+ +    if (fp == NULL || fgets(buf, sizeof(buf), fp) == NULL) {

+ +        /* cannot open or file is empty */

+ +        snprintf(buf, sizeof(buf), "%s", SSL_DEFAULT_CIPHER_LIST);

+ +    }

+ +

+ +    if (fp)

+ +        fclose(fp);

+ +

+ +    slen = strlen(suffix);

+ +    len = strlen(buf);

+ +

+ +    if (buf[len - 1] == '\n') {

+ +        len--;

+ +        buf[len] = 0;

+ +    }

+ +    if (buf[len - 1] == '\r') {

+ +        len--;

+ +        buf[len] = 0;

+ +    }

+ +

+ +    new_rules = OPENSSL_malloc(len + slen + 1);

+ +    if (new_rules == 0)

+ +        return NULL;

+ +

+ +    memcpy(new_rules, buf, len);

+ +    if (slen > 0) {

+ +        memcpy(&new_rules[len], suffix, slen);

+ +        len += slen;

+ +    }

+ +    new_rules[len] = 0;

+ +

+ +    return new_rules;

+ +}

+ +#endif

+ +

+  STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+                                               STACK_OF(SSL_CIPHER) *tls13_ciphersuites,

+                                               STACK_OF(SSL_CIPHER) **cipher_list,

+ @@ -1425,15 +1472,25 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+      CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;

+      const SSL_CIPHER **ca_list = NULL;

+      const SSL_METHOD *ssl_method = ctx->method;

+ +#ifdef SYSTEM_CIPHERS_FILE

+ +    char *new_rules = NULL;

+ +

+ +    if (rule_str != NULL && strncmp(rule_str, "PROFILE=SYSTEM", 14) == 0) {

+ +        char *p = rule_str + 14;

+ +

+ +        new_rules = load_system_str(p);

+ +        rule_str = new_rules;

+ +    }

+ +#endif

+  

+      /*

+       * Return with error if nothing to do.

+       */

+      if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL)

+ -        return NULL;

+ +        goto err;

+ 

+      if (!check_suiteb_cipher_list(ssl_method, c, &rule_str))

+ -        return NULL;

+ +        goto err;

+  

+      /*

+       * To reduce the work to do we only want to process the compiled

+ @@ -1456,7 +1513,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+      co_list = OPENSSL_malloc(sizeof(*co_list) * num_of_ciphers);

+      if (co_list == NULL) {

+          ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);

+ -        return NULL;          /* Failure */

+ +        goto err;

+      }

+  

+      ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers,

+ @@ -1522,8 +1579,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+       * in force within each class

+       */

+      if (!ssl_cipher_strength_sort(&head, &tail)) {

+ -        OPENSSL_free(co_list);

+ -        return NULL;

+ +        goto err;

+      }

+  

+      /*

+ @@ -1568,9 +1624,8 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+      num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;

+      ca_list = OPENSSL_malloc(sizeof(*ca_list) * num_of_alias_max);

+      if (ca_list == NULL) {

+ -        OPENSSL_free(co_list);

+          ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);

+ -        return NULL;          /* Failure */

+ +        goto err;

+      }

+      ssl_cipher_collect_aliases(ca_list, num_of_group_aliases,

+                                 disabled_mkey, disabled_auth, disabled_enc,

+ @@ -1596,8 +1651,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+      OPENSSL_free(ca_list);      /* Not needed anymore */

+  

+      if (!ok) {                  /* Rule processing failure */

+ -        OPENSSL_free(co_list);

+ -        return NULL;

+ +        goto err;

+      }

+  

+      /*

+ @@ -1605,10 +1659,13 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+       * if we cannot get one.

+       */

+      if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) {

+ -        OPENSSL_free(co_list);

+ -        return NULL;

+ +        goto err;

+      }

+  

+ +#ifdef SYSTEM_CIPHERS_FILE

+ +    OPENSSL_free(new_rules);    /* Not needed anymore */

+ +#endif

+ +

+      /* Add TLSv1.3 ciphers first - we always prefer those if possible */

+      for (i = 0; i < sk_SSL_CIPHER_num(tls13_ciphersuites); i++) {

+          const SSL_CIPHER *sslc = sk_SSL_CIPHER_value(tls13_ciphersuites, i);

+ @@ -1622,6 +1679,7 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+  

+          if (!sk_SSL_CIPHER_push(cipherstack, sslc)) {

+              sk_SSL_CIPHER_free(cipherstack);

+ +            OPENSSL_free(co_list);

+              return NULL;

+          }

+      }

+ @@ -1656,6 +1714,14 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_CTX *ctx,

+      *cipher_list = cipherstack;

+  

+      return cipherstack;

+ +

+ +err:

+ +    OPENSSL_free(co_list);

+ +#ifdef SYSTEM_CIPHERS_FILE

+ +    OPENSSL_free(new_rules);

+ +#endif

+ +    return NULL;

+ +  

+  }

+  

+  char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)

+ diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c

+ index d14d5819ba..48d491219a 100644

+ --- a/ssl/ssl_lib.c

+ +++ b/ssl/ssl_lib.c

+ @@ -660,7 +660,7 @@ int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth)

+                                  ctx->tls13_ciphersuites,

+                                  &(ctx->cipher_list),

+                                  &(ctx->cipher_list_by_id),

+ -                                OSSL_default_cipher_list(), ctx->cert);

+ +                                SSL_SYSTEM_DEFAULT_CIPHER_LIST, ctx->cert);

+      if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) {

+          ERR_raise(ERR_LIB_SSL, SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);

+          return 0;

+ @@ -3193,7 +3193,7 @@ SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq,

+      if (!ssl_create_cipher_list(ret,

+                                  ret->tls13_ciphersuites,

+                                  &ret->cipher_list, &ret->cipher_list_by_id,

+ -                                OSSL_default_cipher_list(), ret->cert)

+ +                                SSL_SYSTEM_DEFAULT_CIPHER_LIST, ret->cert)

+          || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {

+          ERR_raise(ERR_LIB_SSL, SSL_R_LIBRARY_HAS_NO_CIPHERS);

+          goto err2;

+ diff --git a/test/cipherlist_test.c b/test/cipherlist_test.c

+ index 380f0727fc..6922a87c30 100644

+ --- a/test/cipherlist_test.c

+ +++ b/test/cipherlist_test.c

+ @@ -244,7 +244,9 @@ end:

+  

+  int setup_tests(void)

+  {

+ +#ifndef SYSTEM_CIPHERS_FILE

+      ADD_TEST(test_default_cipherlist_implicit);

+ +#endif

+      ADD_TEST(test_default_cipherlist_explicit);

+      ADD_TEST(test_default_cipherlist_clear);

+      return 1;

+ diff --git a/util/libcrypto.num b/util/libcrypto.num

+ index 404a706fab..e81fa9ec3e 100644

+ --- a/util/libcrypto.num

+ +++ b/util/libcrypto.num

+ @@ -5282,3 +5282,4 @@ OSSL_DECODER_CTX_set_input_structure    ?	3_0_0	EXIST::FUNCTION:

+  ASN1_TIME_print_ex                      5553	3_0_0	EXIST::FUNCTION:

+  EVP_PKEY_get0_provider                  5554	3_0_0	EXIST::FUNCTION:

+  EVP_PKEY_CTX_get0_provider              5555	3_0_0	EXIST::FUNCTION:

+ +ossl_safe_getenv                        ?	3_0_0	EXIST::FUNCTION:

+ -- 

+ 2.26.2

+ 

+ diff -up openssl-3.0.0-beta1/Configure.sys-default openssl-3.0.0-beta1/Configure

+ --- openssl-3.0.0-beta1/Configure.sys-default	2021-06-29 11:47:58.978144386 +0200

+ +++ openssl-3.0.0-beta1/Configure	2021-06-29 11:52:01.631126260 +0200

+ @@ -27,7 +27,7 @@ use OpenSSL::config;

+  my $orig_death_handler = $SIG{__DIE__};

+  $SIG{__DIE__} = \&death_handler;

+  

+ -my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";

+ +my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--system-ciphers-file=SYSTEMCIPHERFILE] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags]\n";

+  

+  my $banner = <<"EOF";

+  

+ @@ -61,6 +61,10 @@ EOF

+  #               given with --prefix.

+  #               This becomes the value of OPENSSLDIR in Makefile and in C.

+  #               (Default: PREFIX/ssl)

+ +#

+ +# --system-ciphers-file  A file to read cipher string from when the PROFILE=SYSTEM

+ +#		cipher is specified (default).

+ +#

+  # --banner=".." Output specified text instead of default completion banner

+  #

+  # -w            Don't wait after showing a Configure warning

+ @@ -385,6 +389,7 @@ $config{prefix}="";

+  $config{openssldir}="";

+  $config{processor}="";

+  $config{libdir}="";

+ +$config{system_ciphers_file}="";

+  my $auto_threads=1;    # enable threads automatically? true by default

+  my $default_ranlib;

+  

+ @@ -987,6 +992,10 @@ while (@argvcopy)

+                          die "FIPS key too long (64 bytes max)\n"

+                             if length $1 > 64;

+                          }

+ +		elsif (/^--system-ciphers-file=(.*)$/)

+ +			{

+ +			$config{system_ciphers_file}=$1;

+ +			}

+                  elsif (/^--banner=(.*)$/)

+                          {

+                          $banner = $1 . "\n";

@@ -0,0 +1,87 @@ 

+ From 5b2ec9a54037d7b007324bf53e067e73511cdfe4 Mon Sep 17 00:00:00 2001

+ From: Tomas Mraz <tmraz@fedoraproject.org>

+ Date: Thu, 26 Nov 2020 14:00:16 +0100

+ Subject: Add FIPS_mode() compatibility macro

+ 

+ The macro calls EVP_default_properties_is_fips_enabled() on the

+ default context.

+ ---

+  include/openssl/crypto.h.in |  1 +

+  include/openssl/fips.h      | 25 +++++++++++++++++++++++++

+  test/property_test.c        | 13 +++++++++++++

+  3 files changed, 39 insertions(+)

+  create mode 100644 include/openssl/fips.h

+ 

+ diff --git a/include/openssl/crypto.h.in b/include/openssl/crypto.h.in

+ index 1036da9a2b..9d4896fcaf 100644

+ --- a/include/openssl/crypto.h.in

+ +++ b/include/openssl/crypto.h.in

+ @@ -38,6 +38,7 @@ use OpenSSL::stackhash qw(generate_stack_macros);

+  # include <openssl/opensslconf.h>

+  # include <openssl/cryptoerr.h>

+  # include <openssl/core.h>

+ +# include <openssl/fips.h>

+  

+  # ifdef CHARSET_EBCDIC

+  #  include <openssl/ebcdic.h>

+ diff --git a/include/openssl/fips.h b/include/openssl/fips.h

+ new file mode 100644

+ index 0000000000..c64f0f8e8f

+ --- /dev/null

+ +++ b/include/openssl/fips.h

+ @@ -0,0 +1,25 @@

+ +/*

+ + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.

+ + *

+ + * Licensed under the Apache License 2.0 (the "License").  You may not use

+ + * this file except in compliance with the License.  You can obtain a copy

+ + * in the file LICENSE in the source distribution or at

+ + * https://www.openssl.org/source/license.html

+ + */

+ +

+ +#ifndef OPENSSL_FIPS_H

+ +# define OPENSSL_FIPS_H

+ +# pragma once

+ +

+ +# include <openssl/macros.h>

+ +

+ +# ifdef __cplusplus

+ +extern "C" {

+ +# endif

+ +

+ +# define FIPS_mode() EVP_default_properties_is_fips_enabled(NULL)

+ +

+ +# ifdef __cplusplus

+ +}

+ +# endif

+ +#endif

+ diff -up openssl-3.0.0-beta1/test/property_test.c.fips-macro openssl-3.0.0-beta1/test/property_test.c

+ --- openssl-3.0.0-beta1/test/property_test.c.fips-macro	2021-06-29 12:14:58.851557698 +0200

+ +++ openssl-3.0.0-beta1/test/property_test.c	2021-06-29 12:17:14.630143832 +0200

+ @@ -488,6 +488,18 @@ static int test_property_list_to_string(

+      return ret;

+  }

+  

+ +static int test_downstream_FIPS_mode(void)

+ +{

+ +    int ret = 0;

+ +

+ +    ret = TEST_true(EVP_set_default_properties(NULL, "fips=yes"))

+ +          && TEST_true(FIPS_mode())

+ +          && TEST_true(EVP_set_default_properties(NULL, "fips=no"))

+ +          && TEST_false(FIPS_mode());

+ +

+ +    return ret;

+ +}

+ +

+  int setup_tests(void)

+  {

+      ADD_TEST(test_property_string);

+ @@ -500,6 +512,7 @@ int setup_tests(void)

+      ADD_TEST(test_property);

+      ADD_TEST(test_query_cache_stochastic);

+      ADD_TEST(test_fips_mode);

+ +    ADD_TEST(test_downstream_FIPS_mode);

+      ADD_ALL_TESTS(test_property_list_to_string, OSSL_NELEM(to_string_tests));

+      return 1;

+  }

@@ -0,0 +1,79 @@ 

+ diff -up openssl-3.0.0-alpha13/crypto/context.c.kernel-fips openssl-3.0.0-alpha13/crypto/context.c

+ --- openssl-3.0.0-alpha13/crypto/context.c.kernel-fips	2021-03-16 00:09:55.814826432 +0100

+ +++ openssl-3.0.0-alpha13/crypto/context.c	2021-03-16 00:15:55.129043811 +0100

+ @@ -12,11 +12,54 @@

+  #include "internal/bio.h"

+  #include "internal/provider.h"

+  

+ +#ifndef FIPS_MODULE

+ +# include <sys/types.h>

+ +# include <sys/stat.h>

+ +# include <fcntl.h>

+ +# include <unistd.h>

+ +# include <openssl/evp.h>

+ +#endif

+ +

+  struct ossl_lib_ctx_onfree_list_st {

+      ossl_lib_ctx_onfree_fn *fn;

+      struct ossl_lib_ctx_onfree_list_st *next;

+  };

+  

+ +# ifndef FIPS_MODULE

+ +# define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"

+ +

+ +static int kernel_fips_flag;

+ +

+ +static void read_kernel_fips_flag(void)

+ +{

+ +	char buf[2] = "0";

+ +	int fd;

+ +

+ +	if (ossl_safe_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {

+ +		buf[0] = '1';

+ +	} else if ((fd = open(FIPS_MODE_SWITCH_FILE, O_RDONLY)) >= 0) {

+ +		while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR) ;

+ +		close(fd);

+ +	}

+ +

+ +	if (buf[0] == '1') {

+ +		kernel_fips_flag = 1;

+ +	}

+ +

+ +		return;

+ +}

+ +

+ +static int apply_kernel_fips_flag(OSSL_LIB_CTX *ctx)

+ +{

+ +	if (kernel_fips_flag) {

+ +		return EVP_default_properties_enable_fips(ctx, 1);

+ +	}

+ +

+ +	return 1;

+ +}

+ +# endif

+ +

+ +

+  struct ossl_lib_ctx_st {

+      CRYPTO_RWLOCK *lock;

+      CRYPTO_EX_DATA data;

+ @@ -74,6 +117,12 @@ static int context_init(OSSL_LIB_CTX *ct

+      if (!ossl_property_parse_init(ctx))

+          goto err;

+  

+ +# ifndef FIPS_MODULE

+ +	/* Preset the fips=yes default property with kernel FIPS mode */

+ +	if (!apply_kernel_fips_flag(ctx))

+ +		goto err;

+ +# endif

+ +

+      return 1;

+   err:

+      if (exdata_done)

+ @@ -121,6 +170,7 @@ static CRYPTO_THREAD_LOCAL default_conte

+  

+  DEFINE_RUN_ONCE_STATIC(default_context_do_init)

+  {

+ +	 read_kernel_fips_flag();

+      return CRYPTO_THREAD_init_local(&default_context_thread_local, NULL)

+          && context_init(&default_context_int);

+  }

The added file is too large to be shown here, see it at: 0011-Remove-EC-curves.patch
@@ -0,0 +1,75 @@ 

+ diff -up openssl-3.0.0/apps/openssl.cnf.legacy-prov openssl-3.0.0/apps/openssl.cnf

+ --- openssl-3.0.0/apps/openssl.cnf.legacy-prov	2021-09-09 12:06:40.895793297 +0200

+ +++ openssl-3.0.0/apps/openssl.cnf	2021-09-09 12:12:33.947482500 +0200

+ @@ -42,36 +42,29 @@ tsa_policy1 = 1.2.3.4.1

+  tsa_policy2 = 1.2.3.4.5.6

+  tsa_policy3 = 1.2.3.4.5.7

+  

+ -# For FIPS

+ -# Optionally include a file that is generated by the OpenSSL fipsinstall

+ -# application. This file contains configuration data required by the OpenSSL

+ -# fips provider. It contains a named section e.g. [fips_sect] which is

+ -# referenced from the [provider_sect] below.

+ -# Refer to the OpenSSL security policy for more information.

+ -# .include fipsmodule.cnf

+ -

+  [openssl_init]

+  providers = provider_sect

+  # Load default TLS policy configuration

+  ssl_conf = ssl_module

+  

+ -# List of providers to load

+ -[provider_sect]

+ -default = default_sect

+ -# The fips section name should match the section name inside the

+ -# included fipsmodule.cnf.

+ -# fips = fips_sect

+ +# Uncomment the sections that start with ## below to enable the legacy provider.

+ +# Loading the legacy provider enables support for the following algorithms:

+ +# Hashing Algorithms / Message Digests: MD2, MD4, MDC2, WHIRLPOOL, RIPEMD160

+ +# Symmetric Ciphers: Blowfish, CAST, DES, IDEA, RC2, RC4,RC5, SEED

+ +# Key Derivation Function (KDF): PBKDF1

+ +# In general it is not recommended to use the above mentioned algorithms for

+ +# security critical operations, as they are cryptographically weak or vulnerable

+ +# to side-channel attacks and as such have been deprecated.

+  

+ -# If no providers are activated explicitly, the default one is activated implicitly.

+ -# See man 7 OSSL_PROVIDER-default for more details.

+ -#

+ -# If you add a section explicitly activating any other provider(s), you most

+ -# probably need to explicitly activate the default provider, otherwise it

+ -# becomes unavailable in openssl.  As a consequence applications depending on

+ -# OpenSSL may not work correctly which could lead to significant system

+ -# problems including inability to remotely access the system.

+ -[default_sect]

+ -# activate = 1

+ +[provider_sect]

+ +##default = default_sect

+ +##legacy = legacy_sect

+ +##

+ +##[default_sect]

+ +##activate = 1

+ +##

+ +##[legacy_sect]

+ +##activate = 1

+  

+  [ ssl_module ]

+  

+ diff -up openssl-3.0.0/doc/man5/config.pod.legacy-prov openssl-3.0.0/doc/man5/config.pod

+ --- openssl-3.0.0/doc/man5/config.pod.legacy-prov	2021-09-09 12:09:38.079040853 +0200

+ +++ openssl-3.0.0/doc/man5/config.pod	2021-09-09 12:11:56.646224876 +0200

+ @@ -273,6 +273,14 @@ significant.

+  All parameters in the section as well as sub-sections are made

+  available to the provider.

+  

+ +=head3 Loading the legacy provider

+ +

+ +Uncomment the sections that start with ## in openssl.cnf

+ +to enable the legacy provider.

+ +Note: In general it is not recommended to use the above mentioned algorithms for

+ +security critical operations, as they are cryptographically weak or vulnerable

+ +to side-channel attacks and as such have been deprecated.

+ +

+  =head3 Default provider and its activation

+  

+  If no providers are activated explicitly, the default one is activated implicitly.

@@ -0,0 +1,7 @@ 

+ /* Prepended at openssl package build-time.  Don't include this file directly,

+  * use <openssl/opensslconf.h> instead. */

+ 

+ #ifndef openssl_conf_multilib_redirection_h

+ #error "Don't include this file directly, use <openssl/opensslconf.h> instead!"

+ #endif

+ 

@@ -0,0 +1,47 @@ 

+ /* This file is here to prevent a file conflict on multiarch systems.  A

+  * conflict will frequently occur because arch-specific build-time

+  * configuration options are stored (and used, so they can't just be stripped

+  * out) in configuration.h.  The original configuration.h has been renamed.

+  * DO NOT INCLUDE THE NEW FILE DIRECTLY -- ALWAYS INCLUDE THIS ONE INSTEAD. */

+ 

+ #ifdef openssl_conf_multilib_redirection_h

+ #error "Do not define openssl_conf_multilib_redirection_h!"

+ #endif

+ #define openssl_conf_multilib_redirection_h

+ 

+ #if defined(__i386__)

+ #include "configuration-i386.h"

+ #elif defined(__ia64__)

+ #include "configuration-ia64.h"

+ #elif defined(__mips64) && defined(__MIPSEL__)

+ #include "configuration-mips64el.h"

+ #elif defined(__mips64)

+ #include "configuration-mips64.h"

+ #elif defined(__mips) && defined(__MIPSEL__)

+ #include "configuration-mipsel.h"

+ #elif defined(__mips)

+ #include "configuration-mips.h"

+ #elif defined(__powerpc64__)

+ #include <endian.h>

+ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__

+ #include "configuration-ppc64.h"

+ #else

+ #include "configuration-ppc64le.h"

+ #endif

+ #elif defined(__powerpc__)

+ #include "configuration-ppc.h"

+ #elif defined(__s390x__)

+ #include "configuration-s390x.h"

+ #elif defined(__s390__)

+ #include "configuration-s390.h"

+ #elif defined(__sparc__) && defined(__arch64__)

+ #include "configuration-sparc64.h"

+ #elif defined(__sparc__)

+ #include "configuration-sparc.h"

+ #elif defined(__x86_64__)

+ #include "configuration-x86_64.h"

+ #else

+ #error "The openssl-devel package does not work your architecture?"

+ #endif

+ 

+ #undef openssl_conf_multilib_redirection_h

file modified
+133 -87
@@ -1,17 +1,24 @@ 

  /*

-  * Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.

+  * Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.

   * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved

   *

-  * Licensed under the OpenSSL license (the "License").  You may not use

+  * Licensed under the Apache License 2.0 (the "License").  You may not use

   * this file except in compliance with the License.  You can obtain a copy

   * in the file LICENSE in the source distribution or at

   * https://www.openssl.org/source/license.html

   */

  

+ /*

+  * ECDSA low level APIs are deprecated for public use, but still ok for

+  * internal use.

+  */

+ #include "internal/deprecated.h"

+ 

  #include <string.h>

  #include "ec_local.h"

  #include <openssl/err.h>

  #include <openssl/obj_mac.h>

+ #include <openssl/objects.h>

  #include <openssl/opensslconf.h>

  #include "internal/nelem.h"

  
@@ -242,43 +249,115 @@ 

      const char *comment;

  } ec_list_element;

  

+ #ifdef FIPS_MODULE

  static const ec_list_element curve_list[] = {

      /* prime field curves */

      /* secg curves */

- #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128

-     {NID_secp224r1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,

+     {NID_secp224r1, &_EC_NIST_PRIME_224.h,

+ # if !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)

+      EC_GFp_nistp224_method,

+ # else

+      0,

+ # endif

       "NIST/SECG curve over a 224 bit prime field"},

+     /* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */

+     {NID_secp384r1, &_EC_NIST_PRIME_384.h,

+ # if defined(S390X_EC_ASM)

+      EC_GFp_s390x_nistp384_method,

+ # else

+      0,

+ # endif

+      "NIST/SECG curve over a 384 bit prime field"},

+ 

+     {NID_secp521r1, &_EC_NIST_PRIME_521.h,

+ # if defined(S390X_EC_ASM)

+      EC_GFp_s390x_nistp521_method,

+ # elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)

+      EC_GFp_nistp521_method,

+ # else

+      0,

+ # endif

+      "NIST/SECG curve over a 521 bit prime field"},

+ 

+     /* X9.62 curves */

+     {NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,

+ # if defined(ECP_NISTZ256_ASM)

+      EC_GFp_nistz256_method,

+ # elif defined(S390X_EC_ASM)

+      EC_GFp_s390x_nistp256_method,

+ # elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)

+      EC_GFp_nistp256_method,

+ # else

+      0,

+ # endif

+      "X9.62/SECG curve over a 256 bit prime field"},

+ };

+ 

  #else

+ 

+ static const ec_list_element curve_list[] = {

+     /* prime field curves */

+     /* secg curves */

+ # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128

+     {NID_secp224r1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,

+      "NIST/SECG curve over a 224 bit prime field"},

+ # else

      {NID_secp224r1, &_EC_NIST_PRIME_224.h, 0,

       "NIST/SECG curve over a 224 bit prime field"},

- #endif

+ # endif

      {NID_secp256k1, &_EC_SECG_PRIME_256K1.h, 0,

       "SECG curve over a 256 bit prime field"},

      /* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */

-     {NID_secp384r1, &_EC_NIST_PRIME_384.h, 0,

+     {NID_secp384r1, &_EC_NIST_PRIME_384.h,

+ # if defined(S390X_EC_ASM)

+      EC_GFp_s390x_nistp384_method,

+ # else

+      0,

+ # endif

       "NIST/SECG curve over a 384 bit prime field"},

- #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128

-     {NID_secp521r1, &_EC_NIST_PRIME_521.h, EC_GFp_nistp521_method,

-      "NIST/SECG curve over a 521 bit prime field"},

- #else

-     {NID_secp521r1, &_EC_NIST_PRIME_521.h, 0,

+     {NID_secp521r1, &_EC_NIST_PRIME_521.h,

+ # if defined(S390X_EC_ASM)

+      EC_GFp_s390x_nistp521_method,

+ # elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)

+      EC_GFp_nistp521_method,

+ # else

+      0,

+ # endif

       "NIST/SECG curve over a 521 bit prime field"},

- #endif

      /* X9.62 curves */

      {NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,

- #if defined(ECP_NISTZ256_ASM)

+ # if defined(ECP_NISTZ256_ASM)

       EC_GFp_nistz256_method,

- #elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)

+ # elif defined(S390X_EC_ASM)

+      EC_GFp_s390x_nistp256_method,

+ # elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)

       EC_GFp_nistp256_method,

- #else

+ # else

       0,

- #endif

+ # endif

       "X9.62/SECG curve over a 256 bit prime field"},

  };

+ #endif /* FIPS_MODULE */

  

  #define curve_list_length OSSL_NELEM(curve_list)

  

- static EC_GROUP *ec_group_new_from_data(const ec_list_element curve)

+ static const ec_list_element *ec_curve_nid2curve(int nid)

+ {

+     size_t i;

+ 

+     if (nid <= 0)

+         return NULL;

+ 

+     for (i = 0; i < curve_list_length; i++) {

+         if (curve_list[i].nid == nid)

+             return &curve_list[i];

+     }

+     return NULL;

+ }

+ 

+ static EC_GROUP *ec_group_new_from_data(OSSL_LIB_CTX *libctx,

+                                         const char *propq,

+                                         const ec_list_element curve)

  {

      EC_GROUP *group = NULL;

      EC_POINT *P = NULL;
@@ -293,10 +372,11 @@ 

  

      /* If no curve data curve method must handle everything */

      if (curve.data == NULL)

-         return EC_GROUP_new(curve.meth != NULL ? curve.meth() : NULL);

+         return ossl_ec_group_new_ex(libctx, propq,

+                                     curve.meth != NULL ? curve.meth() : NULL);

  

-     if ((ctx = BN_CTX_new()) == NULL) {

-         ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_MALLOC_FAILURE);

+     if ((ctx = BN_CTX_new_ex(libctx)) == NULL) {

+         ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);

          goto err;

      }

  
@@ -309,20 +389,20 @@ 

      if ((p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) == NULL

          || (a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) == NULL

          || (b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) == NULL) {

-         ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);

+         ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);

          goto err;

      }

  

      if (curve.meth != 0) {

          meth = curve.meth();

-         if (((group = EC_GROUP_new(meth)) == NULL) ||

+         if (((group = ossl_ec_group_new_ex(libctx, propq, meth)) == NULL) ||

              (!(group->meth->group_set_curve(group, p, a, b, ctx)))) {

-             ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);

+             ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);

              goto err;

          }

      } else if (data->field_type == NID_X9_62_prime_field) {

          if ((group = EC_GROUP_new_curve_GFp(p, a, b, ctx)) == NULL) {

-             ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);

+             ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);

              goto err;

          }

      }
@@ -331,7 +411,7 @@ 

                                   * NID_X9_62_characteristic_two_field */

  

          if ((group = EC_GROUP_new_curve_GF2m(p, a, b, ctx)) == NULL) {

-             ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);

+             ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);

              goto err;

          }

      }
@@ -340,31 +420,31 @@ 

      EC_GROUP_set_curve_name(group, curve.nid);

  

      if ((P = EC_POINT_new(group)) == NULL) {

-         ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);

+         ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);

          goto err;

      }

  

      if ((x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) == NULL

          || (y = BN_bin2bn(params + 4 * param_len, param_len, NULL)) == NULL) {

-         ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);

+         ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);

          goto err;

      }

      if (!EC_POINT_set_affine_coordinates(group, P, x, y, ctx)) {

-         ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);

+         ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);

          goto err;

      }

      if ((order = BN_bin2bn(params + 5 * param_len, param_len, NULL)) == NULL

          || !BN_set_word(x, (BN_ULONG)data->cofactor)) {

-         ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);

+         ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);

          goto err;

      }

      if (!EC_GROUP_set_generator(group, P, order, x)) {

-         ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);

+         ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);

          goto err;

      }

      if (seed_len) {

          if (!EC_GROUP_set_seed(group, params - seed_len, seed_len)) {

-             ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);

+             ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);

              goto err;

          }

      }
@@ -385,28 +465,33 @@ 

      return group;

  }

  

- EC_GROUP *EC_GROUP_new_by_curve_name(int nid)

+ EC_GROUP *EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX *libctx, const char *propq,

+                                         int nid)

  {

-     size_t i;

      EC_GROUP *ret = NULL;

+     const ec_list_element *curve;

  

-     if (nid <= 0)

-         return NULL;

- 

-     for (i = 0; i < curve_list_length; i++)

-         if (curve_list[i].nid == nid) {

-             ret = ec_group_new_from_data(curve_list[i]);

-             break;

-         }

- 

-     if (ret == NULL) {

-         ECerr(EC_F_EC_GROUP_NEW_BY_CURVE_NAME, EC_R_UNKNOWN_GROUP);

+     if ((curve = ec_curve_nid2curve(nid)) == NULL

+         || (ret = ec_group_new_from_data(libctx, propq, *curve)) == NULL) {

+ #ifndef FIPS_MODULE

+         ERR_raise_data(ERR_LIB_EC, EC_R_UNKNOWN_GROUP,

+                        "name=%s", OBJ_nid2sn(nid));

+ #else

+         ERR_raise(ERR_LIB_EC, EC_R_UNKNOWN_GROUP);

+ #endif

          return NULL;

      }

  

      return ret;

  }

  

+ #ifndef FIPS_MODULE

+ EC_GROUP *EC_GROUP_new_by_curve_name(int nid)

+ {

+     return EC_GROUP_new_by_curve_name_ex(NULL, NULL, nid);

+ }

+ #endif

+ 

  size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems)

  {

      size_t i, min;
@@ -424,49 +509,14 @@ 

      return curve_list_length;

  }

  

- /* Functions to translate between common NIST curve names and NIDs */

- 

- typedef struct {

-     const char *name;           /* NIST Name of curve */

-     int nid;                    /* Curve NID */

- } EC_NIST_NAME;

- 

- static EC_NIST_NAME nist_curves[] = {

-     {"B-163", NID_sect163r2},

-     {"B-233", NID_sect233r1},

-     {"B-283", NID_sect283r1},

-     {"B-409", NID_sect409r1},

-     {"B-571", NID_sect571r1},

-     {"K-163", NID_sect163k1},

-     {"K-233", NID_sect233k1},

-     {"K-283", NID_sect283k1},

-     {"K-409", NID_sect409k1},

-     {"K-571", NID_sect571k1},

-     {"P-192", NID_X9_62_prime192v1},

-     {"P-224", NID_secp224r1},

-     {"P-256", NID_X9_62_prime256v1},

-     {"P-384", NID_secp384r1},

-     {"P-521", NID_secp521r1}

- };

- 

  const char *EC_curve_nid2nist(int nid)

  {

-     size_t i;

-     for (i = 0; i < OSSL_NELEM(nist_curves); i++) {

-         if (nist_curves[i].nid == nid)

-             return nist_curves[i].name;

-     }

-     return NULL;

+     return ossl_ec_curve_nid2nist_int(nid);

  }

  

  int EC_curve_nist2nid(const char *name)

  {

-     size_t i;

-     for (i = 0; i < OSSL_NELEM(nist_curves); i++) {

-         if (strcmp(nist_curves[i].name, name) == 0)

-             return nist_curves[i].nid;

-     }

-     return NID_undef;

+     return ossl_ec_curve_nist2nid_int(name);

  }

  

  #define NUM_BN_FIELDS 6
@@ -478,7 +528,7 @@ 

   * Returns: The nid associated with the found named curve, or NID_undef

   *          if not found. If there was an error it returns -1.

   */

- int ec_curve_nid_from_params(const EC_GROUP *group, BN_CTX *ctx)

+ int ossl_ec_curve_nid_from_params(const EC_GROUP *group, BN_CTX *ctx)

  {

      int ret = -1, nid, len, field_type, param_len;

      size_t i, seed_len;
@@ -486,17 +536,13 @@ 

      unsigned char *param_bytes = NULL;

      const EC_CURVE_DATA *data;

      const EC_POINT *generator = NULL;

-     const EC_METHOD *meth;

      const BIGNUM *cofactor = NULL;

      /* An array of BIGNUMs for (p, a, b, x, y, order) */

      BIGNUM *bn[NUM_BN_FIELDS] = {NULL, NULL, NULL, NULL, NULL, NULL};

  

-     meth = EC_GROUP_method_of(group);

-     if (meth == NULL)

-         return -1;

      /* Use the optional named curve nid as a search field */

      nid = EC_GROUP_get_curve_name(group);

-     field_type = EC_METHOD_get_field_type(meth);

+     field_type = EC_GROUP_get_field_type(group);

      seed_len = EC_GROUP_get_seed_len(group);

      seed = EC_GROUP_get0_seed(group);

      cofactor = EC_GROUP_get0_cofactor(group);

file modified
+928 -163
@@ -1,27 +1,36 @@ 

  /*

-  * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.

+  * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.

   * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved

   *

-  * Licensed under the OpenSSL license (the "License").  You may not use

+  * Licensed under the Apache License 2.0 (the "License").  You may not use

   * this file except in compliance with the License.  You can obtain a copy

   * in the file LICENSE in the source distribution or at

   * https://www.openssl.org/source/license.html

   */

  

+ /*

+  * EC_KEY low level APIs are deprecated for public use, but still ok for

+  * internal use.

+  */

+ #include "internal/deprecated.h"

+ 

+ #include <string.h>

  #include "internal/nelem.h"

  #include "testutil.h"

  

- #ifndef OPENSSL_NO_EC

- # include <openssl/ec.h>

- # ifndef OPENSSL_NO_ENGINE

- #  include <openssl/engine.h>

- # endif

- # include <openssl/err.h>

- # include <openssl/obj_mac.h>

- # include <openssl/objects.h>

- # include <openssl/rand.h>

- # include <openssl/bn.h>

- # include <openssl/opensslconf.h>

+ #include <openssl/ec.h>

+ #ifndef OPENSSL_NO_ENGINE

+ # include <openssl/engine.h>

+ #endif

+ #include <openssl/err.h>

+ #include <openssl/obj_mac.h>

+ #include <openssl/objects.h>

+ #include <openssl/rand.h>

+ #include <openssl/bn.h>

+ #include <openssl/opensslconf.h>

+ #include <openssl/core_names.h>

+ #include <openssl/param_build.h>

+ #include <openssl/evp.h>

  

  static size_t crv_len = 0;

  static EC_builtin_curve *curves = NULL;
@@ -49,7 +58,9 @@ 

      if (!TEST_true(EC_GROUP_get_order(group, order, ctx))

          || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx))

          || !TEST_true(EC_POINT_is_at_infinity(group, Q))

+ #ifndef OPENSSL_NO_DEPRECATED_3_0

          || !TEST_true(EC_GROUP_precompute_mult(group, ctx))

+ #endif

          || !TEST_true(EC_POINT_mul(group, Q, order, NULL, NULL, ctx))

          || !TEST_true(EC_POINT_is_at_infinity(group, Q))

          || !TEST_true(EC_POINT_copy(P, G))
@@ -63,8 +74,10 @@ 

          goto err;

  

      for (i = 1; i <= 2; i++) {

+ #ifndef OPENSSL_NO_DEPRECATED_3_0

          const BIGNUM *scalars[6];

          const EC_POINT *points[6];

+ #endif

  

          if (!TEST_true(BN_set_word(n1, i))

              /*
@@ -96,11 +109,11 @@ 

              /* Add P to verify the result. */

              || !TEST_true(EC_POINT_add(group, Q, Q, P, ctx))

              || !TEST_true(EC_POINT_is_at_infinity(group, Q))

- 

-             /* Exercise EC_POINTs_mul, including corner cases. */

              || !TEST_false(EC_POINT_is_at_infinity(group, P)))

              goto err;

  

+ #ifndef OPENSSL_NO_DEPRECATED_3_0

+         /* Exercise EC_POINTs_mul, including corner cases. */

          scalars[0] = scalars[1] = BN_value_one();

          points[0]  = points[1]  = P;

  
@@ -124,6 +137,7 @@ 

          if (!TEST_true(EC_POINTs_mul(group, P, NULL, 6, points, scalars, ctx))

              || !TEST_true(EC_POINT_is_at_infinity(group, P)))

              goto err;

+ #endif

      }

  

      r = 1;
@@ -146,13 +160,13 @@ 

  {

      BN_CTX *ctx = NULL;

      BIGNUM *p = NULL, *a = NULL, *b = NULL, *scalar3 = NULL;

-     EC_GROUP *group = NULL, *tmp = NULL;

-     EC_GROUP *P_160 = NULL, *P_192 = NULL, *P_224 = NULL,

-              *P_256 = NULL, *P_384 = NULL, *P_521 = NULL;

+     EC_GROUP *group = NULL;

      EC_POINT *P = NULL, *Q = NULL, *R = NULL;

      BIGNUM *x = NULL, *y = NULL, *z = NULL, *yplusone = NULL;

+ #ifndef OPENSSL_NO_DEPRECATED_3_0

      const EC_POINT *points[4];

      const BIGNUM *scalars[4];

+ #endif

      unsigned char buf[100];

      size_t len, r = 0;

      int k;
@@ -165,13 +179,8 @@ 

           * applications should use EC_GROUP_new_curve_GFp so

           * that the library gets to choose the EC_METHOD

           */

-         || !TEST_ptr(group = EC_GROUP_new(EC_GFp_mont_method()))

-         || !TEST_ptr(tmp = EC_GROUP_new(EC_GROUP_method_of(group)))

-         || !TEST_true(EC_GROUP_copy(tmp, group)))

+         || !TEST_ptr(group = EC_GROUP_new(EC_GFp_mont_method())))

          goto err;

-     EC_GROUP_free(group);

-     group = tmp;

-     tmp = NULL;

  

      buf[0] = 0;

      if (!TEST_ptr(P = EC_POINT_new(group))
@@ -187,7 +196,7 @@ 

  

      if (!TEST_true(BN_hex2bn(&p,         "FFFFFFFFFFFFFFFFFFFFFFFF"

                                      "FFFFFFFF000000000000000000000001"))

-         || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))

+         || !TEST_int_eq(1, BN_check_prime(p, ctx, NULL))

          || !TEST_true(BN_hex2bn(&a,         "FFFFFFFFFFFFFFFFFFFFFFFF"

                                      "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE"))

          || !TEST_true(BN_hex2bn(&b,         "B4050A850C04B3ABF5413256"
@@ -219,14 +228,12 @@ 

                                                         ctx))

          || !TEST_int_eq(EC_GROUP_get_degree(group), 224)

          || !group_order_tests(group)

-         || !TEST_ptr(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))

-         || !TEST_true(EC_GROUP_copy(P_224, group))

  

      /* Curve P-256 (FIPS PUB 186-2, App. 6) */

  

          || !TEST_true(BN_hex2bn(&p, "FFFFFFFF000000010000000000000000"

                                      "00000000FFFFFFFFFFFFFFFFFFFFFFFF"))

-         || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))

+         || !TEST_int_eq(1, BN_check_prime(p, ctx, NULL))

          || !TEST_true(BN_hex2bn(&a, "FFFFFFFF000000010000000000000000"

                                      "00000000FFFFFFFFFFFFFFFFFFFFFFFC"))

          || !TEST_true(BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC"
@@ -259,15 +266,13 @@ 

                                                         ctx))

          || !TEST_int_eq(EC_GROUP_get_degree(group), 256)

          || !group_order_tests(group)

-         || !TEST_ptr(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))

-         || !TEST_true(EC_GROUP_copy(P_256, group))

  

      /* Curve P-384 (FIPS PUB 186-2, App. 6) */

  

          || !TEST_true(BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

                                      "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"

                                      "FFFFFFFF0000000000000000FFFFFFFF"))

-         || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))

+         || !TEST_int_eq(1, BN_check_prime(p, ctx, NULL))

          || !TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

                                      "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"

                                      "FFFFFFFF0000000000000000FFFFFFFC"))
@@ -305,8 +310,6 @@ 

                                                         ctx))

          || !TEST_int_eq(EC_GROUP_get_degree(group), 384)

          || !group_order_tests(group)

-         || !TEST_ptr(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))

-         || !TEST_true(EC_GROUP_copy(P_384, group))

  

      /* Curve P-521 (FIPS PUB 186-2, App. 6) */

          || !TEST_true(BN_hex2bn(&p,                              "1FF"
@@ -314,7 +317,7 @@ 

                                      "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

                                      "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

                                      "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"))

-         || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))

+         || !TEST_int_eq(1, BN_check_prime(p, ctx, NULL))

          || !TEST_true(BN_hex2bn(&a,                              "1FF"

                                      "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

                                      "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
@@ -361,8 +364,6 @@ 

                                                         ctx))

          || !TEST_int_eq(EC_GROUP_get_degree(group), 521)

          || !group_order_tests(group)

-         || !TEST_ptr(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))

-         || !TEST_true(EC_GROUP_copy(P_521, group))

  

      /* more tests using the last curve */

  
@@ -378,6 +379,9 @@ 

          || !TEST_true(EC_POINT_is_at_infinity(group, R))    /* R = P + 2Q */

          || !TEST_false(EC_POINT_is_at_infinity(group, Q)))

          goto err;

+ 

+ #ifndef OPENSSL_NO_DEPRECATED_3_0

+     TEST_note("combined multiplication ...");

      points[0] = Q;

      points[1] = Q;

      points[2] = Q;
@@ -388,11 +392,10 @@ 

          || !TEST_BN_even(y)

          || !TEST_true(BN_rshift1(y, y)))

          goto err;

+ 

      scalars[0] = y;         /* (group order + 1)/2, so y*Q + y*Q = Q */

      scalars[1] = y;

  

-     TEST_note("combined multiplication ...");

- 

      /* z is still the group order */

      if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))

          || !TEST_true(EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))
@@ -423,10 +426,8 @@ 

      if (!TEST_true(EC_POINTs_mul(group, P, NULL, 4, points, scalars, ctx))

          || !TEST_true(EC_POINT_is_at_infinity(group, P)))

          goto err;

- 

+ #endif

      TEST_note(" ok\n");

- 

- 

      r = 1;

  err:

      BN_CTX_free(ctx);
@@ -434,7 +435,6 @@ 

      BN_free(a);

      BN_free(b);

      EC_GROUP_free(group);

-     EC_GROUP_free(tmp);

      EC_POINT_free(P);

      EC_POINT_free(Q);

      EC_POINT_free(R);
@@ -443,11 +443,6 @@ 

      BN_free(z);

      BN_free(yplusone);

      BN_free(scalar3);

- 

-     EC_GROUP_free(P_224);

-     EC_GROUP_free(P_256);

-     EC_GROUP_free(P_384);

-     EC_GROUP_free(P_521);

      return r;

  }

  
@@ -484,13 +479,48 @@ 

      return r;

  }

  

- # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128

+ static int group_field_test(void)

+ {

+     int r = 1;

+     BIGNUM *secp521r1_field = NULL;

+     BIGNUM *sect163r2_field = NULL;

+     EC_GROUP *secp521r1_group = NULL;

+     EC_GROUP *sect163r2_group = NULL;

+ 

+     BN_hex2bn(&secp521r1_field,

+                 "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

+                 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

+                 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

+                 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

+                 "FFFF");

+ 

+ 

+     BN_hex2bn(&sect163r2_field,

+                 "08000000000000000000000000000000"

+                 "00000000C9");

+ 

+     secp521r1_group = EC_GROUP_new_by_curve_name(NID_secp521r1);

+     if (BN_cmp(secp521r1_field, EC_GROUP_get0_field(secp521r1_group)))

+       r = 0;

+ 

+     # ifndef OPENSSL_NO_EC2M

+     sect163r2_group = EC_GROUP_new_by_curve_name(NID_sect163r2);

+     if (BN_cmp(sect163r2_field, EC_GROUP_get0_field(sect163r2_group)))

+       r = 0;

+     # endif

+ 

+     EC_GROUP_free(secp521r1_group);

+     EC_GROUP_free(sect163r2_group);

+     BN_free(secp521r1_field);

+     BN_free(sect163r2_field);

+     return r;

+ }

  /*

-  * nistp_test_params contains magic numbers for testing our optimized

-  * implementations of several NIST curves with characteristic > 3.

+  * nistp_test_params contains magic numbers for testing

+  * several NIST curves with characteristic > 3.

   */

  struct nistp_test_params {

-     const EC_METHOD *(*meth) (void);

+     const int nid;

      int degree;

      /*

       * Qx, Qy and D are taken from
@@ -503,7 +533,7 @@ 

  static const struct nistp_test_params nistp_tests_params[] = {

      {

       /* P-224 */

-      EC_GFp_nistp224_method,

+      NID_secp224r1,

       224,

       /* p */

       "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",