diff options
author | Jack Lloyd <[email protected]> | 2016-12-11 15:28:38 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-18 16:48:24 -0500 |
commit | f3cb3edb512bdcab498d825886c3366c341b3f78 (patch) | |
tree | 645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/lib/tls/tls_cbc/tls_cbc.cpp | |
parent | c1dd21253c1f3188ff45d3ad47698efd08235ae8 (diff) |
Convert to using standard uintN_t integer types
Renames a couple of functions for somewhat better name consistency,
eg make_u32bit becomes make_uint32. The old typedefs remain for now
since probably lots of application code uses them.
Diffstat (limited to 'src/lib/tls/tls_cbc/tls_cbc.cpp')
-rw-r--r-- | src/lib/tls/tls_cbc/tls_cbc.cpp | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/lib/tls/tls_cbc/tls_cbc.cpp b/src/lib/tls/tls_cbc/tls_cbc.cpp index bd9ce2528..9b6f511f5 100644 --- a/src/lib/tls/tls_cbc/tls_cbc.cpp +++ b/src/lib/tls/tls_cbc/tls_cbc.cpp @@ -79,7 +79,7 @@ Key_Length_Specification TLS_CBC_HMAC_AEAD_Mode::key_spec() const return Key_Length_Specification(m_cipher_keylen + m_mac_keylen); } -void TLS_CBC_HMAC_AEAD_Mode::key_schedule(const byte key[], size_t keylen) +void TLS_CBC_HMAC_AEAD_Mode::key_schedule(const uint8_t key[], size_t keylen) { // Both keys are of fixed length specified by the ciphersuite @@ -90,7 +90,7 @@ void TLS_CBC_HMAC_AEAD_Mode::key_schedule(const byte key[], size_t keylen) mac().set_key(&key[m_cipher_keylen], m_mac_keylen); } -void TLS_CBC_HMAC_AEAD_Mode::start_msg(const byte nonce[], size_t nonce_len) +void TLS_CBC_HMAC_AEAD_Mode::start_msg(const uint8_t nonce[], size_t nonce_len) { if(!valid_nonce_length(nonce_len)) { @@ -105,43 +105,43 @@ void TLS_CBC_HMAC_AEAD_Mode::start_msg(const byte nonce[], size_t nonce_len) } } -size_t TLS_CBC_HMAC_AEAD_Mode::process(byte buf[], size_t sz) +size_t TLS_CBC_HMAC_AEAD_Mode::process(uint8_t buf[], size_t sz) { m_msg.insert(m_msg.end(), buf, buf + sz); return 0; } -std::vector<byte> TLS_CBC_HMAC_AEAD_Mode::assoc_data_with_len(uint16_t len) +std::vector<uint8_t> TLS_CBC_HMAC_AEAD_Mode::assoc_data_with_len(uint16_t len) { - std::vector<byte> ad = m_ad; + std::vector<uint8_t> ad = m_ad; BOTAN_ASSERT(ad.size() == 13, "Expected AAD size"); ad[11] = get_byte(0, len); ad[12] = get_byte(1, len); return ad; } -void TLS_CBC_HMAC_AEAD_Mode::set_associated_data(const byte ad[], size_t ad_len) +void TLS_CBC_HMAC_AEAD_Mode::set_associated_data(const uint8_t ad[], size_t ad_len) { if(ad_len != 13) throw Exception("Invalid TLS AEAD associated data length"); m_ad.assign(ad, ad + ad_len); } -void TLS_CBC_HMAC_AEAD_Encryption::set_associated_data(const byte ad[], size_t ad_len) +void TLS_CBC_HMAC_AEAD_Encryption::set_associated_data(const uint8_t ad[], size_t ad_len) { TLS_CBC_HMAC_AEAD_Mode::set_associated_data(ad, ad_len); if(use_encrypt_then_mac()) { // AAD hack for EtM - size_t pt_size = make_u16bit(assoc_data()[11], assoc_data()[12]); + size_t pt_size = make_uint16(assoc_data()[11], assoc_data()[12]); size_t enc_size = round_up(iv_size() + pt_size + 1, block_size()); assoc_data()[11] = get_byte<uint16_t>(0, enc_size); assoc_data()[12] = get_byte<uint16_t>(1, enc_size); } } -void TLS_CBC_HMAC_AEAD_Encryption::cbc_encrypt_record(byte buf[], size_t buf_size) +void TLS_CBC_HMAC_AEAD_Encryption::cbc_encrypt_record(uint8_t buf[], size_t buf_size) { const size_t blocks = buf_size / block_size(); BOTAN_ASSERT(buf_size % block_size() == 0, "Valid CBC input"); @@ -165,7 +165,7 @@ size_t TLS_CBC_HMAC_AEAD_Encryption::output_length(size_t input_length) const (use_encrypt_then_mac() ? tag_size() : 0); } -void TLS_CBC_HMAC_AEAD_Encryption::finish(secure_vector<byte>& buffer, size_t offset) +void TLS_CBC_HMAC_AEAD_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { update(buffer, offset); buffer.resize(offset); // truncate, leaving just header @@ -191,12 +191,12 @@ void TLS_CBC_HMAC_AEAD_Encryption::finish(secure_vector<byte>& buffer, size_t of } for(size_t i = 0; i != pad_val + 1; ++i) - buffer.push_back(static_cast<byte>(pad_val)); + buffer.push_back(static_cast<uint8_t>(pad_val)); cbc_encrypt_record(&buffer[header_size], enc_size); } // EtM also uses ciphertext size instead of plaintext size for AEAD input - const byte* mac_input = (use_encrypt_then_mac() ? &buffer[header_size] : msg().data()); + const uint8_t* mac_input = (use_encrypt_then_mac() ? &buffer[header_size] : msg().data()); const size_t mac_input_len = (use_encrypt_then_mac() ? enc_size : msg().size()); mac().update(mac_input, mac_input_len); @@ -207,7 +207,7 @@ void TLS_CBC_HMAC_AEAD_Encryption::finish(secure_vector<byte>& buffer, size_t of if(use_encrypt_then_mac() == false) { for(size_t i = 0; i != pad_val + 1; ++i) - buffer.push_back(static_cast<byte>(pad_val)); + buffer.push_back(static_cast<uint8_t>(pad_val)); cbc_encrypt_record(&buffer[header_size], buf_size); } } @@ -226,30 +226,30 @@ namespace { * Returning 0 in the error case should ensure the MAC check will fail. * This approach is suggested in section 6.2.3.2 of RFC 5246. */ -u16bit check_tls_padding(const byte record[], size_t record_len) +uint16_t check_tls_padding(const uint8_t record[], size_t record_len) { /* * TLS v1.0 and up require all the padding bytes be the same value * and allows up to 255 bytes. */ - const byte pad_byte = record[(record_len-1)]; + const uint8_t pad_byte = record[(record_len-1)]; - byte pad_invalid = 0; + uint8_t pad_invalid = 0; for(size_t i = 0; i != record_len; ++i) { const size_t left = record_len - i - 2; - const byte delim_mask = CT::is_less<u16bit>(static_cast<u16bit>(left), pad_byte) & 0xFF; + const uint8_t delim_mask = CT::is_less<uint16_t>(static_cast<uint16_t>(left), pad_byte) & 0xFF; pad_invalid |= (delim_mask & (record[i] ^ pad_byte)); } - u16bit pad_invalid_mask = CT::expand_mask<u16bit>(pad_invalid); - return CT::select<u16bit>(pad_invalid_mask, 0, pad_byte + 1); + uint16_t pad_invalid_mask = CT::expand_mask<uint16_t>(pad_invalid); + return CT::select<uint16_t>(pad_invalid_mask, 0, pad_byte + 1); } } -void TLS_CBC_HMAC_AEAD_Decryption::cbc_decrypt_record(byte record_contents[], size_t record_len) +void TLS_CBC_HMAC_AEAD_Decryption::cbc_decrypt_record(uint8_t record_contents[], size_t record_len) { BOTAN_ASSERT(record_len % block_size() == 0, "Buffer is an even multiple of block size"); @@ -258,15 +258,15 @@ void TLS_CBC_HMAC_AEAD_Decryption::cbc_decrypt_record(byte record_contents[], si BOTAN_ASSERT(blocks >= 1, "At least one ciphertext block"); - byte* buf = record_contents; + uint8_t* buf = record_contents; - secure_vector<byte> last_ciphertext(block_size()); + secure_vector<uint8_t> last_ciphertext(block_size()); copy_mem(last_ciphertext.data(), buf, block_size()); cipher().decrypt(buf); xor_buf(buf, cbc_state().data(), block_size()); - secure_vector<byte> last_ciphertext2; + secure_vector<uint8_t> last_ciphertext2; for(size_t i = 1; i < blocks; ++i) { @@ -361,18 +361,18 @@ void TLS_CBC_HMAC_AEAD_Decryption::perform_additional_compressions(size_t plen, // If there are no compressions, we just add 55/111 dummy bytes so that no // compression is performed. const uint16_t data_len = block_size * add_compressions + equal * max_bytes_in_first_block; - secure_vector<byte> data(data_len); + secure_vector<uint8_t> data(data_len); mac().update(unlock(data)); // we do not need to clear the MAC since the connection is broken anyway } -void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<byte>& buffer, size_t offset) +void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { update(buffer, offset); buffer.resize(offset); const size_t record_len = msg().size(); - byte* record_contents = msg().data(); + uint8_t* record_contents = msg().data(); // This early exit does not leak info because all the values compared are public if(record_len < tag_size() || @@ -392,7 +392,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<byte>& buffer, size_t of } mac().update(record_contents, enc_size); - std::vector<byte> mac_buf(tag_size()); + std::vector<uint8_t> mac_buf(tag_size()); mac().final(mac_buf.data()); const size_t mac_offset = enc_size; @@ -407,7 +407,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<byte>& buffer, size_t of cbc_decrypt_record(record_contents, enc_size); // 0 if padding was invalid, otherwise 1 + padding_bytes - u16bit pad_size = check_tls_padding(record_contents, enc_size); + uint16_t pad_size = check_tls_padding(record_contents, enc_size); // No oracle here, whoever sent us this had the key since MAC check passed if(pad_size == 0) @@ -415,8 +415,8 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<byte>& buffer, size_t of throw TLS_Exception(Alert::BAD_RECORD_MAC, "Message authentication failure"); } - const byte* plaintext_block = &record_contents[0]; - const u16bit plaintext_length = enc_size - pad_size; + const uint8_t* plaintext_block = &record_contents[0]; + const uint16_t plaintext_length = enc_size - pad_size; buffer.insert(buffer.end(), plaintext_block, plaintext_block + plaintext_length); } @@ -427,7 +427,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<byte>& buffer, size_t of cbc_decrypt_record(record_contents, record_len); // 0 if padding was invalid, otherwise 1 + padding_bytes - u16bit pad_size = check_tls_padding(record_contents, record_len); + uint16_t pad_size = check_tls_padding(record_contents, record_len); /* This mask is zero if there is not enough room in the packet to get a valid MAC. @@ -437,7 +437,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<byte>& buffer, size_t of (sending empty records, instead of 1/(n-1) splitting) */ - const u16bit size_ok_mask = CT::is_lte<u16bit>(static_cast<u16bit>(tag_size() + pad_size), static_cast<u16bit>(record_len + 1)); + const uint16_t size_ok_mask = CT::is_lte<uint16_t>(static_cast<uint16_t>(tag_size() + pad_size), static_cast<uint16_t>(record_len + 1)); pad_size &= size_ok_mask; CT::unpoison(record_contents, record_len); @@ -448,20 +448,20 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<byte>& buffer, size_t of */ CT::unpoison(pad_size); - const byte* plaintext_block = &record_contents[0]; - const u16bit plaintext_length = static_cast<u16bit>(record_len - tag_size() - pad_size); + const uint8_t* plaintext_block = &record_contents[0]; + const uint16_t plaintext_length = static_cast<uint16_t>(record_len - tag_size() - pad_size); mac().update(assoc_data_with_len(plaintext_length)); mac().update(plaintext_block, plaintext_length); - std::vector<byte> mac_buf(tag_size()); + std::vector<uint8_t> mac_buf(tag_size()); mac().final(mac_buf.data()); const size_t mac_offset = record_len - (tag_size() + pad_size); const bool mac_ok = same_mem(&record_contents[mac_offset], mac_buf.data(), tag_size()); - const u16bit ok_mask = size_ok_mask & CT::expand_mask<u16bit>(mac_ok) & CT::expand_mask<u16bit>(pad_size); + const uint16_t ok_mask = size_ok_mask & CT::expand_mask<uint16_t>(mac_ok) & CT::expand_mask<uint16_t>(pad_size); CT::unpoison(ok_mask); |