Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Supported_Groups Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Supported_Groups:
Botan::TLS::Extension

Public Member Functions

std::vector< Group_Params > dh_groups () const
std::vector< Group_Params > ec_groups () const
bool empty () const override
const std::vector< Group_Params > & groups () const
virtual bool is_implemented () const
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 Supported_Groups (std::vector< Group_Params > groups)
 Supported_Groups (TLS_Data_Reader &reader, uint16_t extension_size)
Extension_Code type () const override

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Supported Groups Extension (RFC 7919)

Definition at line 256 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Supported_Groups() [1/2]

Botan::TLS::Supported_Groups::Supported_Groups ( std::vector< Group_Params > groups)
explicit

Definition at line 691 of file tls_extensions.cpp.

691: m_groups(std::move(groups)) {}
const std::vector< Group_Params > & groups() const

References groups().

◆ Supported_Groups() [2/2]

Botan::TLS::Supported_Groups::Supported_Groups ( TLS_Data_Reader & reader,
uint16_t extension_size )

Definition at line 737 of file tls_extensions.cpp.

737 {
738 const uint16_t len = reader.get_uint16_t();
739
740 if(len + 2 != extension_size) {
741 throw Decoding_Error("Inconsistent length field in supported groups list");
742 }
743
744 // RFC 8446 4.2.7: NamedGroup named_group_list<2..2^16-1>;
745 if(len == 0) {
746 throw Decoding_Error("Empty supported groups list");
747 }
748
749 if(len % 2 == 1) {
750 throw Decoding_Error("Supported groups list of strange size");
751 }
752
753 const size_t elems = len / 2;
754
755 std::unordered_set<uint16_t> seen;
756 for(size_t i = 0; i != elems; ++i) {
757 const auto group = static_cast<Group_Params>(reader.get_uint16_t());
758 // Note: RFC 8446 does not explicitly enforce that groups must be unique.
759 if(seen.insert(group.wire_code()).second) {
760 m_groups.push_back(group);
761 }
762 }
763}

References Botan::TLS::TLS_Data_Reader::get_uint16_t().

Member Function Documentation

◆ dh_groups()

std::vector< Group_Params > Botan::TLS::Supported_Groups::dh_groups ( ) const

Definition at line 707 of file tls_extensions.cpp.

707 {
708 std::vector<Group_Params> dh;
709 for(const auto g : m_groups) {
710 if(g.is_in_ffdhe_range()) {
711 dh.push_back(g);
712 }
713 }
714 return dh;
715}

◆ ec_groups()

std::vector< Group_Params > Botan::TLS::Supported_Groups::ec_groups ( ) const

Definition at line 697 of file tls_extensions.cpp.

697 {
698 std::vector<Group_Params> ec;
699 for(const auto g : m_groups) {
700 if(group_may_be_ecc(g)) {
701 ec.push_back(g);
702 }
703 }
704 return ec;
705}
bool group_may_be_ecc(Group_Params group)

References Botan::TLS::group_may_be_ecc().

Referenced by Botan::TLS::Client_Hello_13::Client_Hello_13().

◆ empty()

bool Botan::TLS::Supported_Groups::empty ( ) const
inlineoverridevirtual

Predicate if a TLS extension should be included or not

Returns
true if this extension should be encoded, otherwise false

Implements Botan::TLS::Extension.

Definition at line 277 of file tls_extensions.h.

277{ return m_groups.empty(); }

◆ groups()

const std::vector< Group_Params > & Botan::TLS::Supported_Groups::groups ( ) const

Definition at line 693 of file tls_extensions.cpp.

693 {
694 return m_groups;
695}

Referenced by Botan::TLS::Server_Hello_13::create(), and Supported_Groups().

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited

Predicate if the extension is known/implemented

Note
this exists primarily to support unknown extension handling and doesn't need to be overridden even in the custom extension case.
Returns
true if this extension is known

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 113 of file tls_extensions.h.

113{ return true; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::Supported_Groups::serialize ( Connection_Side whoami) const
overridevirtual

Serialize a TLS extension

Parameters
whoamiwhich peer we are acting as in the protocol
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 717 of file tls_extensions.cpp.

717 {
718 std::vector<uint8_t> buf(2);
719
720 for(const auto g : m_groups) {
721 const uint16_t id = g.wire_code();
722
723 if(id > 0) {
724 buf.push_back(get_byte<0>(id));
725 buf.push_back(get_byte<1>(id));
726 }
727 }
728
729 // RFC 8446 4.2.7: NamedGroup named_group_list<2..2^16-1>;
730 BOTAN_ASSERT_NOMSG(buf.size() - 2 <= 0xFFFF);
731 buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size() - 2));
732 buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size() - 2));
733
734 return buf;
735}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References BOTAN_ASSERT_NOMSG, and Botan::get_byte().

◆ static_type()

Extension_Code Botan::TLS::Supported_Groups::static_type ( )
inlinestatic

Definition at line 258 of file tls_extensions.h.

References Botan::TLS::SupportedGroups.

Referenced by type().

◆ type()

Extension_Code Botan::TLS::Supported_Groups::type ( ) const
inlineoverridevirtual

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 260 of file tls_extensions.h.

260{ return static_type(); }
static Extension_Code static_type()

References static_type().


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