Botan 3.3.0
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 <span>
13#include <string>
14
15namespace Botan {
16
17class RandomNumberGenerator;
18
19/**
20* Octet String
21*/
23 public:
24 /**
25 * @return size of this octet string in bytes
26 */
27 size_t length() const { return m_data.size(); }
28
29 size_t size() const { return m_data.size(); }
30
31 bool empty() const { return m_data.empty(); }
32
33 /**
34 * @return this object as a secure_vector<uint8_t>
35 */
36 secure_vector<uint8_t> bits_of() const { return m_data; }
37
38 /**
39 * @return start of this string
40 */
41 const uint8_t* begin() const { return m_data.data(); }
42
43 /**
44 * @return end of this string
45 */
46 const uint8_t* end() const { return begin() + m_data.size(); }
47
48 /**
49 * @return this encoded as hex
50 */
51 std::string to_string() const;
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 * Deprecated. There is no reason to use this outside of interacting with
64 * some very old or weird system which requires DES and also which do not
65 * automatically ignore the parity bits.
66 */
67 BOTAN_DEPRECATED("Why would you need to do this")
68 void set_odd_parity();
69
70 /**
71 * Create a new OctetString
72 * @param str is a hex encoded string
73 */
74 explicit OctetString(std::string_view str = "");
75
76 /**
77 * Create a new random OctetString
78 * @param rng is a random number generator
79 * @param len is the desired length in bytes
80 */
81 OctetString(RandomNumberGenerator& rng, size_t len);
82
83 /**
84 * Create a new OctetString
85 * @param in is an array
86 * @param len is the length of in in bytes
87 */
88 OctetString(const uint8_t in[], size_t len);
89
90 /**
91 * Create a new OctetString
92 * @param in a bytestring
93 */
94 explicit OctetString(std::span<const uint8_t> in) : m_data(in.begin(), in.end()) {}
95
96 /**
97 * Create a new OctetString
98 * @param in a bytestring
99 */
100 explicit OctetString(secure_vector<uint8_t> in) : m_data(std::move(in)) {}
101
102 private:
104};
105
106/**
107* Compare two strings
108* @param x an octet string
109* @param y an octet string
110* @return if x is equal to y
111*/
112BOTAN_PUBLIC_API(2, 0) bool operator==(const OctetString& x, const OctetString& y);
113
114/**
115* Compare two strings
116* @param x an octet string
117* @param y an octet string
118* @return if x is not equal to y
119*/
120BOTAN_PUBLIC_API(2, 0) bool operator!=(const OctetString& x, const OctetString& y);
121
122/**
123* Concatenate two strings
124* @param x an octet string
125* @param y an octet string
126* @return x concatenated with y
127*/
128BOTAN_PUBLIC_API(2, 0) OctetString operator+(const OctetString& x, const OctetString& y);
129
130/**
131* XOR two strings
132* @param x an octet string
133* @param y an octet string
134* @return x XORed with y
135*/
136BOTAN_PUBLIC_API(2, 0) OctetString operator^(const OctetString& x, const OctetString& y);
137
138/**
139* Alternate name for octet string showing intent to use as a key
140*/
142
143/**
144* Alternate name for octet string showing intent to use as an IV
145*/
147
148} // namespace Botan
149
150#endif
secure_vector< uint8_t > bits_of() const
Definition symkey.h:36
const uint8_t * end() const
Definition symkey.h:46
const uint8_t * begin() const
Definition symkey.h:41
OctetString(secure_vector< uint8_t > in)
Definition symkey.h:100
size_t size() const
Definition symkey.h:29
size_t length() const
Definition symkey.h:27
bool empty() const
Definition symkey.h:31
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_DEPRECATED(msg)
Definition compiler.h:125
std::vector< uint8_t, Alloc > & operator^=(std::vector< uint8_t, Alloc > &out, const std::vector< uint8_t, Alloc2 > &in)
Definition mem_ops.h:444
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61