8 #ifndef BOTAN_SECURE_MEMORY_BUFFERS_H__
9 #define BOTAN_SECURE_MEMORY_BUFFERS_H__
11 #include <botan/mem_ops.h>
15 #include <type_traits>
17 #if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
18 #include <botan/locking_allocator.h>
34 #if !defined(_ITERATOR_DEBUG_LEVEL) || _ITERATOR_DEBUG_LEVEL == 0
35 static_assert(std::is_integral<T>::value,
"secure_allocator supports only integer types");
49 #ifdef BOTAN_BUILD_COMPILER_IS_MSVC_2013
65 {
return std::addressof(x); }
68 {
return std::addressof(x); }
72 #if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
86 #if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
96 return static_cast<size_type
>(-1) /
sizeof(T);
99 template<
typename U,
typename... Args>
102 ::new(static_cast<void*>(p)) U(std::forward<Args>(args)...);
106 #pragma warning(push)
107 #pragma warning(disable: 4100)
108 template<
typename U>
void destroy(U* p) { p->~U(); }
113 template<
typename T,
typename U>
inline bool
117 template<
typename T,
typename U>
inline bool
121 template<
typename T>
using secure_vector = std::vector<T, secure_allocator<T>>;
122 template<
typename T>
using secure_deque = std::deque<T, secure_allocator<T>>;
127 std::vector<T> out(in.size());
128 copy_mem(out.data(), in.data(), in.size());
132 template<
typename T,
typename Alloc>
138 const size_t to_copy =
std::min(input_length, buf.size() - buf_offset);
141 copy_mem(&buf[buf_offset], input, to_copy);
146 template<
typename T,
typename Alloc,
typename Alloc2>
149 const std::vector<T, Alloc2>& input)
151 const size_t to_copy =
std::min(input.size(), buf.size() - buf_offset);
154 copy_mem(&buf[buf_offset], input.data(), to_copy);
159 template<
typename T,
typename Alloc,
typename Alloc2>
160 std::vector<T, Alloc>&
162 const std::vector<T, Alloc2>& in)
164 const size_t copy_offset = out.size();
165 out.resize(out.size() + in.size());
168 copy_mem(&out[copy_offset], in.data(), in.size());
173 template<
typename T,
typename Alloc>
174 std::vector<T, Alloc>&
operator+=(std::vector<T, Alloc>& out, T in)
180 template<
typename T,
typename Alloc,
typename L>
181 std::vector<T, Alloc>&
operator+=(std::vector<T, Alloc>& out,
182 const std::pair<const T*, L>& in)
184 const size_t copy_offset = out.size();
185 out.resize(out.size() + in.second);
188 copy_mem(&out[copy_offset], in.first, in.second);
193 template<
typename T,
typename Alloc,
typename L>
194 std::vector<T, Alloc>&
operator+=(std::vector<T, Alloc>& out,
195 const std::pair<T*, L>& in)
197 const size_t copy_offset = out.size();
198 out.resize(out.size() + in.second);
201 copy_mem(&out[copy_offset], in.first, in.second);
210 template<
typename T,
typename Alloc>
220 template<
typename T,
typename Alloc>
221 void zap(std::vector<T, Alloc>& vec)
void secure_scrub_memory(void *ptr, size_t n)
const T & const_reference
secure_allocator() BOTAN_NOEXCEPT=default
void zap(std::vector< T, Alloc > &vec)
static mlock_allocator & instance()
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
void clear_mem(T *ptr, size_t n)
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
void construct(U *p, Args &&...args)
std::deque< T, secure_allocator< T >> secure_deque
std::vector< T, secure_allocator< T >> secure_vector
~secure_allocator() BOTAN_NOEXCEPT=default
size_type max_size() const BOTAN_NOEXCEPT
std::vector< T, Alloc > & operator+=(std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
pointer allocate(size_type n, const void *=0)
void copy_mem(T *out, const T *in, size_t n)
std::vector< T > unlock(const secure_vector< T > &in)
std::ptrdiff_t difference_type
secure_allocator & operator=(const secure_allocator &) BOTAN_NOEXCEPT=default
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
secure_allocator(const secure_allocator< U > &) BOTAN_NOEXCEPT
const_pointer address(const_reference x) const BOTAN_NOEXCEPT
void deallocate(pointer p, size_type n)
void zeroise(std::vector< T, Alloc > &vec)
pointer address(reference x) const BOTAN_NOEXCEPT