Botan 2.19.2
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::TLS::Datagram_Sequence_Numbers Class Referencefinal

#include <tls_seq_numbers.h>

Inheritance diagram for Botan::TLS::Datagram_Sequence_Numbers:
Botan::TLS::Connection_Sequence_Numbers

Public Member Functions

bool already_seen (uint64_t sequence) const override
 
uint16_t current_read_epoch () const override
 
uint16_t current_write_epoch () const override
 
 Datagram_Sequence_Numbers ()
 
void new_read_cipher_state () override
 
void new_write_cipher_state () override
 
uint64_t next_read_sequence () override
 
uint64_t next_write_sequence (uint16_t epoch) override
 
void read_accept (uint64_t sequence) override
 
void reset () override
 

Detailed Description

Definition at line 70 of file tls_seq_numbers.h.

Constructor & Destructor Documentation

◆ Datagram_Sequence_Numbers()

Botan::TLS::Datagram_Sequence_Numbers::Datagram_Sequence_Numbers ( )
inline

Definition at line 73 of file tls_seq_numbers.h.

References reset().

Member Function Documentation

◆ already_seen()

bool Botan::TLS::Datagram_Sequence_Numbers::already_seen ( uint64_t  sequence) const
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 108 of file tls_seq_numbers.h.

109 {
110 const size_t window_size = sizeof(m_window_bits) * 8;
111
112 if(sequence > m_window_highest)
113 {
114 return false;
115 }
116
117 const uint64_t offset = m_window_highest - sequence;
118
119 if(offset >= window_size)
120 {
121 return true; // really old?
122 }
123
124 return (((m_window_bits >> offset) & 1) == 1);
125 }

◆ current_read_epoch()

uint16_t Botan::TLS::Datagram_Sequence_Numbers::current_read_epoch ( ) const
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 93 of file tls_seq_numbers.h.

93{ return m_read_epoch; }

◆ current_write_epoch()

uint16_t Botan::TLS::Datagram_Sequence_Numbers::current_write_epoch ( ) const
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 94 of file tls_seq_numbers.h.

94{ return m_write_epoch; }

◆ new_read_cipher_state()

void Botan::TLS::Datagram_Sequence_Numbers::new_read_cipher_state ( )
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 85 of file tls_seq_numbers.h.

85{ m_read_epoch++; }

◆ new_write_cipher_state()

void Botan::TLS::Datagram_Sequence_Numbers::new_write_cipher_state ( )
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 87 of file tls_seq_numbers.h.

88 {
89 m_write_epoch++;
90 m_write_seqs[m_write_epoch] = 0;
91 }

◆ next_read_sequence()

uint64_t Botan::TLS::Datagram_Sequence_Numbers::next_read_sequence ( )
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 103 of file tls_seq_numbers.h.

104 {
105 throw Invalid_State("DTLS uses explicit sequence numbers");
106 }

◆ next_write_sequence()

uint64_t Botan::TLS::Datagram_Sequence_Numbers::next_write_sequence ( uint16_t  epoch)
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 96 of file tls_seq_numbers.h.

97 {
98 auto i = m_write_seqs.find(epoch);
99 BOTAN_ASSERT(i != m_write_seqs.end(), "Found epoch");
100 return (static_cast<uint64_t>(epoch) << 48) | i->second++;
101 }
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55

References BOTAN_ASSERT.

◆ read_accept()

void Botan::TLS::Datagram_Sequence_Numbers::read_accept ( uint64_t  sequence)
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 127 of file tls_seq_numbers.h.

128 {
129 const size_t window_size = sizeof(m_window_bits) * 8;
130
131 if(sequence > m_window_highest)
132 {
133 // We've received a later sequence which advances our window
134 const uint64_t offset = sequence - m_window_highest;
135 m_window_highest += offset;
136
137 if(offset >= window_size)
138 m_window_bits = 0;
139 else
140 m_window_bits <<= offset;
141
142 m_window_bits |= 0x01;
143 }
144 else
145 {
146 const uint64_t offset = m_window_highest - sequence;
147
148 if(offset < window_size)
149 {
150 // We've received an old sequence but still within our window
151 m_window_bits |= (static_cast<uint64_t>(1) << offset);
152 }
153 else
154 {
155 // This occurs only if we have reset state (DTLS reconnection case)
156 m_window_highest = sequence;
157 m_window_bits = 0;
158 }
159 }
160 }

◆ reset()

void Botan::TLS::Datagram_Sequence_Numbers::reset ( )
inlineoverridevirtual

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 75 of file tls_seq_numbers.h.

76 {
77 m_write_seqs.clear();
78 m_write_seqs[0] = 0;
79 m_write_epoch = 0;
80 m_read_epoch = 0;
81 m_window_highest = 0;
82 m_window_bits = 0;
83 }

Referenced by Datagram_Sequence_Numbers().


The documentation for this class was generated from the following file: