diff options
author | Simon Warta <[email protected]> | 2015-06-28 13:47:37 +0200 |
---|---|---|
committer | Simon Warta <[email protected]> | 2015-06-28 13:47:37 +0200 |
commit | dc5716db695462217390ddfc7c9189294493600a (patch) | |
tree | 43c90714200839d62b0211543bb89c7541167d6c /src | |
parent | 7f904a4019a27628c145724e8c0bfcbfacb18e11 (diff) | |
parent | d007082daa03ddebd124c38393f42793a1b50811 (diff) |
Merge pull request #144 from webmaster128/bounds-check5
Bounds check round 5
Diffstat (limited to 'src')
53 files changed, 190 insertions, 176 deletions
diff --git a/src/lib/asn1/asn1_time.cpp b/src/lib/asn1/asn1_time.cpp index b79e8a9ba..72bf87df9 100644 --- a/src/lib/asn1/asn1_time.cpp +++ b/src/lib/asn1/asn1_time.cpp @@ -11,6 +11,8 @@ #include <botan/charset.h> #include <botan/parsing.h> #include <botan/calendar.h> +#include <sstream> +#include <iomanip> namespace Botan { @@ -230,14 +232,17 @@ std::string X509_Time::readable_string() const if(time_is_set() == false) throw Invalid_State("X509_Time::readable_string: No time set"); - std::string output(24, 0); - - std::sprintf(&output[0], "%04d/%02d/%02d %02d:%02d:%02d UTC", - year, month, day, hour, minute, second); - - output.resize(23); // remove trailing null - - return output; + // desired format: "%04d/%02d/%02d %02d:%02d:%02d UTC" + std::stringstream output; + { + using namespace std; + output << setfill('0') + << setw(4) << year << "/" << setw(2) << month << "/" << setw(2) << day + << " " + << setw(2) << hour << ":" << setw(2) << minute << ":" << setw(2) << second + << " UTC"; + } + return output.str(); } /* diff --git a/src/lib/asn1/ber_dec.cpp b/src/lib/asn1/ber_dec.cpp index 0ff79399c..e9133d50f 100644 --- a/src/lib/asn1/ber_dec.cpp +++ b/src/lib/asn1/ber_dec.cpp @@ -103,11 +103,11 @@ size_t find_eoc(DataSource* ber) while(true) { - const size_t got = ber->peek(&buffer[0], buffer.size(), data.size()); + const size_t got = ber->peek(buffer.data(), buffer.size(), data.size()); if(got == 0) break; - data += std::make_pair(&buffer[0], got); + data += std::make_pair(buffer.data(), got); } DataSource_Memory source(data); @@ -309,7 +309,7 @@ BER_Decoder::BER_Decoder(const secure_vector<byte>& data) */ BER_Decoder::BER_Decoder(const std::vector<byte>& data) { - source = new DataSource_Memory(&data[0], data.size()); + source = new DataSource_Memory(data.data(), data.size()); owns = true; pushed.type_tag = pushed.class_tag = NO_OBJECT; parent = nullptr; @@ -391,7 +391,7 @@ BER_Decoder& BER_Decoder::decode_octet_string_bigint(BigInt& out) { secure_vector<byte> out_vec; decode(out_vec, OCTET_STRING); - out = BigInt::decode(&out_vec[0], out_vec.size()); + out = BigInt::decode(out_vec.data(), out_vec.size()); return (*this); } @@ -530,7 +530,7 @@ BER_Decoder& BER_Decoder::decode(secure_vector<byte>& buffer, throw BER_Decoding_Error("Bad number of unused bits in BIT STRING"); buffer.resize(obj.value.size() - 1); - copy_mem(&buffer[0], &obj.value[1], obj.value.size() - 1); + copy_mem(buffer.data(), &obj.value[1], obj.value.size() - 1); } return (*this); } @@ -553,7 +553,7 @@ BER_Decoder& BER_Decoder::decode(std::vector<byte>& buffer, throw BER_Decoding_Error("Bad number of unused bits in BIT STRING"); buffer.resize(obj.value.size() - 1); - copy_mem(&buffer[0], &obj.value[1], obj.value.size() - 1); + copy_mem(buffer.data(), &obj.value[1], obj.value.size() - 1); } return (*this); } diff --git a/src/lib/asn1/der_enc.cpp b/src/lib/asn1/der_enc.cpp index ab84c258d..f886e8ed3 100644 --- a/src/lib/asn1/der_enc.cpp +++ b/src/lib/asn1/der_enc.cpp @@ -179,12 +179,12 @@ DER_Encoder& DER_Encoder::end_explicit() */ DER_Encoder& DER_Encoder::raw_bytes(const secure_vector<byte>& val) { - return raw_bytes(&val[0], val.size()); + return raw_bytes(val.data(), val.size()); } DER_Encoder& DER_Encoder::raw_bytes(const std::vector<byte>& val) { - return raw_bytes(&val[0], val.size()); + return raw_bytes(val.data(), val.size()); } /* @@ -238,7 +238,7 @@ DER_Encoder& DER_Encoder::encode(const BigInt& n) DER_Encoder& DER_Encoder::encode(const secure_vector<byte>& bytes, ASN1_Tag real_type) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, real_type, UNIVERSAL); } @@ -248,7 +248,7 @@ DER_Encoder& DER_Encoder::encode(const secure_vector<byte>& bytes, DER_Encoder& DER_Encoder::encode(const std::vector<byte>& bytes, ASN1_Tag real_type) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, real_type, UNIVERSAL); } @@ -311,7 +311,7 @@ DER_Encoder& DER_Encoder::encode(const secure_vector<byte>& bytes, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, type_tag, class_tag); } @@ -322,7 +322,7 @@ DER_Encoder& DER_Encoder::encode(const std::vector<byte>& bytes, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, type_tag, class_tag); } diff --git a/src/lib/asn1/der_enc.h b/src/lib/asn1/der_enc.h index 0e96fea3b..dbb97d1aa 100644 --- a/src/lib/asn1/der_enc.h +++ b/src/lib/asn1/der_enc.h @@ -99,13 +99,13 @@ class BOTAN_DLL DER_Encoder DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const std::vector<byte>& rep) { - return add_object(type_tag, class_tag, &rep[0], rep.size()); + return add_object(type_tag, class_tag, rep.data(), rep.size()); } DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const secure_vector<byte>& rep) { - return add_object(type_tag, class_tag, &rep[0], rep.size()); + return add_object(type_tag, class_tag, rep.data(), rep.size()); } DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, diff --git a/src/lib/base/buf_comp.h b/src/lib/base/buf_comp.h index 564da2262..30e30c71c 100644 --- a/src/lib/base/buf_comp.h +++ b/src/lib/base/buf_comp.h @@ -39,7 +39,7 @@ class BOTAN_DLL Buffered_Computation */ void update(const secure_vector<byte>& in) { - add_data(&in[0], in.size()); + add_data(in.data(), in.size()); } /** @@ -48,7 +48,7 @@ class BOTAN_DLL Buffered_Computation */ void update(const std::vector<byte>& in) { - add_data(&in[0], in.size()); + add_data(in.data(), in.size()); } /** @@ -97,7 +97,7 @@ class BOTAN_DLL Buffered_Computation secure_vector<byte> final() { secure_vector<byte> output(output_length()); - final_result(&output[0]); + final_result(output.data()); return output; } @@ -105,7 +105,7 @@ class BOTAN_DLL Buffered_Computation void final(std::vector<byte, Alloc>& out) { out.resize(output_length()); - final_result(&out[0]); + final_result(out.data()); } /** @@ -129,7 +129,7 @@ class BOTAN_DLL Buffered_Computation */ secure_vector<byte> process(const secure_vector<byte>& in) { - add_data(&in[0], in.size()); + add_data(in.data(), in.size()); return final(); } @@ -141,7 +141,7 @@ class BOTAN_DLL Buffered_Computation */ secure_vector<byte> process(const std::vector<byte>& in) { - add_data(&in[0], in.size()); + add_data(in.data(), in.size()); return final(); } diff --git a/src/lib/base/sym_algo.h b/src/lib/base/sym_algo.h index 7c37b2a47..ee6eb5f4a 100644 --- a/src/lib/base/sym_algo.h +++ b/src/lib/base/sym_algo.h @@ -68,7 +68,7 @@ class BOTAN_DLL SymmetricAlgorithm template<typename Alloc> void set_key(const std::vector<byte, Alloc>& key) { - set_key(&key[0], key.size()); + set_key(key.data(), key.size()); } /** diff --git a/src/lib/base/symkey.cpp b/src/lib/base/symkey.cpp index 0cb0d9e35..88642747b 100644 --- a/src/lib/base/symkey.cpp +++ b/src/lib/base/symkey.cpp @@ -28,7 +28,7 @@ OctetString::OctetString(RandomNumberGenerator& rng, OctetString::OctetString(const std::string& hex_string) { bits.resize(1 + hex_string.length() / 2); - bits.resize(hex_decode(&bits[0], hex_string)); + bits.resize(hex_decode(bits.data(), hex_string)); } /* @@ -77,7 +77,7 @@ void OctetString::set_odd_parity() */ std::string OctetString::as_string() const { - return hex_encode(&bits[0], bits.size()); + return hex_encode(bits.data(), bits.size()); } /* @@ -86,7 +86,7 @@ std::string OctetString::as_string() const OctetString& OctetString::operator^=(const OctetString& k) { if(&k == this) { zeroise(bits); return (*this); } - xor_buf(&bits[0], k.begin(), std::min(length(), k.length())); + xor_buf(bits.data(), k.begin(), std::min(length(), k.length())); return (*this); } @@ -124,8 +124,8 @@ OctetString operator^(const OctetString& k1, const OctetString& k2) { 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()); + copy_mem(ret.data(), k1.begin(), k1.length()); + xor_buf(ret.data(), k2.begin(), k2.length()); return OctetString(ret); } diff --git a/src/lib/base/symkey.h b/src/lib/base/symkey.h index c837e8ca5..23b7d030b 100644 --- a/src/lib/base/symkey.h +++ b/src/lib/base/symkey.h @@ -33,7 +33,7 @@ class BOTAN_DLL OctetString /** * @return start of this string */ - const byte* begin() const { return &bits[0]; } + const byte* begin() const { return bits.data(); } /** * @return end of this string diff --git a/src/lib/base/transform.h b/src/lib/base/transform.h index 75bd5004a..b5916a3a4 100644 --- a/src/lib/base/transform.h +++ b/src/lib/base/transform.h @@ -33,7 +33,7 @@ class BOTAN_DLL Transform template<typename Alloc> secure_vector<byte> start(const std::vector<byte, Alloc>& nonce) { - return start(&nonce[0], nonce.size()); + return start(nonce.data(), nonce.size()); } /** @@ -44,7 +44,7 @@ class BOTAN_DLL Transform BOTAN_DEPRECATED("Use Transform::start") secure_vector<byte> start_vec(const std::vector<byte, Alloc>& nonce) { - return start(&nonce[0], nonce.size()); + return start(nonce.data(), nonce.size()); } /** @@ -147,7 +147,7 @@ class BOTAN_DLL Keyed_Transform : public Transform template<typename Alloc> void set_key(const std::vector<byte, Alloc>& key) { - set_key(&key[0], key.size()); + set_key(key.data(), key.size()); } void set_key(const SymmetricKey& key) diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp index ff8c97b76..b9e00fe6c 100644 --- a/src/lib/block/aes/aes.cpp +++ b/src/lib/block/aes/aes.cpp @@ -677,8 +677,8 @@ void aes_key_schedule(const byte key[], size_t length, EK.resize(length + 24); DK.resize(length + 24); - copy_mem(&EK[0], &XEK[0], EK.size()); - copy_mem(&DK[0], &XDK[0], DK.size()); + copy_mem(EK.data(), XEK.data(), EK.size()); + copy_mem(DK.data(), XDK.data(), DK.size()); } } diff --git a/src/lib/block/aes_ni/aes_ni.cpp b/src/lib/block/aes_ni/aes_ni.cpp index 96a629d06..20aa63c54 100644 --- a/src/lib/block/aes_ni/aes_ni.cpp +++ b/src/lib/block/aes_ni/aes_ni.cpp @@ -113,7 +113,7 @@ void AES_128_NI::encrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* key_mm = reinterpret_cast<const __m128i*>(&EK[0]); + const __m128i* key_mm = reinterpret_cast<const __m128i*>(EK.data()); __m128i K0 = _mm_loadu_si128(key_mm); __m128i K1 = _mm_loadu_si128(key_mm + 1); @@ -189,7 +189,7 @@ void AES_128_NI::decrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* key_mm = reinterpret_cast<const __m128i*>(&DK[0]); + const __m128i* key_mm = reinterpret_cast<const __m128i*>(DK.data()); __m128i K0 = _mm_loadu_si128(key_mm); __m128i K1 = _mm_loadu_si128(key_mm + 1); @@ -280,7 +280,7 @@ void AES_128_NI::key_schedule(const byte key[], size_t) __m128i K9 = AES_128_key_exp(K8, 0x1B); __m128i K10 = AES_128_key_exp(K9, 0x36); - __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]); + __m128i* EK_mm = reinterpret_cast<__m128i*>(EK.data()); _mm_storeu_si128(EK_mm , K0); _mm_storeu_si128(EK_mm + 1, K1); _mm_storeu_si128(EK_mm + 2, K2); @@ -295,7 +295,7 @@ void AES_128_NI::key_schedule(const byte key[], size_t) // Now generate decryption keys - __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]); + __m128i* DK_mm = reinterpret_cast<__m128i*>(DK.data()); _mm_storeu_si128(DK_mm , K10); _mm_storeu_si128(DK_mm + 1, _mm_aesimc_si128(K9)); _mm_storeu_si128(DK_mm + 2, _mm_aesimc_si128(K8)); @@ -326,7 +326,7 @@ void AES_192_NI::encrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* key_mm = reinterpret_cast<const __m128i*>(&EK[0]); + const __m128i* key_mm = reinterpret_cast<const __m128i*>(EK.data()); __m128i K0 = _mm_loadu_si128(key_mm); __m128i K1 = _mm_loadu_si128(key_mm + 1); @@ -408,7 +408,7 @@ void AES_192_NI::decrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* key_mm = reinterpret_cast<const __m128i*>(&DK[0]); + const __m128i* key_mm = reinterpret_cast<const __m128i*>(DK.data()); __m128i K0 = _mm_loadu_si128(key_mm); __m128i K1 = _mm_loadu_si128(key_mm + 1); @@ -494,7 +494,7 @@ void AES_192_NI::key_schedule(const byte key[], size_t) __m128i K1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(key + 8)); K1 = _mm_srli_si128(K1, 8); - load_le(&EK[0], key, 6); + load_le(EK.data(), key, 6); #define AES_192_key_exp(RCON, EK_OFF) \ aes_192_key_expansion(&K0, &K1, \ @@ -513,9 +513,9 @@ void AES_192_NI::key_schedule(const byte key[], size_t) #undef AES_192_key_exp // Now generate decryption keys - const __m128i* EK_mm = reinterpret_cast<const __m128i*>(&EK[0]); + const __m128i* EK_mm = reinterpret_cast<const __m128i*>(EK.data()); - __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]); + __m128i* DK_mm = reinterpret_cast<__m128i*>(DK.data()); _mm_storeu_si128(DK_mm , _mm_loadu_si128(EK_mm + 12)); _mm_storeu_si128(DK_mm + 1, _mm_aesimc_si128(_mm_loadu_si128(EK_mm + 11))); _mm_storeu_si128(DK_mm + 2, _mm_aesimc_si128(_mm_loadu_si128(EK_mm + 10))); @@ -548,7 +548,7 @@ void AES_256_NI::encrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* key_mm = reinterpret_cast<const __m128i*>(&EK[0]); + const __m128i* key_mm = reinterpret_cast<const __m128i*>(EK.data()); __m128i K0 = _mm_loadu_si128(key_mm); __m128i K1 = _mm_loadu_si128(key_mm + 1); @@ -636,7 +636,7 @@ void AES_256_NI::decrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* key_mm = reinterpret_cast<const __m128i*>(&DK[0]); + const __m128i* key_mm = reinterpret_cast<const __m128i*>(DK.data()); __m128i K0 = _mm_loadu_si128(key_mm); __m128i K1 = _mm_loadu_si128(key_mm + 1); @@ -747,7 +747,7 @@ void AES_256_NI::key_schedule(const byte key[], size_t) __m128i K14 = aes_128_key_expansion(K12, _mm_aeskeygenassist_si128(K13, 0x40)); - __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]); + __m128i* EK_mm = reinterpret_cast<__m128i*>(EK.data()); _mm_storeu_si128(EK_mm , K0); _mm_storeu_si128(EK_mm + 1, K1); _mm_storeu_si128(EK_mm + 2, K2); @@ -765,7 +765,7 @@ void AES_256_NI::key_schedule(const byte key[], size_t) _mm_storeu_si128(EK_mm + 14, K14); // Now generate decryption keys - __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]); + __m128i* DK_mm = reinterpret_cast<__m128i*>(DK.data()); _mm_storeu_si128(DK_mm , K14); _mm_storeu_si128(DK_mm + 1, _mm_aesimc_si128(K13)); _mm_storeu_si128(DK_mm + 2, _mm_aesimc_si128(K12)); diff --git a/src/lib/block/aes_ssse3/aes_ssse3.cpp b/src/lib/block/aes_ssse3/aes_ssse3.cpp index b9731d010..f0d506b6e 100644 --- a/src/lib/block/aes_ssse3/aes_ssse3.cpp +++ b/src/lib/block/aes_ssse3/aes_ssse3.cpp @@ -348,7 +348,7 @@ void AES_128_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* keys = reinterpret_cast<const __m128i*>(&EK[0]); + const __m128i* keys = reinterpret_cast<const __m128i*>(EK.data()); for(size_t i = 0; i != blocks; ++i) { @@ -365,7 +365,7 @@ void AES_128_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* keys = reinterpret_cast<const __m128i*>(&DK[0]); + const __m128i* keys = reinterpret_cast<const __m128i*>(DK.data()); for(size_t i = 0; i != blocks; ++i) { @@ -387,8 +387,8 @@ void AES_128_SSSE3::key_schedule(const byte keyb[], size_t) EK.resize(11*4); DK.resize(11*4); - __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]); - __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]); + __m128i* EK_mm = reinterpret_cast<__m128i*>(EK.data()); + __m128i* DK_mm = reinterpret_cast<__m128i*>(DK.data()); _mm_storeu_si128(DK_mm + 10, _mm_shuffle_epi8(key, sr[2])); @@ -426,7 +426,7 @@ void AES_192_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* keys = reinterpret_cast<const __m128i*>(&EK[0]); + const __m128i* keys = reinterpret_cast<const __m128i*>(EK.data()); for(size_t i = 0; i != blocks; ++i) { @@ -443,7 +443,7 @@ void AES_192_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* keys = reinterpret_cast<const __m128i*>(&DK[0]); + const __m128i* keys = reinterpret_cast<const __m128i*>(DK.data()); for(size_t i = 0; i != blocks; ++i) { @@ -463,8 +463,8 @@ void AES_192_SSSE3::key_schedule(const byte keyb[], size_t) EK.resize(13*4); DK.resize(13*4); - __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]); - __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]); + __m128i* EK_mm = reinterpret_cast<__m128i*>(EK.data()); + __m128i* DK_mm = reinterpret_cast<__m128i*>(DK.data()); __m128i key1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(keyb)); __m128i key2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>((keyb + 8))); @@ -533,7 +533,7 @@ void AES_256_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* keys = reinterpret_cast<const __m128i*>(&EK[0]); + const __m128i* keys = reinterpret_cast<const __m128i*>(EK.data()); for(size_t i = 0; i != blocks; ++i) { @@ -550,7 +550,7 @@ void AES_256_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const const __m128i* in_mm = reinterpret_cast<const __m128i*>(in); __m128i* out_mm = reinterpret_cast<__m128i*>(out); - const __m128i* keys = reinterpret_cast<const __m128i*>(&DK[0]); + const __m128i* keys = reinterpret_cast<const __m128i*>(DK.data()); for(size_t i = 0; i != blocks; ++i) { @@ -570,8 +570,8 @@ void AES_256_SSSE3::key_schedule(const byte keyb[], size_t) EK.resize(15*4); DK.resize(15*4); - __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]); - __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]); + __m128i* EK_mm = reinterpret_cast<__m128i*>(EK.data()); + __m128i* DK_mm = reinterpret_cast<__m128i*>(DK.data()); __m128i key1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(keyb)); __m128i key2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>((keyb + 16))); diff --git a/src/lib/block/block_cipher.h b/src/lib/block/block_cipher.h index 73e67b790..060dbb29b 100644 --- a/src/lib/block/block_cipher.h +++ b/src/lib/block/block_cipher.h @@ -82,7 +82,7 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm template<typename Alloc> void encrypt(std::vector<byte, Alloc>& block) const { - return encrypt_n(&block[0], &block[0], block.size() / block_size()); + return encrypt_n(block.data(), block.data(), block.size() / block_size()); } /** @@ -92,7 +92,7 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm template<typename Alloc> void decrypt(std::vector<byte, Alloc>& block) const { - return decrypt_n(&block[0], &block[0], block.size() / block_size()); + return decrypt_n(block.data(), block.data(), block.size() / block_size()); } /** @@ -104,7 +104,7 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm void encrypt(const std::vector<byte, Alloc>& in, std::vector<byte, Alloc2>& out) const { - return encrypt_n(&in[0], &out[0], in.size() / block_size()); + return encrypt_n(in.data(), out.data(), in.size() / block_size()); } /** @@ -116,7 +116,7 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm void decrypt(const std::vector<byte, Alloc>& in, std::vector<byte, Alloc2>& out) const { - return decrypt_n(&in[0], &out[0], in.size() / block_size()); + return decrypt_n(in.data(), out.data(), in.size() / block_size()); } /** diff --git a/src/lib/block/camellia/camellia.cpp b/src/lib/block/camellia/camellia.cpp index 5f04c9d12..887878910 100644 --- a/src/lib/block/camellia/camellia.cpp +++ b/src/lib/block/camellia/camellia.cpp @@ -127,7 +127,7 @@ void encrypt(const byte in[], byte out[], size_t blocks, u64bit D1 = load_be<u64bit>(in, 0); u64bit D2 = load_be<u64bit>(in, 1); - const u64bit* K = &SK[0]; + const u64bit* K = SK.data(); D1 ^= *K++; D2 ^= *K++; diff --git a/src/lib/block/cast/cast128.cpp b/src/lib/block/cast/cast128.cpp index 3ac54f5e8..e19c6dcb1 100644 --- a/src/lib/block/cast/cast128.cpp +++ b/src/lib/block/cast/cast128.cpp @@ -338,7 +338,7 @@ void CAST_128::cast_ks(secure_vector<u32bit>& K, }; secure_vector<u32bit> Z(4); - ByteReader x(&X[0]), z(&Z[0]); + ByteReader x(X.data()), z(Z.data()); Z[0] = X[0] ^ S5[x(13)] ^ S6[x(15)] ^ S7[x(12)] ^ S8[x(14)] ^ S7[x( 8)]; Z[1] = X[2] ^ S5[z( 0)] ^ S6[z( 2)] ^ S7[z( 1)] ^ S8[z( 3)] ^ S8[x(10)]; diff --git a/src/lib/block/des/des.cpp b/src/lib/block/des/des.cpp index 2994b7cb2..c1013b9af 100644 --- a/src/lib/block/des/des.cpp +++ b/src/lib/block/des/des.cpp @@ -157,7 +157,7 @@ void DES::encrypt_n(const byte in[], byte out[], size_t blocks) const u32bit L = static_cast<u32bit>(T >> 32); u32bit R = static_cast<u32bit>(T); - des_encrypt(L, R, &round_key[0]); + des_encrypt(L, R, round_key.data()); T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) | (DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) | @@ -187,7 +187,7 @@ void DES::decrypt_n(const byte in[], byte out[], size_t blocks) const u32bit L = static_cast<u32bit>(T >> 32); u32bit R = static_cast<u32bit>(T); - des_decrypt(L, R, &round_key[0]); + des_decrypt(L, R, round_key.data()); T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) | (DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) | @@ -209,7 +209,7 @@ void DES::decrypt_n(const byte in[], byte out[], size_t blocks) const void DES::key_schedule(const byte key[], size_t) { round_key.resize(32); - des_key_schedule(&round_key[0], key); + des_key_schedule(round_key.data(), key); } void DES::clear() diff --git a/src/lib/block/des/desx.cpp b/src/lib/block/des/desx.cpp index 92cfc83cc..0e19460fc 100644 --- a/src/lib/block/des/desx.cpp +++ b/src/lib/block/des/desx.cpp @@ -19,9 +19,9 @@ void DESX::encrypt_n(const byte in[], byte out[], size_t blocks) const { for(size_t i = 0; i != blocks; ++i) { - xor_buf(out, in, &K1[0], BLOCK_SIZE); + xor_buf(out, in, K1.data(), BLOCK_SIZE); des.encrypt(out); - xor_buf(out, &K2[0], BLOCK_SIZE); + xor_buf(out, K2.data(), BLOCK_SIZE); in += BLOCK_SIZE; out += BLOCK_SIZE; @@ -35,9 +35,9 @@ void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const { for(size_t i = 0; i != blocks; ++i) { - xor_buf(out, in, &K2[0], BLOCK_SIZE); + xor_buf(out, in, K2.data(), BLOCK_SIZE); des.decrypt(out); - xor_buf(out, &K1[0], BLOCK_SIZE); + xor_buf(out, K1.data(), BLOCK_SIZE); in += BLOCK_SIZE; out += BLOCK_SIZE; diff --git a/src/lib/block/idea/idea.cpp b/src/lib/block/idea/idea.cpp index fa98e3754..764115013 100644 --- a/src/lib/block/idea/idea.cpp +++ b/src/lib/block/idea/idea.cpp @@ -110,7 +110,7 @@ void idea_op(const byte in[], byte out[], size_t blocks, const u16bit K[52]) */ void IDEA::encrypt_n(const byte in[], byte out[], size_t blocks) const { - idea_op(in, out, blocks, &EK[0]); + idea_op(in, out, blocks, EK.data()); } /* @@ -118,7 +118,7 @@ void IDEA::encrypt_n(const byte in[], byte out[], size_t blocks) const */ void IDEA::decrypt_n(const byte in[], byte out[], size_t blocks) const { - idea_op(in, out, blocks, &DK[0]); + idea_op(in, out, blocks, DK.data()); } /* diff --git a/src/lib/block/lion/lion.cpp b/src/lib/block/lion/lion.cpp index a3f15fb51..a487e3eb0 100644 --- a/src/lib/block/lion/lion.cpp +++ b/src/lib/block/lion/lion.cpp @@ -42,11 +42,11 @@ void Lion::encrypt_n(const byte in[], byte out[], size_t blocks) const const size_t RIGHT_SIZE = right_size(); secure_vector<byte> buffer_vec(LEFT_SIZE); - byte* buffer = &buffer_vec[0]; + byte* buffer = buffer_vec.data(); for(size_t i = 0; i != blocks; ++i) { - xor_buf(buffer, in, &m_key1[0], LEFT_SIZE); + xor_buf(buffer, in, m_key1.data(), LEFT_SIZE); m_cipher->set_key(buffer, LEFT_SIZE); m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE); @@ -54,7 +54,7 @@ void Lion::encrypt_n(const byte in[], byte out[], size_t blocks) const m_hash->final(buffer); xor_buf(out, in, buffer, LEFT_SIZE); - xor_buf(buffer, out, &m_key2[0], LEFT_SIZE); + xor_buf(buffer, out, m_key2.data(), LEFT_SIZE); m_cipher->set_key(buffer, LEFT_SIZE); m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE); @@ -72,11 +72,11 @@ void Lion::decrypt_n(const byte in[], byte out[], size_t blocks) const const size_t RIGHT_SIZE = right_size(); secure_vector<byte> buffer_vec(LEFT_SIZE); - byte* buffer = &buffer_vec[0]; + byte* buffer = buffer_vec.data(); for(size_t i = 0; i != blocks; ++i) { - xor_buf(buffer, in, &m_key2[0], LEFT_SIZE); + xor_buf(buffer, in, m_key2.data(), LEFT_SIZE); m_cipher->set_key(buffer, LEFT_SIZE); m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE); @@ -84,7 +84,7 @@ void Lion::decrypt_n(const byte in[], byte out[], size_t blocks) const m_hash->final(buffer); xor_buf(out, in, buffer, LEFT_SIZE); - xor_buf(buffer, out, &m_key1[0], LEFT_SIZE); + xor_buf(buffer, out, m_key1.data(), LEFT_SIZE); m_cipher->set_key(buffer, LEFT_SIZE); m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE); @@ -101,8 +101,8 @@ void Lion::key_schedule(const byte key[], size_t length) clear(); const size_t half = length / 2; - copy_mem(&m_key1[0], key, half); - copy_mem(&m_key2[0], key + half, half); + copy_mem(m_key1.data(), key, half); + copy_mem(m_key2.data(), key + half, half); } /* diff --git a/src/lib/block/noekeon/noekeon.cpp b/src/lib/block/noekeon/noekeon.cpp index 09a2f6c15..fb1a215fe 100644 --- a/src/lib/block/noekeon/noekeon.cpp +++ b/src/lib/block/noekeon/noekeon.cpp @@ -97,7 +97,7 @@ void Noekeon::encrypt_n(const byte in[], byte out[], size_t blocks) const for(size_t j = 0; j != 16; ++j) { A0 ^= RC[j]; - theta(A0, A1, A2, A3, &EK[0]); + theta(A0, A1, A2, A3, EK.data()); A1 = rotate_left(A1, 1); A2 = rotate_left(A2, 5); @@ -111,7 +111,7 @@ void Noekeon::encrypt_n(const byte in[], byte out[], size_t blocks) const } A0 ^= RC[16]; - theta(A0, A1, A2, A3, &EK[0]); + theta(A0, A1, A2, A3, EK.data()); store_be(out, A0, A1, A2, A3); @@ -134,7 +134,7 @@ void Noekeon::decrypt_n(const byte in[], byte out[], size_t blocks) const for(size_t j = 16; j != 0; --j) { - theta(A0, A1, A2, A3, &DK[0]); + theta(A0, A1, A2, A3, DK.data()); A0 ^= RC[j]; A1 = rotate_left(A1, 1); @@ -148,7 +148,7 @@ void Noekeon::decrypt_n(const byte in[], byte out[], size_t blocks) const A3 = rotate_right(A3, 2); } - theta(A0, A1, A2, A3, &DK[0]); + theta(A0, A1, A2, A3, DK.data()); A0 ^= RC[0]; store_be(out, A0, A1, A2, A3); diff --git a/src/lib/block/rc2/rc2.cpp b/src/lib/block/rc2/rc2.cpp index 54f85ce00..d1fc8a2e6 100644 --- a/src/lib/block/rc2/rc2.cpp +++ b/src/lib/block/rc2/rc2.cpp @@ -126,7 +126,7 @@ void RC2::key_schedule(const byte key[], size_t length) 0xFE, 0x7F, 0xC1, 0xAD }; secure_vector<byte> L(128); - copy_mem(&L[0], key, length); + copy_mem(L.data(), key, length); for(size_t i = length; i != 128; ++i) L[i] = TABLE[(L[i-1] + L[i-length]) % 256]; @@ -137,7 +137,7 @@ void RC2::key_schedule(const byte key[], size_t length) L[i] = TABLE[L[i+1] ^ L[i+length]]; K.resize(64); - load_le<u16bit>(&K[0], &L[0], 64); + load_le<u16bit>(K.data(), L.data(), 64); } void RC2::clear() diff --git a/src/lib/block/serpent_x86_32/serp_x86_32.cpp b/src/lib/block/serpent_x86_32/serp_x86_32.cpp index 7e52a5118..f055880b3 100644 --- a/src/lib/block/serpent_x86_32/serp_x86_32.cpp +++ b/src/lib/block/serpent_x86_32/serp_x86_32.cpp @@ -52,7 +52,7 @@ void Serpent_X86_32::encrypt_n(const byte in[], byte out[], size_t blocks) const for(size_t i = 0; i != blocks; ++i) { - botan_serpent_x86_32_encrypt(in, out, &keys[0]); + botan_serpent_x86_32_encrypt(in, out, keys.data()); in += BLOCK_SIZE; out += BLOCK_SIZE; } @@ -67,7 +67,7 @@ void Serpent_X86_32::decrypt_n(const byte in[], byte out[], size_t blocks) const for(size_t i = 0; i != blocks; ++i) { - botan_serpent_x86_32_decrypt(in, out, &keys[0]); + botan_serpent_x86_32_decrypt(in, out, keys.data()); in += BLOCK_SIZE; out += BLOCK_SIZE; } @@ -83,7 +83,7 @@ void Serpent_X86_32::key_schedule(const byte key[], size_t length) W[i] = load_le<u32bit>(key, i); W[length / 4] |= u32bit(1) << ((length%4)*8); - botan_serpent_x86_32_key_schedule(&W[0]); + botan_serpent_x86_32_key_schedule(W.data()); this->set_round_keys(&W[8]); } diff --git a/src/lib/cert/cvc/asn1_eac_tm.cpp b/src/lib/cert/cvc/asn1_eac_tm.cpp index 6aad1067c..83a6ef391 100644 --- a/src/lib/cert/cvc/asn1_eac_tm.cpp +++ b/src/lib/cert/cvc/asn1_eac_tm.cpp @@ -13,6 +13,8 @@ #include <botan/parsing.h> #include <botan/internal/rounding.h> #include <botan/calendar.h> +#include <sstream> +#include <iomanip> namespace Botan { @@ -153,11 +155,13 @@ std::string EAC_Time::readable_string() const if(time_is_set() == false) throw Invalid_State("EAC_Time::readable_string: No time set"); - std::string output(11, 0); - - std::sprintf(&output[0], "%04d/%02d/%02d", year, month, day); - - return output; + // desired format: "%04d/%02d/%02d" + std::stringstream output; + output << std::setfill('0') + << std::setw(4) << year << "/" + << std::setw(2) << month << "/" + << std::setw(2) << day; + return output.str(); } /* diff --git a/src/lib/cert/x509/x509_obj.cpp b/src/lib/cert/x509/x509_obj.cpp index 71449098e..0f5999b5b 100644 --- a/src/lib/cert/x509/x509_obj.cpp +++ b/src/lib/cert/x509/x509_obj.cpp @@ -39,7 +39,7 @@ X509_Object::X509_Object(const std::string& file, const std::string& labels) */ X509_Object::X509_Object(const std::vector<byte>& vec, const std::string& labels) { - DataSource_Memory stream(&vec[0], vec.size()); + DataSource_Memory stream(vec.data(), vec.size()); init(stream, labels); } diff --git a/src/lib/codec/base64/base64.cpp b/src/lib/codec/base64/base64.cpp index aaf04d9d2..1b1767aa1 100644 --- a/src/lib/codec/base64/base64.cpp +++ b/src/lib/codec/base64/base64.cpp @@ -84,9 +84,14 @@ std::string base64_encode(const byte input[], std::string output(output_length, 0); size_t consumed = 0; - size_t produced = base64_encode(&output[0], - input, input_length, - consumed, true); + size_t produced = 0; + + if (output_length > 0) + { + produced = base64_encode(&output.front(), + input, input_length, + consumed, true); + } BOTAN_ASSERT_EQUAL(consumed, input_length, "Consumed the entire input"); BOTAN_ASSERT_EQUAL(produced, output.size(), "Produced expected size"); @@ -232,7 +237,7 @@ secure_vector<byte> base64_decode(const char input[], : (round_up<size_t>(input_length, 4) * 3) / 4; secure_vector<byte> bin(output_length); - size_t written = base64_decode(&bin[0], + size_t written = base64_decode(bin.data(), input, input_length, ignore_ws); diff --git a/src/lib/codec/base64/base64.h b/src/lib/codec/base64/base64.h index ab7bb5a1c..92c4dc627 100644 --- a/src/lib/codec/base64/base64.h +++ b/src/lib/codec/base64/base64.h @@ -49,7 +49,7 @@ std::string BOTAN_DLL base64_encode(const byte input[], template<typename Alloc> std::string base64_encode(const std::vector<byte, Alloc>& input) { - return base64_encode(&input[0], input.size()); + return base64_encode(input.data(), input.size()); } /** diff --git a/src/lib/codec/hex/hex.cpp b/src/lib/codec/hex/hex.cpp index 21c5a5a03..4da719320 100644 --- a/src/lib/codec/hex/hex.cpp +++ b/src/lib/codec/hex/hex.cpp @@ -41,7 +41,7 @@ std::string hex_encode(const byte input[], std::string output(2 * input_length, 0); if(input_length) - hex_encode(&output[0], input, input_length, uppercase); + hex_encode(&output.front(), input, input_length, uppercase); return output; } @@ -156,7 +156,7 @@ size_t hex_decode(byte output[], const std::string& input, bool ignore_ws) { - return hex_decode(output, &input[0], input.length(), ignore_ws); + return hex_decode(output, input.data(), input.length(), ignore_ws); } secure_vector<byte> hex_decode_locked(const char input[], @@ -165,7 +165,7 @@ secure_vector<byte> hex_decode_locked(const char input[], { secure_vector<byte> bin(1 + input_length / 2); - size_t written = hex_decode(&bin[0], + size_t written = hex_decode(bin.data(), input, input_length, ignore_ws); @@ -177,7 +177,7 @@ secure_vector<byte> hex_decode_locked(const char input[], secure_vector<byte> hex_decode_locked(const std::string& input, bool ignore_ws) { - return hex_decode_locked(&input[0], input.size(), ignore_ws); + return hex_decode_locked(input.data(), input.size(), ignore_ws); } std::vector<byte> hex_decode(const char input[], @@ -186,7 +186,7 @@ std::vector<byte> hex_decode(const char input[], { std::vector<byte> bin(1 + input_length / 2); - size_t written = hex_decode(&bin[0], + size_t written = hex_decode(bin.data(), input, input_length, ignore_ws); @@ -198,7 +198,7 @@ std::vector<byte> hex_decode(const char input[], std::vector<byte> hex_decode(const std::string& input, bool ignore_ws) { - return hex_decode(&input[0], input.size(), ignore_ws); + return hex_decode(input.data(), input.size(), ignore_ws); } } diff --git a/src/lib/codec/hex/hex.h b/src/lib/codec/hex/hex.h index bd57ec88e..b524c43f0 100644 --- a/src/lib/codec/hex/hex.h +++ b/src/lib/codec/hex/hex.h @@ -46,7 +46,7 @@ template<typename Alloc> std::string hex_encode(const std::vector<byte, Alloc>& input, bool uppercase = true) { - return hex_encode(&input[0], input.size(), uppercase); + return hex_encode(input.data(), input.size(), uppercase); } /** diff --git a/src/lib/compression/compression.cpp b/src/lib/compression/compression.cpp index 0e0221fe6..6057f9408 100644 --- a/src/lib/compression/compression.cpp +++ b/src/lib/compression/compression.cpp @@ -124,7 +124,7 @@ void Stream_Compression::process(secure_vector<byte>& buf, size_t offset, u32bit } } - copy_mem(&m_buffer[0], &buf[0], offset); + copy_mem(m_buffer.data(), buf.data(), offset); buf.swap(m_buffer); } @@ -205,7 +205,7 @@ void Stream_Decompression::process(secure_vector<byte>& buf, size_t offset, u32b } } - copy_mem(&m_buffer[0], &buf[0], offset); + copy_mem(m_buffer.data(), buf.data(), offset); buf.swap(m_buffer); } diff --git a/src/lib/entropy/cryptoapi_rng/es_capi.cpp b/src/lib/entropy/cryptoapi_rng/es_capi.cpp index 2c86152ad..019b55a10 100644 --- a/src/lib/entropy/cryptoapi_rng/es_capi.cpp +++ b/src/lib/entropy/cryptoapi_rng/es_capi.cpp @@ -63,9 +63,9 @@ void Win32_CAPI_EntropySource::poll(Entropy_Accumulator& accum) { CSP_Handle csp(prov_types[i]); - if(size_t got = csp.gen_random(&m_buf[0], m_buf.size())) + if(size_t got = csp.gen_random(m_buf.data(), m_buf.size())) { - accum.add(&m_buf[0], got, 6); + accum.add(m_buf.data(), got, 6); break; } } diff --git a/src/lib/entropy/dev_random/dev_random.cpp b/src/lib/entropy/dev_random/dev_random.cpp index b115e0da2..526835fea 100644 --- a/src/lib/entropy/dev_random/dev_random.cpp +++ b/src/lib/entropy/dev_random/dev_random.cpp @@ -87,9 +87,9 @@ void Device_EntropySource::poll(Entropy_Accumulator& accum) { if(FD_ISSET(m_devices[i], &read_set)) { - const ssize_t got = ::read(m_devices[i], &m_buf[0], m_buf.size()); + const ssize_t got = ::read(m_devices[i], m_buf.data(), m_buf.size()); if(got > 0) - accum.add(&m_buf[0], got, ENTROPY_BITS_PER_BYTE); + accum.add(m_buf.data(), got, ENTROPY_BITS_PER_BYTE); } } } diff --git a/src/lib/entropy/egd/es_egd.cpp b/src/lib/entropy/egd/es_egd.cpp index 728104b44..d64b87ba1 100644 --- a/src/lib/entropy/egd/es_egd.cpp +++ b/src/lib/entropy/egd/es_egd.cpp @@ -145,11 +145,11 @@ void EGD_EntropySource::poll(Entropy_Accumulator& accum) for(size_t i = 0; i != sockets.size(); ++i) { - size_t got = sockets[i].read(&m_buf[0], m_buf.size()); + size_t got = sockets[i].read(m_buf.data(), m_buf.size()); if(got) { - accum.add(&m_buf[0], got, 6); + accum.add(m_buf.data(), got, 6); break; } } diff --git a/src/lib/entropy/proc_walk/proc_walk.cpp b/src/lib/entropy/proc_walk/proc_walk.cpp index 1501f0774..217ed5a52 100644 --- a/src/lib/entropy/proc_walk/proc_walk.cpp +++ b/src/lib/entropy/proc_walk/proc_walk.cpp @@ -133,11 +133,11 @@ void ProcWalking_EntropySource::poll(Entropy_Accumulator& accum) break; } - ssize_t got = ::read(fd, &m_buf[0], m_buf.size()); + ssize_t got = ::read(fd, m_buf.data(), m_buf.size()); ::close(fd); if(got > 0) - accum.add(&m_buf[0], got, ENTROPY_ESTIMATE); + accum.add(m_buf.data(), got, ENTROPY_ESTIMATE); if(accum.polling_finished()) break; diff --git a/src/lib/entropy/unix_procs/unix_procs.cpp b/src/lib/entropy/unix_procs/unix_procs.cpp index d3208b7fc..3c641da70 100644 --- a/src/lib/entropy/unix_procs/unix_procs.cpp +++ b/src/lib/entropy/unix_procs/unix_procs.cpp @@ -237,9 +237,9 @@ void Unix_EntropySource::poll(Entropy_Accumulator& accum) if(FD_ISSET(fd, &read_set)) { - const ssize_t got = ::read(fd, &m_buf[0], m_buf.size()); + const ssize_t got = ::read(fd, m_buf.data(), m_buf.size()); if(got > 0) - accum.add(&m_buf[0], got, ENTROPY_ESTIMATE); + accum.add(m_buf.data(), got, ENTROPY_ESTIMATE); else proc.spawn(next_source()); } diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp index 4fcdb63c1..91acde2bc 100644 --- a/src/lib/ffi/ffi.cpp +++ b/src/lib/ffi/ffi.cpp @@ -110,7 +110,7 @@ inline int write_output(uint8_t out[], size_t* out_len, const uint8_t buf[], siz *out_len = buf_len; if(avail >= buf_len) { - Botan::copy_mem(out, &buf[0], buf_len); + Botan::copy_mem(out, buf, buf_len); return 0; } return -1; @@ -119,7 +119,7 @@ inline int write_output(uint8_t out[], size_t* out_len, const uint8_t buf[], siz template<typename Alloc> int write_vec_output(uint8_t out[], size_t* out_len, const std::vector<uint8_t, Alloc>& buf) { - return write_output(out, out_len, &buf[0], buf.size()); + return write_output(out, out_len, buf.data(), buf.size()); } inline int write_str_output(uint8_t out[], size_t* out_len, const std::string& str) @@ -472,7 +472,7 @@ int botan_cipher_update(botan_cipher_t cipher_obj, if(mbuf.size() <= output_size) { - copy_mem(output, &mbuf[0], mbuf.size()); + copy_mem(output, mbuf.data(), mbuf.size()); mbuf.clear(); return 0; } @@ -486,7 +486,7 @@ int botan_cipher_update(botan_cipher_t cipher_obj, *output_written = mbuf.size(); if(output_size >= mbuf.size()) { - copy_mem(output, &mbuf[0], mbuf.size()); + copy_mem(output, mbuf.data(), mbuf.size()); mbuf.clear(); return 0; } @@ -504,7 +504,7 @@ int botan_cipher_update(botan_cipher_t cipher_obj, const size_t taken = round_down(input_size, ud); *input_consumed = taken; *output_size = taken; - copy_mem(&output[0], input, taken); + copy_mem(output, input, taken); ocm->update_in_place(output, taken); return 0; } @@ -515,7 +515,7 @@ int botan_cipher_update(botan_cipher_t cipher_obj, while(input_size >= ud && output_size >= ud) { - copy_mem(&mbuf[0], input, ud); + copy_mem(mbuf.data(), input, ud); cipher.update(mbuf); input_size -= ud; diff --git a/src/lib/hash/comb4p/comb4p.cpp b/src/lib/hash/comb4p/comb4p.cpp index 4797e2483..843c530ef 100644 --- a/src/lib/hash/comb4p/comb4p.cpp +++ b/src/lib/hash/comb4p/comb4p.cpp @@ -25,14 +25,14 @@ void comb4p_round(secure_vector<byte>& out, h1.update(round_no); h2.update(round_no); - h1.update(&in[0], in.size()); - h2.update(&in[0], in.size()); + h1.update(in.data(), in.size()); + h2.update(in.data(), in.size()); secure_vector<byte> h_buf = h1.final(); - xor_buf(&out[0], &h_buf[0], std::min(out.size(), h_buf.size())); + xor_buf(out.data(), h_buf.data(), std::min(out.size(), h_buf.size())); h_buf = h2.final(); - xor_buf(&out[0], &h_buf[0], std::min(out.size(), h_buf.size())); + xor_buf(out.data(), h_buf.data(), std::min(out.size(), h_buf.size())); } } @@ -98,7 +98,7 @@ void Comb4P::final_result(byte out[]) secure_vector<byte> h2 = m_hash2->final(); // First round - xor_buf(&h1[0], &h2[0], std::min(h1.size(), h2.size())); + xor_buf(h1.data(), h2.data(), std::min(h1.size(), h2.size())); // Second round comb4p_round(h2, h1, 1, *m_hash1, *m_hash2); @@ -106,8 +106,8 @@ void Comb4P::final_result(byte out[]) // Third round comb4p_round(h1, h2, 2, *m_hash1, *m_hash2); - copy_mem(out , &h1[0], h1.size()); - copy_mem(out + h1.size(), &h2[0], h2.size()); + copy_mem(out , h1.data(), h1.size()); + copy_mem(out + h1.size(), h2.data(), h2.size()); // Prep for processing next message, if any m_hash1->update(0); diff --git a/src/lib/hash/gost_3411/gost_3411.cpp b/src/lib/hash/gost_3411/gost_3411.cpp index ad1ee3b98..918556ca0 100644 --- a/src/lib/hash/gost_3411/gost_3411.cpp +++ b/src/lib/hash/gost_3411/gost_3411.cpp @@ -48,7 +48,7 @@ void GOST_34_11::add_data(const byte input[], size_t length) if(position + length >= hash_block_size()) { - compress_n(&buffer[0], 1); + compress_n(buffer.data(), 1); input += (hash_block_size() - position); length -= (hash_block_size() - position); position = 0; @@ -82,7 +82,7 @@ void GOST_34_11::compress_n(const byte input[], size_t blocks) byte S[32] = { 0 }; u64bit U[4], V[4]; - load_be(U, &hash[0], 4); + load_be(U, hash.data(), 4); load_be(V, input + 32*i, 4); for(size_t j = 0; j != 4; ++j) @@ -169,7 +169,7 @@ void GOST_34_11::compress_n(const byte input[], size_t blocks) S[30] = S2[0]; S[31] = S2[1]; - xor_buf(S, &hash[0], 32); + xor_buf(S, hash.data(), 32); // 61 rounds of psi S2[ 0] = S[ 2] ^ S[ 6] ^ S[14] ^ S[20] ^ S[22] ^ S[26] ^ S[28] ^ S[30]; @@ -211,7 +211,7 @@ void GOST_34_11::compress_n(const byte input[], size_t blocks) S2[30] = S[ 2] ^ S[ 4] ^ S[ 8] ^ S[14] ^ S[16] ^ S[18] ^ S[22] ^ S[24] ^ S[28] ^ S[30]; S2[31] = S[ 3] ^ S[ 5] ^ S[ 9] ^ S[15] ^ S[17] ^ S[19] ^ S[23] ^ S[25] ^ S[29] ^ S[31]; - copy_mem(&hash[0], &S2[0], 32); + copy_mem(hash.data(), S2, 32); } } @@ -222,20 +222,20 @@ void GOST_34_11::final_result(byte out[]) { if(position) { - clear_mem(&buffer[0] + position, buffer.size() - position); - compress_n(&buffer[0], 1); + clear_mem(buffer.data() + position, buffer.size() - position); + compress_n(buffer.data(), 1); } secure_vector<byte> length_buf(32); const u64bit bit_count = count * 8; - store_le(bit_count, &length_buf[0]); + store_le(bit_count, length_buf.data()); secure_vector<byte> sum_buf = sum; - compress_n(&length_buf[0], 1); - compress_n(&sum_buf[0], 1); + compress_n(length_buf.data(), 1); + compress_n(sum_buf.data(), 1); - copy_mem(out, &hash[0], 32); + copy_mem(out, hash.data(), 32); clear(); } diff --git a/src/lib/hash/has160/has160.cpp b/src/lib/hash/has160/has160.cpp index 2e6981657..2f2a5f9de 100644 --- a/src/lib/hash/has160/has160.cpp +++ b/src/lib/hash/has160/has160.cpp @@ -68,7 +68,7 @@ void HAS_160::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_le(&X[0], input, 16); + load_le(X.data(), input, 16); X[16] = X[ 0] ^ X[ 1] ^ X[ 2] ^ X[ 3]; X[17] = X[ 4] ^ X[ 5] ^ X[ 6] ^ X[ 7]; diff --git a/src/lib/hash/keccak/keccak.cpp b/src/lib/hash/keccak/keccak.cpp index 842b199a5..8ee2357b6 100644 --- a/src/lib/hash/keccak/keccak.cpp +++ b/src/lib/hash/keccak/keccak.cpp @@ -171,7 +171,7 @@ void Keccak_1600::add_data(const byte input[], size_t length) if(S_pos == bitrate / 8) { - keccak_f_1600(&S[0]); + keccak_f_1600(S.data()); S_pos = 0; } } @@ -184,7 +184,7 @@ void Keccak_1600::final_result(byte output[]) padding[0] = 0x01; padding[padding.size()-1] |= 0x80; - add_data(&padding[0], padding.size()); + add_data(padding.data(), padding.size()); /* * We never have to run the permutation again because we only support diff --git a/src/lib/hash/md2/md2.cpp b/src/lib/hash/md2/md2.cpp index 91d8154cf..6543cf1a0 100644 --- a/src/lib/hash/md2/md2.cpp +++ b/src/lib/hash/md2/md2.cpp @@ -43,7 +43,7 @@ void MD2::hash(const byte input[]) 0x9F, 0x11, 0x83, 0x14 }; buffer_insert(X, 16, input, hash_block_size()); - xor_buf(&X[32], &X[0], &X[16], hash_block_size()); + xor_buf(&X[32], X.data(), &X[16], hash_block_size()); byte T = 0; for(size_t i = 0; i != 18; ++i) @@ -73,7 +73,7 @@ void MD2::add_data(const byte input[], size_t length) if(position + length >= hash_block_size()) { - hash(&buffer[0]); + hash(buffer.data()); input += (hash_block_size() - position); length -= (hash_block_size() - position); while(length >= hash_block_size()) @@ -82,7 +82,7 @@ void MD2::add_data(const byte input[], size_t length) input += hash_block_size(); length -= hash_block_size(); } - copy_mem(&buffer[0], input, length); + copy_mem(buffer.data(), input, length); position = 0; } position += length; @@ -96,9 +96,9 @@ void MD2::final_result(byte output[]) for(size_t i = position; i != hash_block_size(); ++i) buffer[i] = static_cast<byte>(hash_block_size() - position); - hash(&buffer[0]); - hash(&checksum[0]); - copy_mem(output, &X[0], output_length()); + hash(buffer.data()); + hash(checksum.data()); + copy_mem(output, X.data(), output_length()); clear(); } diff --git a/src/lib/hash/md4/md4.cpp b/src/lib/hash/md4/md4.cpp index d9a47315e..cc11baafa 100644 --- a/src/lib/hash/md4/md4.cpp +++ b/src/lib/hash/md4/md4.cpp @@ -52,7 +52,7 @@ void MD4::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_le(&M[0], input, M.size()); + load_le(M.data(), input, M.size()); FF(A,B,C,D,M[ 0], 3); FF(D,A,B,C,M[ 1], 7); FF(C,D,A,B,M[ 2],11); FF(B,C,D,A,M[ 3],19); diff --git a/src/lib/hash/md4_x86_32/md4_x86_32.cpp b/src/lib/hash/md4_x86_32/md4_x86_32.cpp index 5cf7fd896..28860a369 100644 --- a/src/lib/hash/md4_x86_32/md4_x86_32.cpp +++ b/src/lib/hash/md4_x86_32/md4_x86_32.cpp @@ -29,7 +29,7 @@ void MD4_X86_32::compress_n(const byte input[], size_t blocks) { for(size_t i = 0; i != blocks; ++i) { - botan_md4_x86_32_compress(&digest[0], input, &M[0]); + botan_md4_x86_32_compress(digest.data(), input, M.data()); input += hash_block_size(); } } diff --git a/src/lib/hash/md5/md5.cpp b/src/lib/hash/md5/md5.cpp index 772e51478..2ce8df48a 100644 --- a/src/lib/hash/md5/md5.cpp +++ b/src/lib/hash/md5/md5.cpp @@ -65,7 +65,7 @@ void MD5::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_le(&M[0], input, M.size()); + load_le(M.data(), input, M.size()); FF(A,B,C,D,M[ 0], 7,0xD76AA478); FF(D,A,B,C,M[ 1],12,0xE8C7B756); FF(C,D,A,B,M[ 2],17,0x242070DB); FF(B,C,D,A,M[ 3],22,0xC1BDCEEE); diff --git a/src/lib/hash/md5_x86_32/md5_x86_32.cpp b/src/lib/hash/md5_x86_32/md5_x86_32.cpp index b5fd0c78f..083e90900 100644 --- a/src/lib/hash/md5_x86_32/md5_x86_32.cpp +++ b/src/lib/hash/md5_x86_32/md5_x86_32.cpp @@ -26,7 +26,7 @@ void MD5_X86_32::compress_n(const byte input[], size_t blocks) { for(size_t i = 0; i != blocks; ++i) { - botan_md5_x86_32_compress(&digest[0], input, &M[0]); + botan_md5_x86_32_compress(digest.data(), input, M.data()); input += hash_block_size(); } } diff --git a/src/lib/hash/mdx_hash/mdx_hash.cpp b/src/lib/hash/mdx_hash/mdx_hash.cpp index de7e45540..bd754d3cc 100644 --- a/src/lib/hash/mdx_hash/mdx_hash.cpp +++ b/src/lib/hash/mdx_hash/mdx_hash.cpp @@ -48,7 +48,7 @@ void MDx_HashFunction::add_data(const byte input[], size_t length) if(position + length >= buffer.size()) { - compress_n(&buffer[0], 1); + compress_n(buffer.data(), 1); input += (buffer.size() - position); length -= (buffer.size() - position); position = 0; @@ -76,13 +76,13 @@ void MDx_HashFunction::final_result(byte output[]) if(position >= buffer.size() - COUNT_SIZE) { - compress_n(&buffer[0], 1); + compress_n(buffer.data(), 1); zeroise(buffer); } write_count(&buffer[buffer.size() - COUNT_SIZE]); - compress_n(&buffer[0], 1); + compress_n(buffer.data(), 1); copy_out(output); clear(); } diff --git a/src/lib/hash/rmd128/rmd128.cpp b/src/lib/hash/rmd128/rmd128.cpp index 84ac393bb..7138d54d7 100644 --- a/src/lib/hash/rmd128/rmd128.cpp +++ b/src/lib/hash/rmd128/rmd128.cpp @@ -69,7 +69,7 @@ void RIPEMD_128::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_le(&M[0], input, M.size()); + load_le(M.data(), input, M.size()); u32bit A1 = digest[0], A2 = A1, B1 = digest[1], B2 = B1, C1 = digest[2], C2 = C1, D1 = digest[3], D2 = D1; diff --git a/src/lib/hash/rmd160/rmd160.cpp b/src/lib/hash/rmd160/rmd160.cpp index d58704fa0..dad1d367a 100644 --- a/src/lib/hash/rmd160/rmd160.cpp +++ b/src/lib/hash/rmd160/rmd160.cpp @@ -83,7 +83,7 @@ void RIPEMD_160::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_le(&M[0], input, M.size()); + load_le(M.data(), input, M.size()); u32bit A1 = digest[0], A2 = A1, B1 = digest[1], B2 = B1, C1 = digest[2], C2 = C1, D1 = digest[3], D2 = D1, diff --git a/src/lib/hash/sha1/sha160.cpp b/src/lib/hash/sha1/sha160.cpp index be52d0d57..96bc2c682 100644 --- a/src/lib/hash/sha1/sha160.cpp +++ b/src/lib/hash/sha1/sha160.cpp @@ -68,7 +68,7 @@ void SHA_160::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_be(&W[0], input, 16); + load_be(W.data(), input, 16); for(size_t j = 16; j != 80; j += 8) { diff --git a/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp b/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp index 449596db6..c5986221e 100644 --- a/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp +++ b/src/lib/hash/sha1_x86_32/sha1_x86_32.cpp @@ -26,7 +26,7 @@ void SHA_160_X86_32::compress_n(const byte input[], size_t blocks) { for(size_t i = 0; i != blocks; ++i) { - botan_sha160_x86_32_compress(&digest[0], input, &W[0]); + botan_sha160_x86_32_compress(digest.data(), input, W.data()); input += hash_block_size(); } } diff --git a/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp b/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp index 2f5e063bd..f2fbff1a6 100644 --- a/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp +++ b/src/lib/hash/sha1_x86_64/sha1_x86_64.cpp @@ -26,7 +26,7 @@ void SHA_160_X86_64::compress_n(const byte input[], size_t blocks) { for(size_t i = 0; i != blocks; ++i) { - botan_sha160_x86_64_compress(&digest[0], input, &W[0]); + botan_sha160_x86_64_compress(digest.data(), input, W.data()); input += hash_block_size(); } } diff --git a/src/lib/hash/skein/skein_512.cpp b/src/lib/hash/skein/skein_512.cpp index 1ade6bbc5..5e186b996 100644 --- a/src/lib/hash/skein/skein_512.cpp +++ b/src/lib/hash/skein/skein_512.cpp @@ -104,7 +104,7 @@ void Skein_512::ubi_512(const byte msg[], size_t msg_len) const size_t to_proc = std::min<size_t>(msg_len, 64); T[0] += to_proc; - load_le(&M[0], msg, to_proc / 8); + load_le(M.data(), msg, to_proc / 8); if(to_proc % 8) { @@ -132,7 +132,7 @@ void Skein_512::add_data(const byte input[], size_t length) buffer_insert(buffer, buf_pos, input, length); if(buf_pos + length > 64) { - ubi_512(&buffer[0], buffer.size()); + ubi_512(buffer.data(), buffer.size()); input += (64 - buf_pos); length -= (64 - buf_pos); @@ -158,7 +158,7 @@ void Skein_512::final_result(byte out[]) for(size_t i = buf_pos; i != buffer.size(); ++i) buffer[i] = 0; - ubi_512(&buffer[0], buf_pos); + ubi_512(buffer.data(), buf_pos); const byte counter[8] = { 0 }; diff --git a/src/lib/hash/tiger/tiger.cpp b/src/lib/hash/tiger/tiger.cpp index 86da18d24..c6dec2f33 100644 --- a/src/lib/hash/tiger/tiger.cpp +++ b/src/lib/hash/tiger/tiger.cpp @@ -51,7 +51,7 @@ void Tiger::compress_n(const byte input[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_le(&X[0], input, X.size()); + load_le(X.data(), input, X.size()); pass(A, B, C, X, 5); mix(X); pass(C, A, B, X, 7); mix(X); diff --git a/src/lib/hash/whirlpool/whirlpool.cpp b/src/lib/hash/whirlpool/whirlpool.cpp index 25b958e6d..573c49f91 100644 --- a/src/lib/hash/whirlpool/whirlpool.cpp +++ b/src/lib/hash/whirlpool/whirlpool.cpp @@ -27,7 +27,7 @@ void Whirlpool::compress_n(const byte in[], size_t blocks) for(size_t i = 0; i != blocks; ++i) { - load_be(&M[0], in, M.size()); + load_be(M.data(), in, M.size()); u64bit K0, K1, K2, K3, K4, K5, K6, K7; K0 = digest[0]; K1 = digest[1]; K2 = digest[2]; K3 = digest[3]; |