diff options
65 files changed, 218 insertions, 209 deletions
diff --git a/checks/common.h b/checks/common.h index 493e2fc74..6b504c454 100644 --- a/checks/common.h +++ b/checks/common.h @@ -69,12 +69,12 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator Fixed_Output_RNG(const Botan::SecureVector<byte>& in) { - buf.insert(buf.end(), in.begin(), in.begin() + in.size()); + buf.insert(buf.end(), in.begin(), in.end()); } Fixed_Output_RNG(const std::string& in_str) { Botan::SecureVector<byte> in = Botan::hex_decode(in_str); - buf.insert(buf.end(), in.begin(), in.begin() + in.size()); + buf.insert(buf.end(), in.begin(), in.end()); } Fixed_Output_RNG() {} diff --git a/checks/cvc_tests.cpp b/checks/cvc_tests.cpp index 5bd671ba6..ab0158351 100644 --- a/checks/cvc_tests.cpp +++ b/checks/cvc_tests.cpp @@ -42,7 +42,7 @@ void helper_write_file(EAC_Signed_Object const& to_write, std::string const& fil { SecureVector<byte> sv = to_write.BER_encode(); std::ofstream cert_file(file_path.c_str(), std::ios::binary); - cert_file.write((char*)sv.begin(), sv.size()); + cert_file.write((char*)&sv[0], sv.size()); cert_file.close(); } @@ -98,7 +98,7 @@ void test_enc_gen_selfsigned(RandomNumberGenerator& rng) std::ofstream cert_file; cert_file.open(TEST_DATA_DIR "/my_cv_cert.ber", std::ios::binary); //cert_file << der; // this is bad !!! - cert_file.write((char*)der.begin(), der.size()); + cert_file.write((char*)&der[0], der.size()); cert_file.close(); EAC1_1_CVC cert_in(TEST_DATA_DIR "/my_cv_cert.ber"); @@ -106,7 +106,7 @@ void test_enc_gen_selfsigned(RandomNumberGenerator& rng) // encoding it again while it has no dp SecureVector<byte> der2(cert_in.BER_encode()); std::ofstream cert_file2(TEST_DATA_DIR "/my_cv_cert2.ber", std::ios::binary); - cert_file2.write((char*)der2.begin(), der2.size()); + cert_file2.write((char*)&der2[0], der2.size()); cert_file2.close(); // read both and compare them std::ifstream cert_1_in(TEST_DATA_DIR "/my_cv_cert.ber"); @@ -205,7 +205,7 @@ void test_enc_gen_req(RandomNumberGenerator& rng) EAC1_1_Req req = CVC_EAC::create_cvc_req(key, opts.chr, opts.hash_alg, rng); SecureVector<byte> der(req.BER_encode()); std::ofstream req_file(TEST_DATA_DIR "/my_cv_req.ber", std::ios::binary); - req_file.write((char*)der.begin(), der.size()); + req_file.write((char*)&der[0], der.size()); req_file.close(); // read and check signature... @@ -262,7 +262,7 @@ void test_cvc_ado_creation(RandomNumberGenerator& rng) EAC1_1_Req req = CVC_EAC::create_cvc_req(req_key, opts.chr, opts.hash_alg, rng); SecureVector<byte> der(req.BER_encode()); std::ofstream req_file(TEST_DATA_DIR "/my_cv_req.ber", std::ios::binary); - req_file.write((char*)der.begin(), der.size()); + req_file.write((char*)&der[0], der.size()); req_file.close(); // create an ado with that req @@ -277,7 +277,7 @@ void test_cvc_ado_creation(RandomNumberGenerator& rng) std::ofstream ado_file(TEST_DATA_DIR "/ado", std::ios::binary); SecureVector<byte> ado_der(ado.BER_encode()); - ado_file.write((char*)ado_der.begin(), ado_der.size()); + ado_file.write((char*)&ado_der[0], ado_der.size()); ado_file.close(); // read it again and check the signature EAC1_1_ADO ado2(TEST_DATA_DIR "/ado"); @@ -333,7 +333,7 @@ void test_cvc_ado_comparison(RandomNumberGenerator& rng) CHECK_MESSAGE(ado != ado2, "ado's found to be equal where they are not"); // std::ofstream ado_file(TEST_DATA_DIR "/ado"); // SecureVector<byte> ado_der(ado.BER_encode()); - // ado_file.write((char*)ado_der.begin(), ado_der.size()); + // ado_file.write((char*)&ado_der[0], ado_der.size()); // ado_file.close(); // read it again and check the signature @@ -494,7 +494,7 @@ void test_cvc_chain(RandomNumberGenerator& rng) EAC1_1_CVC cvca_cert = DE_EAC::create_cvca(cvca_privk, hash, car, true, true, 12, rng); std::ofstream cvca_file(TEST_DATA_DIR "/cvc_chain_cvca.cer", std::ios::binary); SecureVector<byte> cvca_sv = cvca_cert.BER_encode(); - cvca_file.write((char*)cvca_sv.begin(), cvca_sv.size()); + cvca_file.write((char*)&cvca_sv[0], cvca_sv.size()); cvca_file.close(); ECDSA_PrivateKey cvca_privk2(rng, dom_pars); @@ -503,7 +503,7 @@ void test_cvc_chain(RandomNumberGenerator& rng) EAC1_1_CVC link12 = DE_EAC::link_cvca(cvca_cert, cvca_privk, cvca_cert2, rng); SecureVector<byte> link12_sv = link12.BER_encode(); std::ofstream link12_file(TEST_DATA_DIR "/cvc_chain_link12.cer", std::ios::binary); - link12_file.write((char*)link12_sv.begin(), link12_sv.size()); + link12_file.write((char*)&link12_sv[0], link12_sv.size()); link12_file.close(); // verify the link @@ -518,7 +518,7 @@ void test_cvc_chain(RandomNumberGenerator& rng) EAC1_1_Req dvca_req = DE_EAC::create_cvc_req(dvca_priv_key, ASN1_Chr("DEDVCAEPASS"), hash, rng); std::ofstream dvca_file(TEST_DATA_DIR "/cvc_chain_dvca_req.cer", std::ios::binary); SecureVector<byte> dvca_sv = dvca_req.BER_encode(); - dvca_file.write((char*)dvca_sv.begin(), dvca_sv.size()); + dvca_file.write((char*)&dvca_sv[0], dvca_sv.size()); dvca_file.close(); // sign the dvca_request @@ -532,7 +532,7 @@ void test_cvc_chain(RandomNumberGenerator& rng) EAC1_1_Req dvca_req2 = DE_EAC::create_cvc_req(dvca_priv_key2, ASN1_Chr("DEDVCAEPASS"), hash, rng); std::ofstream dvca_file2(TEST_DATA_DIR "/cvc_chain_dvca_req2.cer", std::ios::binary); SecureVector<byte> dvca_sv2 = dvca_req2.BER_encode(); - dvca_file2.write((char*)dvca_sv2.begin(), dvca_sv2.size()); + dvca_file2.write((char*)&dvca_sv2[0], dvca_sv2.size()); dvca_file2.close(); EAC1_1_ADO dvca_ado2 = CVC_EAC::create_ado_req(dvca_priv_key, dvca_req2, ASN1_Car(dvca_cert1.get_chr().iso_8859()), rng); diff --git a/checks/ec_tests.cpp b/checks/ec_tests.cpp index 39ca1ded5..1f31cb2cf 100644 --- a/checks/ec_tests.cpp +++ b/checks/ec_tests.cpp @@ -75,9 +75,9 @@ void test_point_turn_on_sp_red_mul() SecureVector<byte> sv_a_secp = hex_decode(a_secp); SecureVector<byte> sv_b_secp = hex_decode(b_secp); SecureVector<byte> sv_G_secp_comp = hex_decode(G_secp_comp); - BigInt bi_p_secp = BigInt::decode(sv_p_secp.begin(), sv_p_secp.size()); - BigInt bi_a_secp = BigInt::decode(sv_a_secp.begin(), sv_a_secp.size()); - BigInt bi_b_secp = BigInt::decode(sv_b_secp.begin(), sv_b_secp.size()); + BigInt bi_p_secp = BigInt::decode(&sv_p_secp[0], sv_p_secp.size()); + BigInt bi_a_secp = BigInt::decode(&sv_a_secp[0], sv_a_secp.size()); + BigInt bi_b_secp = BigInt::decode(&sv_b_secp[0], sv_b_secp.size()); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP(sv_G_secp_comp, secp160r1); @@ -139,9 +139,9 @@ void test_coordinates() SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1 (bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_comp, secp160r1 ); PointGFp p0 = p_G; @@ -214,9 +214,9 @@ void test_point_negative() SecureVector<byte> sv_a_secp = hex_decode ( a_secp ); SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_comp, secp160r1 ); @@ -326,9 +326,9 @@ void test_add_point() SecureVector<byte> sv_a_secp = hex_decode ( a_secp ); SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_comp, secp160r1 ); @@ -362,9 +362,9 @@ void test_sub_point() SecureVector<byte> sv_a_secp = hex_decode ( a_secp ); SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_comp, secp160r1 ); @@ -397,9 +397,9 @@ void test_mult_point() SecureVector<byte> sv_a_secp = hex_decode ( a_secp ); SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_comp, secp160r1 ); @@ -426,9 +426,9 @@ void test_basic_operations() SecureVector<byte> sv_a_secp = hex_decode ( a_secp ); SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_comp, secp160r1 ); @@ -490,9 +490,9 @@ void test_enc_dec_compressed_160() SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); @@ -519,9 +519,9 @@ void test_enc_dec_compressed_256() SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); @@ -550,9 +550,9 @@ void test_enc_dec_uncompressed_112() SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_uncomp = hex_decode ( G_secp_uncomp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); @@ -579,17 +579,17 @@ void test_enc_dec_uncompressed_521() SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_uncomp = hex_decode ( G_secp_uncomp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp160r1(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_uncomp, secp160r1 ); SecureVector<byte> sv_result = EC2OSP(p_G, PointGFp::UNCOMPRESSED); - std::string result = hex_encode(sv_result.begin(), sv_result.size()); - std::string exp_result = hex_encode(sv_G_secp_uncomp.begin(), sv_G_secp_uncomp.size()); + std::string result = hex_encode(&sv_result[0], sv_result.size()); + std::string exp_result = hex_encode(&sv_G_secp_uncomp[0], sv_G_secp_uncomp.size()); CHECK_MESSAGE( sv_result == sv_G_secp_uncomp, "\ncalc. result = " << result << "\nexp. result = " << exp_result << "\n"); } @@ -611,9 +611,9 @@ void test_enc_dec_uncompressed_521_prime_too_large() SecureVector<byte> sv_b_secp = hex_decode ( b_secp ); SecureVector<byte> sv_G_secp_uncomp = hex_decode ( G_secp_uncomp ); - BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); + BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); CurveGFp secp521r1 (bi_p_secp, bi_a_secp, bi_b_secp); std::auto_ptr<PointGFp> p_G; diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp index d9a1784fe..9cacad70a 100644 --- a/checks/ecdsa.cpp +++ b/checks/ecdsa.cpp @@ -33,7 +33,7 @@ namespace { std::string to_hex(const SecureVector<byte>& bin) { - return hex_encode(bin.begin(), bin.size()); + return hex_encode(&bin[0], bin.size()); } /** @@ -295,11 +295,11 @@ void test_create_and_verify(RandomNumberGenerator& rng) SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp ); SecureVector<byte> sv_order_g = hex_decode ( order_g ); - // BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() ); + // BigInt bi_p_secp = BigInt::decode ( &sv_p_secp[0], sv_p_secp.size() ); BigInt bi_p_secp("2117607112719756483104013348936480976596328609518055062007450442679169492999007105354629105748524349829824407773719892437896937279095106809"); - BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() ); - BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); - BigInt bi_order_g = BigInt::decode ( sv_order_g.begin(), sv_order_g.size() ); + BigInt bi_a_secp = BigInt::decode ( &sv_a_secp[0], sv_a_secp.size() ); + BigInt bi_b_secp = BigInt::decode ( &sv_b_secp[0], sv_b_secp.size() ); + BigInt bi_order_g = BigInt::decode ( &sv_order_g[0], sv_order_g.size() ); CurveGFp curve(bi_p_secp, bi_a_secp, bi_b_secp); PointGFp p_G = OS2ECP ( sv_G_secp_comp, curve ); diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 41344f104..41108d9ac 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -106,7 +106,7 @@ void benchmark_enc_dec(PK_Encryptor& enc, PK_Decryptor& dec, // Ensure for Raw, etc, it stays large if((i % 100) == 0) { - rng.randomize(plaintext.begin(), plaintext.size()); + rng.randomize(&plaintext[0], plaintext.size()); plaintext[0] |= 0x80; } @@ -143,7 +143,7 @@ void benchmark_sig_ver(PK_Verifier& ver, PK_Signer& sig, if((i % 100) == 0) { message.resize(48); - rng.randomize(message.begin(), message.size()); + rng.randomize(&message[0], message.size()); } sig_timer.start(); diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h index f7aa6f3d1..dc5e90b79 100644 --- a/src/alloc/secmem.h +++ b/src/alloc/secmem.h @@ -101,7 +101,11 @@ class MemoryRegion * @return reference to *this */ MemoryRegion<T>& operator=(const MemoryRegion<T>& other) - { if(this != &other) set(other); return (*this); } + { + if(this != &other) + set(&other[0], other.size()); + return (*this); + } /** * Copy the contents of an array of objects of type T into this buffer. @@ -126,6 +130,14 @@ class MemoryRegion { copy_mem(buf + off, in, (n > size() - off) ? (size() - off) : n); } /** + * Set the contents of this according to the argument. The size of + * this is increased if necessary. + * @param in the array of objects of type T to copy the contents from + * @param n the size of array in + */ + void set(const T in[], u32bit n) { resize(n); copy(in, n); } + + /** * Append data to the end of this buffer. * @param data the array containing the data to append * @param n the size of the array data @@ -144,7 +156,7 @@ class MemoryRegion * @param other the buffer containing the data to append */ void append(const MemoryRegion<T>& other) - { append(other.begin(), other.size()); } + { append(&other[0], other.size()); } /** * Reset this buffer to an empty buffer with size zero. @@ -187,21 +199,6 @@ class MemoryRegion void init(bool locking, u32bit length = 0) { alloc = Allocator::get(locking); resize(length); } - /** - * Set the contents of this according to the argument. The size of - * *this is increased if necessary. - * @param in the array of objects of type T to copy the contents from - * @param n the size of array in - */ - void set(const T in[], u32bit n) { resize(n); copy(in, n); } - - /** - * Set the contents of this according to the argument. The size of - * *this is increased if necessary. - * @param in the buffer to copy the contents from - */ - void set(const MemoryRegion<T>& in) { set(in.begin(), in.size()); } - private: T* allocate(u32bit n) { @@ -290,7 +287,11 @@ class MemoryVector : public MemoryRegion<T> * @return reference to *this */ MemoryVector<T>& operator=(const MemoryRegion<T>& in) - { if(this != &in) set(in); return (*this); } + { + if(this != &in) + set(&in[0], in.size()); + return (*this); + } /** * Create a buffer of the specified length. @@ -311,7 +312,7 @@ class MemoryVector : public MemoryRegion<T> * Copy constructor. */ MemoryVector(const MemoryRegion<T>& in) - { init(false); set(in); } + { init(false); set(&in[0], in.size()); } /** * Create a buffer whose content is the concatenation of two other @@ -320,7 +321,7 @@ class MemoryVector : public MemoryRegion<T> * @param in2 the contents to be appended to in1 */ MemoryVector(const MemoryRegion<T>& in1, const MemoryRegion<T>& in2) - { init(false); set(in1); append(in2); } + { init(false); set(&in1[0], in1.size()); append(in2); } }; /** @@ -344,7 +345,7 @@ class SecureVector : public MemoryRegion<T> * @return reference to *this */ SecureVector<T>& operator=(const MemoryRegion<T>& in) - { if(this != &in) set(in); return (*this); } + { if(this != &in) set(&in[0], in.size()); return (*this); } /** * Create a buffer of the specified length. @@ -363,9 +364,9 @@ class SecureVector : public MemoryRegion<T> { init(true, INITIAL_LEN); if(INITIAL_LEN) - copy(in, n); + copy(&in[0], n); else - set(in, n); + set(&in[0], n); } /** @@ -377,9 +378,9 @@ class SecureVector : public MemoryRegion<T> { init(true, INITIAL_LEN); if(INITIAL_LEN) - copy(in, in.size()); + copy(&in[0], in.size()); else - set(in); + set(&in[0], in.size()); } /** @@ -389,7 +390,7 @@ class SecureVector : public MemoryRegion<T> * @param in2 the contents to be appended to in1 */ SecureVector(const MemoryRegion<T>& in1, const MemoryRegion<T>& in2) - { init(true); set(in1); append(in2); } + { init(true); set(&in1[0], in1.size()); append(in2); } }; /** diff --git a/src/asn1/asn1_alt.cpp b/src/asn1/asn1_alt.cpp index 9fe159356..1fccf6ac0 100644 --- a/src/asn1/asn1_alt.cpp +++ b/src/asn1/asn1_alt.cpp @@ -217,7 +217,7 @@ void AlternativeName::decode_from(BER_Decoder& source) { if(obj.value.size() == 4) { - u32bit ip = load_be<u32bit>(obj.value.begin(), 0); + u32bit ip = load_be<u32bit>(&obj.value[0], 0); add_attribute("IP", ipv4_to_string(ip)); } } diff --git a/src/asn1/asn1_int.cpp b/src/asn1/asn1_int.cpp index 5e18f3961..75cb1f90c 100644 --- a/src/asn1/asn1_int.cpp +++ b/src/asn1/asn1_int.cpp @@ -45,7 +45,7 @@ SecureVector<byte> put_in_sequence(const MemoryRegion<byte>& contents) */ std::string to_string(const BER_Object& obj) { - return std::string(reinterpret_cast<const char*>(obj.value.begin()), + return std::string(reinterpret_cast<const char*>(&obj.value[0]), obj.value.size()); } diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp index dd173590f..0ce633c7a 100644 --- a/src/asn1/der_enc.cpp +++ b/src/asn1/der_enc.cpp @@ -180,7 +180,7 @@ DER_Encoder& DER_Encoder::end_explicit() */ DER_Encoder& DER_Encoder::raw_bytes(const MemoryRegion<byte>& val) { - return raw_bytes(val.begin(), val.size()); + return raw_bytes(&val[0], val.size()); } /* @@ -234,7 +234,7 @@ DER_Encoder& DER_Encoder::encode(const BigInt& n) DER_Encoder& DER_Encoder::encode(const MemoryRegion<byte>& bytes, ASN1_Tag real_type) { - return encode(bytes.begin(), bytes.size(), + return encode(&bytes[0], bytes.size(), real_type, real_type, UNIVERSAL); } @@ -277,7 +277,7 @@ DER_Encoder& DER_Encoder::encode(const BigInt& n, bool extra_zero = (n.bits() % 8 == 0); SecureVector<byte> contents(extra_zero + n.bytes()); - BigInt::encode(contents.begin() + extra_zero, n); + BigInt::encode(&contents[extra_zero], n); if(n < 0) { for(u32bit j = 0; j != contents.size(); ++j) @@ -297,7 +297,7 @@ DER_Encoder& DER_Encoder::encode(const MemoryRegion<byte>& bytes, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag) { - return encode(bytes.begin(), bytes.size(), + return encode(&bytes[0], bytes.size(), real_type, type_tag, class_tag); } @@ -364,7 +364,7 @@ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const MemoryRegion<byte>& rep_buf) { - const byte* rep = rep_buf.begin(); + const byte* rep = &rep_buf[0]; const u32bit rep_len = rep_buf.size(); return add_object(type_tag, class_tag, rep, rep_len); } diff --git a/src/block/des/des.cpp b/src/block/des/des.cpp index bbe564827..a24a1d445 100644 --- a/src/block/des/des.cpp +++ b/src/block/des/des.cpp @@ -203,7 +203,7 @@ void DES::decrypt_n(const byte in[], byte out[], u32bit blocks) const */ void DES::key_schedule(const byte key[], u32bit) { - des_key_schedule(round_key.begin(), key); + des_key_schedule(&round_key[0], key); } /* @@ -283,7 +283,7 @@ void TripleDES::key_schedule(const byte key[], u32bit length) if(length == 24) des_key_schedule(&round_key[64], key + 16); else - copy_mem(&round_key[64], round_key.begin(), 32); + copy_mem(&round_key[64], &round_key[0], 32); } } diff --git a/src/block/des/desx.cpp b/src/block/des/desx.cpp index d19d7da8a..cc97c4e7b 100644 --- a/src/block/des/desx.cpp +++ b/src/block/des/desx.cpp @@ -17,9 +17,9 @@ void DESX::encrypt_n(const byte in[], byte out[], u32bit blocks) const { for(u32bit i = 0; i != blocks; ++i) { - xor_buf(out, in, K1.begin(), BLOCK_SIZE); + xor_buf(out, in, &K1[0], BLOCK_SIZE); des.encrypt(out); - xor_buf(out, K2.begin(), BLOCK_SIZE); + xor_buf(out, &K2[0], BLOCK_SIZE); in += BLOCK_SIZE; out += BLOCK_SIZE; @@ -33,9 +33,9 @@ void DESX::decrypt_n(const byte in[], byte out[], u32bit blocks) const { for(u32bit i = 0; i != blocks; ++i) { - xor_buf(out, in, K2.begin(), BLOCK_SIZE); + xor_buf(out, in, &K2[0], BLOCK_SIZE); des.decrypt(out); - xor_buf(out, K1.begin(), BLOCK_SIZE); + xor_buf(out, &K1[0], BLOCK_SIZE); in += BLOCK_SIZE; out += BLOCK_SIZE; diff --git a/src/cert/cvc/ecdsa_sig.cpp b/src/cert/cvc/ecdsa_sig.cpp index e003bb369..6a44f6803 100644 --- a/src/cert/cvc/ecdsa_sig.cpp +++ b/src/cert/cvc/ecdsa_sig.cpp @@ -47,13 +47,11 @@ ECDSA_Signature decode_concatenation(const MemoryRegion<byte>& concat) if(concat.size() % 2 != 0) throw Invalid_Argument("Erroneous length of signature"); - u32bit rs_len = concat.size()/2; - SecureVector<byte> sv_r; - SecureVector<byte> sv_s; - sv_r.set(concat.begin(), rs_len); - sv_s.set(&concat[rs_len], rs_len); - BigInt r = BigInt::decode(sv_r, sv_r.size()); - BigInt s = BigInt::decode(sv_s, sv_s.size()); + const u32bit rs_len = concat.size() / 2; + + BigInt r = BigInt::decode(&concat[0], rs_len); + BigInt s = BigInt::decode(&concat[rs_len], rs_len); + return ECDSA_Signature(r, s); } diff --git a/src/cms/cms_dec.cpp b/src/cms/cms_dec.cpp index fdb9a4a54..c86e1d0ae 100644 --- a/src/cms/cms_dec.cpp +++ b/src/cms/cms_dec.cpp @@ -86,7 +86,7 @@ std::string CMS_Decoder::get_data() const { if(layer_type() != DATA) throw Invalid_State("CMS: Cannot retrieve data from non-DATA layer"); - return std::string((const char*)data.begin(), data.size()); + return std::string((const char*)&data[0], data.size()); } /* diff --git a/src/constructs/cryptobox/cryptobox.cpp b/src/constructs/cryptobox/cryptobox.cpp index 61fe51a88..0c37949bc 100644 --- a/src/constructs/cryptobox/cryptobox.cpp +++ b/src/constructs/cryptobox/cryptobox.cpp @@ -45,18 +45,22 @@ std::string encrypt(const byte input[], u32bit input_len, RandomNumberGenerator& rng) { SecureVector<byte> pbkdf_salt(PBKDF_SALT_LEN); - rng.randomize(pbkdf_salt.begin(), pbkdf_salt.size()); + rng.randomize(&pbkdf_salt[0], pbkdf_salt.size()); PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512)); - OctetString mk = pbkdf.derive_key(PBKDF_OUTPUT_LEN, passphrase, - &pbkdf_salt[0], pbkdf_salt.size(), - PBKDF_ITERATIONS); + OctetString master_key = pbkdf.derive_key( + PBKDF_OUTPUT_LEN, + passphrase, + &pbkdf_salt[0], + pbkdf_salt.size(), + PBKDF_ITERATIONS); - SymmetricKey cipher_key(mk.begin(), CIPHER_KEY_LEN); - SymmetricKey mac_key(mk.begin() + CIPHER_KEY_LEN, MAC_KEY_LEN); - InitializationVector iv(mk.begin() + CIPHER_KEY_LEN + MAC_KEY_LEN, - CIPHER_IV_LEN); + const byte* mk = master_key.begin(); + + SymmetricKey cipher_key(&mk[0], CIPHER_KEY_LEN); + SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN); + InitializationVector iv(&mk[CIPHER_KEY_LEN + MAC_KEY_LEN], CIPHER_IV_LEN); Pipe pipe(get_cipher("Serpent/CTR-BE", cipher_key, iv, ENCRYPTION), new Fork( @@ -89,8 +93,7 @@ std::string encrypt(const byte input[], u32bit input_len, pipe.read(out_buf + VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN, ciphertext_len, 0); - return PEM_Code::encode(out_buf.begin(), out_buf.size(), - "BOTAN CRYPTOBOX MESSAGE"); + return PEM_Code::encode(out_buf, "BOTAN CRYPTOBOX MESSAGE"); } std::string decrypt(const byte input[], u32bit input_len, @@ -112,14 +115,18 @@ std::string decrypt(const byte input[], u32bit input_len, PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512)); - OctetString mk = pbkdf.derive_key(PBKDF_OUTPUT_LEN, passphrase, - &pbkdf_salt[0], pbkdf_salt.size(), - PBKDF_ITERATIONS); + OctetString master_key = pbkdf.derive_key( + PBKDF_OUTPUT_LEN, + passphrase, + &pbkdf_salt[0], + pbkdf_salt.size(), + PBKDF_ITERATIONS); + + const byte* mk = master_key.begin(); - SymmetricKey cipher_key(mk.begin(), CIPHER_KEY_LEN); - SymmetricKey mac_key(mk.begin() + CIPHER_KEY_LEN, MAC_KEY_LEN); - InitializationVector iv(mk.begin() + CIPHER_KEY_LEN + MAC_KEY_LEN, - CIPHER_IV_LEN); + SymmetricKey cipher_key(&mk[0], CIPHER_KEY_LEN); + SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN); + InitializationVector iv(&mk[CIPHER_KEY_LEN + MAC_KEY_LEN], CIPHER_IV_LEN); Pipe pipe(new Fork( get_cipher("Serpent/CTR-BE", cipher_key, iv, DECRYPTION), diff --git a/src/constructs/passhash/passhash9.cpp b/src/constructs/passhash/passhash9.cpp index 6618f36fa..c120b39c5 100644 --- a/src/constructs/passhash/passhash9.cpp +++ b/src/constructs/passhash/passhash9.cpp @@ -139,8 +139,8 @@ bool check_passhash9(const std::string& pass, const std::string& hash) &bin[ALGID_BYTES + WORKFACTOR_BYTES], SALT_BYTES, kdf_iterations).bits_of(); - return same_mem(cmp.begin(), - bin.begin() + ALGID_BYTES + WORKFACTOR_BYTES + SALT_BYTES, + return same_mem(&cmp[0], + &bin[ALGID_BYTES + WORKFACTOR_BYTES + SALT_BYTES], PASSHASH9_PBKDF_OUTPUT_LEN); } diff --git a/src/constructs/tss/tss.cpp b/src/constructs/tss/tss.cpp index ad45cfcec..1ae027a78 100644 --- a/src/constructs/tss/tss.cpp +++ b/src/constructs/tss/tss.cpp @@ -192,8 +192,8 @@ RTSS_Share::reconstruct(const std::vector<RTSS_Share>& shares) if(shares[i].size() < RTSS_HEADER_SIZE) throw Decoding_Error("Missing or malformed RTSS header"); - if(!same_mem(shares[0].contents.begin(), - shares[i].contents.begin(), RTSS_HEADER_SIZE)) + if(!same_mem(&shares[0].contents[0], + &shares[i].contents[0], RTSS_HEADER_SIZE)) throw Decoding_Error("Different RTSS headers detected"); } @@ -250,7 +250,7 @@ RTSS_Share::reconstruct(const std::vector<RTSS_Share>& shares) hash->update(secret, secret_len); SecureVector<byte> hash_check = hash->final(); - if(!same_mem(hash_check.begin(), secret + secret_len, hash->OUTPUT_LENGTH)) + if(!same_mem(&hash_check[0], secret + secret_len, hash->OUTPUT_LENGTH)) throw Decoding_Error("RTSS hash check failed"); return SecureVector<byte>(secret, secret_len); diff --git a/src/entropy/cryptoapi_rng/es_capi.cpp b/src/entropy/cryptoapi_rng/es_capi.cpp index 367166c62..f3a94ad34 100644 --- a/src/entropy/cryptoapi_rng/es_capi.cpp +++ b/src/entropy/cryptoapi_rng/es_capi.cpp @@ -61,11 +61,11 @@ void Win32_CAPI_EntropySource::poll(Entropy_Accumulator& accum) { CSP_Handle csp(prov_types[j]); - u32bit got = csp.gen_random(io_buffer.begin(), io_buffer.size()); + u32bit got = csp.gen_random(&io_buffer[0], io_buffer.size()); if(got) { - accum.add(io_buffer.begin(), io_buffer.size(), 8); + accum.add(&io_buffer[0], io_buffer.size(), 8); break; } } diff --git a/src/entropy/dev_random/dev_random.cpp b/src/entropy/dev_random/dev_random.cpp index d0babfd1e..a942806d0 100644 --- a/src/entropy/dev_random/dev_random.cpp +++ b/src/entropy/dev_random/dev_random.cpp @@ -111,12 +111,12 @@ void Device_EntropySource::poll(Entropy_Accumulator& accum) for(size_t i = 0; i != devices.size(); ++i) { - u32bit got = devices[i].get(io_buffer.begin(), io_buffer.size(), + u32bit got = devices[i].get(&io_buffer[0], io_buffer.size(), read_wait_ms); if(got) { - accum.add(io_buffer.begin(), got, 8); + accum.add(&io_buffer[0], got, 8); break; } } diff --git a/src/entropy/egd/es_egd.cpp b/src/entropy/egd/es_egd.cpp index 29880a544..7efcf204d 100644 --- a/src/entropy/egd/es_egd.cpp +++ b/src/entropy/egd/es_egd.cpp @@ -143,11 +143,11 @@ void EGD_EntropySource::poll(Entropy_Accumulator& accum) for(size_t i = 0; i != sockets.size(); ++i) { - u32bit got = sockets[i].read(io_buffer.begin(), io_buffer.size()); + u32bit got = sockets[i].read(&io_buffer[0], io_buffer.size()); if(got) { - accum.add(io_buffer.begin(), got, 8); + accum.add(&io_buffer[0], got, 8); break; } } diff --git a/src/entropy/proc_walk/es_ftw.cpp b/src/entropy/proc_walk/es_ftw.cpp index 53e39d834..ce359f03f 100644 --- a/src/entropy/proc_walk/es_ftw.cpp +++ b/src/entropy/proc_walk/es_ftw.cpp @@ -146,11 +146,11 @@ void FTW_EntropySource::poll(Entropy_Accumulator& accum) break; } - ssize_t got = ::read(fd, io_buffer.begin(), io_buffer.size()); + ssize_t got = ::read(fd, &io_buffer[0], io_buffer.size()); ::close(fd); if(got > 0) - accum.add(io_buffer.begin(), got, .01); + accum.add(&io_buffer[0], got, .01); if(accum.polling_goal_achieved()) break; diff --git a/src/entropy/unix_procs/es_unix.cpp b/src/entropy/unix_procs/es_unix.cpp index 5756f93dd..8c6e097c7 100644 --- a/src/entropy/unix_procs/es_unix.cpp +++ b/src/entropy/unix_procs/es_unix.cpp @@ -106,7 +106,7 @@ void Unix_EntropySource::poll(Entropy_Accumulator& accum) u32bit got_this_loop = pipe.read(io_buffer, io_buffer.size()); got_from_src += got_this_loop; - accum.add(io_buffer.begin(), got_this_loop, .005); + accum.add(&io_buffer[0], got_this_loop, .005); } sources[j].working = (got_from_src >= MINIMAL_WORKING) ? true : false; diff --git a/src/filters/data_src.cpp b/src/filters/data_src.cpp index eceb0184a..073be3f47 100644 --- a/src/filters/data_src.cpp +++ b/src/filters/data_src.cpp @@ -128,7 +128,7 @@ u32bit DataSource_Stream::peek(byte out[], u32bit length, u32bit offset) const if(offset) { SecureVector<byte> buf(offset); - source.read(reinterpret_cast<char*>(buf.begin()), buf.size()); + source.read(reinterpret_cast<char*>(&buf[0]), buf.size()); if(source.bad()) throw Stream_IO_Error("DataSource_Stream::peek: Source failure"); got = source.gcount(); diff --git a/src/filters/filter.h b/src/filters/filter.h index d5aa9725b..a0b2e1c7a 100644 --- a/src/filters/filter.h +++ b/src/filters/filter.h @@ -65,7 +65,7 @@ class BOTAN_DLL Filter /** * @param in some input for the filter */ - void send(const MemoryRegion<byte>& in) { send(in.begin(), in.size()); } + void send(const MemoryRegion<byte>& in) { send(&in[0], in.size()); } Filter(); private: Filter(const Filter&) {} diff --git a/src/filters/modes/cts/cts.cpp b/src/filters/modes/cts/cts.cpp index c404d8f33..fd118bc3b 100644 --- a/src/filters/modes/cts/cts.cpp +++ b/src/filters/modes/cts/cts.cpp @@ -88,7 +88,7 @@ void CTS_Encryption::write(const byte input[], u32bit length) } else { - copy_mem(buffer.begin(), buffer + cipher->BLOCK_SIZE, cipher->BLOCK_SIZE); + copy_mem(&buffer[0], buffer + cipher->BLOCK_SIZE, cipher->BLOCK_SIZE); position = cipher->BLOCK_SIZE; } buffer.copy(position, input, length); @@ -191,7 +191,7 @@ void CTS_Decryption::write(const byte input[], u32bit length) } else { - copy_mem(buffer.begin(), buffer + cipher->BLOCK_SIZE, cipher->BLOCK_SIZE); + copy_mem(&buffer[0], buffer + cipher->BLOCK_SIZE, cipher->BLOCK_SIZE); position = cipher->BLOCK_SIZE; } buffer.copy(position, input, length); diff --git a/src/filters/modes/xts/xts.cpp b/src/filters/modes/xts/xts.cpp index 608c315ff..e40dd3cf5 100644 --- a/src/filters/modes/xts/xts.cpp +++ b/src/filters/modes/xts/xts.cpp @@ -98,7 +98,7 @@ void XTS_Encryption::set_iv(const InitializationVector& iv) for(u32bit i = 1; i < blocks_in_tweak; ++i) { tweak.copy(i*cipher->BLOCK_SIZE, - tweak.begin() + (i-1)*cipher->BLOCK_SIZE, + &tweak[(i-1)*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); @@ -158,7 +158,7 @@ void XTS_Encryption::buffered_block(const byte input[], u32bit length) for(u32bit i = 1; i < blocks_in_tweak; ++i) { tweak.copy(i*cipher->BLOCK_SIZE, - tweak.begin() + (i-1)*cipher->BLOCK_SIZE, + &tweak[(i-1)*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); @@ -270,7 +270,7 @@ void XTS_Decryption::set_iv(const InitializationVector& iv) for(u32bit i = 1; i < blocks_in_tweak; ++i) { tweak.copy(i*cipher->BLOCK_SIZE, - tweak.begin() + (i-1)*cipher->BLOCK_SIZE, + &tweak[(i-1)*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); @@ -331,7 +331,7 @@ void XTS_Decryption::buffered_block(const byte input[], u32bit input_length) for(u32bit i = 1; i < blocks_in_tweak; ++i) { tweak.copy(i*cipher->BLOCK_SIZE, - tweak.begin() + (i-1)*cipher->BLOCK_SIZE, + &tweak[(i-1)*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); poly_double(&tweak[i*cipher->BLOCK_SIZE], cipher->BLOCK_SIZE); diff --git a/src/filters/pipe.cpp b/src/filters/pipe.cpp index 22718cd8c..cba5449de 100644 --- a/src/filters/pipe.cpp +++ b/src/filters/pipe.cpp @@ -127,7 +127,7 @@ void Pipe::process_msg(const byte input[], u32bit length) */ void Pipe::process_msg(const MemoryRegion<byte>& input) { - process_msg(input.begin(), input.size()); + process_msg(&input[0], input.size()); } /* diff --git a/src/filters/pipe_io.cpp b/src/filters/pipe_io.cpp index c57be6d53..bf4a05642 100644 --- a/src/filters/pipe_io.cpp +++ b/src/filters/pipe_io.cpp @@ -19,7 +19,7 @@ std::ostream& operator<<(std::ostream& stream, Pipe& pipe) while(stream.good() && pipe.remaining()) { u32bit got = pipe.read(buffer, buffer.size()); - stream.write(reinterpret_cast<const char*>(buffer.begin()), got); + stream.write(reinterpret_cast<const char*>(&buffer[0]), got); } if(!stream.good()) throw Stream_IO_Error("Pipe output operator (iostream) has failed"); @@ -34,7 +34,7 @@ std::istream& operator>>(std::istream& stream, Pipe& pipe) SecureVector<byte> buffer(DEFAULT_BUFFERSIZE); while(stream.good()) { - stream.read(reinterpret_cast<char*>(buffer.begin()), buffer.size()); + stream.read(reinterpret_cast<char*>(&buffer[0]), buffer.size()); pipe.write(buffer, stream.gcount()); } if(stream.bad() || (stream.fail() && !stream.eof())) diff --git a/src/filters/pipe_rw.cpp b/src/filters/pipe_rw.cpp index 20119c75b..ebbfb101a 100644 --- a/src/filters/pipe_rw.cpp +++ b/src/filters/pipe_rw.cpp @@ -43,7 +43,7 @@ void Pipe::write(const byte input[], u32bit length) */ void Pipe::write(const MemoryRegion<byte>& input) { - write(input.begin(), input.size()); + write(&input[0], input.size()); } /* @@ -125,7 +125,7 @@ std::string Pipe::read_all_as_string(message_id msg) u32bit got = read(buffer, buffer.size(), msg); if(got == 0) break; - str.append(reinterpret_cast<const char*>(buffer.begin()), got); + str.append(reinterpret_cast<const char*>(&buffer[0]), got); } return str; diff --git a/src/hash/bmw/bmw_512.cpp b/src/hash/bmw/bmw_512.cpp index a9b580ca6..f511e516b 100644 --- a/src/hash/bmw/bmw_512.cpp +++ b/src/hash/bmw/bmw_512.cpp @@ -143,7 +143,7 @@ void BMW_512::compress_n(const byte input[], u32bit blocks) { for(u32bit i = 0; i != blocks; ++i) { - load_le(M.begin(), input, M.size()); + load_le(&M[0], input, M.size()); BMW_512_compress(H, M, Q); diff --git a/src/hash/gost_3411/gost_3411.cpp b/src/hash/gost_3411/gost_3411.cpp index 7e6fd8fac..ad874fe8a 100644 --- a/src/hash/gost_3411/gost_3411.cpp +++ b/src/hash/gost_3411/gost_3411.cpp @@ -45,7 +45,7 @@ void GOST_34_11::add_data(const byte input[], u32bit length) if(position + length >= HASH_BLOCK_SIZE) { - compress_n(buffer.begin(), 1); + compress_n(&buffer[0], 1); input += (HASH_BLOCK_SIZE - position); length -= (HASH_BLOCK_SIZE - position); position = 0; @@ -219,7 +219,7 @@ void GOST_34_11::final_result(byte out[]) { if(position) { - clear_mem(buffer.begin() + position, buffer.size() - position); + clear_mem(&buffer[0] + position, buffer.size() - position); compress_n(buffer, 1); } @@ -232,7 +232,7 @@ void GOST_34_11::final_result(byte out[]) compress_n(length_buf, 1); compress_n(sum_buf, 1); - copy_mem(out, hash.begin(), 32); + copy_mem(out, &hash[0], 32); clear(); } diff --git a/src/hash/has160/has160.cpp b/src/hash/has160/has160.cpp index fd39e7ea0..5786ae0ee 100644 --- a/src/hash/has160/has160.cpp +++ b/src/hash/has160/has160.cpp @@ -67,7 +67,7 @@ void HAS_160::compress_n(const byte input[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_le(X.begin(), input, 16); + load_le(&X[0], 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/hash/md2/md2.cpp b/src/hash/md2/md2.cpp index b3ccae6df..376a95e93 100644 --- a/src/hash/md2/md2.cpp +++ b/src/hash/md2/md2.cpp @@ -66,7 +66,7 @@ void MD2::add_data(const byte input[], u32bit length) buffer.copy(position, input, length); if(position + length >= HASH_BLOCK_SIZE) { - hash(buffer.begin()); + hash(&buffer[0]); input += (HASH_BLOCK_SIZE - position); length -= (HASH_BLOCK_SIZE - position); while(length >= HASH_BLOCK_SIZE) @@ -90,7 +90,7 @@ void MD2::final_result(byte output[]) buffer[j] = static_cast<byte>(HASH_BLOCK_SIZE - position); hash(buffer); hash(checksum); - copy_mem(output, X.begin(), OUTPUT_LENGTH); + copy_mem(output, &X[0], OUTPUT_LENGTH); clear(); } diff --git a/src/hash/md4/md4.cpp b/src/hash/md4/md4.cpp index edba1d08a..326ca8eba 100644 --- a/src/hash/md4/md4.cpp +++ b/src/hash/md4/md4.cpp @@ -51,7 +51,7 @@ void MD4::compress_n(const byte input[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_le(M.begin(), input, M.size()); + load_le(&M[0], 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/hash/md5/md5.cpp b/src/hash/md5/md5.cpp index 104155e9d..b1745b944 100644 --- a/src/hash/md5/md5.cpp +++ b/src/hash/md5/md5.cpp @@ -64,7 +64,7 @@ void MD5::compress_n(const byte input[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_le(M.begin(), input, M.size()); + load_le(&M[0], 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/hash/mdx_hash/mdx_hash.cpp b/src/hash/mdx_hash/mdx_hash.cpp index ffca0d93b..69341c53f 100644 --- a/src/hash/mdx_hash/mdx_hash.cpp +++ b/src/hash/mdx_hash/mdx_hash.cpp @@ -47,7 +47,7 @@ void MDx_HashFunction::add_data(const byte input[], u32bit length) if(position + length >= HASH_BLOCK_SIZE) { - compress_n(buffer.begin(), 1); + compress_n(&buffer[0], 1); input += (HASH_BLOCK_SIZE - position); length -= (HASH_BLOCK_SIZE - position); position = 0; diff --git a/src/hash/rmd128/rmd128.cpp b/src/hash/rmd128/rmd128.cpp index 9e0f6701e..3e7eb9143 100644 --- a/src/hash/rmd128/rmd128.cpp +++ b/src/hash/rmd128/rmd128.cpp @@ -68,7 +68,7 @@ void RIPEMD_128::compress_n(const byte input[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_le(M.begin(), input, M.size()); + load_le(&M[0], 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/hash/rmd160/rmd160.cpp b/src/hash/rmd160/rmd160.cpp index 4975814f4..f832d4ec1 100644 --- a/src/hash/rmd160/rmd160.cpp +++ b/src/hash/rmd160/rmd160.cpp @@ -82,7 +82,7 @@ void RIPEMD_160::compress_n(const byte input[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_le(M.begin(), input, M.size()); + load_le(&M[0], 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/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp index 1e57f0cf4..0b3d7c346 100644 --- a/src/hash/sha1/sha160.cpp +++ b/src/hash/sha1/sha160.cpp @@ -61,7 +61,7 @@ void SHA_160::compress_n(const byte input[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_be(W.begin(), input, 16); + load_be(&W[0], input, 16); for(u32bit j = 16; j != 80; j += 8) { diff --git a/src/hash/sha2/sha2_32.cpp b/src/hash/sha2/sha2_32.cpp index a18a4d8c4..acd06061e 100644 --- a/src/hash/sha2/sha2_32.cpp +++ b/src/hash/sha2/sha2_32.cpp @@ -56,7 +56,7 @@ void sha2_32_compress(MemoryRegion<u32bit>& W, for(u32bit i = 0; i != blocks; ++i) { - load_be(W.begin(), input, 16); + load_be(&W[0], input, 16); for(u32bit j = 16; j != 64; j += 8) { diff --git a/src/hash/sha2/sha2_64.cpp b/src/hash/sha2/sha2_64.cpp index aecf9a0db..5ca78173c 100644 --- a/src/hash/sha2/sha2_64.cpp +++ b/src/hash/sha2/sha2_64.cpp @@ -55,7 +55,7 @@ void sha2_64_compress(MemoryRegion<u64bit>& W, for(u32bit i = 0; i != blocks; ++i) { - load_be(W.begin(), input, 16); + load_be(&W[0], input, 16); for(u32bit j = 16; j != 80; j += 8) { diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp index 1fdd9fbf6..dabaa5da2 100644 --- a/src/hash/skein/skein_512.cpp +++ b/src/hash/skein/skein_512.cpp @@ -240,7 +240,7 @@ void Skein_512::final_result(byte out[]) { const u32bit to_proc = std::min<u32bit>(out_bytes, 64); - H_out.copy(H.begin(), 8); + H_out.copy(&H[0], 8); reset_tweak(T, SKEIN_OUTPUT, true); ubi_512(H_out, T, counter, sizeof(counter)); diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp index 1812abf12..dd41841c9 100644 --- a/src/hash/tiger/tiger.cpp +++ b/src/hash/tiger/tiger.cpp @@ -38,7 +38,7 @@ void Tiger::compress_n(const byte input[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_le(X.begin(), input, X.size()); + load_le(&X[0], input, X.size()); pass(A, B, C, X, 5); mix(X); pass(C, A, B, X, 7); mix(X); diff --git a/src/hash/whirlpool/whrlpool.cpp b/src/hash/whirlpool/whrlpool.cpp index 6f62695c8..fcd244ce2 100644 --- a/src/hash/whirlpool/whrlpool.cpp +++ b/src/hash/whirlpool/whrlpool.cpp @@ -25,7 +25,7 @@ void Whirlpool::compress_n(const byte in[], u32bit blocks) for(u32bit i = 0; i != blocks; ++i) { - load_be(M.begin(), in, M.size()); + load_be(&M[0], in, M.size()); u64bit K0, K1, K2, K3, K4, K5, K6, K7; K0 = digest[0]; K1 = digest[1]; K2 = digest[2]; K3 = digest[3]; diff --git a/src/kdf/kdf.cpp b/src/kdf/kdf.cpp index 4be8475df..86f5f2476 100644 --- a/src/kdf/kdf.cpp +++ b/src/kdf/kdf.cpp @@ -28,7 +28,7 @@ SecureVector<byte> KDF::derive_key(u32bit key_len, const MemoryRegion<byte>& secret, const byte salt[], u32bit salt_len) const { - return derive_key(key_len, secret.begin(), secret.size(), + return derive_key(key_len, &secret[0], secret.size(), salt, salt_len); } @@ -39,8 +39,8 @@ SecureVector<byte> KDF::derive_key(u32bit key_len, const MemoryRegion<byte>& secret, const MemoryRegion<byte>& salt) const { - return derive_key(key_len, secret.begin(), secret.size(), - salt.begin(), salt.size()); + return derive_key(key_len, &secret[0], secret.size(), + &salt[0], salt.size()); } /* diff --git a/src/kdf/mgf1/mgf1.cpp b/src/kdf/mgf1/mgf1.cpp index 340e87a7c..509a411fa 100644 --- a/src/kdf/mgf1/mgf1.cpp +++ b/src/kdf/mgf1/mgf1.cpp @@ -30,7 +30,7 @@ void MGF1::mask(const byte in[], u32bit in_len, byte out[], SecureVector<byte> buffer = hash->final(); u32bit xored = std::min(buffer.size(), out_len); - xor_buf(out, buffer.begin(), xored); + xor_buf(out, &buffer[0], xored); out += xored; out_len -= xored; diff --git a/src/mac/cbc_mac/cbc_mac.cpp b/src/mac/cbc_mac/cbc_mac.cpp index 206bce55c..387737eac 100644 --- a/src/mac/cbc_mac/cbc_mac.cpp +++ b/src/mac/cbc_mac/cbc_mac.cpp @@ -46,7 +46,7 @@ void CBC_MAC::final_result(byte mac[]) if(position) e->encrypt(state); - copy_mem(mac, state.begin(), state.size()); + copy_mem(mac, &state[0], state.size()); zeroise(state); position = 0; } diff --git a/src/math/bigint/big_io.cpp b/src/math/bigint/big_io.cpp index b50fcceff..f3e7fb861 100644 --- a/src/math/bigint/big_io.cpp +++ b/src/math/bigint/big_io.cpp @@ -31,7 +31,7 @@ std::ostream& operator<<(std::ostream& stream, const BigInt& n) u32bit skip = 0; while(buffer[skip] == '0' && skip < buffer.size()) ++skip; - stream.write(reinterpret_cast<const char*>(buffer.begin()) + skip, + stream.write(reinterpret_cast<const char*>(&buffer[0]) + skip, buffer.size() - skip); } if(!stream.good()) diff --git a/src/math/bigint/big_ops2.cpp b/src/math/bigint/big_ops2.cpp index 193c00e32..554fb1793 100644 --- a/src/math/bigint/big_ops2.cpp +++ b/src/math/bigint/big_ops2.cpp @@ -32,7 +32,7 @@ BigInt& BigInt::operator+=(const BigInt& y) { SecureVector<word> z(reg_size - 1); bigint_sub3(z, y.data(), reg_size - 1, data(), x_sw); - copy_mem(get_reg().begin(), z.begin(), z.size()); + copy_mem(®[0], &z[0], z.size()); set_sign(y.sign()); } else if(relative_size == 0) diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h index 9ce71aeca..cd6997698 100644 --- a/src/math/bigint/bigint.h +++ b/src/math/bigint/bigint.h @@ -291,7 +291,7 @@ class BOTAN_DLL BigInt */ u32bit sig_words() const { - const word* x = reg.begin(); + const word* x = ®[0]; u32bit sig = reg.size(); while(sig && (x[sig-1] == 0)) @@ -316,7 +316,7 @@ class BOTAN_DLL BigInt * @result a pointer to the start of the internal register of * the integer value */ - const word* data() const { return reg.begin(); } + const word* data() const { return ®[0]; } /** * return a reference to the internal register containing the value diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index 93e3392ea..b593443f7 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -56,7 +56,7 @@ void PointGFp::monty_mult(BigInt& z, p.data(), p_size, p_dash); z.get_reg().resize(p_size); - copy_mem(z.get_reg().begin(), &workspace[p_size], p_size); + copy_mem(&z.get_reg()[0], &workspace[p_size], p_size); } // Montgomery squaring @@ -82,7 +82,7 @@ void PointGFp::monty_sqr(BigInt& z, const BigInt& x, p.data(), p_size, p_dash); z.get_reg().resize(p_size); - copy_mem(z.get_reg().begin(), &workspace[p_size], p_size); + copy_mem(&z.get_reg()[0], &workspace[p_size], p_size); } // Point addition @@ -475,8 +475,8 @@ SecureVector<byte> EC2OSP(const PointGFp& point, byte format) SecureVector<byte> result(2*p_bytes+1); result[0] = 4; - result.copy(1, bX.begin(), p_bytes); - result.copy(p_bytes+1, bY.begin(), p_bytes); + result.copy(1, &bX[0], p_bytes); + result.copy(p_bytes+1, &bY[0], p_bytes); return result; } else if(format == PointGFp::COMPRESSED) @@ -484,7 +484,7 @@ SecureVector<byte> EC2OSP(const PointGFp& point, byte format) SecureVector<byte> result(p_bytes+1); result[0] = 2; - result.copy(1, bX.begin(), bX.size()); + result.copy(1, &bX[0], bX.size()); if(y.get_bit(0)) result[0] |= 1; @@ -496,8 +496,8 @@ SecureVector<byte> EC2OSP(const PointGFp& point, byte format) SecureVector<byte> result(2*p_bytes+1); result[0] = 6; - result.copy(1, bX.begin(), bX.size()); - result.copy(p_bytes+1, bY.begin(), bY.size()); + result.copy(1, &bX[0], bX.size()); + result.copy(p_bytes+1, &bY[0], bY.size()); if(y.get_bit(0)) result[0] |= 1; diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp index 80582eaa8..b565d7a21 100644 --- a/src/math/numbertheory/powm_mnt.cpp +++ b/src/math/numbertheory/powm_mnt.cpp @@ -20,7 +20,7 @@ inline void montgomery_reduce(BigInt& out, MemoryRegion<word>& z_buf, const BigInt& x_bn, u32bit x_size, word u) { const word* x = x_bn.data(); - word* z = z_buf.begin(); + word* z = &z_buf[0]; u32bit z_size = z_buf.size(); bigint_monty_redc(z, z_size, x, x_size, u); @@ -52,7 +52,7 @@ void Montgomery_Exponentiator::set_base(const BigInt& base) SecureVector<word> workspace(z.size()); g[0] = (base >= modulus) ? (base % modulus) : base; - bigint_mul(z.begin(), z.size(), workspace, + bigint_mul(&z[0], z.size(), workspace, g[0].data(), g[0].size(), g[0].sig_words(), R2.data(), R2.size(), R2.sig_words()); @@ -67,7 +67,7 @@ void Montgomery_Exponentiator::set_base(const BigInt& base) const u32bit y_sig = y.sig_words(); zeroise(z); - bigint_mul(z.begin(), z.size(), workspace, + bigint_mul(&z[0], z.size(), workspace, x.data(), x.size(), x_sig, y.data(), y.size(), y_sig); @@ -91,7 +91,7 @@ BigInt Montgomery_Exponentiator::execute() const for(u32bit k = 0; k != window_bits; ++k) { zeroise(z); - bigint_sqr(z.begin(), z.size(), workspace, + bigint_sqr(&z[0], z.size(), workspace, x.data(), x.size(), x.sig_words()); montgomery_reduce(x, z, modulus, mod_words, mod_prime); @@ -103,7 +103,7 @@ BigInt Montgomery_Exponentiator::execute() const const BigInt& y = g[nibble-1]; zeroise(z); - bigint_mul(z.begin(), z.size(), workspace, + bigint_mul(&z[0], z.size(), workspace, x.data(), x.size(), x.sig_words(), y.data(), y.size(), y.sig_words()); diff --git a/src/pbkdf/pbkdf2/pbkdf2.cpp b/src/pbkdf/pbkdf2/pbkdf2.cpp index 6f6a514f8..d234fa7f0 100644 --- a/src/pbkdf/pbkdf2/pbkdf2.cpp +++ b/src/pbkdf/pbkdf2/pbkdf2.cpp @@ -35,7 +35,7 @@ OctetString PKCS5_PBKDF2::derive_key(u32bit key_len, SecureVector<byte> key(key_len); - byte* T = key.begin(); + byte* T = &key[0]; u32bit counter = 1; while(key_len) diff --git a/src/pk_pad/emsa4/emsa4.cpp b/src/pk_pad/emsa4/emsa4.cpp index df4005aad..41b1e6971 100644 --- a/src/pk_pad/emsa4/emsa4.cpp +++ b/src/pk_pad/emsa4/emsa4.cpp @@ -94,8 +94,8 @@ bool EMSA4::verify(const MemoryRegion<byte>& const_coded, if(TOP_BITS > 8 - high_bit(coded[0])) return false; - SecureVector<byte> DB(coded.begin(), coded.size() - HASH_SIZE - 1); - SecureVector<byte> H(coded + coded.size() - HASH_SIZE - 1, HASH_SIZE); + SecureVector<byte> DB(&coded[0], coded.size() - HASH_SIZE - 1); + SecureVector<byte> H(&coded[coded.size() - HASH_SIZE - 1], HASH_SIZE); mgf->mask(H, H.size(), DB, coded.size() - H.size() - 1); DB[0] &= 0xFF >> TOP_BITS; diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index b9bd65ae1..eb67c7f4e 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -48,7 +48,7 @@ void HMAC_RNG::randomize(byte out[], u32bit length) const u32bit copied = std::min(K.size(), length); - copy_mem(out, K.begin(), copied); + copy_mem(out, &K[0], copied); out += copied; length -= copied; } diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index fb8dfcd09..b5e2e2748 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -38,7 +38,7 @@ void Randpool::randomize(byte out[], u32bit length) while(length) { const u32bit copied = std::min(length, buffer.size()); - copy_mem(out, buffer.begin(), copied); + copy_mem(out, &buffer[0], copied); out += copied; length -= copied; update_buffer(); diff --git a/src/ssl/cert_req.cpp b/src/ssl/cert_req.cpp index d2f08f2a8..7a7e6eed9 100644 --- a/src/ssl/cert_req.cpp +++ b/src/ssl/cert_req.cpp @@ -76,7 +76,7 @@ void Certificate_Req::deserialize(const MemoryRegion<byte>& buf) if(buf.size() != names_size + types_size + 3) throw Decoding_Error("Certificate_Req: Bad certificate request"); - BER_Decoder decoder(buf.begin() + types_size + 3, names_size); + BER_Decoder decoder(&buf[types_size + 3], names_size); while(decoder.more_items()) { diff --git a/src/ssl/handshake_hash.h b/src/ssl/handshake_hash.h index 8e068f3de..df50e4dfe 100644 --- a/src/ssl/handshake_hash.h +++ b/src/ssl/handshake_hash.h @@ -22,8 +22,10 @@ class BOTAN_DLL HandshakeHash public: void update(const byte in[], u32bit length) { data.append(in, length); } + void update(const MemoryRegion<byte>& in) - { update(in.begin(), in.size()); } + { update(&in[0], in.size()); } + void update(byte in) { update(&in, 1); } diff --git a/src/ssl/rec_read.cpp b/src/ssl/rec_read.cpp index 895026431..86b976417 100644 --- a/src/ssl/rec_read.cpp +++ b/src/ssl/rec_read.cpp @@ -217,7 +217,7 @@ u32bit Record_Reader::get_record(byte& msg_type, throw Decoding_Error("Record_Reader: Record truncated"); const u32bit mac_offset = plaintext.size() - (mac_size + pad_size); - SecureVector<byte> recieved_mac(plaintext.begin() + mac_offset, + SecureVector<byte> recieved_mac(&plaintext[mac_offset], mac_size); const u16bit plain_length = plaintext.size() - (mac_size + pad_size + iv_size); diff --git a/src/ssl/rec_wri.cpp b/src/ssl/rec_wri.cpp index 40dd45219..d983fd363 100644 --- a/src/ssl/rec_wri.cpp +++ b/src/ssl/rec_wri.cpp @@ -160,7 +160,7 @@ void Record_Writer::send(byte type, const byte input[], u32bit length) */ void Record_Writer::flush() { - const byte* buf_ptr = buffer.begin(); + const byte* buf_ptr = &buffer[0]; u32bit offset = 0; while(offset != buf_pos) diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp index a3a2f9a65..90f0f0904 100644 --- a/src/stream/arc4/arc4.cpp +++ b/src/stream/arc4/arc4.cpp @@ -18,13 +18,13 @@ void ARC4::cipher(const byte in[], byte out[], u32bit length) { while(length >= buffer.size() - position) { - xor_buf(out, in, buffer.begin() + position, buffer.size() - position); + xor_buf(out, in, &buffer[position], buffer.size() - position); length -= (buffer.size() - position); in += (buffer.size() - position); out += (buffer.size() - position); generate(); } - xor_buf(out, in, buffer.begin() + position, length); + xor_buf(out, in, &buffer[position], length); position += length; } diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp index cd1b1b7fb..6162a76a0 100644 --- a/src/stream/ctr/ctr.cpp +++ b/src/stream/ctr/ctr.cpp @@ -71,13 +71,13 @@ void CTR_BE::cipher(const byte in[], byte out[], u32bit length) { while(length >= buffer.size() - position) { - xor_buf(out, in, buffer.begin() + position, buffer.size() - position); + xor_buf(out, in, &buffer[position], buffer.size() - position); length -= (buffer.size() - position); in += (buffer.size() - position); out += (buffer.size() - position); increment_counter(); } - xor_buf(out, in, buffer.begin() + position, length); + xor_buf(out, in, &buffer[position], length); position += length; } @@ -100,7 +100,8 @@ void CTR_BE::set_iv(const byte iv[], u32bit iv_len) for(u32bit i = 1; i != PARALLEL_BLOCKS; ++i) { counter.copy(i*BLOCK_SIZE, - counter.begin() + (i-1)*BLOCK_SIZE, BLOCK_SIZE); + &counter[(i-1)*BLOCK_SIZE], + BLOCK_SIZE); for(s32bit j = BLOCK_SIZE - 1; j >= 0; --j) if(++counter[i*BLOCK_SIZE+j]) diff --git a/src/stream/ofb/ofb.cpp b/src/stream/ofb/ofb.cpp index 332673153..6fc8e4b68 100644 --- a/src/stream/ofb/ofb.cpp +++ b/src/stream/ofb/ofb.cpp @@ -68,14 +68,14 @@ void OFB::cipher(const byte in[], byte out[], u32bit length) { while(length >= buffer.size() - position) { - xor_buf(out, in, buffer.begin() + position, buffer.size() - position); + xor_buf(out, in, &buffer[position], buffer.size() - position); length -= (buffer.size() - position); in += (buffer.size() - position); out += (buffer.size() - position); permutation->encrypt(buffer); position = 0; } - xor_buf(out, in, buffer.begin() + position, length); + xor_buf(out, in, &buffer[position], length); position += length; } diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp index bfb2166d8..c53b666ad 100644 --- a/src/stream/turing/turing.cpp +++ b/src/stream/turing/turing.cpp @@ -39,13 +39,13 @@ void Turing::cipher(const byte in[], byte out[], u32bit length) { while(length >= buffer.size() - position) { - xor_buf(out, in, buffer.begin() + position, buffer.size() - position); + xor_buf(out, in, &buffer[position], buffer.size() - position); length -= (buffer.size() - position); in += (buffer.size() - position); out += (buffer.size() - position); generate(); } - xor_buf(out, in, buffer.begin() + position, length); + xor_buf(out, in, &buffer[position], length); position += length; } diff --git a/src/sym_algo/symkey.cpp b/src/sym_algo/symkey.cpp index a04f29181..65eb268cb 100644 --- a/src/sym_algo/symkey.cpp +++ b/src/sym_algo/symkey.cpp @@ -92,7 +92,7 @@ std::string OctetString::as_string() const OctetString& OctetString::operator^=(const OctetString& k) { if(&k == this) { zeroise(bits); return (*this); } - xor_buf(bits.begin(), k.begin(), std::min(length(), k.length())); + xor_buf(&bits[0], k.begin(), std::min(length(), k.length())); return (*this); } diff --git a/src/sym_algo/symkey.h b/src/sym_algo/symkey.h index 07b588329..154ae59da 100644 --- a/src/sym_algo/symkey.h +++ b/src/sym_algo/symkey.h @@ -32,12 +32,12 @@ class BOTAN_DLL OctetString /** * @return start of this string */ - const byte* begin() const { return bits.begin(); } + const byte* begin() const { return &bits[0]; } /** * @return end of this string */ - const byte* end() const { return bits.end(); } + const byte* end() const { return &bits[bits.size()]; } /** * @return this encoded as hex |