Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | List of all members
Botan::TLS::Supported_Groups Class Referencefinal

#include <tls_extensions.h>

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

Public Member Functions

const std::vector< std::string > & curves () const
 
const std::vector< std::string > & dh_groups () const
 
bool empty () const override
 
std::vector< uint8_t > serialize () const override
 
 Supported_Groups (const std::vector< std::string > &groups)
 
 Supported_Groups (TLS_Data_Reader &reader, uint16_t extension_size)
 
Handshake_Extension_Type type () const override
 

Static Public Member Functions

static std::string curve_id_to_name (uint16_t id)
 
static bool is_dh_group (const std::string &group_name)
 
static uint16_t name_to_curve_id (const std::string &name)
 
static Handshake_Extension_Type static_type ()
 

Detailed Description

Supported Groups Extension (RFC 7919)

Definition at line 232 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Supported_Groups() [1/2]

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

Definition at line 278 of file tls_extensions.cpp.

References is_dh_group().

278  :
279  m_groups(groups)
280  {
281  for(const auto& group : m_groups)
282  {
283  if(is_dh_group(group))
284  {
285  m_dh_groups.push_back(group);
286  }
287  else
288  {
289  m_curves.push_back(group);
290  }
291  }
292  }
static bool is_dh_group(const std::string &group_name)

◆ Supported_Groups() [2/2]

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

Definition at line 409 of file tls_extensions.cpp.

References curve_id_to_name(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), and is_dh_group().

411  {
412  uint16_t len = reader.get_uint16_t();
413 
414  if(len + 2 != extension_size)
415  throw Decoding_Error("Inconsistent length field in supported groups list");
416 
417  if(len % 2 == 1)
418  throw Decoding_Error("Supported groups list of strange size");
419 
420  len /= 2;
421 
422  for(size_t i = 0; i != len; ++i)
423  {
424  const uint16_t id = reader.get_uint16_t();
425  const std::string name = curve_id_to_name(id);
426 
427  if(!name.empty())
428  {
429  m_groups.push_back(name);
430  if(is_dh_group(name))
431  {
432  m_dh_groups.push_back(name);
433  }
434  else
435  {
436  m_curves.push_back(name);
437  }
438  }
439  }
440  }
static std::string curve_id_to_name(uint16_t id)
static bool is_dh_group(const std::string &group_name)

Member Function Documentation

◆ curve_id_to_name()

std::string Botan::TLS::Supported_Groups::curve_id_to_name ( uint16_t  id)
static

Definition at line 294 of file tls_extensions.cpp.

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), and Supported_Groups().

295  {
296  switch(id)
297  {
298  case 23:
299  return "secp256r1";
300  case 24:
301  return "secp384r1";
302  case 25:
303  return "secp521r1";
304  case 26:
305  return "brainpool256r1";
306  case 27:
307  return "brainpool384r1";
308  case 28:
309  return "brainpool512r1";
310 
311 #if defined(BOTAN_HAS_CURVE_25519)
312  case 29:
313  return "x25519";
314 #endif
315 
316 #if defined(BOTAN_HOUSE_ECC_CURVE_NAME)
317  case BOTAN_HOUSE_ECC_CURVE_TLS_ID:
318  return BOTAN_HOUSE_ECC_CURVE_NAME;
319 #endif
320 
321  case 256:
322  return "ffdhe/ietf/2048";
323  case 257:
324  return "ffdhe/ietf/3072";
325  case 258:
326  return "ffdhe/ietf/4096";
327  case 259:
328  return "ffdhe/ietf/6144";
329  case 260:
330  return "ffdhe/ietf/8192";
331 
332  default:
333  return ""; // something we don't know or support
334  }
335  }

◆ curves()

const std::vector<std::string>& Botan::TLS::Supported_Groups::curves ( ) const
inline

Definition at line 245 of file tls_extensions.h.

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

245 { return m_curves; }

◆ dh_groups()

const std::vector<std::string>& Botan::TLS::Supported_Groups::dh_groups ( ) const
inline

Definition at line 246 of file tls_extensions.h.

References Botan::TLS::Extension::serialize().

246 { return m_dh_groups; }

◆ empty()

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

Implements Botan::TLS::Extension.

Definition at line 255 of file tls_extensions.h.

255 { return m_groups.empty(); }

◆ is_dh_group()

bool Botan::TLS::Supported_Groups::is_dh_group ( const std::string &  group_name)
static

Definition at line 377 of file tls_extensions.cpp.

Referenced by Botan::TLS::Policy::choose_curve(), Botan::TLS::Policy::choose_dh_group(), and Supported_Groups().

378  {
379  if(group_name == "ffdhe/ietf/2048" || group_name == "ffdhe/ietf/3072"
380  || group_name == "ffdhe/ietf/4096" || group_name == "ffdhe/ietf/6144"
381  || group_name == "ffdhe/ietf/8192")
382  {
383  return true;
384  }
385  return false;
386  }

◆ name_to_curve_id()

uint16_t Botan::TLS::Supported_Groups::name_to_curve_id ( const std::string &  name)
static

Definition at line 337 of file tls_extensions.cpp.

Referenced by serialize(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

338  {
339  if(name == "secp256r1")
340  return 23;
341  if(name == "secp384r1")
342  return 24;
343  if(name == "secp521r1")
344  return 25;
345  if(name == "brainpool256r1")
346  return 26;
347  if(name == "brainpool384r1")
348  return 27;
349  if(name == "brainpool512r1")
350  return 28;
351 
352 #if defined(BOTAN_HAS_CURVE_25519)
353  if(name == "x25519")
354  return 29;
355 #endif
356 
357 #if defined(BOTAN_HOUSE_ECC_CURVE_NAME)
358  if(name == BOTAN_HOUSE_ECC_CURVE_NAME)
359  return BOTAN_HOUSE_ECC_CURVE_TLS_ID;
360 #endif
361 
362  if(name == "ffdhe/ietf/2048")
363  return 256;
364  if(name == "ffdhe/ietf/3072")
365  return 257;
366  if(name == "ffdhe/ietf/4096")
367  return 258;
368  if(name == "ffdhe/ietf/6144")
369  return 259;
370  if(name == "ffdhe/ietf/8192")
371  return 260;
372 
373  // Unknown/unavailable DH groups/EC curves are ignored
374  return 0;
375  }

◆ serialize()

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

Implements Botan::TLS::Extension.

Definition at line 388 of file tls_extensions.cpp.

References Botan::get_byte(), and name_to_curve_id().

389  {
390  std::vector<uint8_t> buf(2);
391 
392  for(size_t i = 0; i != m_groups.size(); ++i)
393  {
394  const uint16_t id = name_to_curve_id(m_groups[i]);
395 
396  if(id > 0)
397  {
398  buf.push_back(get_byte(0, id));
399  buf.push_back(get_byte(1, id));
400  }
401  }
402 
403  buf[0] = get_byte(0, static_cast<uint16_t>(buf.size()-2));
404  buf[1] = get_byte(1, static_cast<uint16_t>(buf.size()-2));
405 
406  return buf;
407  }
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:39
static uint16_t name_to_curve_id(const std::string &name)

◆ static_type()

static Handshake_Extension_Type Botan::TLS::Supported_Groups::static_type ( )
inlinestatic

◆ type()

Handshake_Extension_Type Botan::TLS::Supported_Groups::type ( ) const
inlineoverridevirtual
Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 238 of file tls_extensions.h.

238 { return static_type(); }
static Handshake_Extension_Type static_type()

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