Botan::SecureVector< T, INITIAL_LEN > Class Template Reference

#include <secmem.h>

Inheritance diagram for Botan::SecureVector< T, INITIAL_LEN >:

Botan::MemoryRegion< T >

List of all members.

Public Member Functions

void append (const MemoryRegion< T > &other)
void append (Tx)
void append (const Tdata[], u32bit n)
const T * begin () const
T * begin ()
void clear ()
void copy (u32bit off, const Tin[], u32bit n)
void copy (const Tin[], u32bit n)
void destroy ()
bool empty () const
const T * end () const
T * end ()
void grow_to (u32bit n)
 operator const T * () const
 operator T * ()
bool operator!= (const MemoryRegion< T > &other) const
bool operator< (const MemoryRegion< T > &other) const
SecureVector< T > & operator= (const MemoryRegion< T > &in)
bool operator== (const MemoryRegion< T > &other) const
void resize (u32bit n)
 SecureVector (const MemoryRegion< T > &in1, const MemoryRegion< T > &in2)
 SecureVector (const MemoryRegion< T > &in)
 SecureVector (const T in[], u32bit n)
 SecureVector (u32bit n=INITIAL_LEN)
void set (const MemoryRegion< T > &in)
void set (const Tin[], u32bit n)
u32bit size () const
void swap (MemoryRegion< T > &other)

Protected Member Functions

void init (bool locking, u32bit length=0)


Detailed Description

template<typename T, u32bit INITIAL_LEN = 0>
class Botan::SecureVector< T, INITIAL_LEN >

This class represents variable length buffers using the operating systems capability to lock memory, i.e. keeping it from being swapped out to disk. In this way, a security hole allowing attackers to find swapped out secret keys is closed.

Definition at line 354 of file secmem.h.


Constructor & Destructor Documentation

template<typename T, u32bit INITIAL_LEN = 0>
Botan::SecureVector< T, INITIAL_LEN >::SecureVector ( u32bit  n = INITIAL_LEN  )  [inline]

Create a buffer of the specified length.

Parameters:
n the length of the buffer to create.

Definition at line 374 of file secmem.h.

00375          { init(true, n); }

template<typename T, u32bit INITIAL_LEN = 0>
Botan::SecureVector< T, INITIAL_LEN >::SecureVector ( const T  in[],
u32bit  n 
) [inline]

Create a buffer with the specified contents.

Parameters:
in the array containing the data to be initially copied into the newly created buffer
n the size of the array in

Definition at line 383 of file secmem.h.

00384          {
00385          init(true, INITIAL_LEN);
00386          if(INITIAL_LEN)
00387             copy(in, n);
00388          else
00389             set(in, n);
00390          }

template<typename T, u32bit INITIAL_LEN = 0>
Botan::SecureVector< T, INITIAL_LEN >::SecureVector ( const MemoryRegion< T > &  in  )  [inline]

Create a buffer with contents specified contents.

Parameters:
in the buffer holding the contents that will be copied into the newly created buffer.

Definition at line 397 of file secmem.h.

00398          {
00399          init(true, INITIAL_LEN);
00400          if(INITIAL_LEN)
00401             copy(in, in.size());
00402          else
00403             set(in);
00404          }

template<typename T, u32bit INITIAL_LEN = 0>
Botan::SecureVector< T, INITIAL_LEN >::SecureVector ( const MemoryRegion< T > &  in1,
const MemoryRegion< T > &  in2 
) [inline]

Create a buffer whose content is the concatenation of two other buffers.

Parameters:
in1 the first part of the new contents
in2 the contents to be appended to in1

Definition at line 412 of file secmem.h.

00413          { init(true); set(in1); append(in2); }


Member Function Documentation

void Botan::MemoryRegion< T >::append ( const MemoryRegion< T > &  other  )  [inline, inherited]

Append data to the end of this buffer.

Parameters:
other the buffer containing the data to append

Definition at line 161 of file secmem.h.

00162          { append(other.begin(), other.size()); }

void Botan::MemoryRegion< T >::append ( x  )  [inline, inherited]

Append a single element.

Parameters:
x the element to append

Definition at line 155 of file secmem.h.

00155 { append(&x, 1); }

void Botan::MemoryRegion< T >::append ( const T  data[],
u32bit  n 
) [inline, inherited]

Append data to the end of this buffer.

Parameters:
data the array containing the data to append
n the size of the array data

Definition at line 148 of file secmem.h.

Referenced by Botan::MemoryVector< byte >::MemoryVector(), and Botan::SecureVector< u16bit, 100 >::SecureVector().

00149          { grow_to(size()+n); copy(size() - n, data, n); }

const T * Botan::MemoryRegion< T >::begin (  )  const [inline, inherited]

Get a constant pointer to the first element in the buffer.

Returns:
constant pointer to the first element in the buffer

Definition at line 59 of file secmem.h.

00059 { return buf; }

T * Botan::MemoryRegion< T >::begin (  )  [inline, inherited]

Get a pointer to the first element in the buffer.

Returns:
pointer to the first element in the buffer

Definition at line 53 of file secmem.h.

00053 { return buf; }

void Botan::MemoryRegion< T >::clear (  )  [inline, inherited]

Zeroise the bytes of this buffer. The length remains unchanged.

Definition at line 167 of file secmem.h.

00167 { clear_mem(buf, allocated); }

void Botan::MemoryRegion< T >::copy ( u32bit  off,
const T  in[],
u32bit  n 
) [inline, inherited]

Copy the contents of an array of objects of type T into this buffer. The former contents of *this are discarded. The length of *this must be at least n, otherwise memory errors occur.

Parameters:
off the offset position inside this buffer to start inserting the copied bytes
in the array to copy the contents from
n the length of in

Definition at line 125 of file secmem.h.

00126          { copy_mem(buf + off, in, (n > size() - off) ? (size() - off) : n); }

void Botan::MemoryRegion< T >::copy ( const T  in[],
u32bit  n 
) [inline, inherited]

Copy the contents of an array of objects of type T into this buffer. The former contents of *this are discarded. The length of *this must be at least n, otherwise memory errors occur.

Parameters:
in the array to copy the contents from
n the length of in

Definition at line 113 of file secmem.h.

Referenced by Botan::SecureVector< u16bit, 100 >::SecureVector().

00114          { copy(0, in, n); }

void Botan::MemoryRegion< T >::destroy (  )  [inline, inherited]

Reset this buffer to an empty buffer with size zero.

Definition at line 172 of file secmem.h.

00172 { resize(0); }

bool Botan::MemoryRegion< T >::empty (  )  const [inline, inherited]

Find out whether this buffer is empty.

Returns:
true if the buffer is empty, false otherwise

Definition at line 35 of file secmem.h.

00035 { return (used == 0); }

const T * Botan::MemoryRegion< T >::end (  )  const [inline, inherited]

Get a constant pointer to the last element in the buffer.

Returns:
constant pointer to the last element in the buffer

Definition at line 71 of file secmem.h.

00071 { return (buf + size()); }

T * Botan::MemoryRegion< T >::end (  )  [inline, inherited]

Get a pointer to the last element in the buffer.

Returns:
pointer to the last element in the buffer

Definition at line 65 of file secmem.h.

00065 { return (buf + size()); }

void Botan::MemoryRegion< T >::grow_to ( u32bit  n  )  [inherited]

Change the size to n elements. If n is >= size(), preexisting elements remain unchanged, with later elements zero-initialized. If n < size(), then the last (size() - N) elements are removed.

Parameters:
n the new size

void Botan::MemoryRegion< T >::init ( bool  locking,
u32bit  length = 0 
) [inline, protected, inherited]

Parameters:
locking should we use a locking allocator
length the initial length to use

Definition at line 215 of file secmem.h.

Referenced by Botan::MemoryVector< byte >::MemoryVector(), and Botan::SecureVector< u16bit, 100 >::SecureVector().

00216          { alloc = Allocator::get(locking); resize(length); }

Botan::MemoryRegion< T >::operator const T * (  )  const [inline, inherited]

Get a constant pointer to the first element in the buffer.

Returns:
constant pointer to the first element in the buffer

Definition at line 47 of file secmem.h.

00047 { return buf; }

Botan::MemoryRegion< T >::operator T * (  )  [inline, inherited]

Get a pointer to the first element in the buffer.

Returns:
pointer to the first element in the buffer

Definition at line 41 of file secmem.h.

00041 { return buf; }

bool Botan::MemoryRegion< T >::operator!= ( const MemoryRegion< T > &  other  )  const [inline, inherited]

Check two buffers for inequality.

Returns:
false if the content of both buffers is byte-wise equal, true otherwise.

Definition at line 94 of file secmem.h.

00095          { return (!(*this == other)); }

bool Botan::MemoryRegion< T >::operator< ( const MemoryRegion< T > &  other  )  const [inherited]

Compare two buffers lexicographically.

Returns:
true if this buffer is lexicographically smaller than other.

template<typename T, u32bit INITIAL_LEN = 0>
SecureVector<T>& Botan::SecureVector< T, INITIAL_LEN >::operator= ( const MemoryRegion< T > &  in  )  [inline]

Copy the contents of another buffer into this buffer.

Parameters:
in the buffer to copy the contents from
Returns:
reference to *this

Reimplemented from Botan::MemoryRegion< T >.

Definition at line 367 of file secmem.h.

00368          { if(this != &in) set(in); return (*this); }

bool Botan::MemoryRegion< T >::operator== ( const MemoryRegion< T > &  other  )  const [inline, inherited]

Check two buffers for equality.

Returns:
true iff the content of both buffers is byte-wise equal

Definition at line 77 of file secmem.h.

00078          {
00079          return (size() == other.size() &&
00080                  same_mem(buf, other.buf, size()));
00081          }

void Botan::MemoryRegion< T >::resize ( u32bit  n  )  [inherited]

Reset this buffer to a buffer of specified length. The content will be initialized to zero bytes.

Parameters:
n the new length of the buffer

void Botan::MemoryRegion< T >::set ( const MemoryRegion< T > &  in  )  [inline, inherited]

Set the contents of this according to the argument. The size of *this is increased if necessary.

Parameters:
in the buffer to copy the contents from

Definition at line 141 of file secmem.h.

00141 { set(in.begin(), in.size()); }

void Botan::MemoryRegion< T >::set ( const T  in[],
u32bit  n 
) [inline, inherited]

Set the contents of this according to the argument. The size of *this is increased if necessary.

Parameters:
in the array of objects of type T to copy the contents from
n the size of array in

Definition at line 134 of file secmem.h.

00134 { resize(n); copy(in, n); }

u32bit Botan::MemoryRegion< T >::size (  )  const [inline, inherited]

Find out the size of the buffer, i.e. how many objects of type T it contains.

Returns:
size of the buffer

Definition at line 29 of file secmem.h.

Referenced by Botan::Montgomery_Exponentiator::set_base().

00029 { return used; }

void Botan::MemoryRegion< T >::swap ( MemoryRegion< T > &  other  )  [inherited]

Swap this buffer with another object.


The documentation for this class was generated from the following file:

Generated on Fri Aug 13 16:21:00 2010 for Botan by  doxygen 1.5.8