Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/ube/internal.h

raw
1 // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0 OR ISC
3
4 #ifndef OPENSSL_HEADER_CRYPTO_UBE_INTERNAL_H
5 #define OPENSSL_HEADER_CRYPTO_UBE_INTERNAL_H
6
7 #if defined(__cplusplus)
8 extern "C" {
9 #endif
10
11 #include <openssl/base.h>
12
13 // get_ube_generation_number returns the uniqueness-breaking event (UBE)
14 // generation number for the address space in |current_generation_number|. The
15 // UBE generation number is a non-zero, strictly-monotonic counter with the
16 // following property: if queried in an address space and then subsequently
17 // queried, after an UBE occurred, a greater value will be observed.
18 //
19 // This function should be used to protect unique memory. First cache a UBE
20 // generation number associating it to the unique memory at
21 // creation/initialization time. Before using the unique memory check whether
22 // the generation number has changed. Note, however, that detection methods rely
23 // on technology that is unique to a platform. Hence, support for UBE detection
24 // also depends on the platform AWS-LC is executed on.
25 //
26 // The parameter |current_generation_number| must be synchronized by the caller.
27 //
28 // Returns 1 on success and 0 if not supported. 0 means that UBE detection is
29 // not supported and any unique state must randomize before usage.
30 // In case of an error or if UBE detection is unavailable, all subsequent
31 // entries will immediately return.
32 OPENSSL_EXPORT int CRYPTO_get_ube_generation_number(uint64_t *current_generation_number);
33
34 // set_fork_ube_generation_number_FOR_TESTING sets the fork generation number to
35 // the value |fork_gn|. This value will be the fork generation value used by the
36 // UBE logic, overriding the generation number from the real fork detection.
37 // |allow_mocked_ube_detection_FOR_TESTING| must have been invoked
38 // (once per-process) to allow mocking the fork generation number.
39 OPENSSL_EXPORT void set_fork_ube_generation_number_FOR_TESTING(uint64_t fork_gn);
40
41 // set_vm_ube_generation_number_FOR_TESTING sets the vm_ube generation
42 // number to the value |vm_ube_gn|. This value will be the vm_ube generation
43 // value used by the UBE logic, overriding the generation number from the real
44 // vm_ube detection.
45 // |allow_mocked_ube_detection_FOR_TESTING| must have been invoked (once
46 // per-process) to allow mocking the vm_ube generation number.
47 OPENSSL_EXPORT void set_vm_ube_generation_number_FOR_TESTING(uint32_t vm_ube_gn);
48
49 // allow_mocked_ube_detection_FOR_TESTING allows mocking UBE detection even
50 // though real detection is not available. This function must be called in
51 // test code when mocking the generation numbers, once per-process. Mocking is
52 // process-global i.e. all threads will read the same mocked value.
53 OPENSSL_EXPORT void allow_mocked_ube_detection_FOR_TESTING(void);
54
55 // disable_mocked_ube_detection_FOR_TESTING disables mocking UBE detection. It
56 // also resets any mocked values to default values (0). This function should be
57 // invoked when exiting testing.
58 OPENSSL_EXPORT void disable_mocked_ube_detection_FOR_TESTING(void);
59
60 #if defined(__cplusplus)
61 } // extern C
62 #endif
63
64 #endif // OPENSSL_HEADER_CRYPTO_UBE_INTERNAL_H