6 #ifndef CRYPTOPP_SECBLOCK_H 7 #define CRYPTOPP_SECBLOCK_H 13 #if CRYPTOPP_MSC_VERSION 14 # pragma warning(push) 15 # pragma warning(disable: 4700) 16 # if (CRYPTOPP_MSC_VERSION >= 1400) 17 # pragma warning(disable: 6386) 34 #ifdef CRYPTOPP_MSVCRT6 44 pointer
address(reference r)
const {
return (&r);}
45 const_pointer
address(const_reference r)
const {
return (&r); }
57 #if defined(CRYPTOPP_CXX11_VARIADIC_TEMPLATES) || defined(CRYPTOPP_DOXYGEN_PROCESSING) 66 template<
typename U,
typename... Args>
67 void construct(U* ptr, Args&&... args) {::new ((
void*)ptr) U(std::forward<Args>(args)...);}
74 void destroy(U* ptr) {
if(ptr) ptr->~U();}
95 throw InvalidArgument(
"AllocatorBase: requested size would cause integer overflow");
99 #define CRYPTOPP_INHERIT_ALLOCATOR_TYPES \ 100 typedef typename AllocatorBase<T>::value_type value_type;\ 101 typedef typename AllocatorBase<T>::size_type size_type;\ 102 typedef typename AllocatorBase<T>::difference_type difference_type;\ 103 typedef typename AllocatorBase<T>::pointer pointer;\ 104 typedef typename AllocatorBase<T>::const_pointer const_pointer;\ 105 typedef typename AllocatorBase<T>::reference reference;\ 106 typedef typename AllocatorBase<T>::const_reference const_reference; 118 template <
class T,
class A>
119 typename A::pointer
StandardReallocate(A& alloc,
T *oldPtr,
typename A::size_type oldSize,
typename A::size_type newSize,
bool preserve)
122 if (oldSize == newSize)
127 typename A::pointer newPointer = alloc.allocate(newSize, NULL);
128 const size_t copySize =
STDMIN(oldSize, newSize) *
sizeof(
T);
130 if (oldPtr && newPointer) {
memcpy_s(newPointer, copySize, oldPtr, copySize);}
131 alloc.deallocate(oldPtr, oldSize);
136 alloc.deallocate(oldPtr, oldSize);
137 return alloc.allocate(newSize, NULL);
150 template <
class T,
bool T_Align16 = false>
178 #if CRYPTOPP_BOOL_ALIGN16 180 if (T_Align16 && size*
sizeof(
T) >= 16)
181 return (
pointer)AlignedAllocate(size*
sizeof(
T));
200 #if CRYPTOPP_BOOL_ALIGN16 201 if (T_Align16 && size*
sizeof(
T) >= 16)
202 return AlignedDeallocate(ptr);
247 #if defined(CRYPTOPP_WORD128_AVAILABLE) 250 #if CRYPTOPP_BOOL_X86 300 template <
class T,
size_t S,
class A = NullAllocator<T>,
bool T_Align16 = false>
325 if (size <=
S && !m_allocated)
328 return GetAlignedArray();
331 return m_fallbackAllocator.allocate(size);
349 if (size <=
S && !m_allocated)
352 return GetAlignedArray();
355 return m_fallbackAllocator.allocate(size, hint);
368 if (ptr == GetAlignedArray())
376 m_fallbackAllocator.deallocate(ptr, size);
398 if (oldPtr == GetAlignedArray() && newSize <=
S)
401 if (oldSize > newSize)
407 if (preserve && newSize)
409 const size_t copySize =
STDMIN(oldSize, newSize);
410 memcpy_s(newPointer,
sizeof(
T)*newSize, oldPtr,
sizeof(
T)*copySize);
421 T* GetAlignedArray() {
return m_array;}
436 template <
class T,
class A = AllocatorWithCleanup<T> >
457 : m_size(t.m_size), m_ptr(m_alloc.
allocate(t.m_size, NULL)) {
471 : m_size(len), m_ptr(m_alloc.
allocate(len, NULL)) {
474 memcpy_s(m_ptr, m_size*
sizeof(
T), ptr, len*
sizeof(
T));
476 memset(m_ptr, 0, m_size*
sizeof(
T));
480 {m_alloc.deallocate(m_ptr, m_size);}
486 operator const void *()
const 491 operator const T *()
const 508 {
return m_ptr+m_size;}
511 const_iterator
end()
const 512 {
return m_ptr+m_size;}
516 typename A::pointer
data() {
return m_ptr;}
519 typename A::const_pointer
data()
const {
return m_ptr;}
524 size_type
size()
const {
return m_size;}
527 bool empty()
const {
return m_size == 0;}
547 if (m_ptr && ptr && len)
548 {
memcpy_s(m_ptr, m_size*
sizeof(
T), ptr, len*
sizeof(
T));}
585 const size_type oldSize = m_size;
594 memcpy_s(m_ptr+oldSize, (m_size-oldSize)*
sizeof(
T), m_ptr, oldSize*
sizeof(
T));
624 return m_size == t.
m_size &&
625 VerifyBufsEqual(reinterpret_cast<const byte*>(m_ptr), reinterpret_cast<const byte*>(t.
m_ptr), m_size*
sizeof(
T));
647 void New(size_type newSize)
649 m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize,
false);
663 if (m_ptr) {
memset_z(m_ptr, 0, m_size*
sizeof(
T));}
675 if (newSize > m_size)
677 m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize,
true);
691 if (newSize > m_size)
693 m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize,
true);
694 memset_z(m_ptr+m_size, 0, (newSize-m_size)*
sizeof(
T));
707 m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize,
true);
728 #ifdef CRYPTOPP_DOXYGEN_PROCESSING 752 template <
class T,
unsigned int S,
class A = FixedSizeAllocatorWithCleanup<T, S> >
765 template <
class T,
unsigned int S,
bool T_Align16 = true>
775 template <
class T,
unsigned int S,
class A = FixedSizeAllocatorWithCleanup<T, S, AllocatorWithCleanup<T> > >
783 template<
class T,
bool A,
class U,
bool B>
784 inline bool operator==(
const CryptoPP::AllocatorWithCleanup<T, A>&,
const CryptoPP::AllocatorWithCleanup<U, B>&) {
return (
true);}
785 template<
class T,
bool A,
class U,
bool B>
786 inline bool operator!=(
const CryptoPP::AllocatorWithCleanup<T, A>&,
const CryptoPP::AllocatorWithCleanup<U, B>&) {
return (
false);}
791 template <
class T,
class A>
792 inline void swap(CryptoPP::SecBlock<T, A> &
a, CryptoPP::SecBlock<T, A> &
b)
797 #if defined(_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || (defined(_STLPORT_VERSION) && !defined(_STLP_MEMBER_TEMPLATE_CLASSES)) 799 template <
class _Tp1,
class _Tp2>
800 inline CryptoPP::AllocatorWithCleanup<_Tp2>&
801 __stl_alloc_rebind(CryptoPP::AllocatorWithCleanup<_Tp1>& __a,
const _Tp2*)
803 return (CryptoPP::AllocatorWithCleanup<_Tp2>&)(__a);
809 #if CRYPTOPP_MSC_VERSION 810 # pragma warning(pop) iterator end()
Provides an iterator pointing beyond the last element in the memory block.
#define CRYPTOPP_CONSTEXPR
const_pointer address(const_reference r) const
An invalid argument was detected.
bool operator==(const CryptoPP::AllocatorWithCleanup< T, A > &, const CryptoPP::AllocatorWithCleanup< U, B > &)
Base class for all allocators used by SecBlock.
void swap(SecBlock< T, A > &b)
Swap contents with another SecBlock.
Stack-based SecBlock that grows into the heap.
Utility functions for the Crypto++ library.
FixedSizeSecBlock()
Construct a FixedSizeSecBlock.
void CleanNew(size_type newSize)
Change size without preserving contents.
bool operator!=(const SecBlock< T, A > &t) const
Bitwise compare two SecBlocks.
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
A::const_pointer data() const
Provides a pointer to the first element in the memory block.
bool empty() const
Determines if the SecBlock is empty.
SecBlock< T, A > & operator=(const SecBlock< T, A > &t)
Assign contents from another SecBlock.
void resize(size_type newSize)
Change size and preserve contents.
SecBlock< T, A > & operator+=(const SecBlock< T, A > &t)
Append contents from another SecBlock.
void CleanGrow(size_type newSize)
Change size and preserve contents.
#define NAMESPACE_BEGIN(x)
std::ptrdiff_t difference_type
#define CRYPTOPP_DLL_TEMPLATE_CLASS
void Assign(const SecBlock< T, A > &t)
Copy contents from another SecBlock.
SecBlock< T, A > operator+(const SecBlock< T, A > &t)
Construct a SecBlock from this and another SecBlock.
SecBlock(size_type size=0)
Construct a SecBlock with space for size elements.
const_iterator begin() const
Provides a constant iterator pointing to the first element in the memory block.
Secure memory block with allocator and cleanup.
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
size_type size() const
Provides the count of elements in the SecBlock.
CRYPTOPP_CONSTEXPR size_type max_size() const
Returns the maximum number of elements the allocator can provide.
Library configuration file.
std::hash for asio::adress
pointer allocate(size_type size, const void *hint)
Allocates a block of memory.
CRYPTOPP_CONSTEXPR size_type max_size() const
void New(size_type newSize)
Change size without preserving contents.
void * UnalignedAllocate(size_t size)
Allocates a buffer.
void UnalignedDeallocate(void *p)
Frees a buffer allocated with UnalignedAllocate.
static void CheckSize(size_t size)
Verifies the allocator can satisfy a request based on size.
pointer reallocate(T *oldPtr, size_type oldSize, size_type newSize, bool preserve)
Reallocates a block of memory.
Static secure memory block with cleanup.
Allocates a block of memory with cleanup.
void deallocate(void *ptr, size_type size)
Deallocates a block of memory.
void SecureWipeArray(T *buf, size_t n)
Sets each element of an array to 0.
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
SecBlock< word > SecWordBlock
#define CRYPTOPP_ALIGN_DATA(x)
void deallocate(void *p, size_type n)
CRYPTOPP_INHERIT_ALLOCATOR_TYPES pointer allocate(size_type size, const void *ptr=NULL)
Allocates a block of memory.
bool operator!=(const CryptoPP::AllocatorWithCleanup< T, A > &, const CryptoPP::AllocatorWithCleanup< U, B > &)
const_iterator end() const
Provides a constant iterator pointing beyond the last element in the memory block.
Template class memeber Rebind.
SecBlock< byte > SecByteBlock
A::pointer data()
Provides a pointer to the first element in the memory block.
void Assign(const T *ptr, size_type len)
Set contents and size from an array.
const T & const_reference
#define CRYPTOPP_BOOL_ALIGN16
pointer reallocate(pointer oldPtr, size_type oldSize, size_type newSize, bool preserve)
Reallocates a block of memory.
Fixed size stack-based SecBlock with 16-byte alignment.
A::const_pointer const_iterator
SecBlock< byte, AllocatorWithCleanup< byte, true > > AlignedSecByteBlock
Fixed size stack-based SecBlock.
SecBlock(const SecBlock< T, A > &t)
Copy construct a SecBlock from another SecBlock.
void * memset_z(void *ptr, int value, size_t num)
Memory block initializer and eraser that attempts to survive optimizations.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
void deallocate(void *ptr, size_type size)
Deallocates a block of memory.
iterator begin()
Provides an iterator pointing to the first element in the memory block.
const byte * BytePtr() const
Return a byte pointer to the first element in the memory block.
AllocatorWithCleanup< U, T_Align16 > other
CRYPTOPP_INHERIT_ALLOCATOR_TYPES FixedSizeAllocatorWithCleanup()
Constructs a FixedSizeAllocatorWithCleanup.
CRYPTOPP_INHERIT_ALLOCATOR_TYPES pointer allocate(size_type n, const void *unused=NULL)
void construct(pointer p, const T &val)
SecBlockWithHint(size_t size)
construct a SecBlockWithHint with a count of elements
pointer address(reference r) const
uint8_t const size_t const size
#define CRYPTOPP_UNUSED(x)
CRYPTOPP_ALIGN_DATA(8) T m_array[(CRYPTOPP_BOOL_ALIGN16 &&T_Align16)?S+8/sizeof(T) A m_fallbackAllocator
A::pointer StandardReallocate(A &alloc, T *oldPtr, typename A::size_type oldSize, typename A::size_type newSize, bool preserve)
Reallocation function.
CRYPTOPP_CONSTEXPR size_type max_size() const
SecBlock(const T *ptr, size_type len)
Construct a SecBlock from an array of elements.
pointer allocate(size_type size)
Allocates a block of memory.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
void Grow(size_type newSize)
Change size and preserve contents.
bool operator==(const SecBlock< T, A > &t) const
Bitwise compare two SecBlocks.
size_type SizeInBytes() const
Provides the number of bytes in the SecBlock.
NAMESPACE_END void swap(CryptoPP::SecBlock< T, A > &a, CryptoPP::SecBlock< T, A > &b)
#define CRYPTOPP_INHERIT_ALLOCATOR_TYPES
bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
Performs a near constant-time comparison of two equally sized buffers.
byte * BytePtr()
Provides a byte pointer to the first element in the memory block.