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-2018 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
22
#include "
ndn-cxx/security/key-params.hpp
"
23
24
namespace
ndn
{
25
26
static
const
uint32_t
MIN_RSA_KEY_SIZE
= 2048;
27
static
const
uint32_t
DEFAULT_RSA_KEY_SIZE
= 2048;
28
static
const
uint32_t
EC_KEY_SIZES
[] = {224, 256, 384, 521};
29
static
const
uint32_t
DEFAULT_EC_KEY_SIZE
= 256;
30
static
const
uint32_t
AES_KEY_SIZES
[] = {128, 192, 256};
31
static
const
uint32_t
DEFAULT_AES_KEY_SIZE
= 128;
32
33
KeyParams::KeyParams
(
KeyType
keyType,
KeyIdType
keyIdType)
34
: m_keyType(keyType)
35
, m_keyIdType(keyIdType)
36
{
37
BOOST_ASSERT(keyIdType !=
KeyIdType::USER_SPECIFIED
);
38
}
39
40
KeyParams::KeyParams
(
KeyType
keyType,
const
name::Component
& keyId)
41
: m_keyType(keyType)
42
, m_keyIdType(
KeyIdType
::
USER_SPECIFIED
)
43
, m_keyId(keyId)
44
{
45
BOOST_ASSERT(!keyId.
empty
());
46
}
47
48
KeyParams::~KeyParams
() =
default
;
49
50
namespace
detail {
51
52
uint32_t
53
RsaKeyParamsInfo::checkKeySize
(uint32_t size)
54
{
55
if
(size <
MIN_RSA_KEY_SIZE
)
56
BOOST_THROW_EXCEPTION(
KeyParams::Error
(
"Unsupported RSA key size "
+
to_string
(size)));
57
return
size;
58
}
59
60
uint32_t
61
RsaKeyParamsInfo::getDefaultSize
()
62
{
63
return
DEFAULT_RSA_KEY_SIZE
;
64
}
65
66
uint32_t
67
EcKeyParamsInfo::checkKeySize
(uint32_t size)
68
{
69
for
(
size_t
i = 0; i < (
sizeof
(
EC_KEY_SIZES
) /
sizeof
(
EC_KEY_SIZES
[0])); i++) {
70
if
(
EC_KEY_SIZES
[i] == size)
71
return
size;
72
}
73
BOOST_THROW_EXCEPTION(
KeyParams::Error
(
"Unsupported EC key size "
+
to_string
(size)));
74
}
75
76
uint32_t
77
EcKeyParamsInfo::getDefaultSize
()
78
{
79
return
DEFAULT_EC_KEY_SIZE
;
80
}
81
82
uint32_t
83
AesKeyParamsInfo::checkKeySize
(uint32_t size)
84
{
85
for
(
size_t
i = 0; i < (
sizeof
(
AES_KEY_SIZES
) /
sizeof
(
AES_KEY_SIZES
[0])); i++) {
86
if
(
AES_KEY_SIZES
[i] == size)
87
return
size;
88
}
89
BOOST_THROW_EXCEPTION(
KeyParams::Error
(
"Unsupported AES key size "
+
to_string
(size)));
90
}
91
92
uint32_t
93
AesKeyParamsInfo::getDefaultSize
()
94
{
95
return
DEFAULT_AES_KEY_SIZE
;
96
}
97
98
}
// namespace detail
99
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::DEFAULT_AES_KEY_SIZE
static const uint32_t DEFAULT_AES_KEY_SIZE
Definition:
key-params.cpp:31
ndn::DEFAULT_RSA_KEY_SIZE
static const uint32_t DEFAULT_RSA_KEY_SIZE
Definition:
key-params.cpp:27
ndn::DEFAULT_EC_KEY_SIZE
static const uint32_t DEFAULT_EC_KEY_SIZE
Definition:
key-params.cpp:29
ndn::KeyIdType
KeyIdType
The type of KeyId component in a key name.
Definition:
security-common.hpp:58
ndn::KeyParams::~KeyParams
virtual ~KeyParams()
ndn::detail::EcKeyParamsInfo::checkKeySize
static uint32_t checkKeySize(uint32_t size)
check if size is valid and supported for this key type.
Definition:
key-params.cpp:67
key-params.hpp
ndn::AES_KEY_SIZES
static const uint32_t AES_KEY_SIZES[]
Definition:
key-params.cpp:30
ndn::name::Component::empty
bool empty() const
Definition:
name-component.hpp:485
ndn::detail::AesKeyParamsInfo::checkKeySize
static uint32_t checkKeySize(uint32_t size)
check if size is valid and supported for this key type.
Definition:
key-params.cpp:83
ndn::KeyType
KeyType
The type of a cryptographic key.
Definition:
security-common.hpp:85
ndn::MIN_RSA_KEY_SIZE
static const uint32_t MIN_RSA_KEY_SIZE
Definition:
key-params.cpp:26
ndn::KeyParams::KeyParams
KeyParams(KeyType keyType, KeyIdType keyIdType)
Create a key generation parameter.
Definition:
key-params.cpp:33
ndn::KeyParams::Error
Definition:
key-params.hpp:38
ndn::name::Component
Represents a name component.
Definition:
name-component.hpp:50
ndn::detail::RsaKeyParamsInfo::checkKeySize
static uint32_t checkKeySize(uint32_t size)
check if size is valid and supported for this key type.
Definition:
key-params.cpp:53
ndn::KeyIdType::USER_SPECIFIED
User-specified key ID.
ndn::to_string
std::string to_string(const V &v)
Definition:
backports.hpp:67
ndn::detail::EcKeyParamsInfo::getDefaultSize
static uint32_t getDefaultSize()
Definition:
key-params.cpp:77
ndn::detail::AesKeyParamsInfo::getDefaultSize
static uint32_t getDefaultSize()
Definition:
key-params.cpp:93
ndn::EC_KEY_SIZES
static const uint32_t EC_KEY_SIZES[]
Definition:
key-params.cpp:28
ndn::detail::RsaKeyParamsInfo::getDefaultSize
static uint32_t getDefaultSize()
Definition:
key-params.cpp:61
ndnSIM
ndn-cxx
ndn-cxx
security
key-params.cpp
Generated on Sun Feb 24 2019 22:16:06 for ndnSIM by
1.8.15