Botan 3.4.0
Crypto and TLS for C&
Public Types | Public Member Functions | Static Public Member Functions | List of all members
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 350 of file tls_extensions.h.

Member Enumeration Documentation

◆ ECPointFormat

Enumerator
UNCOMPRESSED 
ANSIX962_COMPRESSED_PRIME 
ANSIX962_COMPRESSED_CHAR2 

Definition at line 352 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 364 of file tls_extensions.h.

364: 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 561 of file tls_extensions.cpp.

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

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 368 of file tls_extensions.h.

368{ 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 116 of file tls_extensions.h.

116{ return true; }

◆ prefers_compressed()

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

Definition at line 370 of file tls_extensions.h.

370{ 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 552 of file tls_extensions.cpp.

552 {
553 // if this extension is sent, it MUST include uncompressed (RFC 4492, section 5.1)
554 if(m_prefers_compressed) {
555 return std::vector<uint8_t>{2, ANSIX962_COMPRESSED_PRIME, UNCOMPRESSED};
556 } else {
557 return std::vector<uint8_t>{1, UNCOMPRESSED};
558 }
559}

References ANSIX962_COMPRESSED_PRIME, and UNCOMPRESSED.

◆ static_type()

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

Definition at line 358 of file tls_extensions.h.

◆ type()

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

Implements Botan::TLS::Extension.

Definition at line 360 of file tls_extensions.h.

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

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