Fabcoin Core
0.16.2
P2P Digital Currency
|
#include "pch.h"
#include "config.h"
#include "misc.h"
#include "words.h"
#include "stdcpp.h"
#include "integer.h"
Go to the source code of this file.
Functions | |
void | xorbuf (byte *buf, const byte *mask, size_t count) |
Performs an XOR of a buffer with a mask. More... | |
void | xorbuf (byte *output, const byte *input, const byte *mask, size_t count) |
Performs an XOR of an input buffer with a mask and stores the result in an output buffer. More... | |
bool | VerifyBufsEqual (const byte *buf, const byte *mask, size_t count) |
Performs a near constant-time comparison of two equally sized buffers. More... | |
std::string | StringNarrow (const wchar_t *str, bool throwOnError) |
Converts a wide character C-string to a multibyte string. More... | |
void | CallNewHandler () |
Attempts to reclaim unused memory. More... | |
void * | UnalignedAllocate (size_t size) |
Allocates a buffer. More... | |
void | UnalignedDeallocate (void *p) |
Frees a buffer allocated with UnalignedAllocate. More... | |
void CallNewHandler | ( | ) |
Attempts to reclaim unused memory.
bad_alloc |
In the normal course of running a program, a request for memory normally succeeds. If a call to AlignedAllocate or UnalignedAllocate fails, then CallNewHandler is called in an effort to recover. Internally, CallNewHandler calls set_new_handler(NULL) in an effort to free memory. There is no guarantee CallNewHandler will be able to procure more memory so an allocation succeeds. If the call to set_new_handler fails, then CallNewHandler throws a bad_alloc exception.
Definition at line 200 of file misc.cpp.
std::string StringNarrow | ( | const wchar_t * | str, |
bool | throwOnError = true |
||
) |
Converts a wide character C-string to a multibyte string.
str | C-string consisting of wide characters |
throwOnError | flag indication the function should throw on error |
StringNarrow converts a wide string to a narrow string using C++ std::wcstombs() under the executing thread's locale. A locale must be set before using this function, and it can be set with std::setlocale() if needed. Upon success, the converted string is returned.
Upon failure with throwOnError as false, the function returns an empty string. If throwOnError as true, the function throws an InvalidArgument() exception.
Definition at line 136 of file misc.cpp.
void* UnalignedAllocate | ( | size_t | size | ) |
void UnalignedDeallocate | ( | void * | ptr | ) |
Performs a near constant-time comparison of two equally sized buffers.
buf1 | the first buffer |
buf2 | the second buffer |
count | the size of the buffers, in bytes |
The function effectively performs an XOR of the elements in two equally sized buffers and retruns a result based on the XOR operation. The function is near constant-time because CPU micro-code timings could affect the "constant-ness". Calling code is responsible for mitigating timing attacks if the buffers are not equally sized.
Definition at line 96 of file misc.cpp.
Performs an XOR of a buffer with a mask.
buf | the buffer to XOR with the mask |
mask | the mask to XOR with the buffer |
count | the size of the buffers, in bytes |
The function effectively visits each element in the buffers and performs buf[i] ^= mask[i]
. buf and mask must be of equal size.
Definition at line 28 of file misc.cpp.
Performs an XOR of an input buffer with a mask and stores the result in an output buffer.
output | the destination buffer |
input | the source buffer to XOR with the mask |
mask | the mask buffer to XOR with the input buffer |
count | the size of the buffers, in bytes |
The function effectively visits each element in the buffers and performs output[i] = input[i] ^ mask[i]
. output, input and mask must be of equal size.