diff options
Diffstat (limited to 'src/algo_base')
-rw-r--r-- | src/algo_base/algo_base.h | 7 | ||||
-rw-r--r-- | src/algo_base/buf_comp.h | 32 | ||||
-rw-r--r-- | src/algo_base/symkey.cpp | 16 | ||||
-rw-r--r-- | src/algo_base/symkey.h | 37 |
4 files changed, 47 insertions, 45 deletions
diff --git a/src/algo_base/algo_base.h b/src/algo_base/algo_base.h index 813216a36..f757a9a83 100644 --- a/src/algo_base/algo_base.h +++ b/src/algo_base/algo_base.h @@ -19,7 +19,6 @@ namespace Botan { class BOTAN_DLL Algorithm { public: - /** * Zeroize internal state */ @@ -31,10 +30,10 @@ class BOTAN_DLL Algorithm virtual std::string name() const = 0; Algorithm() {} + Algorithm(const Algorithm&) = delete; + Algorithm& operator=(const Algorithm&) = delete; + virtual ~Algorithm() {} - private: - Algorithm(const Algorithm&) {} - Algorithm& operator=(const Algorithm&) { return (*this); } }; } diff --git a/src/algo_base/buf_comp.h b/src/algo_base/buf_comp.h index 7838571e9..1dd8be992 100644 --- a/src/algo_base/buf_comp.h +++ b/src/algo_base/buf_comp.h @@ -10,6 +10,7 @@ #include <botan/secmem.h> #include <botan/get_byte.h> +#include <string> namespace Botan { @@ -34,9 +35,18 @@ class BOTAN_DLL Buffered_Computation /** * Add new input to process. - * @param in the input to process as a MemoryRegion + * @param in the input to process as a secure_vector */ - void update(const MemoryRegion<byte>& in) + void update(const secure_vector<byte>& in) + { + add_data(&in[0], in.size()); + } + + /** + * Add new input to process. + * @param in the input to process as a std::vector + */ + void update(const std::vector<byte>& in) { add_data(&in[0], in.size()); } @@ -82,11 +92,11 @@ class BOTAN_DLL Buffered_Computation /** * Complete the computation and retrieve the * final result. - * @return SecureVector holding the result + * @return secure_vector holding the result */ - SecureVector<byte> final() + secure_vector<byte> final() { - SecureVector<byte> output(output_length()); + secure_vector<byte> output(output_length()); final_result(&output[0]); return output; } @@ -98,7 +108,7 @@ class BOTAN_DLL Buffered_Computation * @param length the length of the byte array * @result the result of the call to final() */ - SecureVector<byte> process(const byte in[], size_t length) + secure_vector<byte> process(const byte in[], size_t length) { add_data(in, length); return final(); @@ -110,7 +120,13 @@ class BOTAN_DLL Buffered_Computation * @param in the input to process * @result the result of the call to final() */ - SecureVector<byte> process(const MemoryRegion<byte>& in) + secure_vector<byte> process(const secure_vector<byte>& in) + { + add_data(&in[0], in.size()); + return final(); + } + + secure_vector<byte> process(const std::vector<byte>& in) { add_data(&in[0], in.size()); return final(); @@ -122,7 +138,7 @@ class BOTAN_DLL Buffered_Computation * @param in the input to process as a string * @result the result of the call to final() */ - SecureVector<byte> process(const std::string& in) + secure_vector<byte> process(const std::string& in) { update(in); return final(); diff --git a/src/algo_base/symkey.cpp b/src/algo_base/symkey.cpp index 56648d9c5..52b216361 100644 --- a/src/algo_base/symkey.cpp +++ b/src/algo_base/symkey.cpp @@ -26,7 +26,7 @@ OctetString::OctetString(RandomNumberGenerator& rng, /* * Create an OctetString from a hex string */ -void OctetString::change(const std::string& hex_string) +OctetString::OctetString(const std::string& hex_string) { bits.resize(1 + hex_string.length() / 2); bits.resize(hex_decode(&bits[0], hex_string)); @@ -35,10 +35,9 @@ void OctetString::change(const std::string& hex_string) /* * Create an OctetString from a byte string */ -void OctetString::change(const byte in[], size_t n) +OctetString::OctetString(const byte in[], size_t n) { - bits.resize(n); - bits.copy(in, n); + bits.assign(in, in + n); } /* @@ -113,7 +112,7 @@ bool operator!=(const OctetString& s1, const OctetString& s2) */ OctetString operator+(const OctetString& k1, const OctetString& k2) { - SecureVector<byte> out; + secure_vector<byte> out; out += k1.bits_of(); out += k2.bits_of(); return OctetString(out); @@ -124,9 +123,10 @@ OctetString operator+(const OctetString& k1, const OctetString& k2) */ OctetString operator^(const OctetString& k1, const OctetString& k2) { - SecureVector<byte> ret(std::max(k1.length(), k2.length())); - ret.copy(k1.begin(), k1.length()); - xor_buf(ret, k2.begin(), k2.length()); + secure_vector<byte> ret(std::max(k1.length(), k2.length())); + + copy_mem(&ret[0], k1.begin(), k1.length()); + xor_buf(&ret[0], k2.begin(), k2.length()); return OctetString(ret); } diff --git a/src/algo_base/symkey.h b/src/algo_base/symkey.h index 6735b2b87..b47da8a69 100644 --- a/src/algo_base/symkey.h +++ b/src/algo_base/symkey.h @@ -25,9 +25,9 @@ class BOTAN_DLL OctetString size_t length() const { return bits.size(); } /** - * @return this object as a SecureVector<byte> + * @return this object as a secure_vector<byte> */ - SecureVector<byte> bits_of() const { return bits; } + secure_vector<byte> bits_of() const { return bits; } /** * @return start of this string @@ -57,23 +57,10 @@ class BOTAN_DLL OctetString void set_odd_parity(); /** - * Change the contents of this octet string - * @param hex_string a hex encoded bytestring - */ - void change(const std::string& hex_string); - - /** - * Change the contents of this octet string - * @param in the input - * @param length of in in bytes - */ - void change(const byte in[], size_t length); - - /** - * Change the contents of this octet string - * @param in the input + * Create a new OctetString + * @param str is a hex encoded string */ - void change(const MemoryRegion<byte>& in) { bits = in; } + OctetString(const std::string& str = ""); /** * Create a new random OctetString @@ -84,24 +71,24 @@ class BOTAN_DLL OctetString /** * Create a new OctetString - * @param str is a hex encoded string + * @param in is an array + * @param len is the length of in in bytes */ - OctetString(const std::string& str = "") { change(str); } + OctetString(const byte in[], size_t len); /** * Create a new OctetString - * @param in is an array - * @param len is the length of in in bytes + * @param in a bytestring */ - OctetString(const byte in[], size_t len) { change(in, len); } + OctetString(const secure_vector<byte>& in) : bits(in) {} /** * Create a new OctetString * @param in a bytestring */ - OctetString(const MemoryRegion<byte>& in) { change(in); } + OctetString(const std::vector<byte>& in) : bits(&in[0], &in[in.size()]) {} private: - SecureVector<byte> bits; + secure_vector<byte> bits; }; /** |