Matt Caswell 33388b44b6 Update copyright year 4 tahun lalu
..
aes 33388b44b6 Update copyright year 4 tahun lalu
aria 25f2138b0a Reorganize private crypto header files 5 tahun lalu
asn1 33388b44b6 Update copyright year 4 tahun lalu
async 33388b44b6 Update copyright year 4 tahun lalu
bf 33388b44b6 Update copyright year 4 tahun lalu
bio 33388b44b6 Update copyright year 4 tahun lalu
bn 33388b44b6 Update copyright year 4 tahun lalu
buffer dec95d7589 Rework how our providers are built 5 tahun lalu
camellia 33388b44b6 Update copyright year 4 tahun lalu
cast 33388b44b6 Update copyright year 4 tahun lalu
chacha 33388b44b6 Update copyright year 4 tahun lalu
cmac 33388b44b6 Update copyright year 4 tahun lalu
cmp 33388b44b6 Update copyright year 4 tahun lalu
cms 33388b44b6 Update copyright year 4 tahun lalu
comp 706457b7bd Reorganize local header files 5 tahun lalu
conf 33388b44b6 Update copyright year 4 tahun lalu
crmf 33388b44b6 Update copyright year 4 tahun lalu
ct 33388b44b6 Update copyright year 4 tahun lalu
des 33388b44b6 Update copyright year 4 tahun lalu
dh 33388b44b6 Update copyright year 4 tahun lalu
dsa 33388b44b6 Update copyright year 4 tahun lalu
dso 706457b7bd Reorganize local header files 5 tahun lalu
ec 33388b44b6 Update copyright year 4 tahun lalu
engine 33388b44b6 Update copyright year 4 tahun lalu
err 33388b44b6 Update copyright year 4 tahun lalu
ess 7e06a6758b Fix error handling in x509v3_cache_extensions and related functions 4 tahun lalu
evp 33388b44b6 Update copyright year 4 tahun lalu
ffc a033c9a2e8 Fix some build failures with no-dh 4 tahun lalu
hmac 33388b44b6 Update copyright year 4 tahun lalu
http 4b1fe471ac HTTP client: make server/proxy and port params more consistent; minor other improvements 4 tahun lalu
idea 33388b44b6 Update copyright year 4 tahun lalu
kdf 905b097fd5 Deprecate ERR_load_KDF_strings() 4 tahun lalu
lhash dec95d7589 Rework how our providers are built 5 tahun lalu
md2 33388b44b6 Update copyright year 4 tahun lalu
md4 33388b44b6 Update copyright year 4 tahun lalu
md5 33388b44b6 Update copyright year 4 tahun lalu
mdc2 33388b44b6 Update copyright year 4 tahun lalu
modes 33388b44b6 Update copyright year 4 tahun lalu
objects 33388b44b6 Update copyright year 4 tahun lalu
ocsp 33388b44b6 Update copyright year 4 tahun lalu
pem 33388b44b6 Update copyright year 4 tahun lalu
perlasm 33388b44b6 Update copyright year 4 tahun lalu
pkcs12 33388b44b6 Update copyright year 4 tahun lalu
pkcs7 12a765a523 Explicitly test against NULL; do not use !p or similar 5 tahun lalu
poly1305 33388b44b6 Update copyright year 4 tahun lalu
property 33388b44b6 Update copyright year 4 tahun lalu
rand 33388b44b6 Update copyright year 4 tahun lalu
rc2 33388b44b6 Update copyright year 4 tahun lalu
rc4 33388b44b6 Update copyright year 4 tahun lalu
rc5 33388b44b6 Update copyright year 4 tahun lalu
ripemd 33388b44b6 Update copyright year 4 tahun lalu
rsa 33388b44b6 Update copyright year 4 tahun lalu
seed 33388b44b6 Update copyright year 4 tahun lalu
serializer 33388b44b6 Update copyright year 4 tahun lalu
sha 33388b44b6 Update copyright year 4 tahun lalu
siphash 25f2138b0a Reorganize private crypto header files 5 tahun lalu
sm2 33388b44b6 Update copyright year 4 tahun lalu
sm3 b2055d67f0 Cleanup legacy digest methods. 4 tahun lalu
sm4 25f2138b0a Reorganize private crypto header files 5 tahun lalu
srp 33388b44b6 Update copyright year 4 tahun lalu
stack dec95d7589 Rework how our providers are built 5 tahun lalu
store 33388b44b6 Update copyright year 4 tahun lalu
ts 7e06a6758b Fix error handling in x509v3_cache_extensions and related functions 4 tahun lalu
txt_db 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
ui 33388b44b6 Update copyright year 4 tahun lalu
whrlpool 33388b44b6 Update copyright year 4 tahun lalu
x509 33388b44b6 Update copyright year 4 tahun lalu
LPdir_nyi.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
LPdir_unix.c db5cf86535 Fix a -Warray-bounds gcc warning in OPENSSL_DIR_read 4 tahun lalu
LPdir_vms.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
LPdir_win.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
LPdir_win32.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
LPdir_wince.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
README.sparse_array c2969ff6e7 Fix Typos 5 tahun lalu
alphacpuid.pl 33388b44b6 Update copyright year 4 tahun lalu
arm64cpuid.pl 33388b44b6 Update copyright year 4 tahun lalu
arm_arch.h ae4186b004 Fix header file include guard names 5 tahun lalu
armcap.c 5f40dd158c crypto/armcap.c, crypto/ppccap.c: stricter use of getauxval() 5 tahun lalu
armv4cpuid.pl 33388b44b6 Update copyright year 4 tahun lalu
asn1_dsa.c 79c44b4e30 Fix some typos 4 tahun lalu
bsearch.c 5c3f1e34b5 ossl_bsearch(): New generic internal binary search utility function 5 tahun lalu
build.info 09fafd0606 Add common internal crypto/ modules in liblegacy.a 4 tahun lalu
c64xpluscpuid.pl 33388b44b6 Update copyright year 4 tahun lalu
context.c 33388b44b6 Update copyright year 4 tahun lalu
core_algorithm.c 695d195bbb Replumbing: make it possible for providers to specify multiple names 5 tahun lalu
core_fetch.c 36fa4d8a0d CORE: pass the full algorithm definition to the method constructor 4 tahun lalu
core_namemap.c 33388b44b6 Update copyright year 4 tahun lalu
cpt_err.c 3d83c73536 CORE: ossl_namemap_add_names(): new function to add multiple names 4 tahun lalu
cryptlib.c 25f2138b0a Reorganize private crypto header files 5 tahun lalu
ctype.c 25f2138b0a Reorganize private crypto header files 5 tahun lalu
cversion.c 26b7cc0d20 Cleanup include/openssl/opensslv.h.in 4 tahun lalu
der_writer.c 1d39620b34 PROV: Add the beginning of a DER writing library 4 tahun lalu
dllmain.c 25f2138b0a Reorganize private crypto header files 5 tahun lalu
ebcdic.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
ex_data.c 33388b44b6 Update copyright year 4 tahun lalu
getenv.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
ia64cpuid.S 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
info.c 33388b44b6 Update copyright year 4 tahun lalu
init.c 25f2138b0a Reorganize private crypto header files 5 tahun lalu
initthread.c 33388b44b6 Update copyright year 4 tahun lalu
mem.c 33388b44b6 Update copyright year 4 tahun lalu
mem_clr.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
mem_sec.c 33388b44b6 Update copyright year 4 tahun lalu
mips_arch.h ae4186b004 Fix header file include guard names 5 tahun lalu
o_dir.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
o_fips.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
o_fopen.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
o_init.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
o_str.c 82bd7c2cbd Add OPENSSL_hexstr2buf_ex() and OPENSSL_buf2hexstr_ex() 5 tahun lalu
o_time.c 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
packet.c 33388b44b6 Update copyright year 4 tahun lalu
param_build.c 33388b44b6 Update copyright year 4 tahun lalu
param_build_set.c 96ebe52e89 Add EVP_PKEY_gettable_params support for accessing EVP_PKEY key data fields 4 tahun lalu
params.c 33388b44b6 Update copyright year 4 tahun lalu
params_from_text.c 33388b44b6 Update copyright year 4 tahun lalu
pariscid.pl 33388b44b6 Update copyright year 4 tahun lalu
ppc_arch.h ae4186b004 Fix header file include guard names 5 tahun lalu
ppccap.c 706457b7bd Reorganize local header files 5 tahun lalu
ppccpuid.pl 33388b44b6 Update copyright year 4 tahun lalu
provider.c dca97d0062 Rename provider and core get_param_types functions 5 tahun lalu
provider_conf.c 33388b44b6 Update copyright year 4 tahun lalu
provider_core.c 33388b44b6 Update copyright year 4 tahun lalu
provider_local.h c41f3ae0d9 Replumbing: Add a mechanism to pre-populate the provider store 5 tahun lalu
provider_predefined.c 33388b44b6 Update copyright year 4 tahun lalu
s390x_arch.h 33388b44b6 Update copyright year 4 tahun lalu
s390xcap.c 5768804d5a crypto/s390xcap.c: Add guards around the GETAUXVAL checks 4 tahun lalu
s390xcpuid.pl 33388b44b6 Update copyright year 4 tahun lalu
self_test_core.c 47c239c6b8 Add pairwise consistency self tests to asym keygenerators 4 tahun lalu
sparc_arch.h ae4186b004 Fix header file include guard names 5 tahun lalu
sparccpuid.S 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
sparcv9cap.c 33388b44b6 Update copyright year 4 tahun lalu
sparse_array.c 25f2138b0a Reorganize private crypto header files 5 tahun lalu
threads_none.c 849529257c drbg: ensure fork-safety without using a pthread_atfork handler 5 tahun lalu
threads_pthread.c 849529257c drbg: ensure fork-safety without using a pthread_atfork handler 5 tahun lalu
threads_win.c 33388b44b6 Update copyright year 4 tahun lalu
trace.c 2897b00905 OSSL_STORE: add tracing 4 tahun lalu
uid.c 6b10d29c1a Remove NextStep support 5 tahun lalu
vms_rms.h 0e9725bcb9 Following the license change, modify the boilerplates in crypto/ 5 tahun lalu
x86_64cpuid.pl 33388b44b6 Update copyright year 4 tahun lalu
x86cpuid.pl 33388b44b6 Update copyright year 4 tahun lalu

README.sparse_array

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.