Botan 1.10.17

Public Member Functions | List of all members
Botan::OctetString Class Reference

`#include <symkey.h>`

## Public Member Functions
std::string | as_string () const
const byte * | begin () const
SecureVector< byte > | bits_of () const
void | change (const std::string &hex_string)
void | change (const byte in[], size_t length)
void | change (const MemoryRegion< byte > &in)
const byte * | end () const
size_t | length () const
| OctetString (class RandomNumberGenerator &rng, size_t len)
| OctetString (const std::string &str="")
| OctetString (const byte in[], size_t len)
| OctetString (const MemoryRegion< byte > &in)
OctetString & | operator^= (const OctetString &other)
void | set_odd_parity ()

## Detailed Description

Octet String

Definition at line 19 of file symkey.h.

## Constructor & Destructor Documentation

## ◆ OctetString() [1/4]

Botan::OctetString::OctetString | ( | class RandomNumberGenerator & | rng,
|  | size_t | len
| ) |  |

Create a new random OctetString

Parameters

  rng | is a random number generator
  len | is the desired length in bytes

Definition at line 20 of file symkey.cpp.

22 {
23 bits = rng.random_vec(length);
24 }
Botan::OctetString::length
size_t length() const
Definition: symkey.h:25

## ◆ OctetString() [2/4]

Botan::OctetString::OctetString | ( | const std::string & | str = `""` | ) |
| inline

Create a new OctetString

Parameters

  str | is a hex encoded string

Definition at line 89 of file symkey.h.

89 { change(str); }
Botan::OctetString::change
void change(const std::string &hex_string)
Definition: symkey.cpp:29

## ◆ OctetString() [3/4]

Botan::OctetString::OctetString | ( | const byte | in[],
|  | size_t | len
| ) |  |
| inline

Create a new OctetString

Parameters

  in | is an array
  len | is the length of in in bytes

Definition at line 96 of file symkey.h.

96 { change(in, len); }
Botan::OctetString::change
void change(const std::string &hex_string)
Definition: symkey.cpp:29

## ◆ OctetString() [4/4]

Botan::OctetString::OctetString | ( | const MemoryRegion< byte > & | in | ) |
| inline

Create a new OctetString

Parameters

  in | a bytestring

Definition at line 102 of file symkey.h.

102 { change(in); }
Botan::OctetString::change
void change(const std::string &hex_string)
Definition: symkey.cpp:29

## Member Function Documentation

## ◆ as_string()

std::string Botan::OctetString::as_string | ( |  | ) | const

Returns
  this encoded as hex

Definition at line 80 of file symkey.cpp.

References Botan::hex_encode(), and Botan::MemoryRegion< T >::size().

81 {
82 return hex_encode(&bits[0], bits.size());
83 }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::hex_encode
void hex_encode(char output[], const byte input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14

## ◆ begin()

const byte* Botan::OctetString::begin | ( |  | ) | const
| inline

Returns
  start of this string

Definition at line 35 of file symkey.h.

Referenced by Botan::CryptoBox::decrypt(), Botan::operator^(), operator^=(), Botan::SessionKeys::SessionKeys(), Botan::EAX_Base::set_iv(), Botan::XTS_Encryption::set_iv(), Botan::StreamCipher_Filter::set_iv(), Botan::XTS_Decryption::set_iv(), Botan::XTS_Encryption::set_key(), Botan::SymmetricAlgorithm::set_key(), and Botan::XTS_Decryption::set_key().

35 { return &bits[0]; }

## ◆ bits_of()

SecureVector<byte> Botan::OctetString::bits_of | ( |  | ) | const
| inline

Returns
  this object as a SecureVector<byte>

Definition at line 30 of file symkey.h.

Referenced by Botan::check_passhash9(), Botan::SSL3_PRF::derive(), Botan::operator+(), Botan::operator==(), Botan::CFB_Encryption::set_iv(), Botan::CTS_Encryption::set_iv(), Botan::CBC_Encryption::set_iv(), Botan::CFB_Decryption::set_iv(), Botan::CTS_Decryption::set_iv(), and Botan::CBC_Decryption::set_iv().

30 { return bits; }

## ◆ change() [1/3]

void Botan::OctetString::change | ( | const std::string & | hex_string | ) |

Change the contents of this octet string

Parameters

  hex_string | a hex encoded bytestring

Definition at line 29 of file symkey.cpp.

References Botan::hex_decode(), and Botan::MemoryRegion< T >::resize().

30 {
31 bits.resize(1 + hex_string.length() / 2);
32 bits.resize(hex_decode(&bits[0], hex_string));
33 }
Botan::MemoryRegion::resize
void resize(size_t n)
Definition: secmem.h:217
Botan::hex_decode
size_t hex_decode(byte output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition: hex.cpp:55

## ◆ change() [2/3]

void Botan::OctetString::change | ( | const byte | in[],
|  | size_t | length
| ) |  |

Change the contents of this octet string

Parameters

  in | the input
  length | of in in bytes

Definition at line 38 of file symkey.cpp.

39 {
40 bits.resize(n);
41 bits.copy(in, n);
42 }
Botan::MemoryRegion::resize
void resize(size_t n)
Definition: secmem.h:217
Botan::MemoryRegion::copy
void copy(const T in[], size_t n)
Definition: secmem.h:126

## ◆ change() [3/3]

void Botan::OctetString::change | ( | const MemoryRegion< byte > & | in | ) |
| inline

Change the contents of this octet string

Parameters

  in | the input

Definition at line 76 of file symkey.h.

76 { bits = in; }

## ◆ end()

const byte* Botan::OctetString::end | ( |  | ) | const
| inline

Returns
  end of this string

Definition at line 40 of file symkey.h.

40 { return &bits[bits.size()]; }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ length()

size_t Botan::OctetString::length | ( |  | ) | const
| inline

Returns
  size of this octet string in bytes

Definition at line 25 of file symkey.h.

Referenced by Botan::get_cipher(), Botan::operator^(), operator^=(), Botan::rfc3394_keyunwrap(), Botan::rfc3394_keywrap(), Botan::CFB_Encryption::set_iv(), Botan::CTS_Encryption::set_iv(), Botan::XTS_Encryption::set_iv(), Botan::EAX_Base::set_iv(), Botan::CBC_Encryption::set_iv(), Botan::Keyed_Filter::set_iv(), Botan::StreamCipher_Filter::set_iv(), Botan::CFB_Decryption::set_iv(), Botan::CTS_Decryption::set_iv(), Botan::XTS_Decryption::set_iv(), Botan::CBC_Decryption::set_iv(), Botan::XTS_Encryption::set_key(), Botan::SymmetricAlgorithm::set_key(), and Botan::XTS_Decryption::set_key().

25 { return bits.size(); }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ operator^=()

OctetString & Botan::OctetString::operator^= | ( | const OctetString & | other | ) |

XOR the contents of another octet string into this one

Parameters

  other | octet string

Returns
  reference to this

Definition at line 88 of file symkey.cpp.

References begin(), length(), Botan::CT::min(), Botan::xor_buf(), and Botan::zeroise().

89 {
90 if(&k == this) { zeroise(bits); return (*this); }
91 xor_buf(&bits[0], k.begin(), std::min(length(), k.length()));
92 return (*this);
93 }
Botan::OctetString::length
size_t length() const
Definition: symkey.h:25
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:127
Botan::xor_buf
void xor_buf(byte out[], const byte in[], size_t length)
Definition: xor_buf.h:21
Botan::zeroise
void zeroise(MemoryRegion< T > &vec)
Definition: secmem.h:428

## ◆ set_odd_parity()

void Botan::OctetString::set_odd_parity | ( |  | ) |

Force to have odd parity

Definition at line 47 of file symkey.cpp.

References Botan::MemoryRegion< T >::size().

48 {
49 const byte ODD_PARITY[256] = {
50 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07, 0x08, 0x08, 0x0B, 0x0B,
51 0x0D, 0x0D, 0x0E, 0x0E, 0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16,
52 0x19, 0x19, 0x1A, 0x1A, 0x1C, 0x1C, 0x1F, 0x1F, 0x20, 0x20, 0x23, 0x23,
53 0x25, 0x25, 0x26, 0x26, 0x29, 0x29, 0x2A, 0x2A, 0x2C, 0x2C, 0x2F, 0x2F,
54 0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37, 0x38, 0x38, 0x3B, 0x3B,
55 0x3D, 0x3D, 0x3E, 0x3E, 0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46,
56 0x49, 0x49, 0x4A, 0x4A, 0x4C, 0x4C, 0x4F, 0x4F, 0x51, 0x51, 0x52, 0x52,
57 0x54, 0x54, 0x57, 0x57, 0x58, 0x58, 0x5B, 0x5B, 0x5D, 0x5D, 0x5E, 0x5E,
58 0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67, 0x68, 0x68, 0x6B, 0x6B,
59 0x6D, 0x6D, 0x6E, 0x6E, 0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76,
60 0x79, 0x79, 0x7A, 0x7A, 0x7C, 0x7C, 0x7F, 0x7F, 0x80, 0x80, 0x83, 0x83,
61 0x85, 0x85, 0x86, 0x86, 0x89, 0x89, 0x8A, 0x8A, 0x8C, 0x8C, 0x8F, 0x8F,
62 0x91, 0x91, 0x92, 0x92, 0x94, 0x94, 0x97, 0x97, 0x98, 0x98, 0x9B, 0x9B,
63 0x9D, 0x9D, 0x9E, 0x9E, 0xA1, 0xA1, 0xA2, 0xA2, 0xA4, 0xA4, 0xA7, 0xA7,
64 0xA8, 0xA8, 0xAB, 0xAB, 0xAD, 0xAD, 0xAE, 0xAE, 0xB0, 0xB0, 0xB3, 0xB3,
65 0xB5, 0xB5, 0xB6, 0xB6, 0xB9, 0xB9, 0xBA, 0xBA, 0xBC, 0xBC, 0xBF, 0xBF,
66 0xC1, 0xC1, 0xC2, 0xC2, 0xC4, 0xC4, 0xC7, 0xC7, 0xC8, 0xC8, 0xCB, 0xCB,
67 0xCD, 0xCD, 0xCE, 0xCE, 0xD0, 0xD0, 0xD3, 0xD3, 0xD5, 0xD5, 0xD6, 0xD6,
68 0xD9, 0xD9, 0xDA, 0xDA, 0xDC, 0xDC, 0xDF, 0xDF, 0xE0, 0xE0, 0xE3, 0xE3,
69 0xE5, 0xE5, 0xE6, 0xE6, 0xE9, 0xE9, 0xEA, 0xEA, 0xEC, 0xEC, 0xEF, 0xEF,
70 0xF1, 0xF1, 0xF2, 0xF2, 0xF4, 0xF4, 0xF7, 0xF7, 0xF8, 0xF8, 0xFB, 0xFB,
71 0xFD, 0xFD, 0xFE, 0xFE };
72
73 for(size_t j = 0; j != bits.size(); ++j)
74 bits[j] = ODD_PARITY[bits[j]];
75 }
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

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

- src/algo_base/symkey.h
- src/algo_base/symkey.cpp