openssl/crypto
Matt Caswell a2b6231601 Handle the case where there is no digest in an EVP_MD_CTX
EVP_MD_CTX_ctrl assumes that a digest has always been set. However in a
non-legacy EVP_DigestSign* operation this is not the case because the
digest is handled entirely by the underlying signature implementation.

This fixes one of the travis failures on the master branch.

[extended tests]

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11317)
2020-03-19 11:39:39 +00:00
..
aes aes-s390x.pl: fix stg offset caused by typo in perlasm 2020-03-05 17:19:33 +01:00
aria
asn1 Extract sk_ASN1_UTF8STRING2text() from ts_get_status_text() in ts_rsp_verify.c to asn1_lib.c 2020-03-10 16:09:44 +01:00
async Use swapcontext for Intel CET 2020-02-07 23:25:37 +00:00
bf
bio
bn [BN] harden BN_copy() against leaks from memory accesses 2020-02-18 19:11:10 +02:00
buffer Rework how our providers are built 2019-10-10 14:12:15 +02:00
camellia Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
cast Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
chacha Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
cmac Deprecate the low level CMAC functions 2020-01-29 19:49:22 +10:00
cmp Rename OSSL_{d2i,i2d}_CMP_MSG_bio to {d2i,id2}_OSSL_CMP_MSG_bio 2020-03-18 13:53:42 +01:00
cms Implementation of Russian GOST CMS 2020-03-03 16:34:40 +03:00
comp
conf Make generated copyright year be "now" 2020-01-07 15:53:15 -05:00
crmf Fix error in case CMP msg POPO is not provided in OSSL_CRMF_MSGS_verify_popo() 2020-03-10 16:09:44 +01:00
ct Deprecate the low level SHA functions. 2020-01-19 10:14:39 +10:00
des Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
dh DH: remove DH parameter files that aren't used or installed. 2020-03-14 15:05:56 +10:00
dsa EVP: Check that key methods aren't foreign when exporting 2020-03-09 10:54:01 +01:00
dso Reorganize local header files 2019-09-28 20:26:35 +02:00
ec Implement serializers for ED25519 and ED448 2020-03-18 08:40:33 +10:00
engine Deprecate the low level SHA functions. 2020-01-19 10:14:39 +10:00
err Code to thread-safety in ChangeCipherState 2020-03-13 14:20:14 -07:00
ess Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
evp Handle the case where there is no digest in an EVP_MD_CTX 2020-03-19 11:39:39 +00:00
ffc Change DH_get_nid() to set the value of q if it is not already set 2020-03-07 07:47:58 +10:00
hmac Deprecate the low level HMAC functions 2020-01-29 19:49:23 +10:00
http
idea
kdf Deprecate ERR_load_KDF_strings() 2019-11-12 13:30:35 +01:00
lhash Rework how our providers are built 2019-10-10 14:12:15 +02:00
md2
md4 Adapt all build.info and test recipes to the new $disabled{'deprecated-x.y'} 2020-02-07 14:54:36 +01:00
md5
mdc2 Adapt all build.info and test recipes to the new $disabled{'deprecated-x.y'} 2020-02-07 14:54:36 +01:00
modes
objects
ocsp
pem
perlasm
pkcs7 Explicitly test against NULL; do not use !p or similar 2019-10-09 21:32:15 +02:00
pkcs12
poly1305 Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
property Introduce the provider property 2020-02-21 20:17:02 +00:00
rand AES CTR-DRGB: performance improvement 2020-03-11 12:14:10 +01:00
rc2
rc4 Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
rc5
ripemd Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
rsa Add RSA sign to the fips provider 2020-03-15 17:38:00 +10:00
seed
serializer If the first serializer we find is the desired one that's ok 2020-03-11 15:07:00 +00:00
sha x86_64: Don't assume 8-byte pointer size 2020-02-18 18:03:16 +01:00
siphash Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
sm2
sm3 Cleanup legacy digest methods. 2019-12-18 14:46:01 +10:00
sm4
srp Update source files for pre-3.0 deprecation 2019-11-07 11:37:25 +01:00
stack Rework how our providers are built 2019-10-10 14:12:15 +02:00
store
ts
txt_db
ui
whrlpool Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
x509
alphacpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
arm64cpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
arm_arch.h Fix header file include guard names 2019-09-28 20:26:36 +02:00
armcap.c crypto/armcap.c, crypto/ppccap.c: stricter use of getauxval() 2019-01-16 18:00:48 +01:00
armv4cpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
asn1_dsa.c Fix some typos 2019-12-11 19:04:01 +01:00
bsearch.c ossl_bsearch(): New generic internal binary search utility function 2019-05-08 16:17:16 +02:00
build.info Add pairwise consistency self tests to asym keygenerators 2020-03-03 14:02:36 +10:00
c64xpluscpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
context.c Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
core_algorithm.c Replumbing: make it possible for providers to specify multiple names 2019-10-03 15:47:25 +02:00
core_fetch.c CORE: pass the full algorithm definition to the method constructor 2019-11-29 20:42:12 +01:00
core_namemap.c
cpt_err.c CORE: ossl_namemap_add_names(): new function to add multiple names 2019-11-29 20:42:12 +01:00
cryptlib.c Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
ctype.c Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
cversion.c Cleanup include/openssl/opensslv.h.in 2019-11-08 16:12:57 +01:00
dllmain.c Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
ebcdic.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
ex_data.c
getenv.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
ia64cpuid.S Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
info.c Modify the add_seeds_stringlist() macro to fix a preprocessor error 2020-01-07 16:28:37 +01:00
init.c Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
initthread.c Fix init_thread_stop 2020-01-20 14:41:36 +00:00
LPdir_nyi.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
LPdir_unix.c
LPdir_vms.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
LPdir_win32.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
LPdir_win.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
LPdir_wince.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
mem_clr.c
mem_sec.c secmem: ignore small minsize arguments to CRYPTO_secure_malloc_init(). 2020-02-26 15:38:37 +10:00
mem.c Memory allocator code cleanup 2020-02-10 16:49:10 +10:00
mips_arch.h Fix header file include guard names 2019-09-28 20:26:36 +02:00
o_dir.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
o_fips.c
o_fopen.c
o_init.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
o_str.c Add OPENSSL_hexstr2buf_ex() and OPENSSL_buf2hexstr_ex() 2019-08-12 12:50:41 +02:00
o_time.c Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
packet.c Give WPACKET the ability to have a NULL buffer underneath it 2019-07-12 06:26:46 +10:00
param_build.c Remove unused ossl_param_bld_to_param_ex() function. 2020-02-12 19:45:42 +10:00
params_from_text.c Params: add argument to the _from_text calls to indicate if the param exists. 2020-02-21 13:04:25 +01:00
params.c
pariscid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
ppc_arch.h Fix header file include guard names 2019-09-28 20:26:36 +02:00
ppccap.c Reorganize local header files 2019-09-28 20:26:35 +02:00
ppccpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
provider_conf.c Load the config file by default 2019-08-01 09:59:20 +01:00
provider_core.c Add RSA sign to the fips provider 2020-03-15 17:38:00 +10:00
provider_local.h Replumbing: Add a mechanism to pre-populate the provider store 2019-03-19 14:06:58 +01:00
provider_predefined.c When building of modules is disabled, build the legacy provider into libcrypto 2019-09-26 22:41:47 +02:00
provider.c Rename provider and core get_param_types functions 2019-08-15 11:58:25 +02:00
README.sparse_array Fix Typos 2019-07-02 14:22:29 +02:00
s390x_arch.h
s390xcap.c crypto/s390xcap.c: Add guards around the GETAUXVAL checks 2019-10-21 15:14:09 +02:00
s390xcpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
self_test_core.c Add pairwise consistency self tests to asym keygenerators 2020-03-03 14:02:36 +10:00
sparc_arch.h Fix header file include guard names 2019-09-28 20:26:36 +02:00
sparccpuid.S Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
sparcv9cap.c Fix misspelling errors and typos reported by codespell 2020-02-06 17:01:00 +01:00
sparse_array.c Reorganize private crypto header files 2019-09-28 20:26:34 +02:00
threads_none.c drbg: ensure fork-safety without using a pthread_atfork handler 2019-09-11 11:22:18 +02:00
threads_pthread.c drbg: ensure fork-safety without using a pthread_atfork handler 2019-09-11 11:22:18 +02:00
threads_win.c crypto/threads_win.c: fix preprocessor indentation 2019-09-11 11:22:18 +02:00
trace.c OSSL_STORE: add tracing 2019-11-03 18:38:23 +01:00
uid.c Remove NextStep support 2019-07-01 13:32:46 -04:00
vms_rms.h Following the license change, modify the boilerplates in crypto/ 2018-12-06 15:32:17 +01:00
x86_64cpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00
x86cpuid.pl Also check for errors in x86_64-xlate.pl. 2020-02-17 12:17:53 +10:00

The sparse_array.c file contains an implementation of a sparse array that
attempts to be both space and time efficient.

The sparse array is represented using a tree structure.  Each node in the
tree contains a block of pointers to either the user supplied leaf values or
to another node.

There are a number of parameters used to define the block size:

    OPENSSL_SA_BLOCK_BITS   Specifies the number of bits covered by each block
    SA_BLOCK_MAX            Specifies the number of pointers in each block
    SA_BLOCK_MASK           Specifies a bit mask to perform modulo block size
    SA_BLOCK_MAX_LEVELS     Indicates the maximum possible height of the tree

These constants are inter-related:
    SA_BLOCK_MAX        = 2 ^ OPENSSL_SA_BLOCK_BITS
    SA_BLOCK_MASK       = SA_BLOCK_MAX - 1
    SA_BLOCK_MAX_LEVELS = number of bits in size_t divided by
                          OPENSSL_SA_BLOCK_BITS rounded up to the next multiple
                          of OPENSSL_SA_BLOCK_BITS

OPENSSL_SA_BLOCK_BITS can be defined at compile time and this overrides the
built in setting.

As a space and performance optimisation, the height of the tree is usually
less than the maximum possible height.  Only sufficient height is allocated to
accommodate the largest index added to the data structure.

The largest index used to add a value to the array determines the tree height:

        +----------------------+---------------------+
        | Largest Added Index  |   Height of Tree    |
        +----------------------+---------------------+
        | SA_BLOCK_MAX     - 1 |          1          |
        | SA_BLOCK_MAX ^ 2 - 1 |          2          |
        | SA_BLOCK_MAX ^ 3 - 1 |          3          |
        | ...                  |          ...        |
        | size_t max           | SA_BLOCK_MAX_LEVELS |
        +----------------------+---------------------+

The tree height is dynamically increased as needed based on additions.

An empty tree is represented by a NULL root pointer.  Inserting a value at
index 0 results in the allocation of a top level node full of null pointers
except for the single pointer to the user's data (N = SA_BLOCK_MAX for
brevity):

        +----+
        |Root|
        |Node|
        +-+--+
          |
          |
          |
          v
        +-+-+---+---+---+---+
        | 0 | 1 | 2 |...|N-1|
        |   |nil|nil|...|nil|
        +-+-+---+---+---+---+
          |
          |
          |
          v
        +-+--+
        |User|
        |Data|
        +----+
    Index 0


Inserting at element 2N+1 creates a new root node and pushes down the old root
node.  It then creates a second second level node to hold the pointer to the
user's new data:

        +----+
        |Root|
        |Node|
        +-+--+
          |
          |
          |
          v
        +-+-+---+---+---+---+
        | 0 | 1 | 2 |...|N-1|
        |   |nil|   |...|nil|
        +-+-+---+-+-+---+---+
          |       |
          |       +------------------+
          |                          |
          v                          v
        +-+-+---+---+---+---+      +-+-+---+---+---+---+
        | 0 | 1 | 2 |...|N-1|      | 0 | 1 | 2 |...|N-1|
        |nil|   |nil|...|nil|      |nil|   |nil|...|nil|
        +-+-+---+---+---+---+      +---+-+-+---+---+---+
          |                              |
          |                              |
          |                              |
          v                              v
        +-+--+                         +-+--+
        |User|                         |User|
        |Data|                         |Data|
        +----+                         +----+
    Index 0                       Index 2N+1


The nodes themselves are allocated in a sparse manner.  Only nodes which exist
along a path from the root of the tree to an added leaf will be allocated.
The complexity is hidden and nodes are allocated on an as needed basis.
Because the data is expected to be sparse this doesn't result in a large waste
of space.

Values can be removed from the sparse array by setting their index position to
NULL.  The data structure does not attempt to reclaim nodes or reduce the
height of the tree on removal.  For example, now setting index 0 to NULL would
result in:

        +----+
        |Root|
        |Node|
        +-+--+
          |
          |
          |
          v
        +-+-+---+---+---+---+
        | 0 | 1 | 2 |...|N-1|
        |   |nil|   |...|nil|
        +-+-+---+-+-+---+---+
          |       |
          |       +------------------+
          |                          |
          v                          v
        +-+-+---+---+---+---+      +-+-+---+---+---+---+
        | 0 | 1 | 2 |...|N-1|      | 0 | 1 | 2 |...|N-1|
        |nil|nil|nil|...|nil|      |nil|   |nil|...|nil|
        +---+---+---+---+---+      +---+-+-+---+---+---+
                                         |
                                         |
                                         |
                                         v
                                       +-+--+
                                       |User|
                                       |Data|
                                       +----+
                                  Index 2N+1


Accesses to elements in the sparse array take O(log n) time where n is the
largest element.  The base of the logarithm is SA_BLOCK_MAX, so for moderately
small indices (e.g. NIDs), single level (constant time) access is achievable.
Space usage is O(minimum(m, n log(n)) where m is the number of elements in the
array.

Note: sparse arrays only include pointers to types.  Thus, SPARSE_ARRAY_OF(char)
can be used to store a string.