diff options
Diffstat (limited to 'src/lib/modes')
25 files changed, 312 insertions, 312 deletions
diff --git a/src/lib/modes/aead/aead.h b/src/lib/modes/aead/aead.h index 2cdc6137e..3d3c7287f 100644 --- a/src/lib/modes/aead/aead.h +++ b/src/lib/modes/aead/aead.h @@ -36,7 +36,7 @@ class BOTAN_DLL AEAD_Mode : public Cipher_Mode * @param ad the associated data * @param ad_len length of add in bytes */ - virtual void set_associated_data(const byte ad[], size_t ad_len) = 0; + virtual void set_associated_data(const uint8_t ad[], size_t ad_len) = 0; /** * Set associated data that is not included in the ciphertext but @@ -48,7 +48,7 @@ class BOTAN_DLL AEAD_Mode : public Cipher_Mode * @param ad the associated data */ template<typename Alloc> - void set_associated_data_vec(const std::vector<byte, Alloc>& ad) + void set_associated_data_vec(const std::vector<uint8_t, Alloc>& ad) { set_associated_data(ad.data(), ad.size()); } @@ -63,7 +63,7 @@ class BOTAN_DLL AEAD_Mode : public Cipher_Mode * @param ad the associated data */ template<typename Alloc> - void set_ad(const std::vector<byte, Alloc>& ad) + void set_ad(const std::vector<uint8_t, Alloc>& ad) { 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 de639f23a..db0d2d58b 100644 --- a/src/lib/modes/aead/ccm/ccm.cpp +++ b/src/lib/modes/aead/ccm/ccm.cpp @@ -65,7 +65,7 @@ size_t CCM_Mode::update_granularity() const /* This value does not particularly matter as regardless CCM_Mode::update buffers all input, so in theory this could be 1. However as for instance - Transform_Filter creates update_granularity() byte buffers, use a + Transform_Filter creates update_granularity() uint8_t buffers, use a somewhat large size to avoid bouncing on a tiny buffer. */ return m_cipher->parallel_bytes(); @@ -76,12 +76,12 @@ Key_Length_Specification CCM_Mode::key_spec() const return m_cipher->key_spec(); } -void CCM_Mode::key_schedule(const byte key[], size_t length) +void CCM_Mode::key_schedule(const uint8_t key[], size_t length) { m_cipher->set_key(key, length); } -void CCM_Mode::set_associated_data(const byte ad[], size_t length) +void CCM_Mode::set_associated_data(const uint8_t ad[], size_t length) { m_ad_buf.clear(); @@ -90,15 +90,15 @@ void CCM_Mode::set_associated_data(const byte ad[], size_t length) // FIXME: support larger AD using length encoding rules BOTAN_ASSERT(length < (0xFFFF - 0xFF), "Supported CCM AD length"); - m_ad_buf.push_back(get_byte(0, static_cast<u16bit>(length))); - m_ad_buf.push_back(get_byte(1, static_cast<u16bit>(length))); + m_ad_buf.push_back(get_byte(0, static_cast<uint16_t>(length))); + m_ad_buf.push_back(get_byte(1, static_cast<uint16_t>(length))); m_ad_buf += std::make_pair(ad, length); while(m_ad_buf.size() % CCM_BS) m_ad_buf.push_back(0); // pad with zeros to full block size } } -void CCM_Mode::start_msg(const byte nonce[], size_t nonce_len) +void CCM_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -113,7 +113,7 @@ size_t CCM_Mode::process(uint8_t buf[], size_t sz) return 0; // no output until finished } -void CCM_Mode::encode_length(size_t len, byte out[]) +void CCM_Mode::encode_length(size_t len, uint8_t out[]) { const size_t len_bytes = L(); @@ -125,18 +125,18 @@ void CCM_Mode::encode_length(size_t len, byte out[]) BOTAN_ASSERT((len >> (len_bytes*8)) == 0, "Message length fits in field"); } -void CCM_Mode::inc(secure_vector<byte>& C) +void CCM_Mode::inc(secure_vector<uint8_t>& C) { for(size_t i = 0; i != C.size(); ++i) if(++C[C.size()-i-1]) break; } -secure_vector<byte> CCM_Mode::format_b0(size_t sz) +secure_vector<uint8_t> CCM_Mode::format_b0(size_t sz) { - secure_vector<byte> B0(CCM_BS); + secure_vector<uint8_t> B0(CCM_BS); - const byte b_flags = (m_ad_buf.size() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1); + const uint8_t 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.data(), m_nonce.size()); @@ -145,11 +145,11 @@ secure_vector<byte> CCM_Mode::format_b0(size_t sz) return B0; } -secure_vector<byte> CCM_Mode::format_c0() +secure_vector<uint8_t> CCM_Mode::format_c0() { - secure_vector<byte> C(CCM_BS); + secure_vector<uint8_t> C(CCM_BS); - const byte a_flags = L()-1; + const uint8_t a_flags = L()-1; C[0] = a_flags; copy_mem(&C[1], m_nonce.data(), m_nonce.size()); @@ -157,21 +157,21 @@ secure_vector<byte> CCM_Mode::format_c0() return C; } -void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void CCM_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; - const secure_vector<byte>& ad = ad_buf(); + const secure_vector<uint8_t>& ad = ad_buf(); BOTAN_ASSERT(ad.size() % CCM_BS == 0, "AD is block size multiple"); const BlockCipher& E = cipher(); - secure_vector<byte> T(CCM_BS); + secure_vector<uint8_t> T(CCM_BS); E.encrypt(format_b0(sz), T); for(size_t i = 0; i != ad.size(); i += CCM_BS) @@ -180,14 +180,14 @@ void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) E.encrypt(T); } - secure_vector<byte> C = format_c0(); - secure_vector<byte> S0(CCM_BS); + secure_vector<uint8_t> C = format_c0(); + secure_vector<uint8_t> S0(CCM_BS); E.encrypt(C, S0); inc(C); - secure_vector<byte> X(CCM_BS); + secure_vector<uint8_t> X(CCM_BS); - const byte* buf_end = &buf[sz]; + const uint8_t* buf_end = &buf[sz]; while(buf != buf_end) { @@ -208,23 +208,23 @@ void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) buffer += std::make_pair(T.data(), tag_size()); } -void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void CCM_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "We have the tag"); - const secure_vector<byte>& ad = ad_buf(); + const secure_vector<uint8_t>& ad = ad_buf(); BOTAN_ASSERT(ad.size() % CCM_BS == 0, "AD is block size multiple"); const BlockCipher& E = cipher(); - secure_vector<byte> T(CCM_BS); + secure_vector<uint8_t> T(CCM_BS); E.encrypt(format_b0(sz - tag_size()), T); for(size_t i = 0; i != ad.size(); i += CCM_BS) @@ -233,15 +233,15 @@ void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) E.encrypt(T); } - secure_vector<byte> C = format_c0(); + secure_vector<uint8_t> C = format_c0(); - secure_vector<byte> S0(CCM_BS); + secure_vector<uint8_t> S0(CCM_BS); E.encrypt(C, S0); inc(C); - secure_vector<byte> X(CCM_BS); + secure_vector<uint8_t> X(CCM_BS); - const byte* buf_end = &buf[sz - tag_size()]; + const uint8_t* buf_end = &buf[sz - tag_size()]; while(buf != buf_end) { diff --git a/src/lib/modes/aead/ccm/ccm.h b/src/lib/modes/aead/ccm/ccm.h index 9795354fc..93dd0d7e1 100644 --- a/src/lib/modes/aead/ccm/ccm.h +++ b/src/lib/modes/aead/ccm/ccm.h @@ -25,7 +25,7 @@ class BOTAN_DLL CCM_Mode : public AEAD_Mode public: size_t process(uint8_t buf[], size_t sz) override; - void set_associated_data(const byte ad[], size_t ad_len) override; + void set_associated_data(const uint8_t ad[], size_t ad_len) override; std::string name() const override; @@ -50,26 +50,26 @@ class BOTAN_DLL CCM_Mode : public AEAD_Mode const BlockCipher& cipher() const { return *m_cipher; } - void encode_length(size_t len, byte out[]); + void encode_length(size_t len, uint8_t out[]); - void inc(secure_vector<byte>& C); + void inc(secure_vector<uint8_t>& C); - const secure_vector<byte>& ad_buf() const { return m_ad_buf; } + const secure_vector<uint8_t>& ad_buf() const { return m_ad_buf; } - secure_vector<byte>& msg_buf() { return m_msg_buf; } + secure_vector<uint8_t>& msg_buf() { return m_msg_buf; } - secure_vector<byte> format_b0(size_t msg_size); - secure_vector<byte> format_c0(); + secure_vector<uint8_t> format_b0(size_t msg_size); + secure_vector<uint8_t> format_c0(); private: - void start_msg(const byte nonce[], size_t nonce_len) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void key_schedule(const uint8_t key[], size_t length) override; const size_t m_tag_size; const size_t m_L; std::unique_ptr<BlockCipher> m_cipher; - secure_vector<byte> m_nonce, m_msg_buf, m_ad_buf; + secure_vector<uint8_t> m_nonce, m_msg_buf, m_ad_buf; }; /** @@ -88,7 +88,7 @@ class BOTAN_DLL CCM_Encryption final : public CCM_Mode CCM_Encryption(BlockCipher* cipher, size_t tag_size = 16, size_t L = 3) : CCM_Mode(cipher, tag_size, L) {} - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override { return input_length + tag_size(); } @@ -112,7 +112,7 @@ class BOTAN_DLL CCM_Decryption final : public CCM_Mode CCM_Decryption(BlockCipher* cipher, size_t tag_size = 16, size_t L = 3) : CCM_Mode(cipher, tag_size, L) {} - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override { diff --git a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp index 197d6f921..64169a9b8 100644 --- a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp +++ b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp @@ -37,12 +37,12 @@ void ChaCha20Poly1305_Mode::reset() m_nonce_len = 0; } -void ChaCha20Poly1305_Mode::key_schedule(const byte key[], size_t length) +void ChaCha20Poly1305_Mode::key_schedule(const uint8_t key[], size_t length) { m_chacha->set_key(key, length); } -void ChaCha20Poly1305_Mode::set_associated_data(const byte ad[], size_t length) +void ChaCha20Poly1305_Mode::set_associated_data(const uint8_t ad[], size_t length) { if(m_ctext_len) throw Exception("Too late to set AD for ChaCha20Poly1305"); @@ -51,12 +51,12 @@ void ChaCha20Poly1305_Mode::set_associated_data(const byte ad[], size_t length) void ChaCha20Poly1305_Mode::update_len(size_t len) { - byte len8[8] = { 0 }; - store_le(static_cast<u64bit>(len), len8); + uint8_t len8[8] = { 0 }; + store_le(static_cast<uint64_t>(len), len8); m_poly1305->update(len8, 8); } -void ChaCha20Poly1305_Mode::start_msg(const byte nonce[], size_t nonce_len) +void ChaCha20Poly1305_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -66,7 +66,7 @@ void ChaCha20Poly1305_Mode::start_msg(const byte nonce[], size_t nonce_len) m_chacha->set_iv(nonce, nonce_len); - secure_vector<byte> init(64); // zeros + secure_vector<uint8_t> init(64); // zeros m_chacha->encrypt(init); m_poly1305->set_key(init.data(), 32); @@ -78,7 +78,7 @@ void ChaCha20Poly1305_Mode::start_msg(const byte nonce[], size_t nonce_len) { if(m_ad.size() % 16) { - const byte zeros[16] = { 0 }; + const uint8_t zeros[16] = { 0 }; m_poly1305->update(zeros, 16 - m_ad.size() % 16); } } @@ -96,21 +96,21 @@ size_t ChaCha20Poly1305_Encryption::process(uint8_t buf[], size_t sz) return sz; } -void ChaCha20Poly1305_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void ChaCha20Poly1305_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { update(buffer, offset); if(cfrg_version()) { if(m_ctext_len % 16) { - const byte zeros[16] = { 0 }; + const uint8_t zeros[16] = { 0 }; m_poly1305->update(zeros, 16 - m_ctext_len % 16); } update_len(m_ad.size()); } update_len(m_ctext_len); - const secure_vector<byte> mac = m_poly1305->final(); + const secure_vector<uint8_t> mac = m_poly1305->final(); buffer += std::make_pair(mac.data(), tag_size()); m_ctext_len = 0; } @@ -123,11 +123,11 @@ size_t ChaCha20Poly1305_Decryption::process(uint8_t buf[], size_t sz) return sz; } -void ChaCha20Poly1305_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void ChaCha20Poly1305_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input"); @@ -144,16 +144,16 @@ void ChaCha20Poly1305_Decryption::finish(secure_vector<byte>& buffer, size_t off { if(m_ctext_len % 16) { - const byte zeros[16] = { 0 }; + const uint8_t zeros[16] = { 0 }; m_poly1305->update(zeros, 16 - m_ctext_len % 16); } update_len(m_ad.size()); } update_len(m_ctext_len); - const secure_vector<byte> mac = m_poly1305->final(); + const secure_vector<uint8_t> mac = m_poly1305->final(); - const byte* included_tag = &buf[remaining]; + const uint8_t* included_tag = &buf[remaining]; m_ctext_len = 0; diff --git a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.h b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.h index 58328ac5b..4245e5e01 100644 --- a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.h +++ b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.h @@ -24,7 +24,7 @@ namespace Botan { class BOTAN_DLL ChaCha20Poly1305_Mode : public AEAD_Mode { public: - void set_associated_data(const byte ad[], size_t ad_len) override; + void set_associated_data(const uint8_t ad[], size_t ad_len) override; std::string name() const override { return "ChaCha20Poly1305"; } @@ -47,16 +47,16 @@ class BOTAN_DLL ChaCha20Poly1305_Mode : public AEAD_Mode ChaCha20Poly1305_Mode(); - secure_vector<byte> m_ad; + secure_vector<uint8_t> m_ad; size_t m_nonce_len = 0; size_t m_ctext_len = 0; bool cfrg_version() const { return m_nonce_len == 12; } void update_len(size_t len); private: - void start_msg(const byte nonce[], size_t nonce_len) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void key_schedule(const uint8_t key[], size_t length) override; }; /** @@ -72,7 +72,7 @@ class BOTAN_DLL ChaCha20Poly1305_Encryption final : public ChaCha20Poly1305_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; /** @@ -91,7 +91,7 @@ class BOTAN_DLL ChaCha20Poly1305_Decryption final : public ChaCha20Poly1305_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; } diff --git a/src/lib/modes/aead/eax/eax.cpp b/src/lib/modes/aead/eax/eax.cpp index ba52efcfd..4889ac21a 100644 --- a/src/lib/modes/aead/eax/eax.cpp +++ b/src/lib/modes/aead/eax/eax.cpp @@ -18,9 +18,9 @@ namespace { /* * EAX MAC-based PRF */ -secure_vector<byte> eax_prf(byte tag, size_t block_size, +secure_vector<uint8_t> eax_prf(uint8_t tag, size_t block_size, MessageAuthenticationCode& mac, - const byte in[], size_t length) + const uint8_t in[], size_t length) { for(size_t i = 0; i != block_size - 1; ++i) { @@ -78,7 +78,7 @@ Key_Length_Specification EAX_Mode::key_spec() const /* * Set the EAX key */ -void EAX_Mode::key_schedule(const byte key[], size_t length) +void EAX_Mode::key_schedule(const uint8_t key[], size_t length) { /* * These could share the key schedule, which is one nice part of EAX, @@ -91,12 +91,12 @@ void EAX_Mode::key_schedule(const byte key[], size_t length) /* * Set the EAX associated data */ -void EAX_Mode::set_associated_data(const byte ad[], size_t length) +void EAX_Mode::set_associated_data(const uint8_t ad[], size_t length) { m_ad_mac = eax_prf(1, block_size(), *m_cmac, ad, length); } -void EAX_Mode::start_msg(const byte nonce[], size_t nonce_len) +void EAX_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -117,11 +117,11 @@ size_t EAX_Encryption::process(uint8_t buf[], size_t sz) return sz; } -void EAX_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void EAX_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { update(buffer, offset); - secure_vector<byte> data_mac = m_cmac->final(); + secure_vector<uint8_t> data_mac = m_cmac->final(); xor_buf(data_mac, m_nonce_mac, data_mac.size()); if(m_ad_mac.empty()) @@ -141,11 +141,11 @@ size_t EAX_Decryption::process(uint8_t buf[], size_t sz) return sz; } -void EAX_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void EAX_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input"); @@ -157,9 +157,9 @@ void EAX_Decryption::finish(secure_vector<byte>& buffer, size_t offset) m_ctr->cipher(buf, buf, remaining); } - const byte* included_tag = &buf[remaining]; + const uint8_t* included_tag = &buf[remaining]; - secure_vector<byte> mac = m_cmac->final(); + secure_vector<uint8_t> mac = m_cmac->final(); mac ^= m_nonce_mac; if(m_ad_mac.empty()) diff --git a/src/lib/modes/aead/eax/eax.h b/src/lib/modes/aead/eax/eax.h index c0b6bcf42..fc991ab1f 100644 --- a/src/lib/modes/aead/eax/eax.h +++ b/src/lib/modes/aead/eax/eax.h @@ -22,7 +22,7 @@ namespace Botan { class BOTAN_DLL EAX_Mode : public AEAD_Mode { public: - void set_associated_data(const byte ad[], size_t ad_len) override; + void set_associated_data(const uint8_t ad[], size_t ad_len) override; std::string name() const override; @@ -54,13 +54,13 @@ class BOTAN_DLL EAX_Mode : public AEAD_Mode std::unique_ptr<StreamCipher> m_ctr; std::unique_ptr<MessageAuthenticationCode> m_cmac; - secure_vector<byte> m_ad_mac; + secure_vector<uint8_t> m_ad_mac; - secure_vector<byte> m_nonce_mac; + secure_vector<uint8_t> m_nonce_mac; private: - void start_msg(const byte nonce[], size_t nonce_len) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void key_schedule(const uint8_t key[], size_t length) override; }; /** @@ -83,7 +83,7 @@ class BOTAN_DLL EAX_Encryption final : public EAX_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; /** @@ -109,7 +109,7 @@ class BOTAN_DLL EAX_Decryption final : public EAX_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; } diff --git a/src/lib/modes/aead/gcm/clmul/clmul.cpp b/src/lib/modes/aead/gcm/clmul/clmul.cpp index 725ef3da3..ed3473b4e 100644 --- a/src/lib/modes/aead/gcm/clmul/clmul.cpp +++ b/src/lib/modes/aead/gcm/clmul/clmul.cpp @@ -12,7 +12,7 @@ namespace Botan { BOTAN_FUNC_ISA("pclmul,ssse3") -void gcm_multiply_clmul(byte x[16], const byte H[16]) +void gcm_multiply_clmul(uint8_t x[16], const uint8_t H[16]) { /* * Algorithms 1 and 5 from Intel's CLMUL guide diff --git a/src/lib/modes/aead/gcm/clmul/clmul.h b/src/lib/modes/aead/gcm/clmul/clmul.h index a3d8d9851..5e4a0de35 100644 --- a/src/lib/modes/aead/gcm/clmul/clmul.h +++ b/src/lib/modes/aead/gcm/clmul/clmul.h @@ -12,7 +12,7 @@ namespace Botan { -void gcm_multiply_clmul(byte x[16], const byte H[16]); +void gcm_multiply_clmul(uint8_t x[16], const uint8_t H[16]); } diff --git a/src/lib/modes/aead/gcm/gcm.cpp b/src/lib/modes/aead/gcm/gcm.cpp index e0bc59a8d..0d0cbff3c 100644 --- a/src/lib/modes/aead/gcm/gcm.cpp +++ b/src/lib/modes/aead/gcm/gcm.cpp @@ -20,21 +20,21 @@ namespace Botan { static const size_t GCM_BS = 16; -void GHASH::gcm_multiply(secure_vector<byte>& x) const +void GHASH::gcm_multiply(secure_vector<uint8_t>& x) const { #if defined(BOTAN_HAS_GCM_CLMUL) if(CPUID::has_clmul()) return gcm_multiply_clmul(x.data(), m_H.data()); #endif - static const u64bit R = 0xE100000000000000; + static const uint64_t R = 0xE100000000000000; - u64bit H[2] = { - load_be<u64bit>(m_H.data(), 0), - load_be<u64bit>(m_H.data(), 1) + uint64_t H[2] = { + load_be<uint64_t>(m_H.data(), 0), + load_be<uint64_t>(m_H.data(), 1) }; - u64bit Z[2] = { 0, 0 }; + uint64_t Z[2] = { 0, 0 }; CT::poison(H, 2); CT::poison(Z, 2); @@ -44,30 +44,30 @@ void GHASH::gcm_multiply(secure_vector<byte>& x) const for(size_t i = 0; i != 2; ++i) { - const u64bit X = load_be<u64bit>(x.data(), i); + const uint64_t X = load_be<uint64_t>(x.data(), i); - u64bit mask = 0x8000000000000000; + uint64_t mask = 0x8000000000000000; for(size_t j = 0; j != 64; ++j) { - const u64bit XMASK = CT::expand_mask<u64bit>(X & mask); + const uint64_t XMASK = CT::expand_mask<uint64_t>(X & mask); mask >>= 1; Z[0] ^= H[0] & XMASK; Z[1] ^= H[1] & XMASK; // GCM's bit ops are reversed so we carry out of the bottom - const u64bit carry = R & CT::expand_mask<u64bit>(H[1] & 1); + const uint64_t carry = R & CT::expand_mask<uint64_t>(H[1] & 1); H[1] = (H[1] >> 1) | (H[0] << 63); H[0] = (H[0] >> 1) ^ carry; } } - store_be<u64bit>(x.data(), Z[0], Z[1]); + store_be<uint64_t>(x.data(), Z[0], Z[1]); CT::unpoison(x.data(), x.size()); } -void GHASH::ghash_update(secure_vector<byte>& ghash, - const byte input[], size_t length) +void GHASH::ghash_update(secure_vector<uint8_t>& ghash, + const uint8_t input[], size_t length) { /* This assumes if less than block size input then we're just on the @@ -86,7 +86,7 @@ void GHASH::ghash_update(secure_vector<byte>& ghash, } } -void GHASH::key_schedule(const byte key[], size_t length) +void GHASH::key_schedule(const uint8_t key[], size_t length) { m_H.assign(key, key+length); m_H_ad.resize(GCM_BS); @@ -94,13 +94,13 @@ void GHASH::key_schedule(const byte key[], size_t length) m_text_len = 0; } -void GHASH::start(const byte nonce[], size_t len) +void GHASH::start(const uint8_t nonce[], size_t len) { m_nonce.assign(nonce, nonce + len); m_ghash = m_H_ad; } -void GHASH::set_associated_data(const byte input[], size_t length) +void GHASH::set_associated_data(const uint8_t input[], size_t length) { zeroise(m_H_ad); @@ -108,7 +108,7 @@ void GHASH::set_associated_data(const byte input[], size_t length) m_ad_len = length; } -void GHASH::update(const byte input[], size_t length) +void GHASH::update(const uint8_t input[], size_t length) { BOTAN_ASSERT(m_ghash.size() == GCM_BS, "Key was set"); @@ -117,19 +117,19 @@ void GHASH::update(const byte input[], size_t length) ghash_update(m_ghash, input, length); } -void GHASH::add_final_block(secure_vector<byte>& hash, +void GHASH::add_final_block(secure_vector<uint8_t>& hash, size_t ad_len, size_t text_len) { - secure_vector<byte> final_block(GCM_BS); - store_be<u64bit>(final_block.data(), 8*ad_len, 8*text_len); + secure_vector<uint8_t> final_block(GCM_BS); + store_be<uint64_t>(final_block.data(), 8*ad_len, 8*text_len); ghash_update(hash, final_block.data(), final_block.size()); } -secure_vector<byte> GHASH::final() +secure_vector<uint8_t> GHASH::final() { add_final_block(m_ghash, m_ad_len, m_text_len); - secure_vector<byte> mac; + secure_vector<uint8_t> mac; mac.swap(m_ghash); mac ^= m_nonce; @@ -137,10 +137,10 @@ secure_vector<byte> GHASH::final() return mac; } -secure_vector<byte> GHASH::nonce_hash(const byte nonce[], size_t nonce_len) +secure_vector<uint8_t> GHASH::nonce_hash(const uint8_t nonce[], size_t nonce_len) { BOTAN_ASSERT(m_ghash.size() == 0, "nonce_hash called during wrong time"); - secure_vector<byte> y0(GCM_BS); + secure_vector<uint8_t> y0(GCM_BS); ghash_update(y0, nonce, nonce_len); add_final_block(y0, 0, nonce_len); @@ -217,29 +217,29 @@ Key_Length_Specification GCM_Mode::key_spec() const return m_ctr->key_spec(); } -void GCM_Mode::key_schedule(const byte key[], size_t keylen) +void GCM_Mode::key_schedule(const uint8_t key[], size_t keylen) { m_ctr->set_key(key, keylen); - const std::vector<byte> zeros(GCM_BS); + const std::vector<uint8_t> zeros(GCM_BS); m_ctr->set_iv(zeros.data(), zeros.size()); - secure_vector<byte> H(GCM_BS); + secure_vector<uint8_t> H(GCM_BS); m_ctr->encipher(H); m_ghash->set_key(H); } -void GCM_Mode::set_associated_data(const byte ad[], size_t ad_len) +void GCM_Mode::set_associated_data(const uint8_t ad[], size_t ad_len) { m_ghash->set_associated_data(ad, ad_len); } -void GCM_Mode::start_msg(const byte nonce[], size_t nonce_len) +void GCM_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); - secure_vector<byte> y0(GCM_BS); + secure_vector<uint8_t> y0(GCM_BS); if(nonce_len == 12) { @@ -253,7 +253,7 @@ void GCM_Mode::start_msg(const byte nonce[], size_t nonce_len) m_ctr->set_iv(y0.data(), y0.size()); - secure_vector<byte> m_enc_y0(GCM_BS); + secure_vector<uint8_t> m_enc_y0(GCM_BS); m_ctr->encipher(m_enc_y0); m_ghash->start(m_enc_y0.data(), m_enc_y0.size()); @@ -267,11 +267,11 @@ size_t GCM_Encryption::process(uint8_t buf[], size_t sz) return sz; } -void GCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void GCM_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ARG_CHECK(offset <= buffer.size()); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; m_ctr->cipher(buf, buf, sz); m_ghash->update(buf, sz); @@ -287,11 +287,11 @@ size_t GCM_Decryption::process(uint8_t buf[], size_t sz) return sz; } -void GCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void GCM_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ARG_CHECK(offset <= buffer.size()); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; if(sz < tag_size()) throw Exception("Insufficient input for GCM decryption, tag missing"); @@ -307,7 +307,7 @@ void GCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset) auto mac = m_ghash->final(); - const byte* included_tag = &buffer[remaining+offset]; + const uint8_t* included_tag = &buffer[remaining+offset]; if(!same_mem(mac.data(), included_tag, tag_size())) throw Integrity_Failure("GCM tag check failed"); diff --git a/src/lib/modes/aead/gcm/gcm.h b/src/lib/modes/aead/gcm/gcm.h index 65b6b0474..e2e3a2c9d 100644 --- a/src/lib/modes/aead/gcm/gcm.h +++ b/src/lib/modes/aead/gcm/gcm.h @@ -23,7 +23,7 @@ class GHASH; class BOTAN_DLL GCM_Mode : public AEAD_Mode { public: - void set_associated_data(const byte ad[], size_t ad_len) override; + void set_associated_data(const uint8_t ad[], size_t ad_len) override; std::string name() const override; @@ -52,9 +52,9 @@ class BOTAN_DLL GCM_Mode : public AEAD_Mode std::unique_ptr<StreamCipher> m_ctr; std::unique_ptr<GHASH> m_ghash; private: - void start_msg(const byte nonce[], size_t nonce_len) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void key_schedule(const uint8_t key[], size_t length) override; }; /** @@ -77,7 +77,7 @@ class BOTAN_DLL GCM_Encryption final : public GCM_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; /** @@ -103,7 +103,7 @@ class BOTAN_DLL GCM_Decryption final : public GCM_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; /** @@ -113,18 +113,18 @@ class BOTAN_DLL GCM_Decryption final : public GCM_Mode class BOTAN_DLL GHASH : public SymmetricAlgorithm { public: - void set_associated_data(const byte ad[], size_t ad_len); + void set_associated_data(const uint8_t ad[], size_t ad_len); - secure_vector<byte> nonce_hash(const byte nonce[], size_t len); + secure_vector<uint8_t> nonce_hash(const uint8_t nonce[], size_t len); - void start(const byte nonce[], size_t len); + void start(const uint8_t nonce[], size_t len); /* * Assumes input len is multiple of 16 */ - void update(const byte in[], size_t len); + void update(const uint8_t in[], size_t len); - secure_vector<byte> final(); + secure_vector<uint8_t> final(); Key_Length_Specification key_spec() const override { return Key_Length_Specification(16); } @@ -135,23 +135,23 @@ class BOTAN_DLL GHASH : public SymmetricAlgorithm std::string name() const override { return "GHASH"; } protected: - void ghash_update(secure_vector<byte>& x, - const byte input[], size_t input_len); + void ghash_update(secure_vector<uint8_t>& x, + const uint8_t input[], size_t input_len); - void add_final_block(secure_vector<byte>& x, + void add_final_block(secure_vector<uint8_t>& x, size_t ad_len, size_t pt_len); - secure_vector<byte> m_H; - secure_vector<byte> m_H_ad; - secure_vector<byte> m_ghash; + secure_vector<uint8_t> m_H; + secure_vector<uint8_t> m_H_ad; + secure_vector<uint8_t> m_ghash; size_t m_ad_len = 0; private: - void key_schedule(const byte key[], size_t key_len) override; + void key_schedule(const uint8_t key[], size_t key_len) override; - void gcm_multiply(secure_vector<byte>& x) const; + void gcm_multiply(secure_vector<uint8_t>& x) const; - secure_vector<byte> m_nonce; + secure_vector<uint8_t> m_nonce; size_t m_text_len = 0; }; diff --git a/src/lib/modes/aead/ocb/ocb.cpp b/src/lib/modes/aead/ocb/ocb.cpp index c530dda5d..84787ad38 100644 --- a/src/lib/modes/aead/ocb/ocb.cpp +++ b/src/lib/modes/aead/ocb/ocb.cpp @@ -24,13 +24,13 @@ class L_computer m_L.push_back(poly_double(dollar())); } - const secure_vector<byte>& star() const { return m_L_star; } + const secure_vector<uint8_t>& star() const { return m_L_star; } - const secure_vector<byte>& dollar() const { return m_L_dollar; } + const secure_vector<uint8_t>& dollar() const { return m_L_dollar; } - const secure_vector<byte>& operator()(size_t i) const { return get(i); } + const secure_vector<uint8_t>& operator()(size_t i) const { return get(i); } - const secure_vector<byte>& compute_offsets(secure_vector<byte>& offset, + const secure_vector<uint8_t>& compute_offsets(secure_vector<uint8_t>& offset, size_t block_index, size_t blocks) const { @@ -46,7 +46,7 @@ class L_computer } private: - const secure_vector<byte>& get(size_t i) const + const secure_vector<uint8_t>& get(size_t i) const { while(m_L.size() <= i) m_L.push_back(poly_double(m_L.back())); @@ -54,14 +54,14 @@ class L_computer return m_L.at(i); } - secure_vector<byte> poly_double(const secure_vector<byte>& in) const + secure_vector<uint8_t> poly_double(const secure_vector<uint8_t>& in) const { return CMAC::poly_double(in); } - secure_vector<byte> m_L_dollar, m_L_star; - mutable std::vector<secure_vector<byte>> m_L; - mutable secure_vector<byte> m_offset_buf; + secure_vector<uint8_t> m_L_dollar, m_L_star; + mutable std::vector<secure_vector<uint8_t>> m_L; + mutable secure_vector<uint8_t> m_offset_buf; }; namespace { @@ -69,14 +69,14 @@ namespace { /* * OCB's HASH */ -secure_vector<byte> ocb_hash(const L_computer& L, +secure_vector<uint8_t> ocb_hash(const L_computer& L, const BlockCipher& cipher, - const byte ad[], size_t ad_len) + const uint8_t ad[], size_t ad_len) { - secure_vector<byte> sum(16); - secure_vector<byte> offset(16); + secure_vector<uint8_t> sum(16); + secure_vector<uint8_t> offset(16); - secure_vector<byte> buf(16); + secure_vector<uint8_t> buf(16); const size_t ad_blocks = (ad_len / 16); const size_t ad_remainder = (ad_len % 16); @@ -165,30 +165,30 @@ Key_Length_Specification OCB_Mode::key_spec() const return m_cipher->key_spec(); } -void OCB_Mode::key_schedule(const byte key[], size_t length) +void OCB_Mode::key_schedule(const uint8_t key[], size_t length) { m_cipher->set_key(key, length); m_L.reset(new L_computer(*m_cipher)); } -void OCB_Mode::set_associated_data(const byte ad[], size_t ad_len) +void OCB_Mode::set_associated_data(const uint8_t ad[], size_t ad_len) { BOTAN_ASSERT(m_L, "A key was set"); m_ad_hash = ocb_hash(*m_L, *m_cipher, ad, ad_len); } -secure_vector<byte> -OCB_Mode::update_nonce(const byte nonce[], size_t nonce_len) +secure_vector<uint8_t> +OCB_Mode::update_nonce(const uint8_t nonce[], size_t nonce_len) { BOTAN_ASSERT(nonce_len < 16, "OCB nonce is less than cipher block size"); - secure_vector<byte> nonce_buf(16); + secure_vector<uint8_t> nonce_buf(16); copy_mem(&nonce_buf[16 - nonce_len], nonce, nonce_len); nonce_buf[0] = ((tag_size() * 8) % 128) << 1; nonce_buf[16 - nonce_len - 1] = 1; - const byte bottom = nonce_buf[16-1] & 0x3F; + const uint8_t bottom = nonce_buf[16-1] & 0x3F; nonce_buf[16-1] &= 0xC0; const bool need_new_stretch = (m_last_nonce != nonce_buf); @@ -210,7 +210,7 @@ OCB_Mode::update_nonce(const byte nonce[], size_t nonce_len) const size_t shift_bytes = bottom / 8; const size_t shift_bits = bottom % 8; - secure_vector<byte> offset(16); + secure_vector<uint8_t> offset(16); for(size_t i = 0; i != 16; ++i) { offset[i] = (m_stretch[i+shift_bytes] << shift_bits); @@ -220,7 +220,7 @@ OCB_Mode::update_nonce(const byte nonce[], size_t nonce_len) return offset; } -void OCB_Mode::start_msg(const byte nonce[], size_t nonce_len) +void OCB_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -232,7 +232,7 @@ void OCB_Mode::start_msg(const byte nonce[], size_t nonce_len) m_block_index = 0; } -void OCB_Encryption::encrypt(byte buffer[], size_t blocks) +void OCB_Encryption::encrypt(uint8_t buffer[], size_t blocks) { const size_t par_blocks = m_checksum.size() / 16; @@ -262,11 +262,11 @@ size_t OCB_Encryption::process(uint8_t buf[], size_t sz) return sz; } -void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void OCB_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; if(sz) { @@ -278,27 +278,27 @@ void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) if(remainder_bytes) { BOTAN_ASSERT(remainder_bytes < 16, "Only a partial block left"); - byte* remainder = &buf[sz - remainder_bytes]; + uint8_t* remainder = &buf[sz - 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(16); + secure_vector<uint8_t> zeros(16); m_cipher->encrypt(m_offset, zeros); xor_buf(remainder, zeros.data(), remainder_bytes); } } - secure_vector<byte> checksum(16); + secure_vector<uint8_t> checksum(16); // fold checksum for(size_t i = 0; i != m_checksum.size(); ++i) checksum[i % checksum.size()] ^= m_checksum[i]; // now compute the tag - secure_vector<byte> mac = m_offset; + secure_vector<uint8_t> mac = m_offset; mac ^= checksum; mac ^= m_L->dollar(); @@ -313,7 +313,7 @@ void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) m_block_index = 0; } -void OCB_Decryption::decrypt(byte buffer[], size_t blocks) +void OCB_Decryption::decrypt(uint8_t buffer[], size_t blocks) { const size_t par_bytes = m_cipher->parallel_bytes(); @@ -347,11 +347,11 @@ size_t OCB_Decryption::process(uint8_t buf[], size_t sz) return sz; } -void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void OCB_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= tag_size(), "We have the tag"); @@ -368,11 +368,11 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) { BOTAN_ASSERT(final_bytes < 16, "Only a partial block left"); - byte* remainder = &buf[remaining - final_bytes]; + uint8_t* remainder = &buf[remaining - final_bytes]; m_offset ^= m_L->star(); // Offset_* - secure_vector<byte> pad(16); + secure_vector<uint8_t> pad(16); m_cipher->encrypt(m_offset, pad); // P_* xor_buf(remainder, pad.data(), final_bytes); @@ -382,14 +382,14 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) } } - secure_vector<byte> checksum(16); + secure_vector<uint8_t> checksum(16); // fold checksum for(size_t i = 0; i != m_checksum.size(); ++i) checksum[i % checksum.size()] ^= m_checksum[i]; // compute the mac - secure_vector<byte> mac = m_offset; + secure_vector<uint8_t> mac = m_offset; mac ^= checksum; mac ^= m_L->dollar(); @@ -403,7 +403,7 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) m_block_index = 0; // compare mac - const byte* included_tag = &buf[remaining]; + const uint8_t* included_tag = &buf[remaining]; if(!same_mem(mac.data(), included_tag, tag_size())) throw Integrity_Failure("OCB tag check failed"); diff --git a/src/lib/modes/aead/ocb/ocb.h b/src/lib/modes/aead/ocb/ocb.h index dfdb8c18c..cac87ddb6 100644 --- a/src/lib/modes/aead/ocb/ocb.h +++ b/src/lib/modes/aead/ocb/ocb.h @@ -28,7 +28,7 @@ class L_computer; class BOTAN_DLL OCB_Mode : public AEAD_Mode { public: - void set_associated_data(const byte ad[], size_t ad_len) override; + void set_associated_data(const uint8_t ad[], size_t ad_len) override; std::string name() const override; @@ -58,19 +58,19 @@ class BOTAN_DLL OCB_Mode : public AEAD_Mode size_t m_block_index = 0; - secure_vector<byte> m_checksum; - secure_vector<byte> m_offset; - secure_vector<byte> m_ad_hash; + secure_vector<uint8_t> m_checksum; + secure_vector<uint8_t> m_offset; + secure_vector<uint8_t> m_ad_hash; private: - void start_msg(const byte nonce[], size_t nonce_len) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void key_schedule(const uint8_t key[], size_t length) override; - secure_vector<byte> update_nonce(const byte nonce[], size_t nonce_len); + secure_vector<uint8_t> update_nonce(const uint8_t nonce[], size_t nonce_len); size_t m_tag_size = 0; - secure_vector<byte> m_last_nonce; - secure_vector<byte> m_stretch; + secure_vector<uint8_t> m_last_nonce; + secure_vector<uint8_t> m_stretch; }; class BOTAN_DLL OCB_Encryption final : public OCB_Mode @@ -90,9 +90,9 @@ class BOTAN_DLL OCB_Encryption final : public OCB_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; private: - void encrypt(byte input[], size_t blocks); + void encrypt(uint8_t input[], size_t blocks); }; class BOTAN_DLL OCB_Decryption final : public OCB_Mode @@ -115,9 +115,9 @@ class BOTAN_DLL OCB_Decryption final : public OCB_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; private: - void decrypt(byte input[], size_t blocks); + void decrypt(uint8_t input[], size_t blocks); }; } diff --git a/src/lib/modes/aead/siv/siv.cpp b/src/lib/modes/aead/siv/siv.cpp index 373a2627c..c4db3d785 100644 --- a/src/lib/modes/aead/siv/siv.cpp +++ b/src/lib/modes/aead/siv/siv.cpp @@ -51,7 +51,7 @@ size_t SIV_Mode::update_granularity() const /* This value does not particularly matter as regardless SIV_Mode::update buffers all input, so in theory this could be 1. However as for instance - Transform_Filter creates update_granularity() byte buffers, use a + Transform_Filter creates update_granularity() uint8_t buffers, use a somewhat large size to avoid bouncing on a tiny buffer. */ return 128; @@ -62,7 +62,7 @@ Key_Length_Specification SIV_Mode::key_spec() const return m_cmac->key_spec().multiple(2); } -void SIV_Mode::key_schedule(const byte key[], size_t length) +void SIV_Mode::key_schedule(const uint8_t key[], size_t length) { const size_t keylen = length / 2; m_cmac->set_key(key, keylen); @@ -70,7 +70,7 @@ void SIV_Mode::key_schedule(const byte key[], size_t length) m_ad_macs.clear(); } -void SIV_Mode::set_associated_data_n(size_t n, const byte ad[], size_t length) +void SIV_Mode::set_associated_data_n(size_t n, const uint8_t ad[], size_t length) { if(n >= m_ad_macs.size()) m_ad_macs.resize(n+1); @@ -78,7 +78,7 @@ void SIV_Mode::set_associated_data_n(size_t n, const byte ad[], size_t length) m_ad_macs[n] = m_cmac->process(ad, length); } -void SIV_Mode::start_msg(const byte nonce[], size_t nonce_len) +void SIV_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -98,11 +98,11 @@ size_t SIV_Mode::process(uint8_t buf[], size_t sz) return 0; } -secure_vector<byte> SIV_Mode::S2V(const byte* text, size_t text_len) +secure_vector<uint8_t> SIV_Mode::S2V(const uint8_t* text, size_t text_len) { - const byte zero[16] = { 0 }; + const uint8_t zero[16] = { 0 }; - secure_vector<byte> V = m_cmac->process(zero, 16); + secure_vector<uint8_t> V = m_cmac->process(zero, 16); for(size_t i = 0; i != m_ad_macs.size(); ++i) { @@ -131,7 +131,7 @@ secure_vector<byte> SIV_Mode::S2V(const byte* text, size_t text_len) return m_cmac->final(); } -void SIV_Mode::set_ctr_iv(secure_vector<byte> V) +void SIV_Mode::set_ctr_iv(secure_vector<uint8_t> V) { V[8] &= 0x7F; V[12] &= 0x7F; @@ -139,13 +139,13 @@ void SIV_Mode::set_ctr_iv(secure_vector<byte> V) ctr().set_iv(V.data(), V.size()); } -void SIV_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void SIV_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end()); - secure_vector<byte> V = S2V(buffer.data() + offset, buffer.size() - offset); + secure_vector<uint8_t> V = S2V(buffer.data() + offset, buffer.size() - offset); buffer.insert(buffer.begin() + offset, V.begin(), V.end()); @@ -153,7 +153,7 @@ void SIV_Encryption::finish(secure_vector<byte>& buffer, size_t offset) ctr().cipher1(&buffer[offset + V.size()], buffer.size() - offset - V.size()); } -void SIV_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void SIV_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); @@ -163,7 +163,7 @@ 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.data() + offset, buffer.data() + offset + 16); + secure_vector<uint8_t> V(buffer.data() + offset, buffer.data() + offset + 16); set_ctr_iv(V); @@ -171,7 +171,7 @@ void SIV_Decryption::finish(secure_vector<byte>& buffer, size_t offset) buffer.data() + offset, buffer.size() - offset - V.size()); - secure_vector<byte> T = S2V(buffer.data() + offset, buffer.size() - offset - V.size()); + secure_vector<uint8_t> 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/aead/siv/siv.h b/src/lib/modes/aead/siv/siv.h index 711d9e30c..ea6ad8234 100644 --- a/src/lib/modes/aead/siv/siv.h +++ b/src/lib/modes/aead/siv/siv.h @@ -30,9 +30,9 @@ class BOTAN_DLL SIV_Mode : public AEAD_Mode * @param ad associated data * @param ad_len length of associated data in bytes */ - void set_associated_data_n(size_t n, const byte ad[], size_t ad_len); + void set_associated_data_n(size_t n, const uint8_t ad[], size_t ad_len); - void set_associated_data(const byte ad[], size_t ad_len) override + void set_associated_data(const uint8_t ad[], size_t ad_len) override { set_associated_data_n(0, ad, ad_len); } @@ -56,21 +56,21 @@ class BOTAN_DLL SIV_Mode : public AEAD_Mode StreamCipher& ctr() { return *m_ctr; } - void set_ctr_iv(secure_vector<byte> V); + void set_ctr_iv(secure_vector<uint8_t> V); - secure_vector<byte>& msg_buf() { return m_msg_buf; } + secure_vector<uint8_t>& msg_buf() { return m_msg_buf; } - secure_vector<byte> S2V(const byte text[], size_t text_len); + secure_vector<uint8_t> S2V(const uint8_t text[], size_t text_len); private: - void start_msg(const byte nonce[], size_t nonce_len) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void key_schedule(const uint8_t key[], size_t length) override; const std::string m_name; std::unique_ptr<StreamCipher> m_ctr; std::unique_ptr<MessageAuthenticationCode> m_cmac; - secure_vector<byte> m_nonce, m_msg_buf; - std::vector<secure_vector<byte>> m_ad_macs; + secure_vector<uint8_t> m_nonce, m_msg_buf; + std::vector<secure_vector<uint8_t>> m_ad_macs; }; /** @@ -84,7 +84,7 @@ class BOTAN_DLL SIV_Encryption final : public SIV_Mode */ explicit SIV_Encryption(BlockCipher* cipher) : SIV_Mode(cipher) {} - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override { return input_length + tag_size(); } @@ -103,7 +103,7 @@ class BOTAN_DLL SIV_Decryption final : public SIV_Mode */ explicit SIV_Decryption(BlockCipher* cipher) : SIV_Mode(cipher) {} - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override { diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp index 9fbb7023f..188b4a0aa 100644 --- a/src/lib/modes/cbc/cbc.cpp +++ b/src/lib/modes/cbc/cbc.cpp @@ -62,12 +62,12 @@ bool CBC_Mode::valid_nonce_length(size_t n) const return (n == 0 || n == cipher().block_size()); } -void CBC_Mode::key_schedule(const byte key[], size_t length) +void CBC_Mode::key_schedule(const uint8_t key[], size_t length) { m_cipher->set_key(key, length); } -void CBC_Mode::start_msg(const byte nonce[], size_t nonce_len) +void CBC_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -101,7 +101,7 @@ size_t CBC_Encryption::process(uint8_t buf[], size_t sz) BOTAN_ASSERT(sz % BS == 0, "CBC input is full blocks"); const size_t blocks = sz / BS; - const byte* prev_block = state_ptr(); + const uint8_t* prev_block = state_ptr(); if(blocks) { @@ -118,7 +118,7 @@ size_t CBC_Encryption::process(uint8_t buf[], size_t sz) return sz; } -void CBC_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void CBC_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); @@ -149,10 +149,10 @@ size_t CTS_Encryption::output_length(size_t input_length) const return input_length; // no ciphertext expansion in CTS } -void CTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void CTS_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; const size_t sz = buffer.size() - offset; const size_t BS = cipher().block_size(); @@ -174,7 +174,7 @@ void CTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) const size_t final_bytes = sz - full_blocks; BOTAN_ASSERT(final_bytes > BS && final_bytes < 2*BS, "Left over size in expected range"); - secure_vector<byte> last(buf + full_blocks, buf + full_blocks + final_bytes); + secure_vector<uint8_t> last(buf + full_blocks, buf + full_blocks + final_bytes); buffer.resize(full_blocks + offset); update(buffer, offset); @@ -229,7 +229,7 @@ size_t CBC_Decryption::process(uint8_t buf[], size_t sz) return sz; } -void CBC_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void CBC_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; @@ -265,11 +265,11 @@ size_t CTS_Decryption::minimum_final_size() const return cipher().block_size() + 1; } -void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void CTS_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; const size_t BS = cipher().block_size(); @@ -291,7 +291,7 @@ void CTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset) const size_t final_bytes = sz - full_blocks; BOTAN_ASSERT(final_bytes > BS && final_bytes < 2*BS, "Left over size in expected range"); - secure_vector<byte> last(buf + full_blocks, buf + full_blocks + final_bytes); + secure_vector<uint8_t> last(buf + full_blocks, buf + full_blocks + final_bytes); buffer.resize(full_blocks + offset); update(buffer, offset); diff --git a/src/lib/modes/cbc/cbc.h b/src/lib/modes/cbc/cbc.h index 1b7cbd323..a44a9b5d9 100644 --- a/src/lib/modes/cbc/cbc.h +++ b/src/lib/modes/cbc/cbc.h @@ -46,18 +46,18 @@ class BOTAN_DLL CBC_Mode : public Cipher_Mode return *m_padding; } - secure_vector<byte>& state() { return m_state; } + secure_vector<uint8_t>& state() { return m_state; } - byte* state_ptr() { return m_state.data(); } + uint8_t* state_ptr() { return m_state.data(); } private: - void start_msg(const byte nonce[], size_t nonce_len) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void key_schedule(const uint8_t key[], size_t length) override; std::unique_ptr<BlockCipher> m_cipher; std::unique_ptr<BlockCipherModePaddingMethod> m_padding; - secure_vector<byte> m_state; + secure_vector<uint8_t> m_state; }; /** @@ -75,7 +75,7 @@ class BOTAN_DLL CBC_Encryption : public CBC_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override; @@ -95,7 +95,7 @@ class BOTAN_DLL CTS_Encryption final : public CBC_Encryption size_t output_length(size_t input_length) const override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t minimum_final_size() const override; @@ -117,7 +117,7 @@ class BOTAN_DLL CBC_Decryption : public CBC_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override; @@ -126,7 +126,7 @@ class BOTAN_DLL CBC_Decryption : public CBC_Mode void reset() override; private: - secure_vector<byte> m_tempbuf; + secure_vector<uint8_t> m_tempbuf; }; /** @@ -140,7 +140,7 @@ class BOTAN_DLL CTS_Decryption final : public CBC_Decryption */ explicit CTS_Decryption(BlockCipher* cipher) : CBC_Decryption(cipher, nullptr) {} - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t minimum_final_size() const override; diff --git a/src/lib/modes/cfb/cfb.cpp b/src/lib/modes/cfb/cfb.cpp index 2d1477e27..148e16c6c 100644 --- a/src/lib/modes/cfb/cfb.cpp +++ b/src/lib/modes/cfb/cfb.cpp @@ -70,12 +70,12 @@ bool CFB_Mode::valid_nonce_length(size_t n) const return (n == cipher().block_size()); } -void CFB_Mode::key_schedule(const byte key[], size_t length) +void CFB_Mode::key_schedule(const uint8_t key[], size_t length) { m_cipher->set_key(key, length); } -void CFB_Mode::start_msg(const byte nonce[], size_t nonce_len) +void CFB_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -89,7 +89,7 @@ size_t CFB_Encryption::process(uint8_t buf[], size_t sz) { const size_t BS = cipher().block_size(); - secure_vector<byte>& state = shift_register(); + secure_vector<uint8_t>& state = shift_register(); const size_t shift = feedback(); size_t left = sz; @@ -112,7 +112,7 @@ size_t CFB_Encryption::process(uint8_t buf[], size_t sz) return sz; } -void CFB_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void CFB_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { update(buffer, offset); } @@ -121,7 +121,7 @@ size_t CFB_Decryption::process(uint8_t buf[], size_t sz) { const size_t BS = cipher().block_size(); - secure_vector<byte>& state = shift_register(); + secure_vector<uint8_t>& state = shift_register(); const size_t shift = feedback(); size_t left = sz; @@ -148,7 +148,7 @@ size_t CFB_Decryption::process(uint8_t buf[], size_t sz) return sz; } -void CFB_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void CFB_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { update(buffer, offset); } diff --git a/src/lib/modes/cfb/cfb.h b/src/lib/modes/cfb/cfb.h index 18611f3f2..a128539a4 100644 --- a/src/lib/modes/cfb/cfb.h +++ b/src/lib/modes/cfb/cfb.h @@ -44,17 +44,17 @@ class BOTAN_DLL CFB_Mode : public Cipher_Mode size_t feedback() const { return m_feedback_bytes; } - secure_vector<byte>& shift_register() { return m_shift_register; } + secure_vector<uint8_t>& shift_register() { return m_shift_register; } - secure_vector<byte>& keystream_buf() { return m_keystream_buf; } + secure_vector<uint8_t>& keystream_buf() { return m_keystream_buf; } private: - void start_msg(const byte nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; + void key_schedule(const uint8_t key[], size_t length) override; std::unique_ptr<BlockCipher> m_cipher; - secure_vector<byte> m_shift_register; - secure_vector<byte> m_keystream_buf; + secure_vector<uint8_t> m_shift_register; + secure_vector<uint8_t> m_keystream_buf; size_t m_feedback_bytes; }; @@ -75,7 +75,7 @@ class BOTAN_DLL CFB_Encryption final : public CFB_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; /** @@ -95,7 +95,7 @@ class BOTAN_DLL CFB_Decryption final : public CFB_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; }; } diff --git a/src/lib/modes/cipher_mode.h b/src/lib/modes/cipher_mode.h index 8bf58f10a..cdf16e37c 100644 --- a/src/lib/modes/cipher_mode.h +++ b/src/lib/modes/cipher_mode.h @@ -28,14 +28,14 @@ class BOTAN_DLL Cipher_Mode /* * Prepare for processing a message under the specified nonce */ - virtual void start_msg(const byte nonce[], size_t nonce_len) = 0; + virtual void start_msg(const uint8_t nonce[], size_t nonce_len) = 0; /** * Begin processing a message. * @param nonce the per message nonce */ template<typename Alloc> - void start(const std::vector<byte, Alloc>& nonce) + void start(const std::vector<uint8_t, Alloc>& nonce) { start_msg(nonce.data(), nonce.size()); } @@ -45,7 +45,7 @@ class BOTAN_DLL Cipher_Mode * @param nonce the per message nonce * @param nonce_len length of nonce */ - void start(const byte nonce[], size_t nonce_len) + void start(const uint8_t nonce[], size_t nonce_len) { start_msg(nonce, nonce_len); } @@ -74,14 +74,14 @@ class BOTAN_DLL Cipher_Mode virtual size_t process(uint8_t msg[], size_t msg_len) = 0; /** - * Process some data. Input must be in size update_granularity() byte blocks. + * Process some data. Input must be in size update_granularity() uint8_t blocks. * @param buffer in/out parameter which will possibly be resized * @param offset an offset into blocks to begin processing */ - void update(secure_vector<byte>& buffer, size_t offset = 0) + void update(secure_vector<uint8_t>& buffer, size_t offset = 0) { BOTAN_ASSERT(buffer.size() >= offset, "Offset ok"); - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; const size_t buf_size = buffer.size() - offset; const size_t written = process(buf, buf_size); @@ -95,7 +95,7 @@ class BOTAN_DLL Cipher_Mode * minimum_final_size() bytes, and will be set to any final output * @param offset an offset into final_block to begin processing */ - virtual void finish(secure_vector<byte>& final_block, size_t offset = 0) = 0; + virtual void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) = 0; /** * Returns the size of the output if this transform is used to process a @@ -169,7 +169,7 @@ class BOTAN_DLL Cipher_Mode * @param key contains the key material */ template<typename Alloc> - void set_key(const std::vector<byte, Alloc>& key) + void set_key(const std::vector<uint8_t, Alloc>& key) { set_key(key.data(), key.size()); } @@ -188,7 +188,7 @@ class BOTAN_DLL Cipher_Mode * @param key contains the key material * @param length in bytes of key param */ - void set_key(const byte key[], size_t length) + void set_key(const uint8_t key[], size_t length) { if(!valid_keylength(length)) throw Invalid_Key_Length(name(), length); @@ -202,7 +202,7 @@ class BOTAN_DLL Cipher_Mode virtual std::string provider() const { return "base"; } private: - virtual void key_schedule(const byte key[], size_t length) = 0; + virtual void key_schedule(const uint8_t key[], size_t length) = 0; }; /** diff --git a/src/lib/modes/mode_pad/mode_pad.cpp b/src/lib/modes/mode_pad/mode_pad.cpp index c84c2030e..afcce786d 100644 --- a/src/lib/modes/mode_pad/mode_pad.cpp +++ b/src/lib/modes/mode_pad/mode_pad.cpp @@ -38,11 +38,11 @@ BlockCipherModePaddingMethod* get_bc_pad(const std::string& algo_spec) /* * Pad with PKCS #7 Method */ -void PKCS7_Padding::add_padding(secure_vector<byte>& buffer, +void PKCS7_Padding::add_padding(secure_vector<uint8_t>& buffer, size_t last_byte_pos, size_t block_size) const { - const byte pad_value = static_cast<byte>(block_size - last_byte_pos); + const uint8_t pad_value = static_cast<uint8_t>(block_size - last_byte_pos); for(size_t i = 0; i != pad_value; ++i) buffer.push_back(pad_value); @@ -51,11 +51,11 @@ void PKCS7_Padding::add_padding(secure_vector<byte>& buffer, /* * Unpad with PKCS #7 Method */ -size_t PKCS7_Padding::unpad(const byte block[], size_t size) const +size_t PKCS7_Padding::unpad(const uint8_t block[], size_t size) const { CT::poison(block,size); size_t bad_input = 0; - const byte last_byte = block[size-1]; + const uint8_t last_byte = block[size-1]; bad_input |= CT::expand_mask(last_byte > size); @@ -76,11 +76,11 @@ size_t PKCS7_Padding::unpad(const byte block[], size_t size) const /* * Pad with ANSI X9.23 Method */ -void ANSI_X923_Padding::add_padding(secure_vector<byte>& buffer, +void ANSI_X923_Padding::add_padding(secure_vector<uint8_t>& buffer, size_t last_byte_pos, size_t block_size) const { - const byte pad_value = static_cast<byte>(block_size - last_byte_pos); + const uint8_t pad_value = static_cast<uint8_t>(block_size - last_byte_pos); for(size_t i = last_byte_pos; i < block_size-1; ++i) { @@ -92,7 +92,7 @@ void ANSI_X923_Padding::add_padding(secure_vector<byte>& buffer, /* * Unpad with ANSI X9.23 Method */ -size_t ANSI_X923_Padding::unpad(const byte block[], size_t size) const +size_t ANSI_X923_Padding::unpad(const uint8_t block[], size_t size) const { CT::poison(block,size); size_t bad_input = 0; @@ -116,7 +116,7 @@ size_t ANSI_X923_Padding::unpad(const byte block[], size_t size) const /* * Pad with One and Zeros Method */ -void OneAndZeros_Padding::add_padding(secure_vector<byte>& buffer, +void OneAndZeros_Padding::add_padding(secure_vector<uint8_t>& buffer, size_t last_byte_pos, size_t block_size) const { @@ -129,19 +129,19 @@ void OneAndZeros_Padding::add_padding(secure_vector<byte>& buffer, /* * Unpad with One and Zeros Method */ -size_t OneAndZeros_Padding::unpad(const byte block[], size_t size) const +size_t OneAndZeros_Padding::unpad(const uint8_t block[], size_t size) const { CT::poison(block, size); - byte bad_input = 0; - byte seen_one = 0; + uint8_t bad_input = 0; + uint8_t seen_one = 0; size_t pad_pos = size - 1; size_t i = size; while(i) { - seen_one |= CT::is_equal<byte>(block[i-1],0x80); - pad_pos -= CT::select<byte>(~seen_one, 1, 0); - bad_input |= ~CT::is_zero<byte>(block[i-1]) & ~seen_one; + seen_one |= CT::is_equal<uint8_t>(block[i-1],0x80); + pad_pos -= CT::select<uint8_t>(~seen_one, 1, 0); + bad_input |= ~CT::is_zero<uint8_t>(block[i-1]) & ~seen_one; i--; } bad_input |= ~seen_one; @@ -156,11 +156,11 @@ size_t OneAndZeros_Padding::unpad(const byte block[], size_t size) const /* * Pad with ESP Padding Method */ -void ESP_Padding::add_padding(secure_vector<byte>& buffer, +void ESP_Padding::add_padding(secure_vector<uint8_t>& buffer, size_t last_byte_pos, size_t block_size) const { - byte pad_value = 0x01; + uint8_t pad_value = 0x01; for(size_t i = last_byte_pos; i < block_size; ++i) { @@ -171,7 +171,7 @@ void ESP_Padding::add_padding(secure_vector<byte>& buffer, /* * Unpad with ESP Padding Method */ -size_t ESP_Padding::unpad(const byte block[], size_t size) const +size_t ESP_Padding::unpad(const uint8_t block[], size_t size) const { CT::poison(block,size); diff --git a/src/lib/modes/mode_pad/mode_pad.h b/src/lib/modes/mode_pad/mode_pad.h index 4f07bc6ae..cfa27463b 100644 --- a/src/lib/modes/mode_pad/mode_pad.h +++ b/src/lib/modes/mode_pad/mode_pad.h @@ -32,7 +32,7 @@ class BOTAN_DLL BlockCipherModePaddingMethod * @param final_block_bytes size of the final block in bytes * @param block_size size of each block in bytes */ - virtual void add_padding(secure_vector<byte>& buffer, + virtual void add_padding(secure_vector<uint8_t>& buffer, size_t final_block_bytes, size_t block_size) const = 0; @@ -42,7 +42,7 @@ class BOTAN_DLL BlockCipherModePaddingMethod * @param size the size of the block in bytes * @return number of padding bytes */ - virtual size_t unpad(const byte block[], + virtual size_t unpad(const uint8_t block[], size_t size) const = 0; /** @@ -68,11 +68,11 @@ class BOTAN_DLL BlockCipherModePaddingMethod class BOTAN_DLL PKCS7_Padding final : public BlockCipherModePaddingMethod { public: - void add_padding(secure_vector<byte>& buffer, + void add_padding(secure_vector<uint8_t>& buffer, size_t final_block_bytes, size_t block_size) const override; - size_t unpad(const byte[], size_t) const override; + size_t unpad(const uint8_t[], size_t) const override; bool valid_blocksize(size_t bs) const override { return (bs > 0 && bs < 256); } @@ -85,11 +85,11 @@ class BOTAN_DLL PKCS7_Padding final : public BlockCipherModePaddingMethod class BOTAN_DLL ANSI_X923_Padding final : public BlockCipherModePaddingMethod { public: - void add_padding(secure_vector<byte>& buffer, + void add_padding(secure_vector<uint8_t>& buffer, size_t final_block_bytes, size_t block_size) const override; - size_t unpad(const byte[], size_t) const override; + size_t unpad(const uint8_t[], size_t) const override; bool valid_blocksize(size_t bs) const override { return (bs > 0 && bs < 256); } @@ -102,11 +102,11 @@ class BOTAN_DLL ANSI_X923_Padding final : public BlockCipherModePaddingMethod class BOTAN_DLL OneAndZeros_Padding final : public BlockCipherModePaddingMethod { public: - void add_padding(secure_vector<byte>& buffer, + void add_padding(secure_vector<uint8_t>& buffer, size_t final_block_bytes, size_t block_size) const override; - size_t unpad(const byte[], size_t) const override; + size_t unpad(const uint8_t[], size_t) const override; bool valid_blocksize(size_t bs) const override { return (bs > 0); } @@ -119,11 +119,11 @@ class BOTAN_DLL OneAndZeros_Padding final : public BlockCipherModePaddingMethod class BOTAN_DLL ESP_Padding final : public BlockCipherModePaddingMethod { public: - void add_padding(secure_vector<byte>& buffer, + void add_padding(secure_vector<uint8_t>& buffer, size_t final_block_bytes, size_t block_size) const override; - size_t unpad(const byte[], size_t) const override; + size_t unpad(const uint8_t[], size_t) const override; bool valid_blocksize(size_t bs) const override { return (bs > 0); } @@ -136,9 +136,9 @@ class BOTAN_DLL ESP_Padding final : public BlockCipherModePaddingMethod class BOTAN_DLL Null_Padding final : public BlockCipherModePaddingMethod { public: - void add_padding(secure_vector<byte>&, size_t, size_t) const override {} + void add_padding(secure_vector<uint8_t>&, size_t, size_t) const override {} - size_t unpad(const byte[], size_t size) const override { return size; } + size_t unpad(const uint8_t[], size_t size) const override { return size; } bool valid_blocksize(size_t) const override { return true; } diff --git a/src/lib/modes/stream_mode.h b/src/lib/modes/stream_mode.h index 83b0543c9..e32044a4b 100644 --- a/src/lib/modes/stream_mode.h +++ b/src/lib/modes/stream_mode.h @@ -27,7 +27,7 @@ class BOTAN_DLL Stream_Cipher_Mode : public Cipher_Mode return sz; } - void finish(secure_vector<byte>& buf, size_t offset) override + void finish(secure_vector<uint8_t>& buf, size_t offset) override { return update(buf, offset); } size_t output_length(size_t input_length) const override { return input_length; } @@ -54,12 +54,12 @@ class BOTAN_DLL Stream_Cipher_Mode : public Cipher_Mode void reset() override { /* no msg state */ return; } private: - void start_msg(const byte nonce[], size_t nonce_len) override + void start_msg(const uint8_t nonce[], size_t nonce_len) override { m_cipher->set_iv(nonce, nonce_len); } - void key_schedule(const byte key[], size_t length) override + void key_schedule(const uint8_t key[], size_t length) override { m_cipher->set_key(key, length); } diff --git a/src/lib/modes/xts/xts.cpp b/src/lib/modes/xts/xts.cpp index 13dc932ea..9487bd835 100644 --- a/src/lib/modes/xts/xts.cpp +++ b/src/lib/modes/xts/xts.cpp @@ -13,10 +13,10 @@ namespace Botan { namespace { -void poly_double_128(byte out[], const byte in[]) +void poly_double_128(uint8_t out[], const uint8_t in[]) { - u64bit X0 = load_le<u64bit>(in, 0); - u64bit X1 = load_le<u64bit>(in, 1); + uint64_t X0 = load_le<uint64_t>(in, 0); + uint64_t X1 = load_le<uint64_t>(in, 1); const bool carry = static_cast<bool>((X1 >> 63) != 0); @@ -29,9 +29,9 @@ void poly_double_128(byte out[], const byte in[]) store_le(out, X0, X1); } -void poly_double_64(byte out[], const byte in[]) +void poly_double_64(uint8_t out[], const uint8_t in[]) { - u64bit X = load_le<u64bit>(in, 0); + uint64_t X = load_le<uint64_t>(in, 0); const bool carry = static_cast<bool>((X >> 63) != 0); X <<= 1; if(carry) @@ -39,7 +39,7 @@ void poly_double_64(byte out[], const byte in[]) store_le(X, out); } -inline void poly_double(byte out[], const byte in[], size_t size) +inline void poly_double(uint8_t out[], const uint8_t in[], size_t size) { if(size == 8) poly_double_64(out, in); @@ -100,7 +100,7 @@ bool XTS_Mode::valid_nonce_length(size_t n) const return cipher().block_size() == n; } -void XTS_Mode::key_schedule(const byte key[], size_t length) +void XTS_Mode::key_schedule(const uint8_t key[], size_t length) { const size_t key_half = length / 2; @@ -111,7 +111,7 @@ void XTS_Mode::key_schedule(const byte key[], size_t length) m_tweak_cipher->set_key(&key[key_half], key_half); } -void XTS_Mode::start_msg(const byte nonce[], size_t nonce_len) +void XTS_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) throw Invalid_IV_Length(name(), nonce_len); @@ -167,11 +167,11 @@ size_t XTS_Encryption::process(uint8_t buf[], size_t sz) return sz; } -void XTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void XTS_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input"); @@ -188,7 +188,7 @@ void XTS_Encryption::finish(secure_vector<byte>& buffer, size_t offset) const size_t final_bytes = sz - full_blocks; BOTAN_ASSERT(final_bytes > BS && final_bytes < 2*BS, "Left over size in expected range"); - secure_vector<byte> last(buf + full_blocks, buf + full_blocks + final_bytes); + secure_vector<uint8_t> last(buf + full_blocks, buf + full_blocks + final_bytes); buffer.resize(full_blocks + offset); update(buffer, offset); @@ -243,11 +243,11 @@ size_t XTS_Decryption::process(uint8_t buf[], size_t sz) return sz; } -void XTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void XTS_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; - byte* buf = buffer.data() + offset; + uint8_t* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input"); @@ -264,7 +264,7 @@ void XTS_Decryption::finish(secure_vector<byte>& buffer, size_t offset) const size_t final_bytes = sz - full_blocks; BOTAN_ASSERT(final_bytes > BS && final_bytes < 2*BS, "Left over size in expected range"); - secure_vector<byte> last(buf + full_blocks, buf + full_blocks + final_bytes); + secure_vector<uint8_t> last(buf + full_blocks, buf + full_blocks + final_bytes); buffer.resize(full_blocks + offset); update(buffer, offset); diff --git a/src/lib/modes/xts/xts.h b/src/lib/modes/xts/xts.h index 6d53b4312..69715c8b9 100644 --- a/src/lib/modes/xts/xts.h +++ b/src/lib/modes/xts/xts.h @@ -39,18 +39,18 @@ class BOTAN_DLL XTS_Mode : public Cipher_Mode protected: explicit XTS_Mode(BlockCipher* cipher); - const byte* tweak() const { return m_tweak.data(); } + const uint8_t* tweak() const { return m_tweak.data(); } const BlockCipher& cipher() const { return *m_cipher; } void update_tweak(size_t last_used); private: - void start_msg(const byte nonce[], size_t nonce_len) override; - void key_schedule(const byte key[], size_t length) override; + void start_msg(const uint8_t nonce[], size_t nonce_len) override; + void key_schedule(const uint8_t key[], size_t length) override; std::unique_ptr<BlockCipher> m_cipher, m_tweak_cipher; - secure_vector<byte> m_tweak; + secure_vector<uint8_t> m_tweak; }; /** @@ -66,7 +66,7 @@ class BOTAN_DLL XTS_Encryption final : public XTS_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override; }; @@ -84,7 +84,7 @@ class BOTAN_DLL XTS_Decryption final : public XTS_Mode size_t process(uint8_t buf[], size_t size) override; - void finish(secure_vector<byte>& final_block, size_t offset = 0) override; + void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override; size_t output_length(size_t input_length) const override; }; |