openssl.git
11 months agoHonour mandatory digest on private key in has_usable_cert()
David Woodhouse [Tue, 16 Oct 2018 14:59:46 +0000 (07:59 -0700)]
Honour mandatory digest on private key in has_usable_cert()

If the private key says it can only support one specific digest, then
don't ask it to perform a different one.

Fixes: #7348

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7408)

11 months agoStop marking default digest for EC keys as mandatory
David Woodhouse [Tue, 16 Oct 2018 14:41:17 +0000 (07:41 -0700)]
Stop marking default digest for EC keys as mandatory

ASN1_PKEY_CTRL_DEFAULT_MD_NID is documented to return 2 for a mandatory
digest algorithm, when the key can't support any others. That isn't true
here, so return 1 instead.

Partially fixes #7348

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7408)

11 months agoFix issues with do_rand_init/rand_cleanup_int
Bernd Edlinger [Wed, 7 Nov 2018 20:53:30 +0000 (21:53 +0100)]
Fix issues with do_rand_init/rand_cleanup_int

Fixes #7022

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

11 months agoVMS build: colon after target must be separated with a space
Richard Levitte [Fri, 9 Nov 2018 11:23:53 +0000 (12:23 +0100)]
VMS build: colon after target must be separated with a space

... otherwise, it's taken to be part of a device name.

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

11 months agoHave install targets depend on more precise build targets
Richard Levitte [Wed, 7 Nov 2018 15:13:57 +0000 (16:13 +0100)]
Have install targets depend on more precise build targets

We only had the main 'install' target depend on 'all'.  This changes
the dependencies so targets like install_dev, install_runtime_libs,
install_engines and install_programs depend on build targets that are
correspond to them more specifically.  This increases the parallel
possibilities.

Fixes #7466

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

11 months agoAllow parallel install
Richard Levitte [Thu, 25 Oct 2018 07:09:20 +0000 (09:09 +0200)]
Allow parallel install

When trying 'make -j{n} install', you may occasionally run into
trouble because to sub-targets (install_dev and install_runtime) try
to install the same shared libraries.  That makes parallel install
difficult.

This is solved by dividing install_runtime into two parts, one for
libraries and one for programs, and have install_dev depend on
install_runtime_libs instead of installing the shared runtime
libraries itself.

Fixes #7466

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

11 months agoVMS build: don't add a comma before 'extradefines'
Richard Levitte [Thu, 8 Nov 2018 09:28:33 +0000 (10:28 +0100)]
VMS build: don't add a comma before 'extradefines'

The variable extradefines will have the starting comma, if needed.

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

11 months agorand_unix.c: open random devices on first use only
Dr. Matthias St. Pierre [Thu, 18 Oct 2018 11:27:14 +0000 (13:27 +0200)]
rand_unix.c: open random devices on first use only

Commit c7504aeb640a (pr #6432) fixed a regression for applications in
chroot environments, which compensated the fact that the new OpenSSL CSPRNG
(based on the NIST DRBG) now reseeds periodically, which the previous
one didn't. Now the reseeding could fail in the chroot environment if the
DEVRANDOM devices were not present anymore and no other entropy source
(e.g. getrandom()) was available.

The solution was to keep the file handles for the DEVRANDOM devices open
by default. In fact, the fix did more than this, it opened the DEVRANDOM
devices early and unconditionally in rand_pool_init(), which had the
unwanted side effect that the devices were opened (and kept open) even
in cases when they were not used at all, for example when the getrandom()
system call was available. Due  to a bug (issue #7419) this even happened
when the feature was disabled by the application.

This commit removes the unconditional opening of all DEVRANDOM devices.
They will now only be opened (and kept open) on first use. In particular,
if getrandom() is available, the handles will not be opened unnecessarily.

This change does not introduce a regression for applications compiled for
libcrypto 1.1.0, because the SSLEAY RNG also seeds on first use. So in the
above constellation the CSPRNG will only be properly seeded if it is happens
before the forking and chrooting.

Fixes #7419

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

11 months agoTest: enable internal tests for shared Windows builds
Dr. Matthias St. Pierre [Thu, 25 Oct 2018 23:13:19 +0000 (01:13 +0200)]
Test: enable internal tests for shared Windows builds

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

11 months agoTest: link drbgtest statically against libcrypto
Dr. Matthias St. Pierre [Mon, 22 Oct 2018 16:05:14 +0000 (18:05 +0200)]
Test: link drbgtest statically against libcrypto

and remove duplicate rand_drbg_seedlen() implementation again.

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

11 months agoGive a better error if an attempt is made to set a zero length groups list
Matt Caswell [Fri, 26 Oct 2018 14:29:15 +0000 (15:29 +0100)]
Give a better error if an attempt is made to set a zero length groups list

Previously we indicated this as a malloc failure which isn't very
helpful.

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

11 months agoIgnore disabled ciphers when deciding if we are using ECC
Matt Caswell [Wed, 24 Oct 2018 09:11:00 +0000 (10:11 +0100)]
Ignore disabled ciphers when deciding if we are using ECC

use_ecc() was always returning 1 because there are default (TLSv1.3)
ciphersuites that use ECC - even if those ciphersuites are disabled by
other options.

Fixes #7471

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

11 months agoAdd missing RAND initialisation call.
Pauli [Wed, 7 Nov 2018 21:22:01 +0000 (07:22 +1000)]
Add missing RAND initialisation call.

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

11 months agoRename the rand_drbg_st data member "pool" to "seed_pool"
Bernd Edlinger [Mon, 5 Nov 2018 22:13:11 +0000 (23:13 +0100)]
Rename the rand_drbg_st data member "pool" to "seed_pool"

... to make the intended use more clear and differentiate
it from the data member "adin_pool".

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

11 months agoutil/add-depends.pl: go through shared_sources too
Richard Levitte [Thu, 1 Nov 2018 13:02:21 +0000 (14:02 +0100)]
util/add-depends.pl: go through shared_sources too

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

11 months agoRemove outdated e_chil.txt file
Rich Salz [Tue, 23 Oct 2018 20:13:47 +0000 (16:13 -0400)]
Remove outdated e_chil.txt file

Reviewed-by: Richard Levitte <levitte@openssl.org>
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/7476)

11 months agoFix a race condition in drbgtest.c
Bernd Edlinger [Tue, 30 Oct 2018 21:21:34 +0000 (22:21 +0100)]
Fix a race condition in drbgtest.c

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/7531)

11 months agoFix error handling in RAND_DRBG_uninstantiate
Bernd Edlinger [Fri, 2 Nov 2018 10:46:38 +0000 (11:46 +0100)]
Fix error handling in RAND_DRBG_uninstantiate

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/7517)

11 months agoFix error handling in drbgtest.c
Bernd Edlinger [Tue, 30 Oct 2018 20:02:22 +0000 (21:02 +0100)]
Fix error handling in drbgtest.c

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/7517)

11 months agoFix error handling in rand_drbg_new
Bernd Edlinger [Tue, 30 Oct 2018 19:57:53 +0000 (20:57 +0100)]
Fix error handling in rand_drbg_new

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/7517)

11 months agoFix error handling in RAND_DRBG_set
Bernd Edlinger [Mon, 29 Oct 2018 12:48:53 +0000 (13:48 +0100)]
Fix error handling in RAND_DRBG_set

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/7517)

11 months agoFix return formatting.
Pauli [Mon, 5 Nov 2018 21:06:25 +0000 (07:06 +1000)]
Fix return formatting.

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/7564)

11 months agoCleanse the key log buffer.
Pauli [Mon, 5 Nov 2018 01:04:23 +0000 (11:04 +1000)]
Cleanse the key log buffer.

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/7564)

11 months agoEVP_MAC ctrl numbering duplicate removal.
Pauli [Mon, 5 Nov 2018 04:30:37 +0000 (14:30 +1000)]
EVP_MAC ctrl numbering duplicate removal.

Both EVP_MAC_CTRL_SET_MD and EVP_MAC_CTRL_SET_CIPHER were numbered 4.
This would preclude any future MAC from using both.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Yang <yang.yang@baishancloud.com>
(Merged from https://github.com/openssl/openssl/pull/7566)

11 months agoGMAC: Add subdir info in crypto/build.info for this to build
Richard Levitte [Mon, 5 Nov 2018 15:52:46 +0000 (16:52 +0100)]
GMAC: Add subdir info in crypto/build.info for this to build

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

11 months agoFix a collision in function err numbers
Paul Yang [Mon, 5 Nov 2018 15:08:34 +0000 (23:08 +0800)]
Fix a collision in function err numbers

'make update' complains about this

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

11 months agoSimplify the processing of skipped source directories
Richard Levitte [Sat, 3 Nov 2018 17:38:04 +0000 (18:38 +0100)]
Simplify the processing of skipped source directories

We kept a number of arrays of directory names to keep track of exactly
which directories to look for build.info.  Some of these had the extra
function to hold the directories to actually build.

With the added SUBDIRS keyword, these arrays are no longer needed.
The logic for skipping certain directories needs to be kept, though.
That is now very much simplified, and is made opportunistic.

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

11 months agoCollapse different classes of macro databases
Richard Levitte [Sat, 3 Nov 2018 17:34:09 +0000 (18:34 +0100)]
Collapse different classes of macro databases

We have $config{openssl_algorithm_defines}, $config{openssl_other_defines}
and $config{openssl_thread_defines}.  These are treated exactly the same
in include/openssl/opensslconf.h.in, so having them separated into three
different databases isn't necessary, the reason for the separation being
long gone.  Therefore, we collapse them into one and the same,
$config{openssl_feature_defines}.

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

11 months agoAdd SUBDIRS settings in relevant build.info files
Richard Levitte [Sat, 3 Nov 2018 17:26:35 +0000 (18:26 +0100)]
Add SUBDIRS settings in relevant build.info files

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

11 months agoBuild: make it possibly to specify subdirs in build.info
Richard Levitte [Sat, 3 Nov 2018 14:03:59 +0000 (15:03 +0100)]
Build: make it possibly to specify subdirs in build.info

This adds a keyword SUBDIRS for build.info, to be used like this:

    SUBDIRS=foo bar

This tells Configure that it should look for 'build.info' in the
relative subdirectories 'foo' and 'bar' as well.

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

11 months agoBuild: Make it possible to have defines assigned to end products as well
Richard Levitte [Fri, 2 Nov 2018 12:08:38 +0000 (13:08 +0100)]
Build: Make it possible to have defines assigned to end products as well

This simple fix allows the following construct:

    PROGRAMS=foo
    SOURCE[foo]=foo.c bar.c
    DEFINE[foo]=FOO=1 BAR=0

These will trickle down to the build of object files, so building
foo.o and bar.o will be done with these options: -DFOO=1 -DBAR=0
(exact syntax depending on platform, of course)

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

11 months agoBuild: adapt VMS build file template to use the extra macros
Richard Levitte [Fri, 14 Oct 2016 15:10:15 +0000 (17:10 +0200)]
Build: adapt VMS build file template to use the extra macros

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

11 months agoBuild: adapt Windows makefile template to use the extra macros
Richard Levitte [Fri, 14 Oct 2016 15:10:05 +0000 (17:10 +0200)]
Build: adapt Windows makefile template to use the extra macros

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

11 months agoBuild: adapt Unix Makefile template to use the extra macros
Richard Levitte [Fri, 14 Oct 2016 15:09:52 +0000 (17:09 +0200)]
Build: adapt Unix Makefile template to use the extra macros

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

11 months agoBuild: make it possible to assign macro definitions for specific outputs
Richard Levitte [Fri, 14 Oct 2016 14:56:34 +0000 (16:56 +0200)]
Build: make it possible to assign macro definitions for specific outputs

Sometimes, some specific program or object file might need an extra
macro definition of its own.  This allows that to be easily done.

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

11 months agoAdd poly1305 MAC support
Paul Yang [Mon, 22 Oct 2018 06:54:24 +0000 (14:54 +0800)]
Add poly1305 MAC support

This is based on the latest EVP MAC interface introduced in PR #7393.

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

11 months agoClarify the POD source for the list command.
Pauli [Sun, 4 Nov 2018 22:24:50 +0000 (08:24 +1000)]
Clarify the POD source for the list command.

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

11 months agoGMAC implementation
Pauli [Sun, 4 Nov 2018 22:09:41 +0000 (08:09 +1000)]
GMAC implementation
Remove GMAC demo program because it has been superceded by the EVP MAC one

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

11 months agoRestore sensible "sess_accept" counter tracking
Benjamin Kaduk [Mon, 22 Oct 2018 16:54:20 +0000 (11:54 -0500)]
Restore sensible "sess_accept" counter tracking

Commit 9ef9088c1585e13b9727796f15f77da64dbbe623 switched the SSL/SSL_CTX
statistics counters to using Thread-Sanitizer-friendly primitives.
However, it erroneously converted an addition of -1
(for s->session_ctx->stats.sess_accept) to an addition of +1, since that
is the only counter API provided by the internal tsan_assist.h header
until the previous commit.  This means that for each accepted (initial)
connection, the session_ctx's counter would get doubly incremented, and the
(switched) ctx's counter would also get incremented.

Restore the counter decrement so that each accepted connection increments
exactly one counter exactly once (in net effect).

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

11 months agoAdd tsan_decr() API, counterpart of tsan_counter()
Benjamin Kaduk [Mon, 22 Oct 2018 16:51:35 +0000 (11:51 -0500)]
Add tsan_decr() API, counterpart of tsan_counter()

The existing tsan_counter() API increments a reference counter.
Provide a new API, tsan_decr(), to decrement such a reference counter.
This can be used, for example, when a reference is added to the session_ctx's
sess_accept stats but should more properly be tracked in the regular ctx's
statistics.

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

11 months agocrypto/engine/eng_devcrypto.c: ensure we don't leak resources
Richard Levitte [Fri, 2 Nov 2018 09:24:24 +0000 (10:24 +0100)]
crypto/engine/eng_devcrypto.c: ensure we don't leak resources

If engine building fails for some reason, we must make sure to close
the /dev/crypto handle.

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

11 months agocrypto/engine/eng_devcrypto.c: open /dev/crypto only once
Richard Levitte [Wed, 31 Oct 2018 18:23:44 +0000 (19:23 +0100)]
crypto/engine/eng_devcrypto.c: open /dev/crypto only once

We opened /dev/crypto once for each session, which is quite unnecessary.
With this change, we open /dev/crypto once at engine init, and close
it on unload.

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

11 months agocrypto/engine/eng_devcrypto.c: new compilers are strict on prototypes
Richard Levitte [Sat, 27 Oct 2018 07:26:22 +0000 (09:26 +0200)]
crypto/engine/eng_devcrypto.c: new compilers are strict on prototypes

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

11 months agocrypto/engine/eng_devcrypto.c: add digest copy
Richard Levitte [Sat, 27 Oct 2018 07:15:04 +0000 (09:15 +0200)]
crypto/engine/eng_devcrypto.c: add digest copy

Copying an EVP_MD_CTX, including the implementation local bits, is a
necessary operation.  In this case, though, it's the same as
initializing the local bits to be "copied to".

Fixes #7495

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

11 months agodoc/man7/EVP_MAC_*.pod: incorrect english corrected
Richard Levitte [Fri, 2 Nov 2018 09:11:55 +0000 (10:11 +0100)]
doc/man7/EVP_MAC_*.pod: incorrect english corrected

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

11 months agoapps: Stop pretending to care about Netscape keys
Richard Levitte [Thu, 18 Oct 2018 22:36:04 +0000 (00:36 +0200)]
apps: Stop pretending to care about Netscape keys

The documentation says some commands care, but the code says differently.

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

11 months agoFix a doc-nit in EVP_PKEY_CTX_ctrl.pod
Paul Yang [Thu, 1 Nov 2018 15:27:31 +0000 (23:27 +0800)]
Fix a doc-nit in EVP_PKEY_CTX_ctrl.pod

[skip-ci]

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

11 months agoAdd a constant time flag to one of the bignums to avoid a timing leak.
Pauli [Wed, 31 Oct 2018 22:44:11 +0000 (08:44 +1000)]
Add a constant time flag to one of the bignums to avoid a timing leak.

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

11 months agoopenssl list -mac-algorithms support.
Pauli [Thu, 1 Nov 2018 04:25:20 +0000 (14:25 +1000)]
openssl list -mac-algorithms support.

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

11 months agoConfigure: ensure empty arrays aren't created inadvertently
Richard Levitte [Thu, 1 Nov 2018 12:55:32 +0000 (13:55 +0100)]
Configure: ensure empty arrays aren't created inadvertently

Just refering to a hash table element as an array reference will
automatically create that element.  Avoid that by defaulting to
a separate empty array reference.

Fixes #7543

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

11 months agoAvoid two memory allocations in each RAND_DRBG_bytes
Bernd Edlinger [Sat, 27 Oct 2018 09:31:21 +0000 (11:31 +0200)]
Avoid two memory allocations in each RAND_DRBG_bytes

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/7507)

11 months agoConfiguration: when building the dirinfo structure, include shared_sources
Richard Levitte [Sun, 21 Oct 2018 09:11:04 +0000 (11:11 +0200)]
Configuration: when building the dirinfo structure, include shared_sources

This makes sure that any resulting directory target in the build files
also depend on object files meant for shared libraries.

As a side effect, we move the production of the dirinfo structure from
common.tmpl to Configure, to make it easier to check the result.

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

11 months agoConfigurations/15-android.conf: detect NDK llvm-ar.
Andy Polyakov [Fri, 19 Oct 2018 20:24:30 +0000 (22:24 +0200)]
Configurations/15-android.conf: detect NDK llvm-ar.

This excluses user from additional PATH adjustments in case NDK has
llvm-ar.

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

11 months agoConfigurations/15-android.conf: fix implicit __ANDROID_API__ handling.
Andy Polyakov [Fri, 19 Oct 2018 14:03:28 +0000 (16:03 +0200)]
Configurations/15-android.conf: fix implicit __ANDROID_API__ handling.

03ad7c009e16a233c733098db3169c560142ccd3 failed if one didn't pass
explicit -D__ANDROID_API__=N :-(

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

11 months agoFix a race condition in drbg_add
Bernd Edlinger [Mon, 29 Oct 2018 12:48:53 +0000 (13:48 +0100)]
Fix a race condition in drbg_add

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/7523)

11 months agoAdd a client_cert_cb test
Matt Caswell [Tue, 16 Oct 2018 11:42:59 +0000 (12:42 +0100)]
Add a client_cert_cb test

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/7413)

11 months agoDon't call the client_cert_cb immediately in TLSv1.3
Matt Caswell [Thu, 11 Oct 2018 16:01:06 +0000 (17:01 +0100)]
Don't call the client_cert_cb immediately in TLSv1.3

In TLSv1.2 and below a CertificateRequest is sent after the Certificate
from the server. This means that by the time the client_cert_cb is called
on receipt of the CertificateRequest a call to SSL_get_peer_certificate()
will return the server certificate as expected. In TLSv1.3 a
CertificateRequest is sent before a Certificate message so calling
SSL_get_peer_certificate() returns NULL.

To workaround this we delay calling the client_cert_cb until after we
have processed the CertificateVerify message, when we are doing TLSv1.3.

Fixes #7384

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/7413)

11 months agoAdd blurbs about EVP_MAC in NEWS and CHANGES
Richard Levitte [Tue, 30 Oct 2018 07:57:34 +0000 (08:57 +0100)]
Add blurbs about EVP_MAC in NEWS and CHANGES

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

11 months agoHave a couple of SipHash test uses the EVP_PKEY method
Richard Levitte [Wed, 24 Oct 2018 22:29:02 +0000 (00:29 +0200)]
Have a couple of SipHash test uses the EVP_PKEY method

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

11 months agoEVP_MAC: Integrate SipHash EVP_PKEY_METHOD into generic MAC EVP_PKEY_METHOD
Richard Levitte [Wed, 24 Oct 2018 22:20:48 +0000 (00:20 +0200)]
EVP_MAC: Integrate SipHash EVP_PKEY_METHOD into generic MAC EVP_PKEY_METHOD

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

11 months agoEVP_MAC: Add SipHash implementation
Richard Levitte [Wed, 24 Oct 2018 22:17:45 +0000 (00:17 +0200)]
EVP_MAC: Add SipHash implementation

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

11 months agorand_drbg.h: include <openssl/obj_mac.h>
Dr. Matthias St. Pierre [Mon, 29 Oct 2018 21:27:42 +0000 (22:27 +0100)]
rand_drbg.h: include <openssl/obj_mac.h>

The RAND_DRBG_TYPE preprocessor define depends on a NID, so  we have
to include obj_mac.h to make the header selfcontained.

Fixes #7521

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

11 months agoMake sure at least one HMAC test still uses the EVP_PKEY method
Richard Levitte [Wed, 24 Oct 2018 20:49:49 +0000 (22:49 +0200)]
Make sure at least one HMAC test still uses the EVP_PKEY method

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

11 months agoEVP_MAC: Integrate HMAC EVP_PKEY_METHOD into generic MAC EVP_PKEY_METHOD
Richard Levitte [Wed, 24 Oct 2018 19:25:00 +0000 (21:25 +0200)]
EVP_MAC: Integrate HMAC EVP_PKEY_METHOD into generic MAC EVP_PKEY_METHOD

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

11 months agoEVP_MAC: Add HMAC implementation
Richard Levitte [Wed, 24 Oct 2018 19:20:00 +0000 (21:20 +0200)]
EVP_MAC: Add HMAC implementation

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

11 months agoMake sure at least one CMAC test still uses the EVP_PKEY method
Richard Levitte [Wed, 24 Oct 2018 20:47:28 +0000 (22:47 +0200)]
Make sure at least one CMAC test still uses the EVP_PKEY method

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

11 months agoAdapt other EVP code to use EVP_MAC instead of direct implementation calls
Richard Levitte [Wed, 24 Oct 2018 19:40:00 +0000 (21:40 +0200)]
Adapt other EVP code to use EVP_MAC instead of direct implementation calls

The EVP_PKEY methods for CMAC and HMAC needed a rework, although it
wasn't much change apart from name changes.

This also meant that EVP_PKEY_new_CMAC_key() needed an adjustment.
(the possibility to rewrite this function to work with any MAC is yet
to be explored)

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

11 months agoEVP_MAC: Integrate CMAC EVP_PKEY_METHOD into generic MAC EVP_PKEY_METHOD
Richard Levitte [Wed, 24 Oct 2018 19:35:00 +0000 (21:35 +0200)]
EVP_MAC: Integrate CMAC EVP_PKEY_METHOD into generic MAC EVP_PKEY_METHOD

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

11 months agoEVP_MAC: Add CMAC implementation
Richard Levitte [Wed, 24 Oct 2018 19:30:00 +0000 (21:30 +0200)]
EVP_MAC: Add CMAC implementation

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

11 months agoFix MSVC warning C4819
Chocobo1 [Fri, 19 Oct 2018 14:05:49 +0000 (22:05 +0800)]
Fix MSVC warning C4819

CLA: trivial

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

11 months agoDSA: Check for sanity of input parameters
Vitezslav Cizek [Thu, 25 Oct 2018 11:53:26 +0000 (13:53 +0200)]
DSA: Check for sanity of input parameters

dsa_builtin_paramgen2 expects the L parameter to be greater than N,
otherwise the generation will get stuck in an infinite loop.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/7493)

11 months agotest/evp_test.c: Fixed strcmp() fault in mac_test_init()
Richard Levitte [Mon, 29 Oct 2018 15:27:43 +0000 (16:27 +0100)]
test/evp_test.c: Fixed strcmp() fault in mac_test_init()

When wanting to compare the end of a string with another string, make
sure not to start somewhere before the start of the first string.

[extended tests]

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

11 months agotest/evp_test.c: don't misuse pkey_test_ctrl() in mac_test_run()
Richard Levitte [Fri, 26 Oct 2018 11:42:40 +0000 (13:42 +0200)]
test/evp_test.c: don't misuse pkey_test_ctrl() in mac_test_run()

pkey_test_ctrl() was designed for parsing values, not for using in
test runs.  Relying on its returned value when it returned 1 even for
control errors made it particularly useless for mac_test_run().

Here, it gets replaced with a MAC specific control function, that
parses values the same way but is designed for use in a _run() rather
than a _parse() function.

This uncovers a SipHash test with an invalid control that wasn't
caught properly.  After all, that stanza is supposed to test that
invalid control values do generate an error.  Now we catch that.

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

11 months agoAdd a test where we reuse the EVP_PKEY_CTX for two HKDF test runs
Matt Caswell [Fri, 26 Oct 2018 11:45:27 +0000 (12:45 +0100)]
Add a test where we reuse the EVP_PKEY_CTX for two HKDF test runs

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

11 months agoReset the HKDF state between operations
Matt Caswell [Fri, 26 Oct 2018 11:19:43 +0000 (12:19 +0100)]
Reset the HKDF state between operations

Fixes #7497

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

11 months agoWindows build: build foo.d after foo.obj
Richard Levitte [Tue, 23 Oct 2018 08:35:48 +0000 (10:35 +0200)]
Windows build: build foo.d after foo.obj

We made the build of foo.obj depend on foo.d, meaning the latter gets
built first.  Unfortunately, the way the compiler works, we are forced
to redirect all output to foo.d, meaning that if the source contains
an error, the build fails without showing those errors.

We therefore remove the dependency and force the build of foo.d to
always happen after build of foo.obj.

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

11 months agossl/statem: Don't compare size_t with less than zero
Richard Levitte [Wed, 12 Sep 2018 00:31:10 +0000 (02:31 +0200)]
ssl/statem: Don't compare size_t with less than zero

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

11 months agoVMS & cryptoerr.h: include symhacks.h
Richard Levitte [Wed, 12 Sep 2018 00:30:25 +0000 (02:30 +0200)]
VMS & cryptoerr.h: include symhacks.h

Needed to clear a clash between ERR_load_CRYPTO_strings and
ERR_load_crypto_strings

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

11 months agoapps/rehash.c: Convert ISO-8859-1 to UTF-8
Richard Levitte [Wed, 12 Sep 2018 00:28:35 +0000 (02:28 +0200)]
apps/rehash.c: Convert ISO-8859-1 to UTF-8

Believe it or not, the VMS C compiler is remarking on this

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

11 months agoAdd convenience functions EVP_str2ctrl() and EVP_hex2ctrl()
Richard Levitte [Wed, 24 Oct 2018 18:20:00 +0000 (20:20 +0200)]
Add convenience functions EVP_str2ctrl() and EVP_hex2ctrl()

These functions are generalizations of EVP_PKEY_CTX_str2ctrl() and
EVP_PKEY_CTX_hex2ctrl().  They will parse the value, and then pass the
parsed result and length to a callback that knows exactly how to pass
them on to a main _ctrl function, along with a context structure
pointer.

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

11 months agoAdapt test/evp_test.c to deal with available EVP_MACs
Richard Levitte [Wed, 24 Oct 2018 16:36:31 +0000 (18:36 +0200)]
Adapt test/evp_test.c to deal with available EVP_MACs

If a MAC isn't available as an EVP_MAC, the MAC test falls back to the
corresponding EVP_PKEY method.

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

11 months agoAdd generic EVP_PKEY_METHOD for EVP_MACs
Richard Levitte [Wed, 24 Oct 2018 16:35:32 +0000 (18:35 +0200)]
Add generic EVP_PKEY_METHOD for EVP_MACs

The MAC EVP_PKEY implementations are currently implemented for each
MAC.  However, with the EVP_MAC API, only one such implementation is
needed.

This implementation takes into account the differences between HMAC
and CMAC implementations, and observes that all other current MAC
implementations seem to follow the HMAC model.

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

11 months agoAdd automatic initializations support for EVP_MAC objects
Richard Levitte [Wed, 24 Oct 2018 16:34:53 +0000 (18:34 +0200)]
Add automatic initializations support for EVP_MAC objects

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

11 months agoAdd EVP_MAC API
Richard Levitte [Fri, 12 Oct 2018 20:27:18 +0000 (22:27 +0200)]
Add EVP_MAC API

We currently implement EVP MAC methods as EVP_PKEY methods.  This
change creates a separate EVP API for MACs, to replace the current
EVP_PKEY ones.

A note about this EVP API and how it interfaces with underlying MAC
implementations:

Other EVP APIs pass the EVP API context down to implementations, and
it can be observed that the implementations use the pointer to their
own private data almost exclusively.  The EVP_MAC API deviates from
that pattern by passing the pointer to the implementation's private
data directly, and thereby deny the implementations access to the
EVP_MAC context structure.  This change is made to provide a clearer
separation between the EVP library itself and the implementations of
its supported algorithm classes.

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

11 months agoRework and simplify resource flow in drbg_add
Bernd Edlinger [Fri, 26 Oct 2018 19:06:14 +0000 (21:06 +0200)]
Rework and simplify resource flow in drbg_add

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/7504)

11 months agorandfile.c: fix a Coverity warning
Dr. Matthias St. Pierre [Sun, 28 Oct 2018 12:32:11 +0000 (13:32 +0100)]
randfile.c: fix a Coverity warning

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

11 months agoTiming vulnerability in ECDSA signature generation (CVE-2018-0735)
Pauli [Fri, 26 Oct 2018 00:54:58 +0000 (10:54 +1000)]
Timing vulnerability in ECDSA signature generation (CVE-2018-0735)

Preallocate an extra limb for some of the big numbers to avoid a reallocation
that can potentially provide a side channel.

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

11 months agoTiming vulnerability in DSA signature generation (CVE-2018-0734).
Pauli [Tue, 23 Oct 2018 21:42:46 +0000 (07:42 +1000)]
Timing vulnerability in DSA signature generation (CVE-2018-0734).

Avoid a timing attack that leaks information via a side channel that
triggers when a BN is resized.  Increasing the size of the BNs
prior to doing anything with them suppresses the attack.

Thanks due to Samuel Weiser for finding and locating this.

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

11 months agoDSA mod inverse fix
Pauli [Sun, 28 Oct 2018 20:50:51 +0000 (06:50 +1000)]
DSA mod inverse fix

There is a side channel attack against the division used to calculate one of
the modulo inverses in the DSA algorithm.  This change takes advantage of the
primality of the modulo and Fermat's little theorem to calculate the inverse
without leaking information.

Thanks to Samuel Weiser for finding and reporting this.

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/7487)

11 months agodrbg_lib: avoid NULL pointer dereference in drbg_add
Dr. Matthias St. Pierre [Sun, 28 Oct 2018 12:46:35 +0000 (13:46 +0100)]
drbg_lib: avoid NULL pointer dereference in drbg_add

Found by Coverity Scan

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

11 months agoiOS config targets: disable "async" by default
Richard Levitte [Mon, 15 Oct 2018 16:37:18 +0000 (18:37 +0200)]
iOS config targets: disable "async" by default

This also gave enough reason to collect the stuff that's common for
all iOS config targets into the template "ios-common".

Fixes #7318

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

11 months agoConfigure: Improve warning if no random seed source was configured
Dr. Matthias St. Pierre [Sun, 28 Oct 2018 11:38:49 +0000 (12:38 +0100)]
Configure: Improve warning if no random seed source was configured

The new Configure summary box (41349b5e6db) now hides the warning
about the missing seed source (2805ee1e095) too much. To make it
more visible again, add warning markers.

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

11 months agoSupport GeneralSubtrees with minimum = 0
Fraser Tweedale [Sat, 27 Oct 2018 04:11:41 +0000 (12:11 +0800)]
Support GeneralSubtrees with minimum = 0

The Name Constraints extension contains GeneralSubtree values
indicating included or excluded subtrees.  It is defined as:

  GeneralSubtree ::= SEQUENCE {
    base                    GeneralName,
    minimum         [0]     BaseDistance DEFAULT 0,
    maximum         [1]     BaseDistance OPTIONAL }

RFC 5280 further specifies:

  Within this profile, the minimum and maximum fields are not used with
  any name forms, thus, the minimum MUST be zero, and maximum MUST be
  absent.

Because the minimum fields has DEFAULT 0, and certificates should be
encoded using DER, the situation where minimum = 0 occurs in a
certificate should not arise.  Nevertheless, it does arise.  For
example, I have seen certificates issued by Microsoft programs that
contain GeneralSubtree values encoded thus.

Enhance the Name Constraints matching routine to handle the case
where minimum is specified.  If present, it must be zero.  The
maximum field remains prohibited.

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

11 months agoFix data race in RAND_DRBG_generate
Bernd Edlinger [Sun, 14 Oct 2018 10:35:19 +0000 (12:35 +0200)]
Fix data race in RAND_DRBG_generate

Fixes #7394

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

11 months agoAdd a test for duplicated DTLS records
Matt Caswell [Tue, 16 Oct 2018 16:03:39 +0000 (17:03 +0100)]
Add a test for duplicated DTLS records

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

11 months agoProperly handle duplicated messages from the next epoch
Matt Caswell [Tue, 16 Oct 2018 16:08:11 +0000 (17:08 +0100)]
Properly handle duplicated messages from the next epoch

Since 1fb9fdc30 we may attempt to buffer a record from the next epoch
that has already been buffered. Prior to that this never occurred.

We simply ignore a failure to buffer a duplicated record.

Fixes #6902

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

11 months agoFix a possible crash in rand_drbg_get_entropy
Bernd Edlinger [Tue, 23 Oct 2018 14:30:20 +0000 (16:30 +0200)]
Fix a possible crash in rand_drbg_get_entropy

Reviewed-by: Paul Yang <yang.yang@baishancloud.com>
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/7474)

11 months agoConfigure: Reword the summary output
Dr. Matthias St. Pierre [Thu, 25 Oct 2018 21:31:24 +0000 (23:31 +0200)]
Configure: Reword the summary output

In commit 820e414d2830 (pr #5247) the summary output of the
Configure command was optimized towards instructing people
how to create issue reports.

It turned out that the wording of this message can confuse new
OpenSSL users and make them think that they are seeing an error
message. This commit makes the summary output start with a success
to prevent a misunderstanding. Also it gives more hints to new
OpenSSL users.

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

11 months agoRAND_add()/RAND_seed(): fix failure on short input or low entropy
Dr. Matthias St. Pierre [Sun, 21 Oct 2018 13:45:34 +0000 (15:45 +0200)]
RAND_add()/RAND_seed(): fix failure on short input or low entropy

Commit 5b4cb385c18a (#7382) introduced a bug which had the effect
that RAND_add()/RAND_seed() failed for buffer sizes less than
32 bytes. The reason was that now the added random data was used
exlusively as entropy source for reseeding. When the random input
was too short or contained not enough entropy, the DRBG failed
without querying the available entropy sources.

This commit makes drbg_add() act smarter: it checks the entropy
requirements explicitely. If the random input fails this check,
it won't be added as entropy input, but only as additional data.
More precisely, the behaviour depends on whether an os entropy
source was configured (which is the default on most os):

- If an os entropy source is avaible then we declare the buffer
  content as additional data by setting randomness to zero and
  trigger a regular   reseeding.

- If no os entropy source is available, a reseeding will fail
  inevitably. So drbg_add() uses a trick to mix the buffer contents
  into the DRBG state without forcing a reseeding: it generates a
  dummy random byte, using the buffer content as additional data.

Related-to: #7449

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

11 months agoRAND_load_file(): avoid adding small chunks to RAND_add()
Dr. Matthias St. Pierre [Sun, 21 Oct 2018 16:49:19 +0000 (18:49 +0200)]
RAND_load_file(): avoid adding small chunks to RAND_add()

Increase the load buffer size such that it exceeds the chunk
size by a comfortable amount. This is done to avoid calling
RAND_add() with a small final chunk. Instead, such a small
final chunk will be added together with the previous chunk
(unless it's the only one).

Related-to: #7449

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