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-2017 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 "
key-params.hpp
"
23
24
namespace
ndn
{
25
26
static
const
uint32_t
MIN_RSA_KEY_SIZE
= 1024;
27
static
const
uint32_t
DEFAULT_RSA_KEY_SIZE
= 2048;
28
static
const
uint32_t
EC_KEY_SIZES
[] = {256, 384};
29
static
const
uint32_t
AES_KEY_SIZES
[] = {128, 192, 256};
30
31
KeyParams::KeyParams
(
KeyType
keyType,
KeyIdType
keyIdType)
32
: m_keyType(keyType)
33
, m_keyIdType(keyIdType)
34
{
35
BOOST_ASSERT(keyIdType !=
KeyIdType::USER_SPECIFIED
);
36
}
37
38
KeyParams::KeyParams
(
KeyType
keyType,
const
name::Component
& keyId)
39
: m_keyType(keyType)
40
, m_keyIdType(
KeyIdType
::
USER_SPECIFIED
)
41
, m_keyId(keyId)
42
{
43
BOOST_ASSERT(!keyId.
empty
());
44
}
45
46
KeyParams::~KeyParams
() =
default
;
47
48
namespace
detail {
49
50
uint32_t
51
RsaKeyParamsInfo::checkKeySize
(uint32_t size)
52
{
53
if
(size <
MIN_RSA_KEY_SIZE
)
54
BOOST_THROW_EXCEPTION(
KeyParams::Error
(
"Unsupported RSA key size"
));
55
return
size;
56
}
57
58
uint32_t
59
RsaKeyParamsInfo::getDefaultSize
()
60
{
61
return
DEFAULT_RSA_KEY_SIZE
;
62
}
63
64
uint32_t
65
EcKeyParamsInfo::checkKeySize
(uint32_t size)
66
{
67
for
(
size_t
i = 0; i < (
sizeof
(
EC_KEY_SIZES
) /
sizeof
(
EC_KEY_SIZES
[0])); i++) {
68
if
(
EC_KEY_SIZES
[i] == size)
69
return
size;
70
}
71
BOOST_THROW_EXCEPTION(
KeyParams::Error
(
"Unsupported EC key size"
));
72
}
73
74
uint32_t
75
EcKeyParamsInfo::getDefaultSize
()
76
{
77
return
EC_KEY_SIZES
[0];
78
}
79
80
uint32_t
81
AesKeyParamsInfo::checkKeySize
(uint32_t size)
82
{
83
for
(
size_t
i = 0; i < (
sizeof
(
AES_KEY_SIZES
) /
sizeof
(
AES_KEY_SIZES
[0])); i++) {
84
if
(
AES_KEY_SIZES
[i] == size)
85
return
size;
86
}
87
BOOST_THROW_EXCEPTION(
KeyParams::Error
(
"Unsupported AES key size"
));
88
}
89
90
uint32_t
91
AesKeyParamsInfo::getDefaultSize
()
92
{
93
return
AES_KEY_SIZES
[0];
94
}
95
96
}
// namespace detail
97
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::DEFAULT_RSA_KEY_SIZE
static const uint32_t DEFAULT_RSA_KEY_SIZE
Definition:
key-params.cpp:27
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:65
key-params.hpp
ndn::AES_KEY_SIZES
static const uint32_t AES_KEY_SIZES[]
Definition:
key-params.cpp:29
ndn::name::Component::empty
bool empty() const
Definition:
name-component.hpp:471
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:81
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:31
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:51
ndn::KeyIdType::USER_SPECIFIED
User-specified key ID.
ndn::detail::EcKeyParamsInfo::getDefaultSize
static uint32_t getDefaultSize()
Definition:
key-params.cpp:75
ndn::detail::AesKeyParamsInfo::getDefaultSize
static uint32_t getDefaultSize()
Definition:
key-params.cpp:91
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:59
ndnSIM
ndn-cxx
src
security
key-params.cpp
Generated on Tue Aug 7 2018 16:19:16 for ndnSIM by
1.8.14