aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/tls/tls_seq_numbers.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-10-06 01:29:13 +0000
committerlloyd <[email protected]>2014-10-06 01:29:13 +0000
commit2d6a5e530c8db496aad61b5a9ab3107dd1ed646b (patch)
tree29d92fc311f65ca88b812dadf3462c3ad1fdb0f9 /src/lib/tls/tls_seq_numbers.h
parent97010abaf527fdbe6e308cb3570f9167c1dc9ec1 (diff)
Add support for DTLS handshake timeouts and retransmissions.
Diffstat (limited to 'src/lib/tls/tls_seq_numbers.h')
-rw-r--r--src/lib/tls/tls_seq_numbers.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/tls/tls_seq_numbers.h b/src/lib/tls/tls_seq_numbers.h
index 87edf3130..d7b8c919c 100644
--- a/src/lib/tls/tls_seq_numbers.h
+++ b/src/lib/tls/tls_seq_numbers.h
@@ -24,7 +24,7 @@ class Connection_Sequence_Numbers
virtual u16bit current_read_epoch() const = 0;
virtual u16bit current_write_epoch() const = 0;
- virtual u64bit next_write_sequence() = 0;
+ virtual u64bit next_write_sequence(u16bit) = 0;
virtual u64bit next_read_sequence() = 0;
virtual bool already_seen(u64bit seq) const = 0;
@@ -40,7 +40,7 @@ class Stream_Sequence_Numbers : public Connection_Sequence_Numbers
u16bit current_read_epoch() const override { return m_read_epoch; }
u16bit current_write_epoch() const override { return m_write_epoch; }
- u64bit next_write_sequence() override { return m_write_seq_no++; }
+ u64bit next_write_sequence(u16bit) override { return m_write_seq_no++; }
u64bit next_read_sequence() override { return m_read_seq_no; }
bool already_seen(u64bit) const override { return false; }
@@ -55,18 +55,25 @@ class Stream_Sequence_Numbers : public Connection_Sequence_Numbers
class Datagram_Sequence_Numbers : public Connection_Sequence_Numbers
{
public:
+ Datagram_Sequence_Numbers() { m_write_seqs[0] = 0; }
+
void new_read_cipher_state() override { m_read_epoch += 1; }
void new_write_cipher_state() override
{
- // increment epoch
- m_write_seq_no = ((m_write_seq_no >> 48) + 1) << 48;
+ m_write_epoch += 1;
+ m_write_seqs[m_write_epoch] = 0;
}
u16bit current_read_epoch() const override { return m_read_epoch; }
- u16bit current_write_epoch() const override { return (m_write_seq_no >> 48); }
+ u16bit current_write_epoch() const override { return m_write_epoch; }
- u64bit next_write_sequence() override { return m_write_seq_no++; }
+ u64bit next_write_sequence(u16bit epoch) override
+ {
+ auto i = m_write_seqs.find(epoch);
+ BOTAN_ASSERT(i != m_write_seqs.end(), "Found epoch");
+ return (static_cast<u64bit>(epoch) << 48) | i->second++;
+ }
u64bit next_read_sequence() override
{
@@ -112,7 +119,8 @@ class Datagram_Sequence_Numbers : public Connection_Sequence_Numbers
}
private:
- u64bit m_write_seq_no = 0;
+ std::map<u16bit, u64bit> m_write_seqs;
+ u16bit m_write_epoch = 0;
u16bit m_read_epoch = 0;
u64bit m_window_highest = 0;
u64bit m_window_bits = 0;