Botan  2.8.0
Crypto and TLS for C++11
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
 

Detailed Description

Definition at line 57 of file tls_seq_numbers.h.

Constructor & Destructor Documentation

◆ Datagram_Sequence_Numbers()

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

Definition at line 60 of file tls_seq_numbers.h.

60 { m_write_seqs[0] = 0; }

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

86  {
87  const size_t window_size = sizeof(m_window_bits) * 8;
88 
89  if(sequence > m_window_highest)
90  return false;
91 
92  const uint64_t offset = m_window_highest - sequence;
93 
94  if(offset >= window_size)
95  return true; // really old?
96 
97  return (((m_window_bits >> offset) & 1) == 1);
98  }

◆ current_read_epoch()

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

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 70 of file tls_seq_numbers.h.

70 { 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 71 of file tls_seq_numbers.h.

71 { 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 62 of file tls_seq_numbers.h.

62 { 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 64 of file tls_seq_numbers.h.

65  {
66  m_write_epoch++;
67  m_write_seqs[m_write_epoch] = 0;
68  }

◆ next_read_sequence()

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

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 80 of file tls_seq_numbers.h.

81  {
82  throw Exception("DTLS uses explicit sequence numbers");
83  }

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

References BOTAN_ASSERT.

74  {
75  auto i = m_write_seqs.find(epoch);
76  BOTAN_ASSERT(i != m_write_seqs.end(), "Found epoch");
77  return (static_cast<uint64_t>(epoch) << 48) | i->second++;
78  }
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55

◆ read_accept()

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

Implements Botan::TLS::Connection_Sequence_Numbers.

Definition at line 100 of file tls_seq_numbers.h.

101  {
102  const size_t window_size = sizeof(m_window_bits) * 8;
103 
104  if(sequence > m_window_highest)
105  {
106  const uint64_t offset = sequence - m_window_highest;
107  m_window_highest += offset;
108 
109  if(offset >= window_size)
110  m_window_bits = 0;
111  else
112  m_window_bits <<= offset;
113 
114  m_window_bits |= 0x01;
115  }
116  else
117  {
118  const uint64_t offset = m_window_highest - sequence;
119  m_window_bits |= (static_cast<uint64_t>(1) << offset);
120  }
121  }

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