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