openssl/crypto
Richard Levitte d5aef5946b Adapt ASN1_item_sign_ctx() for use with provided keypairs
The mechanism to do this is to ask the signature operation for the DER
encoded AlgorithmIdentifier that corresponds to the combination of
signature algorithm and digest algorithm.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10920)
2020-01-28 08:06:01 +01:00
..
aes Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
aria
asn1 Adapt ASN1_item_sign_ctx() for use with provided keypairs 2020-01-28 08:06:01 +01:00
async
bf Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
bio BIO: Add BIO_f_prefix(), a text line prefixing filter 2019-12-18 19:42:44 +01:00
bn Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
buffer
camellia Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
cast Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
chacha Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
cmac
cmp
cms Don't use the low level AES key wrap APIs in CMS 2020-01-06 15:09:57 +00:00
comp
conf Make generated copyright year be "now" 2020-01-07 15:53:15 -05:00
crmf
ct Deprecate the low level SHA functions. 2020-01-19 10:14:39 +10:00
des Deprecate the low level DES functions. 2020-01-25 09:30:59 +10:00
dh Modify DSA and DH keys to use a shared FFC_PARAMS struct 2020-01-24 14:09:33 +10:00
dsa Modify DSA and DH keys to use a shared FFC_PARAMS struct 2020-01-24 14:09:33 +10:00
dso
ec Check ECC-CDH is compliant with SP800-56A-r3 2020-01-23 20:17:05 +10:00
engine Deprecate the low level SHA functions. 2020-01-19 10:14:39 +10:00
err
ess
evp Modify EVP_PKEY_CTX_new_from_pkey() to add a propquery parameter 2020-01-27 08:45:17 +00:00
ffc Modify DSA and DH keys to use a shared FFC_PARAMS struct 2020-01-24 14:09:33 +10:00
hmac Don't store an HMAC key for longer than we need 2020-01-06 10:46:05 +00:00
idea Deprecate the low level IDEA functions. 2020-01-19 10:38:49 +10:00
kdf
lhash
md2 Deprecate the low level MD2 functions. 2020-01-12 12:02:17 +10:00
md4 Deprecate the low level MD4 functions. 2020-01-12 12:02:17 +10:00
md5 Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
mdc2 Deprecate the low level MDC2 functions. 2020-01-12 12:02:17 +10:00
modes Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
objects Make generated copyright year be "now" 2020-01-07 15:53:15 -05:00
ocsp
pem
perlasm Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
pkcs7
pkcs12
poly1305 Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
property
rand Convert rand_bytes_ex and rand_priv_bytes_ex to public functions 2020-01-20 14:54:31 +00:00
rc2 Deprecate the low level RC2 functions 2020-01-16 07:07:27 +10:00
rc4 Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
rc5 Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
ripemd Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
rsa libcrypto: Eliminate as much use of EVP_PKEY_size() as possible 2020-01-19 02:47:46 +01:00
seed Deprecate the low level SEED functions 2020-01-16 07:06:14 +10:00
serializer
sha Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
siphash
sm2
sm3
sm4
srp
stack
store
ts
txt_db
ui
whrlpool Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
x509 Update man3/verify documentation, error text 2020-01-23 23:18:33 +01:00
alphacpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
arm64cpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
arm_arch.h
armcap.c
armv4cpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
asn1_dsa.c
bsearch.c
build.info Modify DSA and DH keys to use a shared FFC_PARAMS struct 2020-01-24 14:09:33 +10:00
c64xpluscpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
context.c
core_algorithm.c
core_fetch.c
core_namemap.c Modify EVP_CIPHER_is_a() and EVP_MD_is_a() to handle legacy methods too 2020-01-17 08:59:41 +01:00
cpt_err.c
cryptlib.c
ctype.c
cversion.c
dllmain.c
ebcdic.c
ex_data.c
getenv.c
ia64cpuid.S
info.c Modify the add_seeds_stringlist() macro to fix a preprocessor error 2020-01-07 16:28:37 +01:00
init.c
initthread.c Fix init_thread_stop 2020-01-20 14:41:36 +00:00
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
param_build.c param_bld: add a padded BN call. 2020-01-19 10:20:06 +10:00
params_from_text.c
params.c
pariscid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
ppc_arch.h
ppccap.c
ppccpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
provider_conf.c
provider_core.c PROV: Add support for error queue marks and implement in FIPS module 2020-01-21 14:06:54 +01:00
provider_local.h
provider_predefined.c
provider.c
README.sparse_array
s390x_arch.h
s390xcap.c
s390xcpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
self_test_core.c Add FIPS Self test kats for digests 2020-01-15 10:48:01 +10:00
sparc_arch.h
sparccpuid.S
sparcv9cap.c
sparse_array.c
threads_none.c
threads_pthread.c
threads_win.c
trace.c
uid.c
vms_rms.h
x86_64cpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01:00
x86cpuid.pl Do not silently truncate files on perlasm errors 2020-01-22 18:11:30 +01: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.