NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
key-params.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
23 
24 namespace ndn {
25 
27  : m_keyType(keyType)
28  , m_keyIdType(keyIdType)
29 {
30  BOOST_ASSERT(keyIdType != KeyIdType::USER_SPECIFIED);
31 }
32 
34  : m_keyType(keyType)
35  , m_keyIdType(KeyIdType::USER_SPECIFIED)
36  , m_keyId(keyId)
37 {
38  BOOST_ASSERT(!keyId.empty());
39 }
40 
41 KeyParams::~KeyParams() = default;
42 
43 namespace detail {
44 
45 const uint32_t MIN_RSA_KEY_SIZE = 2048;
46 const uint32_t DEFAULT_RSA_KEY_SIZE = 2048;
47 const uint32_t EC_KEY_SIZES[] = {224, 256, 384, 521};
48 const uint32_t DEFAULT_EC_KEY_SIZE = 256;
49 const uint32_t AES_KEY_SIZES[] = {128, 192, 256};
50 const uint32_t DEFAULT_AES_KEY_SIZE = 128;
51 const uint32_t DEFAULT_HMAC_KEY_SIZE = 256;
52 
53 uint32_t
54 RsaKeyParamsInfo::checkKeySize(uint32_t size)
55 {
56  if (size < MIN_RSA_KEY_SIZE)
57  NDN_THROW(KeyParams::Error("Unsupported RSA key size " + to_string(size)));
58  return size;
59 }
60 
61 uint32_t
62 RsaKeyParamsInfo::getDefaultSize()
63 {
64  return DEFAULT_RSA_KEY_SIZE;
65 }
66 
67 uint32_t
68 EcKeyParamsInfo::checkKeySize(uint32_t size)
69 {
70  for (size_t i = 0; i < (sizeof(EC_KEY_SIZES) / sizeof(EC_KEY_SIZES[0])); i++) {
71  if (EC_KEY_SIZES[i] == size)
72  return size;
73  }
74  NDN_THROW(KeyParams::Error("Unsupported EC key size " + to_string(size)));
75 }
76 
77 uint32_t
78 EcKeyParamsInfo::getDefaultSize()
79 {
80  return DEFAULT_EC_KEY_SIZE;
81 }
82 
83 uint32_t
84 AesKeyParamsInfo::checkKeySize(uint32_t size)
85 {
86  for (size_t i = 0; i < (sizeof(AES_KEY_SIZES) / sizeof(AES_KEY_SIZES[0])); i++) {
87  if (AES_KEY_SIZES[i] == size)
88  return size;
89  }
90  NDN_THROW(KeyParams::Error("Unsupported AES key size " + to_string(size)));
91 }
92 
93 uint32_t
94 AesKeyParamsInfo::getDefaultSize()
95 {
96  return DEFAULT_AES_KEY_SIZE;
97 }
98 
99 uint32_t
100 HmacKeyParamsInfo::checkKeySize(uint32_t size)
101 {
102  if (size == 0 || size % 8 != 0)
103  NDN_THROW(KeyParams::Error("Unsupported HMAC key size " + to_string(size)));
104  return size;
105 }
106 
107 uint32_t
108 HmacKeyParamsInfo::getDefaultSize()
109 {
110  return DEFAULT_HMAC_KEY_SIZE;
111 }
112 
113 } // namespace detail
114 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
const uint32_t DEFAULT_AES_KEY_SIZE
Definition: key-params.cpp:50
std::string to_string(const T &val)
Definition: backports.hpp:86
const uint32_t EC_KEY_SIZES[]
Definition: key-params.cpp:47
KeyIdType
The type of KeyId component in a key name.
virtual ~KeyParams()
NDN_CXX_NODISCARD bool empty() const
const uint32_t AES_KEY_SIZES[]
Definition: key-params.cpp:49
#define NDN_THROW(e)
Definition: exception.hpp:61
const uint32_t DEFAULT_EC_KEY_SIZE
Definition: key-params.cpp:48
KeyType
The type of a cryptographic key.
const uint32_t DEFAULT_HMAC_KEY_SIZE
Definition: key-params.cpp:51
const uint32_t MIN_RSA_KEY_SIZE
Definition: key-params.cpp:45
const uint32_t DEFAULT_RSA_KEY_SIZE
Definition: key-params.cpp:46
KeyParams(KeyType keyType, KeyIdType keyIdType)
Constructor.
Definition: key-params.cpp:26
Represents a name component.
User-specified key id.
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span-lite.hpp:1535