add EncryptionTLV Encoding and Decoding
Change-Id: I67f6f733e0a02b894e49155167600963c3b2964e
diff --git a/src/crypto-support/crypto-helper.cpp b/src/crypto-support/crypto-helper.cpp
index 297bbef..8fba982 100644
--- a/src/crypto-support/crypto-helper.cpp
+++ b/src/crypto-support/crypto-helper.cpp
@@ -22,8 +22,8 @@
#include "../logging.hpp"
#include <openssl/err.h>
-#include <openssl/pem.h>
#include <openssl/hmac.h>
+#include <openssl/pem.h>
#include <ndn-cxx/encoding/buffer-stream.hpp>
#include <ndn-cxx/security/transform/base64-decode.hpp>
@@ -81,7 +81,7 @@
}
// initializes a public key algorithm context
- if (1 != EVP_PKEY_keygen_init(context->ctx_keygen)){
+ if (1 != EVP_PKEY_keygen_init(context->ctx_keygen)) {
handleErrors("Could not init context for key generation.");
return;
}
@@ -95,21 +95,21 @@
ECDHState::~ECDHState()
{
// Contexts
- if(context->ctx_params != nullptr){
+ if (context->ctx_params != nullptr) {
EVP_PKEY_CTX_free(context->ctx_params);
}
- if(context->ctx_keygen != nullptr){
+ if (context->ctx_keygen != nullptr) {
EVP_PKEY_CTX_free(context->ctx_keygen);
}
// Keys
- if(context->privkey != nullptr){
+ if (context->privkey != nullptr) {
EVP_PKEY_free(context->privkey);
}
- if(context->peerkey != nullptr){
+ if (context->peerkey != nullptr) {
EVP_PKEY_free(context->peerkey);
}
- if(context->params != nullptr){
+ if (context->params != nullptr) {
EVP_PKEY_free(context->params);
}
}
@@ -147,9 +147,7 @@
}
std::ostringstream os;
- t::bufferSource(context->publicKey, context->publicKeyLen)
- >> t::base64Encode(false)
- >> t::streamSink(os);
+ t::bufferSource(context->publicKey, context->publicKeyLen) >> t::base64Encode(false) >> t::streamSink(os);
return os.str();
}
@@ -196,9 +194,9 @@
}
int
-ndn_compute_hmac_sha256(const uint8_t *data, const unsigned data_length,
- const uint8_t *key, const unsigned key_length,
- uint8_t *prk)
+ndn_compute_hmac_sha256(const uint8_t* data, const unsigned data_length,
+ const uint8_t* key, const unsigned key_length,
+ uint8_t* prk)
{
HMAC(EVP_sha256(), key, key_length,
(unsigned char*)data, data_length,
@@ -240,8 +238,7 @@
t::PrivateKey privKey;
privKey.loadRaw(KeyType::HMAC, prk, dig_len);
OBufferStream os;
- source >> t::signerFilter(DigestAlgorithm::SHA256, privKey)
- >> t::streamSink(os);
+ source >> t::signerFilter(DigestAlgorithm::SHA256, privKey) >> t::streamSink(os);
if (i > 1) {
source.write(prev, dig_len);
@@ -263,7 +260,7 @@
aes_gcm_128_encrypt(const uint8_t* plaintext, size_t plaintext_len, const uint8_t* associated, size_t associated_len,
const uint8_t* key, const uint8_t* iv, uint8_t* ciphertext, uint8_t* tag)
{
- EVP_CIPHER_CTX *ctx;
+ EVP_CIPHER_CTX* ctx;
int len;
int ciphertext_len;
@@ -274,7 +271,7 @@
// Initialise the encryption operation.
if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), nullptr, nullptr, nullptr)) {
- handleErrors("Cannot initialise the encryption operation when calling EVP_EncryptInit_ex()");
+ handleErrors("Cannot initialise the encryption operation when calling EVP_EncryptInit_ex()");
}
// Set IV length if default 12 bytes (96 bits) is not appropriate
@@ -387,5 +384,5 @@
BOOST_THROW_EXCEPTION(CryptoError("Error in CRYPTO SUPPORT: " + errorInfo));
}
-} // namespace ndncert
-} // namespace ndn
+} // namespace ndncert
+} // namespace ndn