openssl/crypto
Dr. David von Oheimb 642f60d840 Rename CMP_PROTECTEDPART to OSSL_CMP_PROTECTEDPART for consistency
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11386)
2020-04-18 19:54:17 +02:00
..
aes Use build.info, not ifdef for crypto modules 2020-04-16 13:52:22 +02:00
aria
asn1 Use build.info, not ifdef for crypto modules 2020-04-16 13:52:22 +02:00
async
bf Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
bio BIO_do_accept: correct error return value 2020-04-14 11:51:41 +02:00
bn Use build.info, not ifdef for crypto modules 2020-04-16 13:52:22 +02:00
buffer
camellia
cast Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
chacha
cmac
cmp Rename CMP_PROTECTEDPART to OSSL_CMP_PROTECTEDPART for consistency 2020-04-18 19:54:17 +02:00
cms CMS KARI: Temporarly downgrade newly generated EVP_PKEYs to legacy 2020-04-10 22:15:25 +02:00
comp
conf Add support for passing the libctx to the config loader 2020-03-20 20:25:39 +10:00
crmf Constify various mostly X509-related parameter types in crypto/ and apps/ 2020-03-23 08:30:37 +01:00
ct Make the CT code library context aware 2020-04-09 14:51:48 +01:00
des Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
dh When calling the import_to function pass the libctx too 2020-04-17 12:26:56 +01:00
dsa When calling the import_to function pass the libctx too 2020-04-17 12:26:56 +01:00
dso
ec When calling the import_to function pass the libctx too 2020-04-17 12:26:56 +01:00
engine Fix Dynamic engine loading so that the call to ENGINE_load_builtin_engines() is performed. 2020-04-15 11:09:04 +03:00
err ecx: check for errors creating public keys from private ones. 2020-04-17 19:51:37 +10:00
ess Fix error handling in x509v3_cache_extensions and related functions 2020-03-21 18:46:36 +01:00
evp When calling the import_to function pass the libctx too 2020-04-17 12:26:56 +01:00
ffc Add DH keygen to providers 2020-04-16 01:14:00 +10:00
hmac
http HTTP client: make server/proxy and port params more consistent; minor other improvements 2020-04-02 18:31:06 +02:00
idea Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
kdf
lhash
md2
md4
md5
mdc2
modes
objects GOST cipher names adjustment 2020-04-17 16:21:51 +03:00
ocsp Add OCSP_RESPID_set_by_key_ex() and OCSP_RESPID_match_ex() 2020-03-27 11:20:39 +00:00
pem Teach PEM_read_bio_PrivateKey about libctx 2020-04-15 11:24:13 +01:00
perlasm
pkcs7
pkcs12 Fix error handling in x509v3_cache_extensions and related functions 2020-03-21 18:46:36 +01:00
poly1305
property
rand Put sys-specific files in build.info 2020-04-16 13:52:23 +02:00
rc2 Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
rc4 Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
rc5 Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
ripemd
rsa When calling the import_to function pass the libctx too 2020-04-17 12:26:56 +01:00
seed Move legacy ciphers into the legacy provider 2020-04-09 12:47:46 +10:00
serializer
sha
siphash
sm2
sm3
sm4
srp Make SRP library context aware 2020-03-27 11:29:24 +00:00
stack
store Teach the OSSL_STORE code about libctx 2020-04-15 11:24:13 +01:00
ts Fix error handling in x509v3_cache_extensions and related functions 2020-03-21 18:46:36 +01:00
txt_db
ui Constify various mostly X509-related parameter types in crypto/ and apps/ 2020-03-23 08:30:37 +01:00
whrlpool
x509 Introduce an internal version of X509_check_issued() 2020-04-16 14:19:52 +01:00
alphacpuid.pl
arm64cpuid.pl
arm_arch.h
armcap.c
armv4cpuid.pl
asn1_dsa.c
bsearch.c
build.info Add common internal crypto/ modules in liblegacy.a 2020-04-09 19:49:06 +02:00
c64xpluscpuid.pl
context.c Put an error on the stack in the event of a fetch failure 2020-03-27 11:12:27 +00:00
core_algorithm.c
core_fetch.c
core_namemap.c
cpt_err.c
cryptlib.c
ctype.c
cversion.c
der_writer.c PROV: Add the beginning of a DER writing library 2020-04-07 11:16:56 +02:00
dllmain.c
ebcdic.c
ex_data.c
getenv.c
ia64cpuid.S
info.c
init.c
initthread.c
LPdir_nyi.c
LPdir_unix.c
LPdir_vms.c
LPdir_win32.c
LPdir_win.c
LPdir_wince.c
mem_clr.c
mem_sec.c
mem.c
mips_arch.h
o_dir.c
o_fips.c
o_fopen.c
o_init.c
o_str.c
o_time.c
packet.c Add "endfirst" writing to WPACKET 2020-04-04 10:35:09 +01:00
param_build_set.c Add EVP_PKEY_gettable_params support for accessing EVP_PKEY key data fields 2020-04-01 15:51:18 +10:00
param_build.c Param builder: Remove the static size limit. 2020-03-28 12:27:22 +10:00
params_from_text.c
params.c params: avoid a core dump with a null pointer and a get string call 2020-04-08 09:14:17 +10:00
pariscid.pl
ppc_arch.h
ppccap.c
ppccpuid.pl
provider_conf.c Add support for passing the libctx to the config loader 2020-03-20 20:25:39 +10:00
provider_core.c Fix off-by-1 bug on provider_activate with custom error strings 2020-03-30 17:06:56 +03:00
provider_local.h
provider_predefined.c Add a null provider which implements no algorithms. 2020-04-09 17:12:35 +10:00
provider.c
README.sparse_array
s390x_arch.h s390: ECX key generation fixes. 2020-04-17 19:51:37 +10:00
s390xcap.c
s390xcpuid.pl
self_test_core.c
sparc_arch.h
sparccpuid.S
sparcv9cap.c
sparse_array.c
threads_none.c
threads_pthread.c
threads_win.c Windows: Add type casting in CRYPTO_atomic_add to remove warning 2020-04-17 13:21:13 +02:00
trace.c
uid.c
vms_rms.h
x86_64cpuid.pl
x86cpuid.pl

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.