Botan 2.19.5 Crypto and TLS for C&

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_PUBLIC_API(2,0) OctetString final
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 to_string() const;
47
48 std::string BOTAN_DEPRECATED("Use OctetString::to_string") as_string() const
49 {
50 return this->to_string();
51 }
52
53 /**
54 * XOR the contents of another octet string into this one
55 * @param other octet string
56 * @return reference to this
57 */
58 OctetString& operator^=(const OctetString& other);
59
60 /**
61 * Force to have odd parity
62 */
63 void set_odd_parity();
64
65 /**
66 * Create a new OctetString
67 * @param str is a hex encoded string
68 */
69 explicit OctetString(const std::string& str = "");
70
71 /**
72 * Create a new random OctetString
73 * @param rng is a random number generator
74 * @param len is the desired length in bytes
75 */
76 OctetString(class RandomNumberGenerator& rng, size_t len);
77
78 /**
79 * Create a new OctetString
80 * @param in is an array
81 * @param len is the length of in in bytes
82 */
83 OctetString(const uint8_t in[], size_t len);
84
85 /**
86 * Create a new OctetString
87 * @param in a bytestring
88 */
89 OctetString(const secure_vector<uint8_t>& in) : m_data(in) {}
90
91 /**
92 * Create a new OctetString
93 * @param in a bytestring
94 */
95 OctetString(const std::vector<uint8_t>& in) : m_data(in.begin(), in.end()) {}
96
97 private:
98 secure_vector<uint8_t> m_data;
99 };
100
101/**
102* Compare two strings
103* @param x an octet string
104* @param y an octet string
105* @return if x is equal to y
106*/
107 BOTAN_PUBLIC_API(2,0) bool operator==(const OctetString& x,
108 const OctetString& y);
109
110/**
111* Compare two strings
112* @param x an octet string
113* @param y an octet string
114* @return if x is not equal to y
115*/
116 BOTAN_PUBLIC_API(2,0) bool operator!=(const OctetString& x,
117 const OctetString& y);
118
119/**
120* Concatenate two strings
121* @param x an octet string
122* @param y an octet string
123* @return x concatenated with y
124*/
125 BOTAN_PUBLIC_API(2,0) OctetString operator+(const OctetString& x,
126 const OctetString& y);
127
128/**
129* XOR two strings
130* @param x an octet string
131* @param y an octet string
132* @return x XORed with y
133*/
134 BOTAN_PUBLIC_API(2,0) OctetString operator^(const OctetString& x,
135 const OctetString& y);
136
137
138/**
139* Alternate name for octet string showing intent to use as a key
140*/
141using SymmetricKey = OctetString;
142
143/**
144* Alternate name for octet string showing intent to use as an IV
145*/
146using InitializationVector = OctetString;
147
148}
149
150#endif
Botan::OctetString
Definition: symkey.h:20
Botan::OctetString::bits_of
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
Botan::OctetString::end
const uint8_t * end() const
Definition: symkey.h:41
Botan::OctetString::OctetString
OctetString(const secure_vector< uint8_t > &in)
Definition: symkey.h:89
Botan::OctetString::begin
const uint8_t * begin() const
Definition: symkey.h:36
Botan::OctetString::size
size_t size() const
Definition: symkey.h:26
Botan::OctetString::OctetString
OctetString(const std::vector< uint8_t > &in)
Definition: symkey.h:95
Botan::OctetString::length
size_t length() const
Definition: symkey.h:25
Botan::RandomNumberGenerator
Definition: rng.h:26
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan
Definition: alg_id.cpp:13
Botan::operator^=
std::vector< uint8_t, Alloc > & operator^=(std::vector< uint8_t, Alloc > &out, const std::vector< uint8_t, Alloc2 > &in)
Definition: mem_ops.h:353
Botan::to_string
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65