NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
openssl-helper.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2022 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/impl/openssl-helper.hpp
"
23
24
namespace
ndn
{
25
namespace
security
{
26
namespace
detail {
27
28
const
EVP_MD*
29
digestAlgorithmToEvpMd
(
DigestAlgorithm
algo)
30
{
31
switch
(algo) {
32
case
DigestAlgorithm::SHA224
:
33
return
EVP_sha224();
34
case
DigestAlgorithm::SHA256
:
35
return
EVP_sha256();
36
case
DigestAlgorithm::SHA384
:
37
return
EVP_sha384();
38
case
DigestAlgorithm::SHA512
:
39
return
EVP_sha512();
40
#ifndef OPENSSL_NO_BLAKE2
41
case
DigestAlgorithm::BLAKE2B_512
:
42
return
EVP_blake2b512();
43
case
DigestAlgorithm::BLAKE2S_256
:
44
return
EVP_blake2s256();
45
#endif
46
case
DigestAlgorithm::SHA3_224
:
47
return
EVP_sha3_224();
48
case
DigestAlgorithm::SHA3_256
:
49
return
EVP_sha3_256();
50
case
DigestAlgorithm::SHA3_384
:
51
return
EVP_sha3_384();
52
case
DigestAlgorithm::SHA3_512
:
53
return
EVP_sha3_512();
54
default
:
55
return
nullptr
;
56
}
57
}
58
59
int
60
getEvpPkeyType
(
const
EVP_PKEY* key)
61
{
62
return
EVP_PKEY_base_id(key);
63
}
64
65
EvpMdCtx::EvpMdCtx
()
66
: m_ctx(EVP_MD_CTX_new())
67
{
68
if
(m_ctx ==
nullptr
)
69
NDN_THROW
(std::runtime_error(
"EVP_MD_CTX creation failed"
));
70
}
71
72
EvpMdCtx::~EvpMdCtx
()
73
{
74
EVP_MD_CTX_free(m_ctx);
75
}
76
77
EvpPkeyCtx::EvpPkeyCtx
(EVP_PKEY* key)
78
: m_ctx(EVP_PKEY_CTX_new(key, nullptr))
79
{
80
if
(m_ctx ==
nullptr
)
81
NDN_THROW
(std::runtime_error(
"EVP_PKEY_CTX creation failed"
));
82
}
83
84
EvpPkeyCtx::EvpPkeyCtx
(
int
id
)
85
: m_ctx(EVP_PKEY_CTX_new_id(id, nullptr))
86
{
87
if
(m_ctx ==
nullptr
)
88
NDN_THROW
(std::runtime_error(
"EVP_PKEY_CTX creation failed"
));
89
}
90
91
EvpPkeyCtx::~EvpPkeyCtx
()
92
{
93
EVP_PKEY_CTX_free(m_ctx);
94
}
95
96
Bio::Bio
(
const
BIO_METHOD*
method
)
97
: m_bio(BIO_new(method))
98
{
99
if
(m_bio ==
nullptr
)
100
NDN_THROW
(std::runtime_error(
"BIO creation failed"
));
101
}
102
103
Bio::~Bio
()
104
{
105
BIO_free_all(m_bio);
106
}
107
108
bool
109
Bio::read
(span<uint8_t> buf)
const
noexcept
110
{
111
BOOST_ASSERT(buf.size() <= std::numeric_limits<int>::max());
112
int
n = BIO_read(m_bio, buf.data(),
static_cast<
int
>
(buf.size()));
113
return
n >= 0 &&
static_cast<
size_t
>
(n) == buf.size();
114
}
115
116
bool
117
Bio::write
(span<const uint8_t> buf) noexcept
118
{
119
BOOST_ASSERT(buf.size() <= std::numeric_limits<int>::max());
120
int
n = BIO_write(m_bio, buf.data(),
static_cast<
int
>
(buf.size()));
121
return
n >= 0 &&
static_cast<
size_t
>
(n) == buf.size();
122
}
123
124
}
// namespace detail
125
}
// namespace security
126
}
// namespace ndn
ndn::security::detail::Bio::read
NDN_CXX_NODISCARD bool read(span< uint8_t > buf) const noexcept
Definition:
openssl-helper.cpp:109
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::DigestAlgorithm::SHA224
ndn::DigestAlgorithm::SHA3_384
websocketpp::http::parser::state::method
Definition:
parser.hpp:45
ndn::security::detail::Bio::~Bio
~Bio()
Definition:
openssl-helper.cpp:103
ndn::security::detail::digestAlgorithmToEvpMd
const EVP_MD * digestAlgorithmToEvpMd(DigestAlgorithm algo)
Definition:
openssl-helper.cpp:29
ndn::security::detail::getEvpPkeyType
int getEvpPkeyType(const EVP_PKEY *key)
Definition:
openssl-helper.cpp:60
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
ndn::security::detail::Bio::write
NDN_CXX_NODISCARD bool write(span< const uint8_t > buf) noexcept
Definition:
openssl-helper.cpp:117
ndn::security::detail::EvpPkeyCtx::~EvpPkeyCtx
~EvpPkeyCtx()
Definition:
openssl-helper.cpp:91
ndn::security::detail::EvpPkeyCtx::EvpPkeyCtx
EvpPkeyCtx(EVP_PKEY *key)
Definition:
openssl-helper.cpp:77
ndn::security::detail::EvpMdCtx::~EvpMdCtx
~EvpMdCtx()
Definition:
openssl-helper.cpp:72
ndn::DigestAlgorithm::SHA3_512
ndn::KeyIdType::SHA256
Use the SHA-256 hash of the public key as key id.
ndn::DigestAlgorithm::SHA512
ndn::DigestAlgorithm::SHA384
ndn::security
Definition:
dummy-keychain.cpp:28
ndn::security::detail::EvpMdCtx::EvpMdCtx
EvpMdCtx()
Definition:
openssl-helper.cpp:65
ndn::DigestAlgorithm::SHA3_224
openssl-helper.hpp
ndn::DigestAlgorithm::BLAKE2S_256
ndn::DigestAlgorithm::SHA3_256
ndn::security::detail::Bio::Bio
Bio(const BIO_METHOD *method)
Definition:
openssl-helper.cpp:96
ndn::DigestAlgorithm
DigestAlgorithm
Definition:
security-common.hpp:106
ndn::DigestAlgorithm::BLAKE2B_512
ndnSIM
ndn-cxx
ndn-cxx
security
impl
openssl-helper.cpp
Generated on Fri May 6 2022 12:34:12 for ndnSIM by
1.8.13