oweals/openssl.git
5 years agoDocument recent changes in NEWS and CHANGES
Richard Levitte [Wed, 31 Jul 2019 04:59:37 +0000 (06:59 +0200)]
Document recent changes in NEWS and CHANGES

More should be added there

Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
(Merged from https://github.com/openssl/openssl/pull/9486)

5 years agoCheck for NULL return from zalloc in dh_dupctx.
Pauli [Tue, 30 Jul 2019 21:19:33 +0000 (07:19 +1000)]
Check for NULL return from zalloc in dh_dupctx.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9485)

5 years agoAvoid using ERR_put_error() directly in OpenSSL code
Richard Levitte [Wed, 24 Jul 2019 14:55:32 +0000 (16:55 +0200)]
Avoid using ERR_put_error() directly in OpenSSL code

If compiled with 'no-deprecated', ERR_put_error() is undefined.  We
had one spot where we were using it directly, because the file and
line information was passed from elsewhere.

Fortunately, it's possible to use ERR_raise() for that situation, and
call ERR_set_debug() immediately after and thereby override the
information that ERR_raise() stored in the error record.

util/mkerr.pl needed a small adjustment to not generate code that
won't compile in a 'no-deprecated' configuration.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoAdapt the FIPS provider to use the new core error functions
Richard Levitte [Wed, 24 Jul 2019 12:00:39 +0000 (14:00 +0200)]
Adapt the FIPS provider to use the new core error functions

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoRefactor provider support for reporting errors
Richard Levitte [Wed, 24 Jul 2019 11:37:42 +0000 (13:37 +0200)]
Refactor provider support for reporting errors

The core now supplies its own versions of ERR_new(), ERR_set_debug()
and ERR_vset_error().  This should suffice for a provider to have any
OpenSSL compatible functionlity it desires.

The main difference between the ERR functions and the core
counterparts is that the core counterparts take an OSSL_PROVIDER
parameter instead of the library number.  That way, providers do not
need to know what number they have been assigned, that information
stays in the core.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoERR: Remove ERR_put_func_error() and reimplement ERR_put_error() as a macro
Richard Levitte [Wed, 24 Jul 2019 11:25:56 +0000 (13:25 +0200)]
ERR: Remove ERR_put_func_error() and reimplement ERR_put_error() as a macro

Also, deprecate ERR_put_error()

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoERR: Implement the macros ERR_raise() and ERR_raise_data() and use them
Richard Levitte [Wed, 24 Jul 2019 11:13:52 +0000 (13:13 +0200)]
ERR: Implement the macros ERR_raise() and ERR_raise_data() and use them

The ERR_raise() macro uses a trick in C.  The following is permitted:

    #include <stdio.h>

    void first(void)
    {
        printf("Hello! ");
    }

    void foo(const char *bar)
    {
        printf("%s", bar);
    }

    int main()
    {
        /* This */
        (first(),foo)("cookie");
    }

ERR_raise_data() can be used to implement FUNCerr() as well, which
takes away the need for the special function ERR_put_func_error().

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoERR: Add new building blocks for reporting errors
Richard Levitte [Wed, 24 Jul 2019 11:03:32 +0000 (13:03 +0200)]
ERR: Add new building blocks for reporting errors

The new building block are ERR_new(), ERR_set_debug(),
ERR_set_error(), ERR_vset_error(), which allocate a new error record
and set the diverse data in them.  They are designed in such a way
that it's reasonably easy to create macros that use all of them but
then rely completely on the function signature of ERR_set_error() or
ERR_vset_error().

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoERR: refactor useful inner macros to err_locl.h. Add function name field
Richard Levitte [Wed, 24 Jul 2019 10:56:58 +0000 (12:56 +0200)]
ERR: refactor useful inner macros to err_locl.h.  Add function name field

The useful inner macros are now static inline functions.  That will
make them easier to debug in the future.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoMove some macros from include/openssl/opensslconf.h.in, add OPENSSL_FUNC
Richard Levitte [Wed, 24 Jul 2019 10:53:36 +0000 (12:53 +0200)]
Move some macros from include/openssl/opensslconf.h.in, add OPENSSL_FUNC

New header file, include/openssl/macros.h, which contains diverse
useful macros that we use elsewhere.

We also add the new macro OPENSSL_FUNC, which is an alias for
__FUNC__, __FUNCTION__, __FUNCSIG or __func__, depending on what the
compiler supports.  In the worst case, it's an alias for the string
"(unknown function)".

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)

5 years agoFix BIO_printf format warnings
Bernd Edlinger [Mon, 29 Jul 2019 10:26:06 +0000 (12:26 +0200)]
Fix BIO_printf format warnings

[extended tests]

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9479)

5 years agoUse OPENSSL_strlcpy instead of strncpy in e_afalg.c
Bernd Edlinger [Mon, 29 Jul 2019 09:39:34 +0000 (11:39 +0200)]
Use OPENSSL_strlcpy instead of strncpy in e_afalg.c

This avoids a spurious gcc warning:
./config enable-asan --strict-warnings
=>
In function 'afalg_create_sk',
    inlined from 'afalg_cipher_init' at engines/e_afalg.c:545:11:
engines/e_afalg.c:376:5: error: '__builtin_strncpy' output may be
    truncated copying 63 bytes from a string of length 63 [-Werror=stringop-truncation]
  376 |     strncpy((char *) sa.salg_name, ciphername, ALG_MAX_SALG_NAME);
      |     ^~~~~~~

[extended tests]

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9478)

5 years agoDocument the provider CIPHER operation
Matt Caswell [Thu, 25 Jul 2019 10:55:00 +0000 (11:55 +0100)]
Document the provider CIPHER operation

Extends the existing provider documentation with information about the
CIPHER operation. This is primarily for provider authors.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9473)

5 years agoFix coverity 1452084
Pauli [Sun, 28 Jul 2019 08:21:07 +0000 (18:21 +1000)]
Fix coverity 1452084
Fix coverity 1452083

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9470)

5 years agoERR: re-use the err_data field when possible
Richard Levitte [Thu, 25 Jul 2019 15:51:30 +0000 (17:51 +0200)]
ERR: re-use the err_data field when possible

To deallocate the err_data field and then allocating it again might be
a waste of processing, but may also be a source of errors when memory
is scarce.  While we normally tolerate that, the ERR sub-system is an
exception and we need to pay closer attention to how we handle memory.

This adds a new err_data flag, ERR_TXT_IGNORE, which means that even
if there is err_data memory allocated, its contents should be ignored.
Deallocation of the err_data field is much more selective, aand should
only happen when ERR_free_state() is called.

Fixes #9458

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9459)

5 years agoAdd weak platform independent PRNG to test framework.
Pauli [Fri, 26 Jul 2019 02:56:01 +0000 (12:56 +1000)]
Add weak platform independent PRNG to test framework.

Implement the GNU C library's random(3) pseudorandom number generator.
The algorithm is described: https://www.mscs.dal.ca/~selinger/random/

The rationale is to make the tests repeatable across differing platforms with
different underlying implementations of the random(3) library call.

More specifically: when executing tests with random ordering.

[extended tests]

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9463)

5 years agos390x assembly pack: use getauxval to detect hw capabilities
Patrick Steuer [Thu, 18 Jul 2019 09:42:58 +0000 (11:42 +0200)]
s390x assembly pack: use getauxval to detect hw capabilities

if available.

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9410)

5 years agotest/recipes/30-test_evp.t: Modify to test with different providers
Richard Levitte [Wed, 17 Jul 2019 12:26:26 +0000 (14:26 +0200)]
test/recipes/30-test_evp.t: Modify to test with different providers

Different providers will give different results, and we need to test
them all.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9398)

5 years agotest/evp_test.c: modify to use OSSL_PROVIDER_available()
Richard Levitte [Wed, 17 Jul 2019 09:34:14 +0000 (11:34 +0200)]
test/evp_test.c: modify to use OSSL_PROVIDER_available()

This changes the stanza format used so far.  Some test stanza had the
following line, only possible for digests:

    Legacy = 1

These have been traded for the following:

    Availablein = legacy

That line is globally available in all test stanza and can be used to
tell what providers a certain algorithm may be available in.  Only one
provider needs to match, so one might have something like this for
some tests:

    Availablein = default fips

This means that one of those providers must be available for the test
stanza to be performed.

If the providers mentioned for a stanza aren't available, the test is
skipped.
If this line isn't used in a stanza, the algorithm is assumed to be
available unconditionally (either by fallback providers, or providers
loaded by the config file).

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9398)

5 years agoAdd functions to see if a provider is available for use.
Richard Levitte [Wed, 17 Jul 2019 09:29:04 +0000 (11:29 +0200)]
Add functions to see if a provider is available for use.

Public function OSSL_PROVIDER_available() takes a library context and
a provider name, and returns 1 if it's available for use, i.e. if it's
possible to fetch implementations from it, otherwise 0.

Internal function ossl_provider_activated() returns 1 if the given
OSSL_PROVIDER is activated, otherwise 0.

To make this possible, the activation of fallbacks got refactored out
to a separate function, which ended up simplifying the code.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9398)

5 years agoDon't generate an unnecessary Diffie-Hellman key in TLS 1.3 clients.
David Benjamin [Tue, 23 Jul 2019 18:14:48 +0000 (14:14 -0400)]
Don't generate an unnecessary Diffie-Hellman key in TLS 1.3 clients.

tls_parse_stoc_key_share was generating a new EVP_PKEY public/private
keypair and then overrides it with the server public key, so the
generation was a waste anyway. Instead, it should create a
parameters-only EVP_PKEY.

(This is a consequence of OpenSSL using the same type for empty key,
empty key with key type, empty key with key type + parameters, public
key, and private key. As a result, it's easy to mistakenly mix such
things up, as happened here.)

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/9445)

5 years agoDocument the provider DIGEST operation
Matt Caswell [Wed, 24 Jul 2019 14:24:01 +0000 (15:24 +0100)]
Document the provider DIGEST operation

Extends the existing provider documentation with information about the
DIGEST operation. This is primarily for provider authors.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9453)

5 years agoRemove HEADER_X509_H and HEADER_SSL_H include detectors from apps
Dr. Matthias St. Pierre [Fri, 12 Jul 2019 20:49:42 +0000 (22:49 +0200)]
Remove HEADER_X509_H and HEADER_SSL_H include detectors from apps

The HEADER_X509_H check is redundant, because <openssl/x509.h>
is already included.

Instead of of checking for HEADER_SSL_H, include <openssl/ssl.h>
explicitly in "s_apps.h" and don't include "s_apps.h" where it's
not necessary.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9364)

5 years agoRemove OPENSSL_X509V3_H include detector from openssl/cms.h
Dr. Matthias St. Pierre [Fri, 5 Jul 2019 13:50:50 +0000 (15:50 +0200)]
Remove OPENSSL_X509V3_H include detector from openssl/cms.h

The check is redundant, because <openssl/x509v3.h> is included.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9364)

5 years agoRemove HEADER_BSS_FILE_C module include guard
Dr. Matthias St. Pierre [Thu, 4 Jul 2019 10:38:43 +0000 (12:38 +0200)]
Remove HEADER_BSS_FILE_C module include guard

This include guard inside an object file comes as a surprise and
serves no purpose anymore. It seems like this object file was
included by crypto/threads/mttest.c at some time, but the include
directive was removed in commit bb8abd6.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9364)

5 years agoEnforce a minimum DH modulus size of 512 bits
Bernd Edlinger [Mon, 22 Jul 2019 20:50:19 +0000 (22:50 +0200)]
Enforce a minimum DH modulus size of 512 bits

[extended tests]

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9437)

5 years agoAdapt DH to use with KEYMGMT
Richard Levitte [Sun, 7 Jul 2019 08:56:46 +0000 (10:56 +0200)]
Adapt DH to use with KEYMGMT

The biggest part in this was to move the key->param builder from EVP
to the DH ASN.1 method, and to implement the KEYMGMT support in the
provider DH.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9394)

5 years agoRemove some utilities from the core to provider interface
Matt Caswell [Mon, 22 Jul 2019 14:19:02 +0000 (15:19 +0100)]
Remove some utilities from the core to provider interface

The core provides a number of essential functions as "upcalls" to
providers. Some of those were just utility functions that wrap other
upcalls - which don't seem essential and bloat the interface. We should
remove them in order to simplify the interface.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9432)

5 years agoDon't complain if function name doesn't match
Rich Salz [Thu, 18 Jul 2019 19:40:12 +0000 (15:40 -0400)]
Don't complain if function name doesn't match

The "function" argument is now unused in the XXXerr defines, so mkerr
doesn't need to check if the value/name match.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9413)

5 years agoMake rand_pool buffers more dynamic in their sizing.
Pauli [Tue, 23 Jul 2019 08:07:19 +0000 (18:07 +1000)]
Make rand_pool buffers more dynamic in their sizing.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9428)

5 years agoAvoid double clearing some BIGNUMs
Pauli [Tue, 23 Jul 2019 06:54:52 +0000 (16:54 +1000)]
Avoid double clearing some BIGNUMs

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9438)

5 years agoReplace OSSL_ITEM with OSSL_PARAM as parameter descriptor, everywhere
Richard Levitte [Thu, 11 Jul 2019 10:19:33 +0000 (12:19 +0200)]
Replace OSSL_ITEM with OSSL_PARAM as parameter descriptor, everywhere

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9346)

5 years agoDescribe OSSL_PARAM as a parameter descriptor
Richard Levitte [Thu, 11 Jul 2019 10:18:42 +0000 (12:18 +0200)]
Describe OSSL_PARAM as a parameter descriptor

This affects doc/man3/OSSL_PARAM.pod and doc/man7/openssl-core.h.pod

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9346)

5 years agoRe-implement the cipher and digest listings for 'openssl list'
Richard Levitte [Sat, 13 Jul 2019 05:04:01 +0000 (07:04 +0200)]
Re-implement the cipher and digest listings for 'openssl list'

They now display both legacy and provided algorithms.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoAdd EVP_CIPHER_do_all_ex() and EVP_MD_do_all_ex()
Richard Levitte [Sat, 13 Jul 2019 05:02:54 +0000 (07:02 +0200)]
Add EVP_CIPHER_do_all_ex() and EVP_MD_do_all_ex()

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoAdd internal function evp_generic_do_all()
Richard Levitte [Sat, 13 Jul 2019 04:53:44 +0000 (06:53 +0200)]
Add internal function evp_generic_do_all()

This function is used to traverse all algorithm implementations for a
given operation type, and execute the given function for each of them.

For each algorithm implementation, a method is created and passed to
the given function, and then freed after that function's return.  If
the caller wishes to keep the method for longer, they must call the
appropriate up_ref function on the method, and they must also make
sure to free the passed methods at some point.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoRefactor ossl_method_construct() in terms of ossl_algorithm_do_all()
Richard Levitte [Wed, 10 Jul 2019 21:14:03 +0000 (23:14 +0200)]
Refactor ossl_method_construct() in terms of ossl_algorithm_do_all()

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoAdd internal function ossl_algorithm_do_all()
Richard Levitte [Wed, 10 Jul 2019 21:11:27 +0000 (23:11 +0200)]
Add internal function ossl_algorithm_do_all()

This function is used to traverse all the implementations provided by
one provider, or all implementation for a specific operation across
all loaded providers, or both, and execute a given function for each
occurence.

This will be used by ossl_method_construct(), but also by information
processing functions.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoAdd OSSL_PROVIDER_name()
Richard Levitte [Wed, 10 Jul 2019 21:00:22 +0000 (23:00 +0200)]
Add OSSL_PROVIDER_name()

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoAdd EVP_MD_provider() and EVP_CIPHER_provider()
Richard Levitte [Wed, 10 Jul 2019 20:59:07 +0000 (22:59 +0200)]
Add EVP_MD_provider() and EVP_CIPHER_provider()

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoRe-implement EVP_MD_name() and EVP_CIPHER_name() as functions
Richard Levitte [Wed, 10 Jul 2019 20:24:00 +0000 (22:24 +0200)]
Re-implement EVP_MD_name() and EVP_CIPHER_name() as functions

They will do the same as usual for non-provider algorithms
implementations, but can handle provider implementations as well.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoAdd a mechnism to save the name of fetched methods
Richard Levitte [Wed, 10 Jul 2019 20:22:16 +0000 (22:22 +0200)]
Add a mechnism to save the name of fetched methods

This will be useful for information display, as well as for code that
want to check the name of an algorithm.  This can eventually replace
all NID checks.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9356)

5 years agoprovider-keymgmt(7): Document the KEYMGMT interface
Richard Levitte [Mon, 22 Jul 2019 08:46:10 +0000 (10:46 +0200)]
provider-keymgmt(7): Document the KEYMGMT interface

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9429)

5 years agoRemove superfluous call to OPENSSL_cpuid_setup
Patrick Steuer [Fri, 19 Jul 2019 14:41:46 +0000 (16:41 +0200)]
Remove superfluous call to OPENSSL_cpuid_setup

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9417)

5 years agoChange DH parameters to generate the order q subgroup instead of 2q
Bernd Edlinger [Wed, 10 Jul 2019 13:52:36 +0000 (15:52 +0200)]
Change DH parameters to generate the order q subgroup instead of 2q

This avoids leaking bit 0 of the private key.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/9363)

5 years agoDocumentation: add provider-base(7), describing the base functions
Richard Levitte [Thu, 18 Jul 2019 13:07:13 +0000 (15:07 +0200)]
Documentation: add provider-base(7), describing the base functions

The base functions are the first tables of function pointers that
libcrypto and the provider pass to each other, thereby providing a
baseline with which they can communicate further with each other.

This also contains an example for a ficticious provider, providing an
implement of a fictitious algorithm for a fictitious operation.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9409)

5 years agoDocumentation: Move the description of the fetching functions
Richard Levitte [Thu, 18 Jul 2019 10:24:55 +0000 (12:24 +0200)]
Documentation: Move the description of the fetching functions

Now that the general descriptions have moved from
doc/man3/EVP_MD_fetch.pod to doc/man7/provider.pod, the description of
the fetching functions themselves can be moved to other pages where
related functions are already described.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9409)

5 years agoDocumentation: Add provider(7), for general description of providers
Richard Levitte [Thu, 18 Jul 2019 10:23:23 +0000 (12:23 +0200)]
Documentation: Add provider(7), for general description of providers

This includes an enumeration of the providers supplied with OpenSSL,
and what implementations they offer.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9409)

5 years agoInclude deprecated SYS_F_xxx codes
Rich Salz [Tue, 16 Jul 2019 23:55:44 +0000 (19:55 -0400)]
Include deprecated SYS_F_xxx codes

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9072)

5 years agoDeprecate SYSerr, add new FUNCerr macro
Rich Salz [Tue, 16 Jul 2019 16:54:24 +0000 (12:54 -0400)]
Deprecate SYSerr, add new FUNCerr macro

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9072)

5 years agoAdd ERR_put_func_error, and use it.
Rich Salz [Tue, 11 Jun 2019 19:42:42 +0000 (15:42 -0400)]
Add ERR_put_func_error, and use it.

Change SYSerr to have the function name; remove SYS_F_xxx defines
Add a test and documentation.
Use get_last_socket_err, which removes some ifdef's in OpenSSL code.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9072)

5 years agoAllocate DRBG additional data pool from non-secure memory
Bernd Edlinger [Sat, 20 Jul 2019 09:22:46 +0000 (11:22 +0200)]
Allocate DRBG additional data pool from non-secure memory

The additional data allocates 12K per DRBG instance in the
secure memory, which is not necessary. Also nonces are not
considered secret.

[extended tests]

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9423)

5 years agox509: publish X509_PUBKEY_dup
Dr. Matthias St. Pierre [Fri, 12 Jul 2019 10:42:39 +0000 (12:42 +0200)]
x509: publish X509_PUBKEY_dup

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9353)

5 years agox509: add missing X509 dup functions
Dr. Matthias St. Pierre [Fri, 12 Jul 2019 10:00:58 +0000 (12:00 +0200)]
x509: add missing X509 dup functions

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9353)

5 years agox509: sort X509 dup functions alphabetically
Dr. Matthias St. Pierre [Fri, 12 Jul 2019 09:59:42 +0000 (11:59 +0200)]
x509: sort X509 dup functions alphabetically

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9353)

5 years agoAdd an internal API to access the KEYMGMT provider functions
Richard Levitte [Thu, 11 Jul 2019 10:52:16 +0000 (12:52 +0200)]
Add an internal API to access the KEYMGMT provider functions

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9312)

5 years agoAdd evp_keymgmt_clear_pkey_cache() and use it
Richard Levitte [Wed, 10 Jul 2019 12:30:55 +0000 (14:30 +0200)]
Add evp_keymgmt_clear_pkey_cache() and use it

This function clears the cache of provider key references, and is used
in evp_keymgmt_export_to_provider() when the internal key is dirty, as
well as by EVP_PKEY_free_it().

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9312)

5 years agoAdapt int_ctx_new() to use with providers
Richard Levitte [Tue, 9 Jul 2019 15:31:24 +0000 (17:31 +0200)]
Adapt int_ctx_new() to use with providers

This affects all its callers: EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id().
They are now possible to called with "zero" values, i.e.:

    EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(NULL, NULL);

or

    EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(0, NULL);

This is suitable for provider use, as the key functionality is tied
with its keys, and the operation time is determined by the init
functions the EVP_PKEY_CTX is used with.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9312)

5 years agoAdd evp_keymgmt_export_to_provider(), for key transfer between providers
Richard Levitte [Sat, 6 Jul 2019 19:57:15 +0000 (21:57 +0200)]
Add evp_keymgmt_export_to_provider(), for key transfer between providers

This function is used to transport private key materia from whatever
is already attached to the EVP_PKEY to the new provider, using key
data export and import functionality.

If a legacy lower level key has been assigned to the EVP_PKEY, we use
its data to create a provider side key, and thereby have a bridge
between old style public key types and the EVP_PKEY on providers.

If successful, this function returns a reference to the appropriate
provider side data for the key.

This can be used by any operation that wants to use this key.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9312)

5 years agoAdd basic EVP_KEYMGMT API and libcrypto <-> provider interface
Richard Levitte [Thu, 4 Jul 2019 22:31:42 +0000 (00:31 +0200)]
Add basic EVP_KEYMGMT API and libcrypto <-> provider interface

The idea with the key management "operation" is to support the
following set of functionality:

- Key domain parameter generation
- Key domain parameter import
- Key domain parameter export

- Key generation
- Key import
- Key export
- Key loading (HSM / hidden key support)

With that set of function, we can support handling domain parameters
on one provider, key handling on another, and key usage on a third,
with transparent export / import of applicable data.  Of course, if a
provider doesn't offer export / import functionality, then all
operations surrounding a key must be performed with the same
provider.

This method also avoids having to do anything special with legacy
assignment of libcrypto key structures, i.e. EVP_PKEY_assign_RSA().
They will simply be used as keys to be exported from whenever they are
used with provider based operations.

This change only adds the EVP_KEYMGMT API and the libcrypto <->
provider interface.  Further changes will integrate them into existing
libcrypto functionality.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9312)

5 years agoAdd param builder free function.
Pauli [Thu, 18 Jul 2019 15:14:07 +0000 (01:14 +1000)]
Add param builder free function.

This means include deallocation information in the return from
the ossl_param_bld_to_param function.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9404)

5 years agoCygwin: enable the use of Dl_info and dladdr()
Richard Levitte [Wed, 17 Jul 2019 19:22:42 +0000 (21:22 +0200)]
Cygwin: enable the use of Dl_info and dladdr()

These weren't available in Cygwin at the time our DSO code was
written, but things have changed since.

Fixes #9385

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9402)

5 years agotest/enginetest.c: Make sure no config file is loaded
Richard Levitte [Tue, 16 Jul 2019 10:21:47 +0000 (12:21 +0200)]
test/enginetest.c: Make sure no config file is loaded

If a config file gets loaded, the tests get disturbed.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9393)

5 years agodoc: fix some links
Richard Levitte [Thu, 18 Jul 2019 07:19:43 +0000 (09:19 +0200)]
doc: fix some links

Some links are aged and need an adjustment.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9407)

5 years agoutil/find-doc-nits: fixups
Richard Levitte [Thu, 18 Jul 2019 07:03:18 +0000 (09:03 +0200)]
util/find-doc-nits: fixups

- Treat .pod.in files as well, and parse out the base name for those
  too.
- Correct the detection of the description part in the NAME section
  (the separating dash MUST be preceeded with a space)
- Allow slahes in names of the NAME section (convert them to dashes
  for file name comparison).  This allows manual pages for some of our
  header files, such as openssl/core.h.
- Properly detect repeated names in the NAME section.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9407)

5 years agoFix no-dh
Matt Caswell [Wed, 17 Jul 2019 10:40:41 +0000 (11:40 +0100)]
Fix no-dh

The recent move of the DH code into the default provider broke no-dh. This
adds back in various missing guards.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9399)

5 years agoCorrect some OSSL_PARAM documentation
Richard Levitte [Thu, 18 Jul 2019 07:25:24 +0000 (09:25 +0200)]
Correct some OSSL_PARAM documentation

The documentation wasn't quite in sync with the implementation.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9408)

5 years agoAdd value_barriers in constant time select functions
Bernd Edlinger [Fri, 21 Jun 2019 19:26:19 +0000 (21:26 +0200)]
Add value_barriers in constant time select functions

The barriers prevent the compiler from narrowing down the
possible value range of the mask and ~mask in the select
statements, which avoids the recognition of the select
and turning it into a conditional load or branch.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/9217)

5 years agoFix S390X compile error due to missing defines
Shane Lontis [Wed, 17 Jul 2019 22:25:44 +0000 (08:25 +1000)]
Fix S390X compile error due to missing defines

Add the missing S390X_aes_XXX_gcm_CAPABLE() macros into aes_platform.h.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9403)

5 years agoCleanup use of X509 STORE locks
Shane Lontis [Mon, 15 Jul 2019 02:42:38 +0000 (12:42 +1000)]
Cleanup use of X509 STORE locks

Cosmetic changes to use the X509_STORE_lock/unlock functions.
Renamed some ctx variables to store.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9366)

5 years agoFix init_get_thread_local()
Dr. Matthias St. Pierre [Wed, 17 Jul 2019 17:14:01 +0000 (19:14 +0200)]
Fix init_get_thread_local()

Previously, init_get_thread_local() pushed the thread event handler
list onto the global register before calling CRYPTO_THREAD_set_local(),
and when the latter failed, forgot to pop the list from the stack again.

Instead of cleaning the stack on error, this commit avoids the situation
entirely by postponing the push operation until all other operations
succeeded. This reordering also significantly reduces the scope of the
critical section.

Another simplification of the code is achieved by moving the push operation
onto the register (which is disabled in FIPS mode) into a separate function.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9401)

5 years agoDeprecated {OPENSSL,CRYPTO}_debug_mem_{push,pop}
Rich Salz [Wed, 10 Jul 2019 20:22:12 +0000 (16:22 -0400)]
Deprecated {OPENSSL,CRYPTO}_debug_mem_{push,pop}

They were only used for recursive ASN1 parsing.
Even if the internal memory-debugging facility remains,
this simplification seems worthwhile.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9342)

5 years agoFix the return value for SSL_get0_chain_certs()
Matt Caswell [Tue, 16 Jul 2019 14:32:35 +0000 (15:32 +0100)]
Fix the return value for SSL_get0_chain_certs()

This function was always returning 0. It should return 1 on success.

Fixes #9374

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/9395)

5 years agoParameter building utilities.
Pauli [Wed, 17 Jul 2019 06:59:09 +0000 (16:59 +1000)]
Parameter building utilities.

A fuller implementation of PARAMS_TEMPLATE as per #9266 but renamed.
This introduces a statis data type which can be used to constructor a
description of a parameter array.  It can then be converted into a OSSL_PARAM
array and the allocated storage freed by a single call to OPENSSL_free.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9305)

5 years agoremove end of line spaces
Pauli [Tue, 16 Jul 2019 10:35:42 +0000 (20:35 +1000)]
remove end of line spaces

Reviewed-by: Paul Yang <yang.yang@baishancloud.com>
(Merged from https://github.com/openssl/openssl/pull/9397)

5 years agoRemove tab characters from C source files.
Pauli [Tue, 16 Jul 2019 10:24:10 +0000 (20:24 +1000)]
Remove tab characters from C source files.

Some have been creeping into the source code.

Reviewed-by: Paul Yang <yang.yang@baishancloud.com>
(Merged from https://github.com/openssl/openssl/pull/9397)

5 years agoAuto add a label depending on the type of issue they report.
Kurt Roeckx [Sun, 7 Jul 2019 09:04:32 +0000 (11:04 +0200)]
Auto add a label depending on the type of issue they report.

Reviewed-by: Richard Levitte <levitte@openssl.org>
GH: #9319

5 years agoProvider config module: allow providers to already be loaded
Richard Levitte [Mon, 15 Jul 2019 09:55:33 +0000 (11:55 +0200)]
Provider config module: allow providers to already be loaded

This allows 'default' to be configured in the config file, if needed.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9371)

5 years agoFix SSL_CTX_set_session_id_context() docs
Todd Short [Mon, 15 Jul 2019 13:55:13 +0000 (09:55 -0400)]
Fix SSL_CTX_set_session_id_context() docs

Also, use define rather than sizeof

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9377)

5 years agos390x assembly pack: fix restoring of SIGILL action
Patrick Steuer [Mon, 15 Jul 2019 15:00:15 +0000 (17:00 +0200)]
s390x assembly pack: fix restoring of SIGILL action

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9381)

5 years agoActually silently ignore GET / OCSP requests
Viktor Dukhovni [Mon, 15 Jul 2019 17:12:04 +0000 (13:12 -0400)]
Actually silently ignore GET / OCSP requests

Reviewed-by: Matt Caswell <matt@openssl.org>
5 years agoDocument the new EVP_KEYEXCH type and related functions
Matt Caswell [Fri, 28 Jun 2019 08:50:56 +0000 (09:50 +0100)]
Document the new EVP_KEYEXCH type and related functions

Previous commits added the EVP_KEYEXCH type for representing key exchange
algorithms. They also added various functions for fetching and using them,
so we document all of those functions.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9266)

5 years agoAdd the ability to set PKCS#3 DH padding in providers
Matt Caswell [Thu, 27 Jun 2019 15:37:44 +0000 (16:37 +0100)]
Add the ability to set PKCS#3 DH padding in providers

This also adds the ability to set arbitrary parameters on key exchange
algorithms. The ability to pad the output is one such parameter for DH.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9266)

5 years agoEnable PKCS#3 DH in the providers
Matt Caswell [Thu, 27 Jun 2019 14:03:55 +0000 (15:03 +0100)]
Enable PKCS#3 DH in the providers

The default provider now has support for PKCS#3 Diffie-Hellman so we
switch libcrypto to using providers for that algorithm.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9266)

5 years agoImplement PKCS#3 DH Key Exchange in the default provider
Matt Caswell [Thu, 27 Jun 2019 11:36:30 +0000 (12:36 +0100)]
Implement PKCS#3 DH Key Exchange in the default provider

We add the capability for the default provider to perform PKCS#3
Diffie-Hellman key exchange. At this point the implementation is not used
because libcrypto still uses legacy handling for Diffie-Hellman.

Note X9.42 DH is not touched by this commit.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9266)

5 years agoMake the EVP Key Exchange code provider aware
Matt Caswell [Thu, 27 Jun 2019 09:48:17 +0000 (10:48 +0100)]
Make the EVP Key Exchange code provider aware

We introduce a new EVP_KEYEXCH type to represent key exchange algorithms
and refactor the existing code to use it where available.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9266)

5 years agoRegenerate mkerr files
Rich Salz [Thu, 11 Jul 2019 18:01:56 +0000 (14:01 -0400)]
Regenerate mkerr files

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9058)

5 years agoRemove function name from errors
Rich Salz [Fri, 31 May 2019 17:52:45 +0000 (13:52 -0400)]
Remove function name from errors

Deprecate all xxx_F_ defines.
Removed some places that tested for a specific function.
Use empty field for the function names in output.
Update documentation.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9058)

5 years agoRemove DRBG from SSL structure.
Pauli [Tue, 16 Jul 2019 02:28:08 +0000 (12:28 +1000)]
Remove DRBG from SSL structure.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9390)

5 years agoAdd Common shared code needed to move aes ciphers to providers
Shane Lontis [Mon, 15 Jul 2019 23:46:14 +0000 (09:46 +1000)]
Add Common shared code needed to move aes ciphers to providers

Custom aes ciphers will be placed into multiple new files
(instead of the monolithic setup used in the e_aes.c legacy code)
so it makes sense to have a header for the platform specific
code that needs to be shared between files.
modes_lcl.h has also moved to modes_int.h to allow sharing with the
provider source.
Code that will be common to AEAD ciphers has also been added. These
will be used by seperate PR's for GCM, CCM & OCB.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9301)

5 years agoremove end of line whitespace
Pauli [Thu, 11 Jul 2019 20:27:19 +0000 (06:27 +1000)]
remove end of line whitespace

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9111)

5 years agoConvert asn1_dsa.c to use the WPACKET API instead
Matt Caswell [Mon, 10 Jun 2019 16:52:15 +0000 (17:52 +0100)]
Convert asn1_dsa.c to use the WPACKET API instead

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9111)

5 years agoGive WPACKET the ability to have a NULL buffer underneath it
Matt Caswell [Mon, 10 Jun 2019 16:48:26 +0000 (17:48 +0100)]
Give WPACKET the ability to have a NULL buffer underneath it

This means the WPACKET API can be used for calculating the number of
bytes that would have been written if a non-NULL buffer had been used.
This enables us to calculate the number of length bytes required when
encoding ASN.1

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9111)

5 years agoConvert asn1_dsa.c to use the PACKET API instead
Matt Caswell [Fri, 7 Jun 2019 16:40:21 +0000 (17:40 +0100)]
Convert asn1_dsa.c to use the PACKET API instead

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9111)

5 years agoMake the PACKET/WPACKET code available to both libcrypto and libssl
Matt Caswell [Fri, 7 Jun 2019 15:32:49 +0000 (16:32 +0100)]
Make the PACKET/WPACKET code available to both libcrypto and libssl

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9111)

5 years agoAdd simple ASN.1 utils for DSA signature DER.
David Makepeace [Mon, 3 Jun 2019 04:58:54 +0000 (14:58 +1000)]
Add simple ASN.1 utils for DSA signature DER.

Adds simple utility functions to allow both the default and fips providers to
encode and decode DSA-Sig-Value and ECDSA-Sig-Value (DSA_SIG and ECDSA_SIG
structures) to/from ASN.1 DER without requiring those providers to have a
dependency on the asn1 module.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9111)

5 years agoCoverity #1451596: check dirlen for being negative
Pauli [Sun, 14 Jul 2019 07:55:15 +0000 (17:55 +1000)]
Coverity #1451596: check dirlen for being negative

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9362)

5 years agoCoverity #1451595: use correct free function.
Pauli [Sun, 14 Jul 2019 07:53:17 +0000 (17:53 +1000)]
Coverity #1451595: use correct free function.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9362)

5 years agoutil/opensslwrap.sh: adjust to define OPENSSL_MODULES as well
Richard Levitte [Mon, 15 Jul 2019 14:14:35 +0000 (16:14 +0200)]
util/opensslwrap.sh: adjust to define OPENSSL_MODULES as well

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9379)

5 years agoIn documentation, consistently refer to OpenSSL 3.0
Richard Levitte [Mon, 15 Jul 2019 13:03:44 +0000 (15:03 +0200)]
In documentation, consistently refer to OpenSSL 3.0

3.0.0 is a habit from pre-3.0 OpenSSL, which doesn't make sense with
the new version scheme.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9376)