Botan 3.7.1
Crypto and TLS for C&
|
Classes | |
class | Echo_Suppression |
class | Socket |
class | SocketUDP |
Functions | |
std::vector< void * > | allocate_locked_pages (size_t count) |
std::string BOTAN_TEST_API | format_time (time_t time, const std::string &format) |
void | free_locked_pages (const std::vector< void * > &pages) |
std::optional< std::pair< unsigned long, unsigned long > > | get_auxval_hwcap () |
size_t BOTAN_TEST_API | get_cpu_available () |
uint64_t BOTAN_TEST_API | get_cpu_cycle_counter () |
uint64_t BOTAN_TEST_API | get_high_resolution_clock () |
size_t | get_memory_locking_limit () |
uint32_t BOTAN_TEST_API | get_process_id () |
uint64_t BOTAN_TEST_API | get_system_timestamp_ns () |
std::unique_ptr< Socket > BOTAN_TEST_API | open_socket (std::string_view hostname, std::string_view service, std::chrono::milliseconds timeout) |
std::unique_ptr< SocketUDP > BOTAN_TEST_API | open_socket_udp (std::string_view hostname, std::string_view service, std::chrono::microseconds timeout) |
std::unique_ptr< SocketUDP > BOTAN_TEST_API | open_socket_udp (std::string_view uri, std::chrono::microseconds timeout) |
void | page_allow_access (void *page) |
void | page_named (void *page, size_t size) |
void | page_prohibit_access (void *page) |
bool | read_env_variable (std::string &value_out, std::string_view var_name) |
size_t | read_env_variable_sz (std::string_view var_name, size_t def_value=0) |
int BOTAN_TEST_API | run_cpu_instruction_probe (const std::function< int()> &probe_fn) |
std::unique_ptr< Echo_Suppression > BOTAN_UNSTABLE_API | suppress_echo_on_terminal () |
size_t | system_page_size () |
std::vector< void * > Botan::OS::allocate_locked_pages | ( | size_t | count | ) |
Request count pages of RAM which are locked into memory using mlock, VirtualLock, or some similar OS specific API. Free it with free_locked_pages.
Returns an empty list on failure. This function is allowed to return fewer than count pages.
The contents of the allocated pages are undefined.
Each page is preceded by and followed by a page which is marked as noaccess, such that accessing it will cause a crash. This turns out of bound reads/writes into crash events.
count | requested number of locked pages |
Definition at line 516 of file os_utils.cpp.
References BOTAN_UNUSED, page_named(), page_prohibit_access(), and system_page_size().
Referenced by Botan::mlock_allocator::mlock_allocator().
std::string Botan::OS::format_time | ( | time_t | time, |
const std::string & | format ) |
Format a time
Converts the time_t to a local time representation, then invokes std::put_time with the specified format.
Definition at line 342 of file os_utils.cpp.
void Botan::OS::free_locked_pages | ( | const std::vector< void * > & | pages | ) |
Free memory allocated by allocate_locked_pages
pages | a list of pages returned by allocate_locked_pages |
Definition at line 635 of file os_utils.cpp.
References page_allow_access(), Botan::secure_scrub_memory(), and system_page_size().
Referenced by Botan::mlock_allocator::~mlock_allocator().
std::optional< std::pair< unsigned long, unsigned long > > Botan::OS::get_auxval_hwcap | ( | ) |
If this system supports getauxval (or an equivalent interface, like FreeBSD's elf_aux_info) queries AT_HWCAP and AT_HWCAP2 and returns both.
Otherwise returns nullopt.
Definition at line 150 of file os_utils.cpp.
size_t Botan::OS::get_cpu_available | ( | ) |
Definition at line 240 of file os_utils.cpp.
Referenced by Botan::Thread_Pool::Thread_Pool().
uint64_t Botan::OS::get_cpu_cycle_counter | ( | ) |
On Windows, calls QueryPerformanceCounter.
Under GCC or Clang on supported platforms the hardware cycle counter is queried. Currently supported processors are x86, PPC, Alpha, SPARC, IA-64, S/390x, and HP-PA. If no CPU cycle counter is available on this system, returns zero.
Definition at line 183 of file os_utils.cpp.
Referenced by get_high_resolution_clock().
uint64_t Botan::OS::get_high_resolution_clock | ( | ) |
Definition at line 272 of file os_utils.cpp.
References get_cpu_cycle_counter().
Referenced by Botan::RandomNumberGenerator::randomize_with_ts_input().
size_t Botan::OS::get_memory_locking_limit | ( | ) |
Definition at line 382 of file os_utils.cpp.
References BOTAN_UNUSED, read_env_variable_sz(), and system_page_size().
Referenced by Botan::mlock_allocator::mlock_allocator().
uint32_t Botan::OS::get_process_id | ( | ) |
On Unix and Windows systems, this always returns a result
On systems where there is no processes to speak of (for example on baremetal systems or within a unikernel), this function returns zero.
Definition at line 82 of file os_utils.cpp.
Referenced by Botan::RandomNumberGenerator::randomize_with_ts_input(), and Botan::Stateful_RNG::reseed_check().
uint64_t Botan::OS::get_system_timestamp_ns | ( | ) |
If the system does not have a real time clock this function will throw Not_Implemented
Definition at line 326 of file os_utils.cpp.
Referenced by Botan::measure_cost().
std::unique_ptr< OS::Socket > Botan::OS::open_socket | ( | std::string_view | hostname, |
std::string_view | service, | ||
std::chrono::milliseconds | timeout ) |
Open up a socket. Will throw on error. Returns null if sockets are not available on this platform.
Definition at line 349 of file socket.cpp.
References BOTAN_UNUSED.
std::unique_ptr< OS::SocketUDP > Botan::OS::open_socket_udp | ( | std::string_view | hostname, |
std::string_view | service, | ||
std::chrono::microseconds | timeout ) |
Open up a socket. Will throw on error. Returns null if sockets are not available on this platform.
Definition at line 317 of file socket_udp.cpp.
References BOTAN_UNUSED.
Referenced by Botan::Roughtime::online_request(), and open_socket_udp().
std::unique_ptr< OS::SocketUDP > Botan::OS::open_socket_udp | ( | std::string_view | uri, |
std::chrono::microseconds | timeout ) |
Open up a socket. Will throw on error. Returns null if sockets are not available on this platform.
Definition at line 332 of file socket_udp.cpp.
References Botan::URI::from_any(), and open_socket_udp().
void Botan::OS::page_allow_access | ( | void * | page | ) |
Set the MMU to allow R/W access to this page
Definition at line 607 of file os_utils.cpp.
References BOTAN_UNUSED, and system_page_size().
Referenced by Botan::Memory_Pool::allocate(), free_locked_pages(), Botan::Sodium::sodium_mprotect_readwrite(), and Botan::Memory_Pool::~Memory_Pool().
void Botan::OS::page_named | ( | void * | page, |
size_t | size ) |
Set a ID to a page's range expressed by size bytes
Definition at line 657 of file os_utils.cpp.
References BOTAN_UNUSED, and name.
Referenced by allocate_locked_pages().
void Botan::OS::page_prohibit_access | ( | void * | page | ) |
Set the MMU to prohibit access to this page
Definition at line 621 of file os_utils.cpp.
References BOTAN_UNUSED, and system_page_size().
Referenced by allocate_locked_pages(), Botan::Memory_Pool::deallocate(), Botan::Memory_Pool::Memory_Pool(), and Botan::Sodium::sodium_mprotect_noaccess().
bool Botan::OS::read_env_variable | ( | std::string & | value_out, |
std::string_view | var_name ) |
Read the value of an environment variable, setting it to value_out if it exists. Returns false and sets value_out to empty string if no such variable is set. If the process seems to be running in a privileged state (such as setuid) then always returns false and does not examine the environment.
Definition at line 443 of file os_utils.cpp.
References name.
Referenced by Botan_FFI::ffi_error_exception_thrown(), and read_env_variable_sz().
size_t Botan::OS::read_env_variable_sz | ( | std::string_view | var_name, |
size_t | def_value = 0 ) |
Read the value of an environment variable and convert it to an integer. If not set or conversion fails, returns the default value.
If the process seems to be running in a privileged state (such as setuid) then always returns nullptr, similiar to glibc's secure_getenv.
Definition at line 476 of file os_utils.cpp.
References name, and read_env_variable().
Referenced by get_memory_locking_limit().
int Botan::OS::run_cpu_instruction_probe | ( | const std::function< int()> & | probe_fn | ) |
Run a probe instruction to test for support for a CPU instruction. Runs in system-specific env that catches illegal instructions; this function always fails if the OS doesn't provide this. Returns value of probe_fn, if it could run. If error occurs, returns negative number. This allows probe_fn to indicate errors of its own, if it wants. For example the instruction might not only be only available on some CPUs, but also buggy on some subset of these - the probe function can test to make sure the instruction works properly before indicating that the instruction is available.
If probe_fn throws an exception the result is undefined.
Return codes: -1 illegal instruction detected
Definition at line 717 of file os_utils.cpp.
References BOTAN_UNUSED.
std::unique_ptr< OS::Echo_Suppression > Botan::OS::suppress_echo_on_terminal | ( | ) |
Suppress echo on the terminal Returns null if this operation is not supported on the current system.
Definition at line 757 of file os_utils.cpp.
size_t Botan::OS::system_page_size | ( | ) |
Return the size of a memory page, if that can be derived on the current system. Otherwise returns some default value (eg 4096)
Definition at line 362 of file os_utils.cpp.
References BOTAN_UNUSED.
Referenced by allocate_locked_pages(), free_locked_pages(), get_memory_locking_limit(), Botan::mlock_allocator::mlock_allocator(), page_allow_access(), and page_prohibit_access().