Botan 3.6.1
Crypto and TLS for C&
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 75 of file tls_seq_numbers.h.

Constructor & Destructor Documentation

◆ Datagram_Sequence_Numbers()

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

Definition at line 77 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 107 of file tls_seq_numbers.h.

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

◆ current_read_epoch()

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

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 95 of file tls_seq_numbers.h.

95{ 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 97 of file tls_seq_numbers.h.

97{ 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 88 of file tls_seq_numbers.h.

88{ 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 90 of file tls_seq_numbers.h.

90 {
91 m_write_epoch++;
92 m_write_seqs[m_write_epoch] = 0;
93 }

◆ next_read_sequence()

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

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 105 of file tls_seq_numbers.h.

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

◆ 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 99 of file tls_seq_numbers.h.

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

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 123 of file tls_seq_numbers.h.

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

◆ reset()

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

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 79 of file tls_seq_numbers.h.

79 {
80 m_write_seqs.clear();
81 m_write_seqs[0] = 0;
82 m_write_epoch = 0;
83 m_read_epoch = 0;
84 m_window_highest = 0;
85 m_window_bits = 0;
86 }

Referenced by Datagram_Sequence_Numbers().


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