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

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Supported_Elliptic_Curves:
Botan::TLS::Extension

Public Member Functions

const std::vector< std::string > & curves () const
 
bool empty () const override
 
std::vector< uint8_t > serialize () const override
 
 Supported_Elliptic_Curves (const std::vector< std::string > &curves)
 
 Supported_Elliptic_Curves (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 uint16_t name_to_curve_id (const std::string &name)
 
static Handshake_Extension_Type static_type ()
 

Detailed Description

Supported Elliptic Curves Extension (RFC 4492)

Definition at line 232 of file tls_extensions.h.

Constructor & Destructor Documentation

Botan::TLS::Supported_Elliptic_Curves::Supported_Elliptic_Curves ( const std::vector< std::string > &  curves)
inlineexplicit

Definition at line 247 of file tls_extensions.h.

247  :
248  m_curves(curves) {}
const std::vector< std::string > & curves() const
Botan::TLS::Supported_Elliptic_Curves::Supported_Elliptic_Curves ( TLS_Data_Reader reader,
uint16_t  extension_size 
)

Definition at line 362 of file tls_extensions.cpp.

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

364  {
365  uint16_t len = reader.get_uint16_t();
366 
367  if(len + 2 != extension_size)
368  throw Decoding_Error("Inconsistent length field in elliptic curve list");
369 
370  if(len % 2 == 1)
371  throw Decoding_Error("Elliptic curve list of strange size");
372 
373  len /= 2;
374 
375  for(size_t i = 0; i != len; ++i)
376  {
377  const uint16_t id = reader.get_uint16_t();
378  const std::string name = curve_id_to_name(id);
379 
380  if(!name.empty())
381  m_curves.push_back(name);
382  }
383  }
static std::string curve_id_to_name(uint16_t id)

Member Function Documentation

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

Definition at line 280 of file tls_extensions.cpp.

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

281  {
282  switch(id)
283  {
284  case 23:
285  return "secp256r1";
286  case 24:
287  return "secp384r1";
288  case 25:
289  return "secp521r1";
290  case 26:
291  return "brainpool256r1";
292  case 27:
293  return "brainpool384r1";
294  case 28:
295  return "brainpool512r1";
296 
297 #if defined(BOTAN_HAS_CURVE_25519)
298  case 29:
299  return "x25519";
300 #endif
301 
302 #if defined(BOTAN_HOUSE_ECC_CURVE_NAME)
303  case BOTAN_HOUSE_ECC_CURVE_TLS_ID:
304  return BOTAN_HOUSE_ECC_CURVE_NAME;
305 #endif
306 
307  default:
308  return ""; // something we don't know or support
309  }
310  }
const std::vector<std::string>& Botan::TLS::Supported_Elliptic_Curves::curves ( ) const
inline

Definition at line 243 of file tls_extensions.h.

243 { return m_curves; }
bool Botan::TLS::Supported_Elliptic_Curves::empty ( ) const
inlineoverridevirtual
Returns
if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 253 of file tls_extensions.h.

253 { return m_curves.empty(); }
uint16_t Botan::TLS::Supported_Elliptic_Curves::name_to_curve_id ( const std::string &  name)
static

Definition at line 312 of file tls_extensions.cpp.

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

313  {
314  if(name == "secp256r1")
315  return 23;
316  if(name == "secp384r1")
317  return 24;
318  if(name == "secp521r1")
319  return 25;
320  if(name == "brainpool256r1")
321  return 26;
322  if(name == "brainpool384r1")
323  return 27;
324  if(name == "brainpool512r1")
325  return 28;
326 
327 #if defined(BOTAN_HAS_CURVE_25519)
328  if(name == "x25519")
329  return 29;
330 #endif
331 
332 #if defined(BOTAN_HOUSE_ECC_CURVE_NAME)
333  if(name == BOTAN_HOUSE_ECC_CURVE_NAME)
334  return BOTAN_HOUSE_ECC_CURVE_TLS_ID;
335 #endif
336 
337  // Unknown/unavailable EC curves are ignored
338  return 0;
339  }
std::vector< uint8_t > Botan::TLS::Supported_Elliptic_Curves::serialize ( ) const
overridevirtual
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 341 of file tls_extensions.cpp.

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

342  {
343  std::vector<uint8_t> buf(2);
344 
345  for(size_t i = 0; i != m_curves.size(); ++i)
346  {
347  const uint16_t id = name_to_curve_id(m_curves[i]);
348 
349  if(id > 0)
350  {
351  buf.push_back(get_byte(0, id));
352  buf.push_back(get_byte(1, id));
353  }
354  }
355 
356  buf[0] = get_byte(0, static_cast<uint16_t>(buf.size()-2));
357  buf[1] = get_byte(1, static_cast<uint16_t>(buf.size()-2));
358 
359  return buf;
360  }
static uint16_t name_to_curve_id(const std::string &name)
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47
static Handshake_Extension_Type Botan::TLS::Supported_Elliptic_Curves::static_type ( )
inlinestatic
Handshake_Extension_Type Botan::TLS::Supported_Elliptic_Curves::type ( ) const
inlineoverridevirtual
Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 238 of file tls_extensions.h.

References static_type().

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

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