Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

symkey.h
Go to the documentation of this file.
1 /*
2 * OctetString
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_SYMKEY_H__
9 #define BOTAN_SYMKEY_H__
10
11 #include <botan/secmem.h>
12 #include <string>
13
14 namespace Botan {
15
16 /**
17 * Octet String
18 */
19 class BOTAN_DLL OctetString
20 {
21 public:
22 /**
23 * @return size of this octet string in bytes
24 */
25 size_t length() const { return m_data.size(); }
26 size_t size() const { return m_data.size(); }
27
28 /**
29 * @return this object as a secure_vector<uint8_t>
30 */
31 secure_vector<uint8_t> bits_of() const { return m_data; }
32
33 /**
34 * @return start of this string
35 */
36 const uint8_t* begin() const { return m_data.data(); }
37
38 /**
39 * @return end of this string
40 */
41 const uint8_t* end() const { return begin() + m_data.size(); }
42
43 /**
44 * @return this encoded as hex
45 */
46 std::string as_string() const;
47
48 /**
49 * XOR the contents of another octet string into this one
50 * @param other octet string
51 * @return reference to this
52 */
53 OctetString& operator^=(const OctetString& other);
54
55 /**
56 * Force to have odd parity
57 */
58 void set_odd_parity();
59
60 /**
61 * Create a new OctetString
62 * @param str is a hex encoded string
63 */
64 explicit OctetString(const std::string& str = "");
65
66 /**
67 * Create a new random OctetString
68 * @param rng is a random number generator
69 * @param len is the desired length in bytes
70 */
71 OctetString(class RandomNumberGenerator& rng, size_t len);
72
73 /**
74 * Create a new OctetString
75 * @param in is an array
76 * @param len is the length of in in bytes
77 */
78 OctetString(const uint8_t in[], size_t len);
79
80 /**
81 * Create a new OctetString
82 * @param in a bytestring
83 */
84 OctetString(const secure_vector<uint8_t>& in) : m_data(in) {}
85
86 /**
87 * Create a new OctetString
88 * @param in a bytestring
89 */
90 OctetString(const std::vector<uint8_t>& in) : m_data(in.begin(), in.end()) {}
91
92 private:
93 secure_vector<uint8_t> m_data;
94 };
95
96 /**
97 * Compare two strings
98 * @param x an octet string
99 * @param y an octet string
100 * @return if x is equal to y
101 */
102 BOTAN_DLL bool operator==(const OctetString& x,
103 const OctetString& y);
104
105 /**
106 * Compare two strings
107 * @param x an octet string
108 * @param y an octet string
109 * @return if x is not equal to y
110 */
111 BOTAN_DLL bool operator!=(const OctetString& x,
112 const OctetString& y);
113
114 /**
115 * Concatenate two strings
116 * @param x an octet string
117 * @param y an octet string
118 * @return x concatenated with y
119 */
120 BOTAN_DLL OctetString operator+(const OctetString& x,
121 const OctetString& y);
122
123 /**
124 * XOR two strings
125 * @param x an octet string
126 * @param y an octet string
127 * @return x XORed with y
128 */
129 BOTAN_DLL OctetString operator^(const OctetString& x,
130 const OctetString& y);
131
132
133 /**
134 * Alternate name for octet string showing intent to use as a key
135 */
136 using SymmetricKey = OctetString;
137
138 /**
139 * Alternate name for octet string showing intent to use as an IV
140 */
141 using InitializationVector = OctetString;
142
143 }
144
145 #endif
Botan::operator^=
std::vector< T, Alloc > & operator^=(std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
Definition: mem_ops.h:168
Botan::OctetString::bits_of
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
Botan::OctetString
Definition: symkey.h:19
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::operator!=
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:82
Botan::operator==
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:67
Botan::OctetString::length
size_t length() const
Definition: symkey.h:25
Botan::operator+
OID operator+(const OID &oid, uint32_t component)
Definition: asn1_oid.cpp:87
Botan::operator^
OctetString operator^(const OctetString &k1, const OctetString &k2)
Definition: symkey.cpp:122
Botan::OctetString::end
const uint8_t * end() const
Definition: symkey.h:41
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan
Definition: alg_id.cpp:13
Botan::OctetString::begin
const uint8_t * begin() const
Definition: symkey.h:36
Botan::OctetString::OctetString
OctetString(const std::vector< uint8_t > &in)
Definition: symkey.h:90
Botan::OctetString::OctetString
OctetString(const secure_vector< uint8_t > &in)
Definition: symkey.h:84
Botan::OctetString::size
size_t size() const
Definition: symkey.h:26