Fabcoin Core  0.16.2
P2P Digital Currency
secblock.h
Go to the documentation of this file.
1 // secblock.h - written and placed in the public domain by Wei Dai
2 
5 
6 #ifndef CRYPTOPP_SECBLOCK_H
7 #define CRYPTOPP_SECBLOCK_H
8 
9 #include "config.h"
10 #include "stdcpp.h"
11 #include "misc.h"
12 
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)
18 # endif
19 #endif
20 
22 
23 // ************** secure memory allocation ***************
24 
25 template<class T>
30 {
31 public:
32  typedef T value_type;
33  typedef size_t size_type;
34 #ifdef CRYPTOPP_MSVCRT6
35  typedef ptrdiff_t difference_type;
36 #else
37  typedef std::ptrdiff_t difference_type;
38 #endif
39  typedef T * pointer;
40  typedef const T * const_pointer;
41  typedef T & reference;
42  typedef const T & const_reference;
43 
44  pointer address(reference r) const {return (&r);}
45  const_pointer address(const_reference r) const {return (&r); }
46  void construct(pointer p, const T& val) {new (p) T(val);}
47  void destroy(pointer p) {CRYPTOPP_UNUSED(p); p->~T();}
48 
55  CRYPTOPP_CONSTEXPR size_type max_size() const {return (SIZE_MAX/sizeof(T));}
56 
57 #if defined(CRYPTOPP_CXX11_VARIADIC_TEMPLATES) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
58 
66  template<typename U, typename... Args>
67  void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);}
68 
73  template<typename U>
74  void destroy(U* ptr) {if(ptr) ptr->~U();}
75 
76 #endif
77 
78 protected:
79 
91  static void CheckSize(size_t size)
92  {
93  // C++ throws std::bad_alloc (C++03) or std::bad_array_new_length (C++11) here.
94  if (size > (SIZE_MAX/sizeof(T)))
95  throw InvalidArgument("AllocatorBase: requested size would cause integer overflow");
96  }
97 };
98 
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;
107 
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)
120 {
121  CRYPTOPP_ASSERT((oldPtr && oldSize) || !(oldPtr || oldSize));
122  if (oldSize == newSize)
123  return oldPtr;
124 
125  if (preserve)
126  {
127  typename A::pointer newPointer = alloc.allocate(newSize, NULL);
128  const size_t copySize = STDMIN(oldSize, newSize) * sizeof(T);
129 
130  if (oldPtr && newPointer) {memcpy_s(newPointer, copySize, oldPtr, copySize);}
131  alloc.deallocate(oldPtr, oldSize);
132  return newPointer;
133  }
134  else
135  {
136  alloc.deallocate(oldPtr, oldSize);
137  return alloc.allocate(newSize, NULL);
138  }
139 }
140 
150 template <class T, bool T_Align16 = false>
152 {
153 public:
155 
171  pointer allocate(size_type size, const void *ptr = NULL)
172  {
173  CRYPTOPP_UNUSED(ptr); CRYPTOPP_ASSERT(ptr == NULL);
174  this->CheckSize(size);
175  if (size == 0)
176  return NULL;
177 
178 #if CRYPTOPP_BOOL_ALIGN16
179  // TODO: should this need the test 'size*sizeof(T) >= 16'?
180  if (T_Align16 && size*sizeof(T) >= 16)
181  return (pointer)AlignedAllocate(size*sizeof(T));
182 #endif
183 
184  return (pointer)UnalignedAllocate(size*sizeof(T));
185  }
186 
195  void deallocate(void *ptr, size_type size)
196  {
197  CRYPTOPP_ASSERT((ptr && size) || !(ptr || size));
198  SecureWipeArray((pointer)ptr, size);
199 
200 #if CRYPTOPP_BOOL_ALIGN16
201  if (T_Align16 && size*sizeof(T) >= 16)
202  return AlignedDeallocate(ptr);
203 #endif
204 
205  UnalignedDeallocate(ptr);
206  }
207 
221  pointer reallocate(T *oldPtr, size_type oldSize, size_type newSize, bool preserve)
222  {
223  CRYPTOPP_ASSERT((oldPtr && oldSize) || !(oldPtr || oldSize));
224  return StandardReallocate(*this, oldPtr, oldSize, newSize, preserve);
225  }
226 
236  template <class U> struct rebind { typedef AllocatorWithCleanup<U, T_Align16> other; };
237 #if _MSC_VER >= 1500
239  template <class U, bool A> AllocatorWithCleanup(const AllocatorWithCleanup<U, A> &) {}
240 #endif
241 };
242 
247 #if defined(CRYPTOPP_WORD128_AVAILABLE)
249 #endif
250 #if CRYPTOPP_BOOL_X86
252 #endif
253 
262 template <class T>
263 class NullAllocator : public AllocatorBase<T>
264 {
265 public:
266  //LCOV_EXCL_START
268 
269  // TODO: should this return NULL or throw bad_alloc? Non-Windows C++ standard
270  // libraries always throw. And late mode Windows throws. Early model Windows
271  // (circa VC++ 6.0) returned NULL.
272  pointer allocate(size_type n, const void* unused = NULL)
273  {
274  CRYPTOPP_UNUSED(n); CRYPTOPP_UNUSED(unused);
275  CRYPTOPP_ASSERT(false); return NULL;
276  }
277 
278  void deallocate(void *p, size_type n)
279  {
281  CRYPTOPP_ASSERT(false);
282  }
283 
285  //LCOV_EXCL_STOP
286 };
287 
300 template <class T, size_t S, class A = NullAllocator<T>, bool T_Align16 = false>
302 {
303 public:
305 
307  FixedSizeAllocatorWithCleanup() : m_allocated(false) {}
308 
322  {
323  CRYPTOPP_ASSERT(IsAlignedOn(m_array, 8));
324 
325  if (size <= S && !m_allocated)
326  {
327  m_allocated = true;
328  return GetAlignedArray();
329  }
330  else
331  return m_fallbackAllocator.allocate(size);
332  }
333 
347  pointer allocate(size_type size, const void *hint)
348  {
349  if (size <= S && !m_allocated)
350  {
351  m_allocated = true;
352  return GetAlignedArray();
353  }
354  else
355  return m_fallbackAllocator.allocate(size, hint);
356  }
357 
366  void deallocate(void *ptr, size_type size)
367  {
368  if (ptr == GetAlignedArray())
369  {
370  CRYPTOPP_ASSERT(size <= S);
371  CRYPTOPP_ASSERT(m_allocated);
372  m_allocated = false;
373  SecureWipeArray((pointer)ptr, size);
374  }
375  else
376  m_fallbackAllocator.deallocate(ptr, size);
377  }
378 
396  pointer reallocate(pointer oldPtr, size_type oldSize, size_type newSize, bool preserve)
397  {
398  if (oldPtr == GetAlignedArray() && newSize <= S)
399  {
400  CRYPTOPP_ASSERT(oldSize <= S);
401  if (oldSize > newSize)
402  SecureWipeArray(oldPtr+newSize, oldSize-newSize);
403  return oldPtr;
404  }
405 
406  pointer newPointer = allocate(newSize, NULL);
407  if (preserve && newSize)
408  {
409  const size_t copySize = STDMIN(oldSize, newSize);
410  memcpy_s(newPointer, sizeof(T)*newSize, oldPtr, sizeof(T)*copySize);
411  }
412  deallocate(oldPtr, oldSize);
413  return newPointer;
414  }
415 
416  CRYPTOPP_CONSTEXPR size_type max_size() const {return STDMAX(m_fallbackAllocator.max_size(), S);}
417 
418 private:
419 
420 #ifdef __BORLANDC__
421  T* GetAlignedArray() {return m_array;}
422  T m_array[S];
423 #else
424  T* GetAlignedArray() {return (CRYPTOPP_BOOL_ALIGN16 && T_Align16) ? (T*)(void *)(((byte *)m_array) + (0-(size_t)m_array)%16) : m_array;}
425  CRYPTOPP_ALIGN_DATA(8) T m_array[(CRYPTOPP_BOOL_ALIGN16 && T_Align16) ? S+8/sizeof(T) : S];
426 #endif
427 
430 };
431 
436 template <class T, class A = AllocatorWithCleanup<T> >
437 class SecBlock
438 {
439 public:
440  typedef typename A::value_type value_type;
441  typedef typename A::pointer iterator;
442  typedef typename A::const_pointer const_iterator;
443  typedef typename A::size_type size_type;
444 
450  explicit SecBlock(size_type size=0)
451  : m_size(size), m_ptr(m_alloc.allocate(size, NULL)) { }
452 
457  : m_size(t.m_size), m_ptr(m_alloc.allocate(t.m_size, NULL)) {
458  CRYPTOPP_ASSERT((!t.m_ptr && !m_size) || (t.m_ptr && m_size));
459  if (t.m_ptr) {memcpy_s(m_ptr, m_size*sizeof(T), t.m_ptr, t.m_size*sizeof(T));}
460  }
461 
470  SecBlock(const T *ptr, size_type len)
471  : m_size(len), m_ptr(m_alloc.allocate(len, NULL)) {
472  CRYPTOPP_ASSERT((!m_ptr && !m_size) || (m_ptr && m_size));
473  if (ptr && m_ptr)
474  memcpy_s(m_ptr, m_size*sizeof(T), ptr, len*sizeof(T));
475  else if (m_size)
476  memset(m_ptr, 0, m_size*sizeof(T));
477  }
478 
480  {m_alloc.deallocate(m_ptr, m_size);}
481 
482 #ifdef __BORLANDC__
483  operator T *() const
484  {return (T*)m_ptr;}
485 #else
486  operator const void *() const
487  {return m_ptr;}
488  operator void *()
489  {return m_ptr;}
490 
491  operator const T *() const
492  {return m_ptr;}
493  operator T *()
494  {return m_ptr;}
495 #endif
496 
499  iterator begin()
500  {return m_ptr;}
503  const_iterator begin() const
504  {return m_ptr;}
507  iterator end()
508  {return m_ptr+m_size;}
511  const_iterator end() const
512  {return m_ptr+m_size;}
513 
516  typename A::pointer data() {return m_ptr;}
519  typename A::const_pointer data() const {return m_ptr;}
520 
524  size_type size() const {return m_size;}
527  bool empty() const {return m_size == 0;}
528 
531  byte * BytePtr() {return (byte *)m_ptr;}
534  const byte * BytePtr() const {return (const byte *)m_ptr;}
538  size_type SizeInBytes() const {return m_size*sizeof(T);}
539 
544  void Assign(const T *ptr, size_type len)
545  {
546  New(len);
547  if (m_ptr && ptr && len)
548  {memcpy_s(m_ptr, m_size*sizeof(T), ptr, len*sizeof(T));}
549  }
550 
555  void Assign(const SecBlock<T, A> &t)
556  {
557  if (this != &t)
558  {
559  New(t.m_size);
560  if (m_ptr && t.m_ptr && t.m_size)
561  {memcpy_s(m_ptr, m_size*sizeof(T), t, t.m_size*sizeof(T));}
562  }
563  }
564 
570  {
571  // Assign guards for self-assignment
572  Assign(t);
573  return *this;
574  }
575 
580  {
581  CRYPTOPP_ASSERT((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
582 
583  if(t.m_size)
584  {
585  const size_type oldSize = m_size;
586  if(this != &t) // s += t
587  {
588  Grow(m_size+t.m_size);
589  memcpy_s(m_ptr+oldSize, (m_size-oldSize)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
590  }
591  else // t += t
592  {
593  Grow(m_size*2);
594  memcpy_s(m_ptr+oldSize, (m_size-oldSize)*sizeof(T), m_ptr, oldSize*sizeof(T));
595  }
596  }
597  return *this;
598  }
599 
605  {
606  CRYPTOPP_ASSERT((!m_ptr && !m_size) || (m_ptr && m_size));
607  CRYPTOPP_ASSERT((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
608  if(!t.m_size) return SecBlock(*this);
609 
610  SecBlock<T, A> result(m_size+t.m_size);
611  if(m_size) {memcpy_s(result.m_ptr, result.m_size*sizeof(T), m_ptr, m_size*sizeof(T));}
612  memcpy_s(result.m_ptr+m_size, (result.m_size-m_size)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
613  return result;
614  }
615 
622  bool operator==(const SecBlock<T, A> &t) const
623  {
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));
626  }
627 
635  bool operator!=(const SecBlock<T, A> &t) const
636  {
637  return !operator==(t);
638  }
639 
647  void New(size_type newSize)
648  {
649  m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize, false);
650  m_size = newSize;
651  }
652 
660  void CleanNew(size_type newSize)
661  {
662  New(newSize);
663  if (m_ptr) {memset_z(m_ptr, 0, m_size*sizeof(T));}
664  }
665 
673  void Grow(size_type newSize)
674  {
675  if (newSize > m_size)
676  {
677  m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize, true);
678  m_size = newSize;
679  }
680  }
681 
689  void CleanGrow(size_type newSize)
690  {
691  if (newSize > m_size)
692  {
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));
695  m_size = newSize;
696  }
697  }
698 
705  void resize(size_type newSize)
706  {
707  m_ptr = m_alloc.reallocate(m_ptr, m_size, newSize, true);
708  m_size = newSize;
709  }
710 
715  {
716  // Swap must occur on the allocator in case its FixedSize that spilled into the heap.
717  std::swap(m_alloc, b.m_alloc);
718  std::swap(m_size, b.m_size);
719  std::swap(m_ptr, b.m_ptr);
720  }
721 
722 // protected:
724  size_type m_size;
726 };
727 
728 #ifdef CRYPTOPP_DOXYGEN_PROCESSING
729 class SecByteBlock : public SecBlock<byte> {};
734 class SecWordBlock : public SecBlock<word> {};
737 class AlignedSecByteBlock : public SecBlock<byte, AllocatorWithCleanup<byte, true> > {};
738 #else
742 #endif
743 
744 // No need for move semantics on derived class *if* the class does not add any
745 // data members; see http://stackoverflow.com/q/31755703, and Rule of {0|3|5}.
746 
752 template <class T, unsigned int S, class A = FixedSizeAllocatorWithCleanup<T, S> >
753 class FixedSizeSecBlock : public SecBlock<T, A>
754 {
755 public:
757  explicit FixedSizeSecBlock() : SecBlock<T, A>(S) {}
758 };
759 
765 template <class T, unsigned int S, bool T_Align16 = true>
766 class FixedSizeAlignedSecBlock : public FixedSizeSecBlock<T, S, FixedSizeAllocatorWithCleanup<T, S, NullAllocator<T>, T_Align16> >
767 {
768 };
769 
775 template <class T, unsigned int S, class A = FixedSizeAllocatorWithCleanup<T, S, AllocatorWithCleanup<T> > >
776 class SecBlockWithHint : public SecBlock<T, A>
777 {
778 public:
780  explicit SecBlockWithHint(size_t size) : SecBlock<T, A>(size) {}
781 };
782 
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);}
787 
789 
791 template <class T, class A>
792 inline void swap(CryptoPP::SecBlock<T, A> &a, CryptoPP::SecBlock<T, A> &b)
793 {
794  a.swap(b);
795 }
796 
797 #if defined(_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || (defined(_STLPORT_VERSION) && !defined(_STLP_MEMBER_TEMPLATE_CLASSES))
798 // working for STLport 5.1.3 and MSVC 6 SP5
799 template <class _Tp1, class _Tp2>
800 inline CryptoPP::AllocatorWithCleanup<_Tp2>&
801 __stl_alloc_rebind(CryptoPP::AllocatorWithCleanup<_Tp1>& __a, const _Tp2*)
802 {
803  return (CryptoPP::AllocatorWithCleanup<_Tp2>&)(__a);
804 }
805 #endif
806 
808 
809 #if CRYPTOPP_MSC_VERSION
810 # pragma warning(pop)
811 #endif
812 
813 #endif
iterator end()
Provides an iterator pointing beyond the last element in the memory block.
Definition: secblock.h:507
#define CRYPTOPP_CONSTEXPR
Definition: config.h:893
const_pointer address(const_reference r) const
Definition: secblock.h:45
An invalid argument was detected.
Definition: cryptlib.h:184
uint8_t byte
Definition: Common.h:57
T & reference
Definition: secblock.h:41
bool operator==(const CryptoPP::AllocatorWithCleanup< T, A > &, const CryptoPP::AllocatorWithCleanup< U, B > &)
Definition: secblock.h:784
Base class for all allocators used by SecBlock.
Definition: secblock.h:29
void swap(SecBlock< T, A > &b)
Swap contents with another SecBlock.
Definition: secblock.h:714
Stack-based SecBlock that grows into the heap.
Definition: secblock.h:776
Utility functions for the Crypto++ library.
FixedSizeSecBlock()
Construct a FixedSizeSecBlock.
Definition: secblock.h:757
void CleanNew(size_type newSize)
Change size without preserving contents.
Definition: secblock.h:660
bool operator!=(const SecBlock< T, A > &t) const
Bitwise compare two SecBlocks.
Definition: secblock.h:635
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Definition: Interface.h:284
A::const_pointer data() const
Provides a pointer to the first element in the memory block.
Definition: secblock.h:519
bool empty() const
Determines if the SecBlock is empty.
Definition: secblock.h:527
size_type m_size
Definition: secblock.h:724
A m_alloc
Definition: secblock.h:723
SecBlock< T, A > & operator=(const SecBlock< T, A > &t)
Assign contents from another SecBlock.
Definition: secblock.h:569
void resize(size_type newSize)
Change size and preserve contents.
Definition: secblock.h:705
SecBlock< T, A > & operator+=(const SecBlock< T, A > &t)
Append contents from another SecBlock.
Definition: secblock.h:579
#define T(i, x)
void CleanGrow(size_type newSize)
Change size and preserve contents.
Definition: secblock.h:689
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
std::ptrdiff_t difference_type
Definition: secblock.h:37
#define CRYPTOPP_DLL_TEMPLATE_CLASS
Definition: config.h:720
const T * const_pointer
Definition: secblock.h:40
void Assign(const SecBlock< T, A > &t)
Copy contents from another SecBlock.
Definition: secblock.h:555
SecBlock< T, A > operator+(const SecBlock< T, A > &t)
Construct a SecBlock from this and another SecBlock.
Definition: secblock.h:604
SecBlock(size_type size=0)
Construct a SecBlock with space for size elements.
Definition: secblock.h:450
const_iterator begin() const
Provides a constant iterator pointing to the first element in the memory block.
Definition: secblock.h:503
Secure memory block with allocator and cleanup.
Definition: secblock.h:437
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
Definition: misc.h:366
size_type size() const
Provides the count of elements in the SecBlock.
Definition: secblock.h:524
CRYPTOPP_CONSTEXPR size_type max_size() const
Returns the maximum number of elements the allocator can provide.
Definition: secblock.h:55
Library configuration file.
std::hash for asio::adress
Definition: Common.h:323
pointer allocate(size_type size, const void *hint)
Allocates a block of memory.
Definition: secblock.h:347
CRYPTOPP_CONSTEXPR size_type max_size() const
Definition: secblock.h:416
void New(size_type newSize)
Change size without preserving contents.
Definition: secblock.h:647
void * UnalignedAllocate(size_t size)
Allocates a buffer.
Definition: misc.cpp:257
void UnalignedDeallocate(void *p)
Frees a buffer allocated with UnalignedAllocate.
Definition: misc.cpp:265
static void CheckSize(size_t size)
Verifies the allocator can satisfy a request based on size.
Definition: secblock.h:91
pointer reallocate(T *oldPtr, size_type oldSize, size_type newSize, bool preserve)
Reallocates a block of memory.
Definition: secblock.h:221
Static secure memory block with cleanup.
Definition: secblock.h:301
Allocates a block of memory with cleanup.
Definition: secblock.h:151
void deallocate(void *ptr, size_type size)
Deallocates a block of memory.
Definition: secblock.h:366
void destroy(pointer p)
Definition: secblock.h:47
A::size_type size_type
Definition: secblock.h:443
void SecureWipeArray(T *buf, size_t n)
Sets each element of an array to 0.
Definition: misc.h:1192
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
Definition: misc.h:954
#define a(i)
SecBlock< word > SecWordBlock
Definition: secblock.h:740
#define CRYPTOPP_ALIGN_DATA(x)
Definition: config.h:338
void deallocate(void *p, size_type n)
Definition: secblock.h:278
CRYPTOPP_INHERIT_ALLOCATOR_TYPES pointer allocate(size_type size, const void *ptr=NULL)
Allocates a block of memory.
Definition: secblock.h:171
bool operator!=(const CryptoPP::AllocatorWithCleanup< T, A > &, const CryptoPP::AllocatorWithCleanup< U, B > &)
Definition: secblock.h:786
const_iterator end() const
Provides a constant iterator pointing beyond the last element in the memory block.
Definition: secblock.h:511
T * m_ptr
Definition: secblock.h:725
Template class memeber Rebind.
Definition: secblock.h:236
SecBlock< byte > SecByteBlock
Definition: secblock.h:739
A::pointer data()
Provides a pointer to the first element in the memory block.
Definition: secblock.h:516
void Assign(const T *ptr, size_type len)
Set contents and size from an array.
Definition: secblock.h:544
const T & const_reference
Definition: secblock.h:42
#define CRYPTOPP_BOOL_ALIGN16
Definition: config.h:505
pointer reallocate(pointer oldPtr, size_type oldSize, size_type newSize, bool preserve)
Reallocates a block of memory.
Definition: secblock.h:396
Fixed size stack-based SecBlock with 16-byte alignment.
Definition: secblock.h:766
A::const_pointer const_iterator
Definition: secblock.h:442
SecBlock< byte, AllocatorWithCleanup< byte, true > > AlignedSecByteBlock
Definition: secblock.h:741
Fixed size stack-based SecBlock.
Definition: secblock.h:753
SecBlock(const SecBlock< T, A > &t)
Copy construct a SecBlock from another SecBlock.
Definition: secblock.h:456
void * memset_z(void *ptr, int value, size_t num)
Memory block initializer and eraser that attempts to survive optimizations.
Definition: misc.h:461
#define b(i, j)
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
Definition: misc.h:477
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
void deallocate(void *ptr, size_type size)
Deallocates a block of memory.
Definition: secblock.h:195
iterator begin()
Provides an iterator pointing to the first element in the memory block.
Definition: secblock.h:499
const byte * BytePtr() const
Return a byte pointer to the first element in the memory block.
Definition: secblock.h:534
NULL allocator.
Definition: secblock.h:263
A::pointer iterator
Definition: secblock.h:441
AllocatorWithCleanup< U, T_Align16 > other
Definition: secblock.h:236
CRYPTOPP_INHERIT_ALLOCATOR_TYPES FixedSizeAllocatorWithCleanup()
Constructs a FixedSizeAllocatorWithCleanup.
Definition: secblock.h:307
CRYPTOPP_INHERIT_ALLOCATOR_TYPES pointer allocate(size_type n, const void *unused=NULL)
Definition: secblock.h:272
void construct(pointer p, const T &val)
Definition: secblock.h:46
SecBlockWithHint(size_t size)
construct a SecBlockWithHint with a count of elements
Definition: secblock.h:780
pointer address(reference r) const
Definition: secblock.h:44
uint8_t const size_t const size
Definition: sha3.h:20
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
CRYPTOPP_ALIGN_DATA(8) T m_array[(CRYPTOPP_BOOL_ALIGN16 &&T_Align16)?S+8/sizeof(T) A m_fallbackAllocator
Definition: secblock.h:425
A::pointer StandardReallocate(A &alloc, T *oldPtr, typename A::size_type oldSize, typename A::size_type newSize, bool preserve)
Reallocation function.
Definition: secblock.h:119
CRYPTOPP_CONSTEXPR size_type max_size() const
Definition: secblock.h:284
SecBlock(const T *ptr, size_type len)
Construct a SecBlock from an array of elements.
Definition: secblock.h:470
pointer allocate(size_type size)
Allocates a block of memory.
Definition: secblock.h:321
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
Definition: misc.h:487
#define NAMESPACE_END
Definition: config.h:201
void Grow(size_type newSize)
Change size and preserve contents.
Definition: secblock.h:673
size_t size_type
Definition: secblock.h:33
bool operator==(const SecBlock< T, A > &t) const
Bitwise compare two SecBlocks.
Definition: secblock.h:622
#define S(a)
Definition: mars.cpp:50
size_type SizeInBytes() const
Provides the number of bytes in the SecBlock.
Definition: secblock.h:538
NAMESPACE_END void swap(CryptoPP::SecBlock< T, A > &a, CryptoPP::SecBlock< T, A > &b)
Definition: secblock.h:792
~SecBlock()
Definition: secblock.h:479
A::value_type value_type
Definition: secblock.h:440
#define CRYPTOPP_INHERIT_ALLOCATOR_TYPES
Definition: secblock.h:99
bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
Performs a near constant-time comparison of two equally sized buffers.
Definition: misc.cpp:96
#define SIZE_MAX
Definition: misc.h:113
byte * BytePtr()
Provides a byte pointer to the first element in the memory block.
Definition: secblock.h:531