Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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:

## 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 | ) |
| inline explicit

Definition at line 247 of file tls_extensions.h.

247 :
248 m_curves(curves) {}
Botan::TLS::Supported_Elliptic_Curves::curves
const std::vector< std::string > & curves() const
Definition: tls_extensions.h:243

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 }
Botan::TLS::Supported_Elliptic_Curves::curve_id_to_name
static std::string curve_id_to_name(uint16_t id)
Definition: tls_extensions.cpp:280

## 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
| inline override virtual

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
| override virtual

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 }
Botan::TLS::Supported_Elliptic_Curves::name_to_curve_id
static uint16_t name_to_curve_id(const std::string &name)
Definition: tls_extensions.cpp:312
Botan::get_byte
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 | ( |  | ) |
| inline static

Definition at line 235 of file tls_extensions.h.

References Botan::TLS::TLSEXT_USABLE_ELLIPTIC_CURVES.

Referenced by type().

236 { return TLSEXT_USABLE_ELLIPTIC_CURVES; }
Botan::TLS::TLSEXT_USABLE_ELLIPTIC_CURVES
Definition: tls_extensions.h:32

Handshake_Extension_Type Botan::TLS::Supported_Elliptic_Curves::type | ( |  | ) | const
| inline override virtual

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(); }
Botan::TLS::Supported_Elliptic_Curves::static_type
static Handshake_Extension_Type static_type()
Definition: tls_extensions.h:235

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

- src/lib/tls/tls_extensions.h
- src/lib/tls/tls_extensions.cpp