diff options
Diffstat (limited to 'src/lib/modes')
-rw-r--r-- | src/lib/modes/aead/aead.h | 4 | ||||
-rw-r--r-- | src/lib/modes/aead/ccm/ccm.cpp | 26 | ||||
-rw-r--r-- | src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp | 12 | ||||
-rw-r--r-- | src/lib/modes/aead/eax/eax.cpp | 12 | ||||
-rw-r--r-- | src/lib/modes/aead/gcm/clmul/clmul.cpp | 6 | ||||
-rw-r--r-- | src/lib/modes/aead/gcm/gcm.cpp | 34 | ||||
-rw-r--r-- | src/lib/modes/aead/ocb/ocb.cpp | 46 | ||||
-rw-r--r-- | src/lib/modes/aead/siv/siv.cpp | 18 | ||||
-rw-r--r-- | src/lib/modes/cbc/cbc.cpp | 28 | ||||
-rw-r--r-- | src/lib/modes/cbc/cbc.h | 2 | ||||
-rw-r--r-- | src/lib/modes/cfb/cfb.cpp | 16 | ||||
-rw-r--r-- | src/lib/modes/ecb/ecb.cpp | 8 | ||||
-rw-r--r-- | src/lib/modes/xts/xts.cpp | 16 | ||||
-rw-r--r-- | src/lib/modes/xts/xts.h | 2 |
14 files changed, 115 insertions, 115 deletions
diff --git a/src/lib/modes/aead/aead.h b/src/lib/modes/aead/aead.h index 6bbb39dcb..1fff41f97 100644 --- a/src/lib/modes/aead/aead.h +++ b/src/lib/modes/aead/aead.h @@ -41,13 +41,13 @@ class BOTAN_DLL AEAD_Mode : public Cipher_Mode template<typename Alloc> void set_associated_data_vec(const std::vector<byte, Alloc>& ad) { - set_associated_data(&ad[0], ad.size()); + set_associated_data(ad.data(), ad.size()); } template<typename Alloc> void set_ad(const std::vector<byte, Alloc>& ad) { - set_associated_data(&ad[0], ad.size()); + set_associated_data(ad.data(), ad.size()); } /** diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp index cc692e364..b40e6e62b 100644 --- a/src/lib/modes/aead/ccm/ccm.cpp +++ b/src/lib/modes/aead/ccm/ccm.cpp @@ -106,7 +106,7 @@ void CCM_Mode::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_msg_buf.insert(m_msg_buf.end(), buf, buf + sz); buffer.resize(offset); // truncate msg @@ -138,7 +138,7 @@ secure_vector<byte> CCM_Mode::format_b0(size_t sz) const byte b_flags = (m_ad_buf.size() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1); B0[0] = b_flags; - copy_mem(&B0[1], &m_nonce[0], m_nonce.size()); + copy_mem(&B0[1], m_nonce.data(), m_nonce.size()); encode_length(sz, &B0[m_nonce.size()+1]); return B0; @@ -151,7 +151,7 @@ secure_vector<byte> CCM_Mode::format_c0() const byte a_flags = L()-1; C[0] = a_flags; - copy_mem(&C[1], &m_nonce[0], m_nonce.size()); + copy_mem(&C[1], m_nonce.data(), m_nonce.size()); return C; } @@ -163,7 +163,7 @@ void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const secure_vector<byte>& ad = ad_buf(); BOTAN_ASSERT(ad.size() % BS == 0, "AD is block size multiple"); @@ -175,7 +175,7 @@ void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) for(size_t i = 0; i != ad.size(); i += BS) { - xor_buf(&T[0], &ad[i], BS); + xor_buf(T.data(), &ad[i], BS); E.encrypt(T); } @@ -192,11 +192,11 @@ void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) { const size_t to_proc = std::min<size_t>(BS, buf_end - buf); - xor_buf(&T[0], buf, to_proc); + xor_buf(T.data(), buf, to_proc); E.encrypt(T); E.encrypt(C, X); - xor_buf(buf, &X[0], to_proc); + xor_buf(buf, X.data(), to_proc); inc(C); buf += to_proc; @@ -204,7 +204,7 @@ void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) T ^= S0; - buffer += std::make_pair(&T[0], tag_size()); + buffer += std::make_pair(T.data(), tag_size()); } void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) @@ -214,7 +214,7 @@ void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "We have the tag"); @@ -228,7 +228,7 @@ void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) for(size_t i = 0; i != ad.size(); i += BS) { - xor_buf(&T[0], &ad[i], BS); + xor_buf(T.data(), &ad[i], BS); E.encrypt(T); } @@ -247,10 +247,10 @@ void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) const size_t to_proc = std::min<size_t>(BS, buf_end - buf); E.encrypt(C, X); - xor_buf(buf, &X[0], to_proc); + xor_buf(buf, X.data(), to_proc); inc(C); - xor_buf(&T[0], buf, to_proc); + xor_buf(T.data(), buf, to_proc); E.encrypt(T); buf += to_proc; @@ -258,7 +258,7 @@ void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) T ^= S0; - if(!same_mem(&T[0], buf_end, tag_size())) + if(!same_mem(T.data(), buf_end, tag_size())) throw Integrity_Failure("CCM tag check failed"); buffer.resize(buffer.size() - tag_size()); diff --git a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp index 37e0ef96b..3dc9d7f6d 100644 --- a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp +++ b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp @@ -63,7 +63,7 @@ secure_vector<byte> ChaCha20Poly1305_Mode::start_raw(const byte nonce[], size_t secure_vector<byte> zeros(64); m_chacha->encrypt(zeros); - m_poly1305->set_key(&zeros[0], 32); + m_poly1305->set_key(zeros.data(), 32); // Remainder of output is discard m_poly1305->update(m_ad); @@ -85,7 +85,7 @@ void ChaCha20Poly1305_Encryption::update(secure_vector<byte>& buffer, size_t off { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_chacha->cipher1(buf, sz); m_poly1305->update(buf, sz); // poly1305 of ciphertext @@ -104,7 +104,7 @@ void ChaCha20Poly1305_Encryption::finish(secure_vector<byte>& buffer, size_t off update_len(m_ctext_len); const secure_vector<byte> mac = m_poly1305->final(); - buffer += std::make_pair(&mac[0], tag_size()); + buffer += std::make_pair(mac.data(), tag_size()); m_ctext_len = 0; } @@ -112,7 +112,7 @@ void ChaCha20Poly1305_Decryption::update(secure_vector<byte>& buffer, size_t off { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_poly1305->update(buf, sz); // poly1305 of ciphertext m_chacha->cipher1(buf, sz); @@ -123,7 +123,7 @@ void ChaCha20Poly1305_Decryption::finish(secure_vector<byte>& buffer, size_t off { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input"); @@ -150,7 +150,7 @@ void ChaCha20Poly1305_Decryption::finish(secure_vector<byte>& buffer, size_t off m_ctext_len = 0; - if(!same_mem(&mac[0], included_tag, tag_size())) + if(!same_mem(mac.data(), included_tag, tag_size())) throw Integrity_Failure("ChaCha20Poly1305 tag check failed"); buffer.resize(offset + remaining); } diff --git a/src/lib/modes/aead/eax/eax.cpp b/src/lib/modes/aead/eax/eax.cpp index 3b0c94416..22e772d75 100644 --- a/src/lib/modes/aead/eax/eax.cpp +++ b/src/lib/modes/aead/eax/eax.cpp @@ -100,7 +100,7 @@ secure_vector<byte> EAX_Mode::start_raw(const byte nonce[], size_t nonce_len) m_nonce_mac = eax_prf(0, block_size(), *m_cmac, nonce, nonce_len); - m_ctr->set_iv(&m_nonce_mac[0], m_nonce_mac.size()); + m_ctr->set_iv(m_nonce_mac.data(), m_nonce_mac.size()); for(size_t i = 0; i != block_size() - 1; ++i) m_cmac->update(0); @@ -113,7 +113,7 @@ void EAX_Encryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_ctr->cipher(buf, buf, sz); m_cmac->update(buf, sz); @@ -127,14 +127,14 @@ void EAX_Encryption::finish(secure_vector<byte>& buffer, size_t offset) xor_buf(data_mac, m_nonce_mac, data_mac.size()); xor_buf(data_mac, m_ad_mac, data_mac.size()); - buffer += std::make_pair(&data_mac[0], tag_size()); + buffer += std::make_pair(data_mac.data(), tag_size()); } void EAX_Decryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_cmac->update(buf, sz); m_ctr->cipher(buf, buf, sz); @@ -144,7 +144,7 @@ void EAX_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input"); @@ -162,7 +162,7 @@ void EAX_Decryption::finish(secure_vector<byte>& buffer, size_t offset) mac ^= m_nonce_mac; mac ^= m_ad_mac; - if(!same_mem(&mac[0], included_tag, tag_size())) + if(!same_mem(mac.data(), included_tag, tag_size())) throw Integrity_Failure("EAX tag check failed"); buffer.resize(offset + remaining); diff --git a/src/lib/modes/aead/gcm/clmul/clmul.cpp b/src/lib/modes/aead/gcm/clmul/clmul.cpp index 4f7eb8dc0..6e1db7012 100644 --- a/src/lib/modes/aead/gcm/clmul/clmul.cpp +++ b/src/lib/modes/aead/gcm/clmul/clmul.cpp @@ -18,8 +18,8 @@ void gcm_multiply_clmul(byte x[16], const byte H[16]) */ const __m128i BSWAP_MASK = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); - __m128i a = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&x[0])); - __m128i b = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&H[0])); + __m128i a = _mm_loadu_si128(reinterpret_cast<const __m128i*>(x)); + __m128i b = _mm_loadu_si128(reinterpret_cast<const __m128i*>(H)); a = _mm_shuffle_epi8(a, BSWAP_MASK); b = _mm_shuffle_epi8(b, BSWAP_MASK); @@ -71,7 +71,7 @@ void gcm_multiply_clmul(byte x[16], const byte H[16]) T3 = _mm_shuffle_epi8(T3, BSWAP_MASK); - _mm_storeu_si128(reinterpret_cast<__m128i*>(&x[0]), T3); + _mm_storeu_si128(reinterpret_cast<__m128i*>(x), T3); } } diff --git a/src/lib/modes/aead/gcm/gcm.cpp b/src/lib/modes/aead/gcm/gcm.cpp index 049df4686..130ff6aad 100644 --- a/src/lib/modes/aead/gcm/gcm.cpp +++ b/src/lib/modes/aead/gcm/gcm.cpp @@ -22,14 +22,14 @@ void GHASH::gcm_multiply(secure_vector<byte>& x) const { #if defined(BOTAN_HAS_GCM_CLMUL) if(CPUID::has_clmul()) - return gcm_multiply_clmul(&x[0], &m_H[0]); + return gcm_multiply_clmul(x.data(), m_H.data()); #endif static const u64bit R = 0xE100000000000000; u64bit H[2] = { - load_be<u64bit>(&m_H[0], 0), - load_be<u64bit>(&m_H[0], 1) + load_be<u64bit>(m_H.data(), 0), + load_be<u64bit>(m_H.data(), 1) }; u64bit Z[2] = { 0, 0 }; @@ -38,7 +38,7 @@ void GHASH::gcm_multiply(secure_vector<byte>& x) const for(size_t i = 0; i != 2; ++i) { - const u64bit X = load_be<u64bit>(&x[0], i); + const u64bit X = load_be<u64bit>(x.data(), i); for(size_t j = 0; j != 64; ++j) { @@ -55,7 +55,7 @@ void GHASH::gcm_multiply(secure_vector<byte>& x) const } } - store_be<u64bit>(&x[0], Z[0], Z[1]); + store_be<u64bit>(x.data(), Z[0], Z[1]); } void GHASH::ghash_update(secure_vector<byte>& ghash, @@ -71,7 +71,7 @@ void GHASH::ghash_update(secure_vector<byte>& ghash, { const size_t to_proc = std::min(length, BS); - xor_buf(&ghash[0], &input[0], to_proc); + xor_buf(ghash.data(), input, to_proc); gcm_multiply(ghash); @@ -115,8 +115,8 @@ void GHASH::add_final_block(secure_vector<byte>& hash, size_t ad_len, size_t text_len) { secure_vector<byte> final_block(16); - store_be<u64bit>(&final_block[0], 8*ad_len, 8*text_len); - ghash_update(hash, &final_block[0], final_block.size()); + store_be<u64bit>(final_block.data(), 8*ad_len, 8*text_len); + ghash_update(hash, final_block.data(), final_block.size()); } secure_vector<byte> GHASH::final() @@ -195,7 +195,7 @@ void GCM_Mode::key_schedule(const byte key[], size_t keylen) m_ctr->set_key(key, keylen); const std::vector<byte> zeros(BS); - m_ctr->set_iv(&zeros[0], zeros.size()); + m_ctr->set_iv(zeros.data(), zeros.size()); secure_vector<byte> H(BS); m_ctr->encipher(H); @@ -216,7 +216,7 @@ secure_vector<byte> GCM_Mode::start_raw(const byte nonce[], size_t nonce_len) if(nonce_len == 12) { - copy_mem(&y0[0], nonce, nonce_len); + copy_mem(y0.data(), nonce, nonce_len); y0[15] = 1; } else @@ -224,12 +224,12 @@ secure_vector<byte> GCM_Mode::start_raw(const byte nonce[], size_t nonce_len) y0 = m_ghash->nonce_hash(nonce, nonce_len); } - m_ctr->set_iv(&y0[0], y0.size()); + m_ctr->set_iv(y0.data(), y0.size()); secure_vector<byte> m_enc_y0(BS); m_ctr->encipher(m_enc_y0); - m_ghash->start(&m_enc_y0[0], m_enc_y0.size()); + m_ghash->start(m_enc_y0.data(), m_enc_y0.size()); return secure_vector<byte>(); } @@ -238,7 +238,7 @@ void GCM_Encryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_ctr->cipher(buf, buf, sz); m_ghash->update(buf, sz); @@ -248,14 +248,14 @@ void GCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) { update(buffer, offset); auto mac = m_ghash->final(); - buffer += std::make_pair(&mac[0], tag_size()); + buffer += std::make_pair(mac.data(), tag_size()); } void GCM_Decryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_ghash->update(buf, sz); m_ctr->cipher(buf, buf, sz); @@ -265,7 +265,7 @@ void GCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input"); @@ -282,7 +282,7 @@ void GCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) const byte* included_tag = &buffer[remaining]; - if(!same_mem(&mac[0], included_tag, tag_size())) + if(!same_mem(mac.data(), included_tag, tag_size())) throw Integrity_Failure("GCM tag check failed"); buffer.resize(offset + remaining); diff --git a/src/lib/modes/aead/ocb/ocb.cpp b/src/lib/modes/aead/ocb/ocb.cpp index 2ba6d3ee6..ee5583bea 100644 --- a/src/lib/modes/aead/ocb/ocb.cpp +++ b/src/lib/modes/aead/ocb/ocb.cpp @@ -41,7 +41,7 @@ class L_computer for(size_t i = 0; i != blocks; ++i) { // could be done in parallel offset ^= get(ctz(block_index + 1 + i)); - copy_mem(&m_offset_buf[BS*i], &offset[0], BS); + copy_mem(&m_offset_buf[BS*i], offset.data(), BS); } return m_offset_buf; @@ -91,7 +91,7 @@ secure_vector<byte> ocb_hash(const L_computer& L, offset ^= L(ctz(i+1)); buf = offset; - xor_buf(&buf[0], &ad[BS*i], BS); + xor_buf(buf.data(), &ad[BS*i], BS); cipher.encrypt(buf); @@ -103,7 +103,7 @@ secure_vector<byte> ocb_hash(const L_computer& L, offset ^= L.star(); buf = offset; - xor_buf(&buf[0], &ad[BS*ad_blocks], ad_remainder); + xor_buf(buf.data(), &ad[BS*ad_blocks], ad_remainder); buf[ad_len % BS] ^= 0x80; cipher.encrypt(buf); @@ -174,7 +174,7 @@ void OCB_Mode::key_schedule(const byte key[], size_t length) void OCB_Mode::set_associated_data(const byte ad[], size_t ad_len) { BOTAN_ASSERT(m_L, "A key was set"); - m_ad_hash = ocb_hash(*m_L, *m_cipher, &ad[0], ad_len); + m_ad_hash = ocb_hash(*m_L, *m_cipher, ad, ad_len); } secure_vector<byte> @@ -245,11 +245,11 @@ void OCB_Encryption::encrypt(byte buffer[], size_t blocks) const auto& offsets = m_L->compute_offsets(m_offset, m_block_index, proc_blocks); - xor_buf(&m_checksum[0], &buffer[0], proc_bytes); + xor_buf(m_checksum.data(), buffer, proc_bytes); - xor_buf(&buffer[0], &offsets[0], proc_bytes); - m_cipher->encrypt_n(&buffer[0], &buffer[0], proc_blocks); - xor_buf(&buffer[0], &offsets[0], proc_bytes); + xor_buf(buffer, offsets.data(), proc_bytes); + m_cipher->encrypt_n(buffer, buffer, proc_blocks); + xor_buf(buffer, offsets.data(), proc_bytes); buffer += proc_bytes; blocks -= proc_blocks; @@ -261,7 +261,7 @@ void OCB_Encryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz % BS() == 0, "Input length is an even number of blocks"); encrypt(buf, sz / BS()); @@ -271,7 +271,7 @@ void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; if(sz) { @@ -285,14 +285,14 @@ void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) BOTAN_ASSERT(remainder_bytes < BS(), "Only a partial block left"); byte* remainder = &buf[sz - remainder_bytes]; - xor_buf(&m_checksum[0], &remainder[0], remainder_bytes); + xor_buf(m_checksum.data(), remainder, remainder_bytes); m_checksum[remainder_bytes] ^= 0x80; m_offset ^= m_L->star(); // Offset_* secure_vector<byte> zeros(BS()); m_cipher->encrypt(m_offset, zeros); - xor_buf(&remainder[0], &zeros[0], remainder_bytes); + xor_buf(remainder, zeros.data(), remainder_bytes); } } @@ -311,7 +311,7 @@ void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) mac ^= m_ad_hash; - buffer += std::make_pair(&mac[0], tag_size()); + buffer += std::make_pair(mac.data(), tag_size()); zeroise(m_checksum); zeroise(m_offset); @@ -333,11 +333,11 @@ void OCB_Decryption::decrypt(byte buffer[], size_t blocks) const auto& offsets = m_L->compute_offsets(m_offset, m_block_index, proc_blocks); - xor_buf(&buffer[0], &offsets[0], proc_bytes); - m_cipher->decrypt_n(&buffer[0], &buffer[0], proc_blocks); - xor_buf(&buffer[0], &offsets[0], proc_bytes); + xor_buf(buffer, offsets.data(), proc_bytes); + m_cipher->decrypt_n(buffer, buffer, proc_blocks); + xor_buf(buffer, offsets.data(), proc_bytes); - xor_buf(&m_checksum[0], &buffer[0], proc_bytes); + xor_buf(m_checksum.data(), buffer, proc_bytes); buffer += proc_bytes; blocks -= proc_blocks; @@ -349,7 +349,7 @@ void OCB_Decryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz % BS() == 0, "Input length is an even number of blocks"); @@ -360,7 +360,7 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "We have the tag"); @@ -371,7 +371,7 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) const size_t final_full_blocks = remaining / BS(); const size_t final_bytes = remaining - (final_full_blocks * BS()); - decrypt(&buf[0], final_full_blocks); + decrypt(buf, final_full_blocks); if(final_bytes) { @@ -384,9 +384,9 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) secure_vector<byte> pad(BS()); m_cipher->encrypt(m_offset, pad); // P_* - xor_buf(&remainder[0], &pad[0], final_bytes); + xor_buf(remainder, pad.data(), final_bytes); - xor_buf(&m_checksum[0], &remainder[0], final_bytes); + xor_buf(m_checksum.data(), remainder, final_bytes); m_checksum[final_bytes] ^= 0x80; } } @@ -414,7 +414,7 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) // compare mac const byte* included_tag = &buf[remaining]; - if(!same_mem(&mac[0], included_tag, tag_size())) + if(!same_mem(mac.data(), included_tag, tag_size())) throw Integrity_Failure("OCB tag check failed"); // remove tag from end of message diff --git a/src/lib/modes/aead/siv/siv.cpp b/src/lib/modes/aead/siv/siv.cpp index c1416e209..5b22216cf 100644 --- a/src/lib/modes/aead/siv/siv.cpp +++ b/src/lib/modes/aead/siv/siv.cpp @@ -91,7 +91,7 @@ void SIV_Mode::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; m_msg_buf.insert(m_msg_buf.end(), buf, buf + sz); buffer.resize(offset); // truncate msg @@ -118,13 +118,13 @@ secure_vector<byte> SIV_Mode::S2V(const byte* text, size_t text_len) if(text_len < 16) { V = CMAC::poly_double(V); - xor_buf(&V[0], text, text_len); + xor_buf(V.data(), text, text_len); V[text_len] ^= 0x80; return m_cmac->process(V); } m_cmac->update(text, text_len - 16); - xor_buf(&V[0], &text[text_len - 16], 16); + xor_buf(V.data(), &text[text_len - 16], 16); m_cmac->update(V); return m_cmac->final(); @@ -135,7 +135,7 @@ void SIV_Mode::set_ctr_iv(secure_vector<byte> V) V[8] &= 0x7F; V[12] &= 0x7F; - ctr().set_iv(&V[0], V.size()); + ctr().set_iv(V.data(), V.size()); } void SIV_Encryption::finish(secure_vector<byte>& buffer, size_t offset) @@ -144,7 +144,7 @@ void SIV_Encryption::finish(secure_vector<byte>& buffer, size_t offset) buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); - secure_vector<byte> V = S2V(&buffer[offset], buffer.size() - offset); + secure_vector<byte> V = S2V(buffer.data() + offset, buffer.size() - offset); buffer.insert(buffer.begin() + offset, V.begin(), V.end()); @@ -162,15 +162,15 @@ void SIV_Decryption::finish(secure_vector<byte>& buffer, size_t offset) BOTAN_ASSERT(sz >= tag_size(), "We have the tag"); - secure_vector<byte> V(&buffer[offset], &buffer[offset + 16]); + secure_vector<byte> V(buffer.data() + offset, buffer.data() + offset + 16); set_ctr_iv(V); - ctr().cipher(&buffer[offset + V.size()], - &buffer[offset], + ctr().cipher(buffer.data() + offset + V.size(), + buffer.data() + offset, buffer.size() - offset - V.size()); - secure_vector<byte> T = S2V(&buffer[offset], buffer.size() - offset - V.size()); + secure_vector<byte> T = S2V(buffer.data() + offset, buffer.size() - offset - V.size()); if(T != V) throw Integrity_Failure("SIV tag check failed"); diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp index 7cee72081..27f2bce4a 100644 --- a/src/lib/modes/cbc/cbc.cpp +++ b/src/lib/modes/cbc/cbc.cpp @@ -112,7 +112,7 @@ void CBC_Encryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -168,7 +168,7 @@ size_t CTS_Encryption::output_length(size_t input_length) const void CTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t sz = buffer.size() - offset; const size_t BS = cipher().block_size(); @@ -194,8 +194,8 @@ void CTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) buffer.resize(full_blocks + offset); update(buffer, offset); - xor_buf(&last[0], state_ptr(), BS); - cipher().encrypt(&last[0]); + xor_buf(last.data(), state_ptr(), BS); + cipher().encrypt(last.data()); for(size_t i = 0; i != final_bytes - BS; ++i) { @@ -203,7 +203,7 @@ void CTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) last[i + BS] ^= last[i]; } - cipher().encrypt(&last[0]); + cipher().encrypt(last.data()); buffer += last; } @@ -223,7 +223,7 @@ void CBC_Decryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -234,13 +234,13 @@ void CBC_Decryption::update(secure_vector<byte>& buffer, size_t offset) { const size_t to_proc = std::min(BS * blocks, m_tempbuf.size()); - cipher().decrypt_n(buf, &m_tempbuf[0], to_proc / BS); + cipher().decrypt_n(buf, m_tempbuf.data(), to_proc / BS); - xor_buf(&m_tempbuf[0], state_ptr(), BS); + xor_buf(m_tempbuf.data(), state_ptr(), BS); xor_buf(&m_tempbuf[BS], buf, to_proc - BS); copy_mem(state_ptr(), buf + (to_proc - BS), BS); - copy_mem(buf, &m_tempbuf[0], to_proc); + copy_mem(buf, m_tempbuf.data(), to_proc); buf += to_proc; blocks -= to_proc / BS; @@ -277,7 +277,7 @@ void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -303,15 +303,15 @@ void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset) buffer.resize(full_blocks + offset); update(buffer, offset); - cipher().decrypt(&last[0]); + cipher().decrypt(last.data()); - xor_buf(&last[0], &last[BS], final_bytes - BS); + xor_buf(last.data(), &last[BS], final_bytes - BS); for(size_t i = 0; i != final_bytes - BS; ++i) std::swap(last[i], last[i + BS]); - cipher().decrypt(&last[0]); - xor_buf(&last[0], state_ptr(), BS); + cipher().decrypt(last.data()); + xor_buf(last.data(), state_ptr(), BS); buffer += last; } diff --git a/src/lib/modes/cbc/cbc.h b/src/lib/modes/cbc/cbc.h index 2de303da9..963e92666 100644 --- a/src/lib/modes/cbc/cbc.h +++ b/src/lib/modes/cbc/cbc.h @@ -44,7 +44,7 @@ class BOTAN_DLL CBC_Mode : public Cipher_Mode secure_vector<byte>& state() { return m_state; } - byte* state_ptr() { return &m_state[0]; } + byte* state_ptr() { return m_state.data(); } private: secure_vector<byte> start_raw(const byte nonce[], size_t nonce_len) override; diff --git a/src/lib/modes/cfb/cfb.cpp b/src/lib/modes/cfb/cfb.cpp index c1fd98dfb..7e4048a2b 100644 --- a/src/lib/modes/cfb/cfb.cpp +++ b/src/lib/modes/cfb/cfb.cpp @@ -87,7 +87,7 @@ void CFB_Encryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -97,11 +97,11 @@ void CFB_Encryption::update(secure_vector<byte>& buffer, size_t offset) while(sz) { const size_t took = std::min(shift, sz); - xor_buf(&buf[0], &keystream_buf()[0], took); + xor_buf(buf, &keystream_buf()[0], took); // Assumes feedback-sized block except for last input - copy_mem(&state[0], &state[shift], BS - shift); - copy_mem(&state[BS-shift], &buf[0], took); + copy_mem(state.data(), &state[shift], BS - shift); + copy_mem(&state[BS-shift], buf, took); cipher().encrypt(state, keystream_buf()); buf += took; @@ -118,7 +118,7 @@ void CFB_Decryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -130,11 +130,11 @@ void CFB_Decryption::update(secure_vector<byte>& buffer, size_t offset) const size_t took = std::min(shift, sz); // first update shift register with ciphertext - copy_mem(&state[0], &state[shift], BS - shift); - copy_mem(&state[BS-shift], &buf[0], took); + copy_mem(state.data(), &state[shift], BS - shift); + copy_mem(&state[BS-shift], buf, took); // then decrypt - xor_buf(&buf[0], &keystream_buf()[0], took); + xor_buf(buf, &keystream_buf()[0], took); // then update keystream cipher().encrypt(state, keystream_buf()); diff --git a/src/lib/modes/ecb/ecb.cpp b/src/lib/modes/ecb/ecb.cpp index eaab1810d..73a241394 100644 --- a/src/lib/modes/ecb/ecb.cpp +++ b/src/lib/modes/ecb/ecb.cpp @@ -90,14 +90,14 @@ void ECB_Encryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); BOTAN_ASSERT(sz % BS == 0, "ECB input is full blocks"); const size_t blocks = sz / BS; - cipher().encrypt_n(&buf[0], &buf[0], blocks); + cipher().encrypt_n(buf, buf, blocks); } void ECB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) @@ -131,14 +131,14 @@ void ECB_Decryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); BOTAN_ASSERT(sz % BS == 0, "Input is full blocks"); size_t blocks = sz / BS; - cipher().decrypt_n(&buf[0], &buf[0], blocks); + cipher().decrypt_n(buf, buf, blocks); } void ECB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) diff --git a/src/lib/modes/xts/xts.cpp b/src/lib/modes/xts/xts.cpp index b2b8386bb..cc0e6d54c 100644 --- a/src/lib/modes/xts/xts.cpp +++ b/src/lib/modes/xts/xts.cpp @@ -103,7 +103,7 @@ void XTS_Mode::key_schedule(const byte key[], size_t length) if(length % 2 == 1 || !m_cipher->valid_keylength(key_half)) throw Invalid_Key_Length(name(), length); - m_cipher->set_key(&key[0], key_half); + m_cipher->set_key(key, key_half); m_tweak_cipher->set_key(&key[key_half], key_half); } @@ -112,8 +112,8 @@ secure_vector<byte> XTS_Mode::start_raw(const byte nonce[], size_t nonce_len) if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); - copy_mem(&m_tweak[0], nonce, nonce_len); - m_tweak_cipher->encrypt(&m_tweak[0]); + copy_mem(m_tweak.data(), nonce, nonce_len); + m_tweak_cipher->encrypt(m_tweak.data()); update_tweak(0); @@ -125,7 +125,7 @@ void XTS_Mode::update_tweak(size_t which) const size_t BS = m_tweak_cipher->block_size(); if(which > 0) - poly_double(&m_tweak[0], &m_tweak[(which-1)*BS], BS); + poly_double(m_tweak.data(), &m_tweak[(which-1)*BS], BS); const size_t blocks_in_tweak = update_granularity() / BS; @@ -142,7 +142,7 @@ void XTS_Encryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -171,7 +171,7 @@ void XTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input"); @@ -221,7 +221,7 @@ void XTS_Decryption::update(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -250,7 +250,7 @@ void XTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = &buffer[offset]; + byte* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input"); diff --git a/src/lib/modes/xts/xts.h b/src/lib/modes/xts/xts.h index 7e0a1f5c4..b0a46144f 100644 --- a/src/lib/modes/xts/xts.h +++ b/src/lib/modes/xts/xts.h @@ -35,7 +35,7 @@ class BOTAN_DLL XTS_Mode : public Cipher_Mode protected: XTS_Mode(BlockCipher* cipher); - const byte* tweak() const { return &m_tweak[0]; } + const byte* tweak() const { return m_tweak.data(); } const BlockCipher& cipher() const { return *m_cipher; } |