You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Pauli 86cde3187d
ffc: use sizeof(*pointer) instead of sizeof(struct) in memset(3) call.
3 years ago
..
aes Also check for errors in x86_64-xlate.pl. 3 years ago
aria Reorganize private crypto header files 4 years ago
asn1 Adapt i2d_PrivateKey for provider only keys 3 years ago
async Use swapcontext for Intel CET 3 years ago
bf Also check for errors in x86_64-xlate.pl. 3 years ago
bio add BIO_socket_wait(), BIO_wait(), and BIO_connect_retry() improving timeout support 3 years ago
bn Also check for errors in x86_64-xlate.pl. 3 years ago
buffer Rework how our providers are built 3 years ago
camellia Also check for errors in x86_64-xlate.pl. 3 years ago
cast Also check for errors in x86_64-xlate.pl. 3 years ago
chacha Also check for errors in x86_64-xlate.pl. 3 years ago
cmac Deprecate the low level CMAC functions 3 years ago
cmp chunk 7 of CMP contribution to OpenSSL 3 years ago
cms Don't use the low level AES key wrap APIs in CMS 3 years ago
comp Reorganize local header files 4 years ago
conf Make generated copyright year be "now" 3 years ago
crmf fix various formatting nits in CMP contribution chunks 1-6 found by the new util/check-format.pl 3 years ago
ct Deprecate the low level SHA functions. 3 years ago
des Also check for errors in x86_64-xlate.pl. 3 years ago
dh Add FFC param/key validation 3 years ago
dsa Add FFC param/key validation 3 years ago
dso Reorganize local header files 4 years ago
ec Also check for errors in x86_64-xlate.pl. 3 years ago
engine Deprecate the low level SHA functions. 3 years ago
err chunk 7 of CMP contribution to OpenSSL 3 years ago
ess Reorganize private crypto header files 4 years ago
evp Deprecate the low level DSA functions. 3 years ago
ffc ffc: use sizeof(*pointer) instead of sizeof(struct) in memset(3) call. 3 years ago
hmac Deprecate the low level HMAC functions 3 years ago
http fix build for new HTTP client in case OPENSSL_NO_CMP or OPENSSL_NO_OCSP 3 years ago
idea Deprecate the low level IDEA functions. 3 years ago
kdf Deprecate ERR_load_KDF_strings() 3 years ago
lhash Rework how our providers are built 3 years ago
md2 Adapt all build.info and test recipes to the new $disabled{'deprecated-x.y'} 3 years ago
md4 Adapt all build.info and test recipes to the new $disabled{'deprecated-x.y'} 3 years ago
md5 Also check for errors in x86_64-xlate.pl. 3 years ago
mdc2 Adapt all build.info and test recipes to the new $disabled{'deprecated-x.y'} 3 years ago
modes Also check for errors in x86_64-xlate.pl. 3 years ago
objects Add support for DH 'modp' group parameters (RFC 3526) 3 years ago
ocsp Generalize the HTTP client so far implemented mostly in crypto/ocsp/ocsp_ht.c 3 years ago
pem Deprecate the low level DSA functions. 3 years ago
perlasm Also check for errors in x86_64-xlate.pl. 3 years ago
pkcs7 Explicitly test against NULL; do not use !p or similar 3 years ago
pkcs12 Deprecate the low level HMAC functions 3 years ago
poly1305 Also check for errors in x86_64-xlate.pl. 3 years ago
property Fix some typos 3 years ago
rand RAND_DRBG: add a callback data for entropy and nonce callbacks 3 years ago
rc2 Deprecate the low level RC2 functions 3 years ago
rc4 Also check for errors in x86_64-xlate.pl. 3 years ago
rc5 Also check for errors in x86_64-xlate.pl. 3 years ago
ripemd Also check for errors in x86_64-xlate.pl. 3 years ago
rsa Make the RSA ASYM_CIPHER implementation available inside the FIPS module 3 years ago
seed Deprecate the low level SEED functions 3 years ago
serializer Redesign the KEYMGMT libcrypto <-> provider interface - the basics 3 years ago
sha Also check for errors in x86_64-xlate.pl. 3 years ago
siphash Reorganize private crypto header files 4 years ago
sm2 Remove unused OSSL_PARAM_construct_from_text() function. 3 years ago
sm3 Cleanup legacy digest methods. 3 years ago
sm4 Reorganize private crypto header files 4 years ago
srp Update source files for pre-3.0 deprecation 3 years ago
stack Rework how our providers are built 3 years ago
store OSSL_STORE: add tracing 3 years ago
ts Fix typo and create compatibility macro 3 years ago
txt_db Following the license change, modify the boilerplates in crypto/ 4 years ago
ui UI_UTIL_wrap_read_pem_callback(): when |cb| is NULL, use PEM_def_callback 3 years ago
whrlpool Also check for errors in x86_64-xlate.pl. 3 years ago
x509 chunk 7 of CMP contribution to OpenSSL 3 years ago
LPdir_nyi.c Following the license change, modify the boilerplates in crypto/ 4 years ago
LPdir_unix.c Fix a -Warray-bounds gcc warning in OPENSSL_DIR_read 3 years ago
LPdir_vms.c Following the license change, modify the boilerplates in crypto/ 4 years ago
LPdir_win.c Following the license change, modify the boilerplates in crypto/ 4 years ago
LPdir_win32.c Following the license change, modify the boilerplates in crypto/ 4 years ago
LPdir_wince.c Following the license change, modify the boilerplates in crypto/ 4 years ago
README.sparse_array Fix Typos 4 years ago
alphacpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
arm64cpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
arm_arch.h Fix header file include guard names 4 years ago
armcap.c crypto/armcap.c, crypto/ppccap.c: stricter use of getauxval() 4 years ago
armv4cpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
asn1_dsa.c Fix some typos 3 years ago
bsearch.c ossl_bsearch(): New generic internal binary search utility function 4 years ago
build.info Generalize the HTTP client so far implemented mostly in crypto/ocsp/ocsp_ht.c 3 years ago
c64xpluscpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
context.c Reorganize private crypto header files 4 years ago
core_algorithm.c Replumbing: make it possible for providers to specify multiple names 4 years ago
core_fetch.c CORE: pass the full algorithm definition to the method constructor 3 years ago
core_namemap.c Modify EVP_CIPHER_is_a() and EVP_MD_is_a() to handle legacy methods too 3 years ago
cpt_err.c CORE: ossl_namemap_add_names(): new function to add multiple names 3 years ago
cryptlib.c Reorganize private crypto header files 4 years ago
ctype.c Reorganize private crypto header files 4 years ago
cversion.c Cleanup include/openssl/opensslv.h.in 3 years ago
dllmain.c Reorganize private crypto header files 4 years ago
ebcdic.c Following the license change, modify the boilerplates in crypto/ 4 years ago
ex_data.c Deprecate most of debug-memory 3 years ago
getenv.c Following the license change, modify the boilerplates in crypto/ 4 years ago
ia64cpuid.S Following the license change, modify the boilerplates in crypto/ 4 years ago
info.c Modify the add_seeds_stringlist() macro to fix a preprocessor error 3 years ago
init.c Reorganize private crypto header files 4 years ago
initthread.c Fix init_thread_stop 3 years ago
mem.c Memory allocator code cleanup 3 years ago
mem_clr.c Following the license change, modify the boilerplates in crypto/ 4 years ago
mem_sec.c Make secure-memory be a config option 3 years ago
mips_arch.h Fix header file include guard names 4 years ago
o_dir.c Following the license change, modify the boilerplates in crypto/ 4 years ago
o_fips.c Following the license change, modify the boilerplates in crypto/ 4 years ago
o_fopen.c Following the license change, modify the boilerplates in crypto/ 4 years ago
o_init.c Following the license change, modify the boilerplates in crypto/ 4 years ago
o_str.c Add OPENSSL_hexstr2buf_ex() and OPENSSL_buf2hexstr_ex() 4 years ago
o_time.c Following the license change, modify the boilerplates in crypto/ 4 years ago
packet.c Give WPACKET the ability to have a NULL buffer underneath it 4 years ago
param_build.c Remove unused ossl_param_bld_to_param_ex() function. 3 years ago
params.c Allow strings in params to be of zero length 3 years ago
params_from_text.c Remove unused OSSL_PARAM_construct_from_text() function. 3 years ago
pariscid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
ppc_arch.h Fix header file include guard names 4 years ago
ppccap.c Reorganize local header files 4 years ago
ppccpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
provider.c Rename provider and core get_param_types functions 4 years ago
provider_conf.c Load the config file by default 4 years ago
provider_core.c PROV: Add support for error queue marks and implement in FIPS module 3 years ago
provider_local.h Replumbing: Add a mechanism to pre-populate the provider store 4 years ago
provider_predefined.c When building of modules is disabled, build the legacy provider into libcrypto 4 years ago
s390x_arch.h Fix header file include guard names 4 years ago
s390xcap.c crypto/s390xcap.c: Add guards around the GETAUXVAL checks 3 years ago
s390xcpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
self_test_core.c Add FIPS Self test kats for digests 3 years ago
sparc_arch.h Fix header file include guard names 4 years ago
sparccpuid.S Following the license change, modify the boilerplates in crypto/ 4 years ago
sparcv9cap.c Fix misspelling errors and typos reported by codespell 3 years ago
sparse_array.c Reorganize private crypto header files 4 years ago
threads_none.c drbg: ensure fork-safety without using a pthread_atfork handler 4 years ago
threads_pthread.c drbg: ensure fork-safety without using a pthread_atfork handler 4 years ago
threads_win.c crypto/threads_win.c: fix preprocessor indentation 4 years ago
trace.c OSSL_STORE: add tracing 3 years ago
uid.c Remove NextStep support 4 years ago
vms_rms.h Following the license change, modify the boilerplates in crypto/ 4 years ago
x86_64cpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago
x86cpuid.pl Also check for errors in x86_64-xlate.pl. 3 years ago

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.