|
Botan 3.14.1
Crypto and TLS for C&
|
#include <botan/ffi.h>#include <botan/assert.h>#include <botan/base64.h>#include <botan/hex.h>#include <botan/mem_ops.h>#include <botan/version.h>#include <botan/internal/ct_utils.h>#include <botan/internal/ffi_util.h>#include <cstdio>#include <cstring>#include <type_traits>Go to the source code of this file.
Namespaces | |
| namespace | Botan_FFI |
Functions | |
| int | botan_base64_decode (const char *base64_str, size_t in_len, uint8_t *out, size_t *out_len) |
| int | botan_base64_encode (const uint8_t *in, size_t len, char *out, size_t *out_len) |
| int | botan_constant_time_compare (const uint8_t *x, const uint8_t *y, size_t len) |
| const char * | botan_error_description (int err) |
| const char * | botan_error_last_exception_message () |
| uint32_t | botan_ffi_api_version () |
| int | botan_ffi_supports_api (uint32_t api_version) |
| uint32_t | botan_ffi_tls_api_version () |
| int | botan_ffi_tls_supports_api (uint32_t api_version) |
| int | botan_hex_decode (const char *hex_str, size_t in_len, uint8_t *out, size_t *out_len) |
| int | botan_hex_encode (const uint8_t *in, size_t len, char *out, uint32_t flags) |
| int | botan_is_shared (void *handle) |
| int | botan_same_mem (const uint8_t *x, const uint8_t *y, size_t len) |
| int | botan_scrub_mem (void *mem, size_t bytes) |
| int | botan_use_count (void *handle, size_t *out_use_count) |
| uint32_t | botan_version_datestamp () |
| uint32_t | botan_version_major () |
| uint32_t | botan_version_minor () |
| uint32_t | botan_version_patch () |
| const char * | botan_version_string () |
| int | Botan_FFI::botan_view_bin_bounce_fn (botan_view_ctx vctx, const uint8_t *buf, size_t len) |
| int | Botan_FFI::botan_view_str_bounce_fn (botan_view_ctx vctx, const char *str, size_t len) |
| void | Botan_FFI::ffi_clear_last_exception () |
| int | Botan_FFI::ffi_error_exception_thrown (const char *func_name, const char *exn, Botan::ErrorType err) |
| int | Botan_FFI::ffi_error_exception_thrown (const char *func_name, const char *exn, int rc) |
| int botan_base64_decode | ( | const char * | base64_str, |
| size_t | in_len, | ||
| uint8_t * | out, | ||
| size_t * | out_len ) |
Perform base64 decoding
Definition at line 419 of file ffi.cpp.
References Botan_FFI::any_null_pointers(), Botan::base64_decode(), Botan::base64_decode_max_output(), BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().
| int botan_base64_encode | ( | const uint8_t * | x, |
| size_t | len, | ||
| char * | out, | ||
| size_t * | out_len ) |
Perform base64 encoding
| x | the input data |
| len | the length of x |
| out | the output buffer |
| out_len | the size of the output buffer on input, set to the number of bytes written |
Definition at line 409 of file ffi.cpp.
References Botan::base64_encode(), BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::write_str_output().
| int botan_constant_time_compare | ( | const uint8_t * | x, |
| const uint8_t * | y, | ||
| size_t | len ) |
Returns 0 if x[0..len] == y[0..len], or otherwise -1
Definition at line 367 of file ffi.cpp.
References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, and Botan::CT::is_equal().
Referenced by botan_same_mem().
| const char * botan_error_description | ( | int | err | ) |
Convert an error code into a string. Returns "Unknown error" if the error code is not a known one.
Definition at line 161 of file ffi.cpp.
References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_BAD_MAC, BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_EXCEPTION_THROWN, BOTAN_FFI_ERROR_HTTP_ERROR, BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE, BOTAN_FFI_ERROR_INTERNAL_ERROR, BOTAN_FFI_ERROR_INVALID_INPUT, BOTAN_FFI_ERROR_INVALID_KEY_LENGTH, BOTAN_FFI_ERROR_INVALID_OBJECT, BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_KEY_NOT_SET, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_MEMORY, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR, BOTAN_FFI_ERROR_SYSTEM_ERROR, BOTAN_FFI_ERROR_TLS_ERROR, BOTAN_FFI_ERROR_UNKNOWN_ERROR, BOTAN_FFI_INVALID_VERIFIER, and BOTAN_FFI_SUCCESS.
| const char * botan_error_last_exception_message | ( | void | ) |
Return the message of the last exception caught in this thread.
This pointer can/will be reallocated or overwritten the next time this thread calls any other Botan FFI function and must be copied to persistent storage first.
Definition at line 157 of file ffi.cpp.
| uint32_t botan_ffi_api_version | ( | void | ) |
Return the version of the currently supported FFI API. This is expressed in the form YYYYMMDD of the release date of this version of the API.
Definition at line 238 of file ffi.cpp.
References BOTAN_HAS_FFI.
| int botan_ffi_supports_api | ( | uint32_t | api_version | ) |
Return 0 (ok) if the version given is one this library supports. botan_ffi_supports_api(botan_ffi_api_version()) will always return 0.
Definition at line 242 of file ffi.cpp.
References BOTAN_FFI_SUCCESS.
| uint32_t botan_ffi_tls_api_version | ( | void | ) |
Return the version of the TLS FFI API (declared in ffi_tls.h) provided by this library, in the form YYYYMMDD, or 0 if the library was built without the experimental ffi_tls module. This function is always available, so applications can detect the TLS API at runtime.
Definition at line 327 of file ffi.cpp.
| int botan_ffi_tls_supports_api | ( | uint32_t | api_version | ) |
Return 0 (ok) if this library supports the given version of the TLS FFI API, otherwise -1 (also whenever the ffi_tls module is not built). botan_ffi_tls_supports_api(botan_ffi_tls_api_version()) returns 0 if botan_ffi_tls_api_version() is nonzero.
Definition at line 335 of file ffi.cpp.
References BOTAN_FFI_SUCCESS, and BOTAN_UNUSED.
| int botan_hex_decode | ( | const char * | hex_str, |
| size_t | in_len, | ||
| uint8_t * | out, | ||
| size_t * | out_len ) |
Perform hex decoding
| hex_str | a string of hex chars (whitespace is ignored) |
| in_len | the length of hex_str |
| out | the output buffer should be at least strlen(hex_str)/2 bytes |
| out_len | the size of the output buffer on input, set to the number of bytes written |
Definition at line 399 of file ffi.cpp.
References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan::hex_decode(), and Botan_FFI::write_vec_output().
| int botan_hex_encode | ( | const uint8_t * | x, |
| size_t | len, | ||
| char * | out, | ||
| uint32_t | flags ) |
Perform hex encoding
| x | is some binary data |
| len | length of x in bytes |
| out | an array of at least x*2 bytes |
| flags | flags out be upper or lower case? |
Definition at line 388 of file ffi.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_HEX_LOWER_CASE, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::hex_encode().
| int botan_is_shared | ( | void * | handle | ) |
Some handles created by functions like botan_*_init() allow sharing internal ownership of the underlying C++ object via a std::shared_ptr. Typically, this is used when some other handle needs to retain ownership of the same object for continuous use internally. The botan_rng_t handle is such an internally sharable object, for instance.
Calling botan_*_destroy() on such a handle drops the shared_ptr reference held by the application, but the underlying object may still be alive because of other handles that retain the internal shared_ptr.
This lets the application query if some handle can be shared internally. That way users can determine if a call to botan_*_destroy() will certainly destroy the underlying object or not.
Definition at line 435 of file ffi.cpp.
References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_INVALID_OBJECT, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::botan_ffi_obj_base::is_shared().
| int botan_same_mem | ( | const uint8_t * | x, |
| const uint8_t * | y, | ||
| size_t | len ) |
Deprecated equivalent to botan_constant_time_compare
Definition at line 376 of file ffi.cpp.
References botan_constant_time_compare().
| int botan_scrub_mem | ( | void * | mem, |
| size_t | bytes ) |
Clear out memory using a system specific approach to bypass elision by the compiler (currently using RtlSecureZeroMemory or tricks with volatile pointers).
Definition at line 380 of file ffi.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan::secure_scrub_memory().
| int botan_use_count | ( | void * | handle, |
| size_t * | out_use_count ) |
Some handles created by functions like botan_*_init() allow sharing internal ownership of the underlying C++ object via a std::shared_ptr. Typically, this is used when some other handle needs to retain ownership of the same object for continuous use internally. The botan_rng_t handle is such an internally sharable object, for instance.
Calling botan_*_destroy() on such a handle drops the shared_ptr reference held by the application, but the underlying object may still be alive because of other handles that retain the internal shared_ptr.
This lets the application query the current internal reference count of such an object. Assuming no concurrent access, a return value of 1 means that the application is the sole owner of the underlying object and that a call to botan_*_destroy() will destroy the underlying object. Handles for which botan_is_shared() returns 0 will always return 1 for botan_use_count().
Definition at line 450 of file ffi.cpp.
References Botan_FFI::any_null_pointers(), BOTAN_FFI_ERROR_INVALID_OBJECT, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::botan_ffi_obj_base::use_count().
| uint32_t botan_version_datestamp | ( | void | ) |
Return the date this version was released as an integer.
Returns 0 if the library was not built from an official release
Definition at line 363 of file ffi.cpp.
References Botan::version_datestamp().
| uint32_t botan_version_major | ( | void | ) |
Return the major version of the library
Definition at line 351 of file ffi.cpp.
References Botan::version_major().
| uint32_t botan_version_minor | ( | void | ) |
Return the minor version of the library
Definition at line 355 of file ffi.cpp.
References Botan::version_minor().
| uint32_t botan_version_patch | ( | void | ) |
Return the patch version of the library
Definition at line 359 of file ffi.cpp.
References Botan::version_patch().
| const char * botan_version_string | ( | void | ) |
Return a free-form version string, e.g., 2.0.0
Definition at line 347 of file ffi.cpp.
References Botan::version_cstr().