diff options
author | Jack Lloyd <[email protected]> | 2019-07-04 14:53:17 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-07-04 14:53:17 -0400 |
commit | ae37dd372bb7ccd9afb25866ecededa4de10a36a (patch) | |
tree | 9f6cb9afc8779e1902211b925a2e81157f1823d6 /src | |
parent | a84506ddf491c7e216d98a571b732ab7b1424025 (diff) |
Remove Record_Message struct
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/tls/tls_channel.cpp | 6 | ||||
-rw-r--r-- | src/lib/tls/tls_record.cpp | 22 | ||||
-rw-r--r-- | src/lib/tls/tls_record.h | 37 |
3 files changed, 25 insertions, 40 deletions
diff --git a/src/lib/tls/tls_channel.cpp b/src/lib/tls/tls_channel.cpp index ced5dd3f1..a2f24dc69 100644 --- a/src/lib/tls/tls_channel.cpp +++ b/src/lib/tls/tls_channel.cpp @@ -520,12 +520,12 @@ void Channel::write_record(Connection_Cipher_State* cipher_state, uint16_t epoch const Protocol_Version record_version = (m_pending_state) ? (m_pending_state->version()) : (m_active_state->version()); - Record_Message record_message(record_type, 0, input, length); - TLS::write_record(m_writebuf, - record_message, + record_type, record_version, sequence_numbers().next_write_sequence(epoch), + input, + length, cipher_state, m_rng); diff --git a/src/lib/tls/tls_record.cpp b/src/lib/tls/tls_record.cpp index 27714af0b..45a1603cf 100644 --- a/src/lib/tls/tls_record.cpp +++ b/src/lib/tls/tls_record.cpp @@ -189,41 +189,43 @@ inline void append_u16_len(secure_vector<uint8_t>& output, size_t len_field) } void write_record(secure_vector<uint8_t>& output, - Record_Message msg, + uint8_t record_type, Protocol_Version version, - uint64_t seq, + uint64_t record_sequence, + const uint8_t* message, + size_t message_len, Connection_Cipher_State* cs, RandomNumberGenerator& rng) { output.clear(); - output.push_back(msg.get_type()); + output.push_back(record_type); output.push_back(version.major_version()); output.push_back(version.minor_version()); if(version.is_datagram_protocol()) { for(size_t i = 0; i != 8; ++i) - output.push_back(get_byte(i, seq)); + output.push_back(get_byte(i, record_sequence)); } if(!cs) // initial unencrypted handshake records { - append_u16_len(output, msg.get_size()); - output.insert(output.end(), msg.get_data(), msg.get_data() + msg.get_size()); + append_u16_len(output, message_len); + output.insert(output.end(), message, message + message_len); return; } AEAD_Mode& aead = cs->aead(); - std::vector<uint8_t> aad = cs->format_ad(seq, msg.get_type(), version, static_cast<uint16_t>(msg.get_size())); + std::vector<uint8_t> aad = cs->format_ad(record_sequence, record_type, version, static_cast<uint16_t>(message_len)); - const size_t ctext_size = aead.output_length(msg.get_size()); + const size_t ctext_size = aead.output_length(message_len); const size_t rec_size = ctext_size + cs->nonce_bytes_from_record(); aead.set_ad(aad); - const std::vector<uint8_t> nonce = cs->aead_nonce(seq, rng); + const std::vector<uint8_t> nonce = cs->aead_nonce(record_sequence, rng); append_u16_len(output, rec_size); @@ -236,7 +238,7 @@ void write_record(secure_vector<uint8_t>& output, } const size_t header_size = output.size(); - output += std::make_pair(msg.get_data(), msg.get_size()); + output += std::make_pair(message, message_len); aead.start(nonce); aead.finish(output, header_size); diff --git a/src/lib/tls/tls_record.h b/src/lib/tls/tls_record.h index d0ffc0270..3a29164b5 100644 --- a/src/lib/tls/tls_record.h +++ b/src/lib/tls/tls_record.h @@ -105,27 +105,6 @@ class Record final size_t m_size; }; -class Record_Message final - { - public: - Record_Message(const uint8_t* data, size_t size) - : m_type(0), m_sequence(0), m_data(data), m_size(size) {} - Record_Message(uint8_t type, uint64_t sequence, const uint8_t* data, size_t size) - : m_type(type), m_sequence(sequence), m_data(data), - m_size(size) {} - - uint8_t& get_type() { return m_type; } - uint64_t& get_sequence() { return m_sequence; } - const uint8_t* get_data() { return m_data; } - size_t& get_size() { return m_size; } - - private: - uint8_t m_type; - uint64_t m_sequence; - const uint8_t* m_data; - size_t m_size; -}; - class Record_Raw_Input final { public: @@ -154,16 +133,20 @@ class Record_Raw_Input final /** * Create a TLS record * @param write_buffer the output record is placed here -* @param rec_msg is the plaintext message -* @param version is the protocol version -* @param msg_sequence is the sequence number +* @param record_type the record layer type +* @param record_version the record layer version +* @param record_sequence the record layer sequence number +* @param message the record contents +* @param message_len is size of message * @param cipherstate is the writing cipher state * @param rng is a random number generator */ void write_record(secure_vector<uint8_t>& write_buffer, - Record_Message rec_msg, - Protocol_Version version, - uint64_t msg_sequence, + uint8_t record_type, + Protocol_Version record_version, + uint64_t record_sequence, + const uint8_t* message, + size_t message_len, Connection_Cipher_State* cipherstate, RandomNumberGenerator& rng); |