Botan 3.8.1
Crypto and TLS for C&
Botan::TLS::Supported_Point_Formats Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Supported_Point_Formats:
Botan::TLS::Extension

Public Types

enum  ECPointFormat : uint8_t { UNCOMPRESSED = 0 , ANSIX962_COMPRESSED_PRIME = 1 , ANSIX962_COMPRESSED_CHAR2 = 2 }
 

Public Member Functions

bool empty () const override
 
virtual bool is_implemented () const
 
bool prefers_compressed () const
 
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 
 Supported_Point_Formats (bool prefer_compressed)
 
 Supported_Point_Formats (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 Point Formats Extension (RFC 4492)

Definition at line 349 of file tls_extensions.h.

Member Enumeration Documentation

◆ ECPointFormat

Enumerator
UNCOMPRESSED 
ANSIX962_COMPRESSED_PRIME 
ANSIX962_COMPRESSED_CHAR2 

Definition at line 351 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Supported_Point_Formats() [1/2]

Botan::TLS::Supported_Point_Formats::Supported_Point_Formats ( bool prefer_compressed)
inlineexplicit

Definition at line 363 of file tls_extensions.h.

363: m_prefers_compressed(prefer_compressed) {}

◆ Supported_Point_Formats() [2/2]

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

Definition at line 569 of file tls_extensions.cpp.

569 {
570 uint8_t len = reader.get_byte();
571
572 if(len + 1 != extension_size) {
573 throw Decoding_Error("Inconsistent length field in supported point formats list");
574 }
575
576 bool includes_uncompressed = false;
577 for(size_t i = 0; i != len; ++i) {
578 uint8_t format = reader.get_byte();
579
580 if(static_cast<ECPointFormat>(format) == UNCOMPRESSED) {
581 m_prefers_compressed = false;
582 reader.discard_next(len - i - 1);
583 return;
584 } else if(static_cast<ECPointFormat>(format) == ANSIX962_COMPRESSED_PRIME) {
585 m_prefers_compressed = true;
586 std::vector<uint8_t> remaining_formats = reader.get_fixed<uint8_t>(len - i - 1);
587 includes_uncompressed =
588 std::any_of(std::begin(remaining_formats), std::end(remaining_formats), [](uint8_t remaining_format) {
589 return static_cast<ECPointFormat>(remaining_format) == UNCOMPRESSED;
590 });
591 break;
592 }
593
594 // ignore ANSIX962_COMPRESSED_CHAR2, we don't support these curves
595 }
596
597 // RFC 4492 5.1.:
598 // If the Supported Point Formats Extension is indeed sent, it MUST contain the value 0 (uncompressed)
599 // as one of the items in the list of point formats.
600 // Note:
601 // RFC 8422 5.1.2. explicitly requires this check,
602 // but only if the Supported Groups extension was sent.
603 if(!includes_uncompressed) {
604 throw TLS_Exception(Alert::IllegalParameter,
605 "Supported Point Formats Extension must contain the uncompressed point format");
606 }
607}

References ANSIX962_COMPRESSED_PRIME, Botan::TLS::TLS_Data_Reader::discard_next(), Botan::TLS::TLS_Data_Reader::get_byte(), Botan::TLS::TLS_Data_Reader::get_fixed(), and UNCOMPRESSED.

Member Function Documentation

◆ empty()

bool Botan::TLS::Supported_Point_Formats::empty ( ) const
inlineoverridevirtual
Returns
if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 367 of file tls_extensions.h.

367{ return false; }

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited
Returns
true if this extension is known and implemented by Botan

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 115 of file tls_extensions.h.

115{ return true; }

◆ prefers_compressed()

bool Botan::TLS::Supported_Point_Formats::prefers_compressed ( ) const
inline

Definition at line 369 of file tls_extensions.h.

369{ return m_prefers_compressed; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::Supported_Point_Formats::serialize ( Connection_Side whoami) const
overridevirtual
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 560 of file tls_extensions.cpp.

560 {
561 // if this extension is sent, it MUST include uncompressed (RFC 4492, section 5.1)
562 if(m_prefers_compressed) {
563 return std::vector<uint8_t>{2, ANSIX962_COMPRESSED_PRIME, UNCOMPRESSED};
564 } else {
565 return std::vector<uint8_t>{1, UNCOMPRESSED};
566 }
567}

References ANSIX962_COMPRESSED_PRIME, and UNCOMPRESSED.

◆ static_type()

static Extension_Code Botan::TLS::Supported_Point_Formats::static_type ( )
inlinestatic

Definition at line 357 of file tls_extensions.h.

References Botan::TLS::EcPointFormats.

Referenced by type().

◆ type()

Extension_Code Botan::TLS::Supported_Point_Formats::type ( ) const
inlineoverridevirtual
Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 359 of file tls_extensions.h.

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

References static_type().


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