Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
OpenSSLAesCcm.hxx File Reference
#include <string>
#include <openssl/evp.h>
#include "utils/logging.h"

Go to the source code of this file.

Classes

class  MD
 Helper class to do hashing algorithms via OpenSSL library. More...
 

Macros

#define ASSERT_EQ(expected, actual)
 

Functions

void CCMEncrypt (const std::string &aes_key, const std::string &iv, const std::string &auth_data, const std::string &plain, std::string *cipher, std::string *tag)
 Performs authenticated encryption using AES-CCM.
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Helper function to perform encryption/authentication/decryption using AES-CCM algorithm with OpenSSL crypt library.

In order to use this function, you need to install libssl-dev package and add to the makefile of your application target to link against it:

SYSLIBRARIESEXTRA+=-lcrypto

Author
Balazs Racz
Date
4 Mar 2017

Definition in file OpenSSLAesCcm.hxx.

Macro Definition Documentation

◆ ASSERT_EQ

#define ASSERT_EQ (   expected,
  actual 
)
Value:
do \
{ \
int __ret = (actual); \
int __e = (expected); \
if (__e != __ret) \
{ \
LOG(FATAL, "At %s(%d): Failed assertion " #actual \
": expected %d actual %d\n", \
__FILE__, __LINE__, __e, __ret); \
HASSERT(0); \
} \
} while (false)
static const int FATAL
Loglevel that kills the current process.
Definition logging.h:51

Definition at line 50 of file OpenSSLAesCcm.hxx.

Function Documentation

◆ CCMEncrypt()

void CCMEncrypt ( const std::string &  aes_key,
const std::string &  iv,
const std::string &  auth_data,
const std::string &  plain,
std::string *  cipher,
std::string *  tag 
)

Performs authenticated encryption using AES-CCM.

Parameters
aes_keyis the 256-bit key.
ivis the unique initialization vector, must be 11 bytes long.
auth_datais plaintext additional authenticated data.
plainwill be encrypted.
cipheris the output of the encryption.
tagis the output of the signature. Will use 16 bytes.

Definition at line 72 of file OpenSSLAesCcm.hxx.