CXI
Loading...
Searching...
No Matches
Public Member Functions | List of all members
MechParamCCM Class Reference

Constructs a mechanism parameter for AES encryption or decryption with "Counter with Cipher Block Chaining - Message Authentication Code", abbreviated CCM (see NIST SP 800-38C). More...

Inheritance diagram for MechParamCCM:
[legend]
Collaboration diagram for MechParamCCM:
[legend]

Public Member Functions

 MechParamCCM (int mech, const ByteArray &nonce, const ByteArray &ad, int datalen, int maclen=16, int nonce_gen_func=CXI_MECH_PARAM_NONCE_NO_GENERATE)
 
MechanismParameter getEncoded (void)
 
- Public Member Functions inherited from MechParam
 MechParam (int mech)
 Constructs a mechanism parameter with the given mechanism specifier. More...
 
MechanismParameter getEncoded (void)
 

Detailed Description

Constructs a mechanism parameter for AES encryption or decryption with "Counter with Cipher Block Chaining - Message Authentication Code", abbreviated CCM (see NIST SP 800-38C).

The following example illustrates the usage of the MechParamCCM class:

Key key = ...;
ByteArray nonce = ByteArray("1234567890ABCD");
ByteArray ad = "My Little Secret";
ByteArray data = ...;
ByteArray tag1 = ByteArray(16);
// encrypt data
MechParamCCM mechParam = MechParamCCM(CXI_MECH_MODE_ENCRYPT, nonce, ad, data.length());
ByteArray crypt = cxi->crypt(CXI_FLAG_CRYPT_INIT | CXI_FLAG_CRYPT_FINAL, key, mechParam.getEncoded(), data, iv, tag1);
// decrypt data
mechParam = MechParamCCM(CXI_MECH_MODE_DECRYPT, nonce, ad, data.length());
iv.clear;
ByteArray tag2 = ByteArray(16);
// authenticated decryption, tag is verified internally
ByteArray plain = cxi->crypt(CXI_FLAG_CRYPT_INIT | CXI_FLAG_CRYPT_FINAL, key, mechParam.getEncoded(), crypt, iv, tag2, tag1);
if (plain != data)
throw Exception("<decrypt>", "decrypted data doesn't match original data");
Encapsulates an array of primitive type char in an object and provides methods to operate on binary d...
Definition: sw/cxi_api_c/def/bytearray.h:22
int length(void) const
Definition: bytearray.cpp:180
void clear(void)
Definition: bytearray.cpp:165
Constructs an exception object.
Definition: sw/cxi_api_c/def/exception.h:22
Encapsulates key handles or key blobs of type 'Backup Blob', see Format of Key Blobs.
Definition: sw/cxi_api_c/def/key.h:19
Constructs a mechanism parameter for AES encryption or decryption with "Counter with Cipher Block Cha...
Definition: sw/cxi_api_c/def/mechparam.h:155
MechanismParameter getEncoded(void)
Definition: mechparam.cpp:1004
#define CXI_FLAG_CRYPT_INIT
Initialize En/Decryption Operation.
Definition: fw/cxi/def/cxi_defs.h:509
#define CXI_FLAG_CRYPT_FINAL
Finalize En/Decryption Operation.
Definition: fw/cxi/def/cxi_defs.h:510
#define CXI_MECH_MODE_DECRYPT
Decryption mode.
Definition: fw/cxi/def/cxi_defs.h:333
#define CXI_MECH_MODE_ENCRYPT
Encryption mode.
Definition: fw/cxi/def/cxi_defs.h:332
Definition: cxi.cpp:173

Constructor & Destructor Documentation

◆ MechParamCCM()

MechParamCCM ( int  mech,
const ByteArray nonce,
const ByteArray ad,
int  datalen,
int  maclen = 16,
int  nonce_gen_func = CXI_MECH_PARAM_NONCE_NO_GENERATE 
)

Constructs mechanism parameter for Galois Counter Mode (see NIST SP-800-38D).

Parameters
mechXOR combination of mechanism specifier:
  • crypt mode (see Mode Parameter)
    • CXI_MECH_MODE_ENCRYPT
    • CXI_MECH_MODE_DECRYPT
nonce_gen_funcnonce generation function:
  • cxi_ccm_nonce_no_generate the host has to provide the nonce.
  • cxi_ccm_nonce_generate the cryptoserver generates a random nonce with length of nonce. This nonce is returned by the final encryption call and must then be used as nonce for the decryption.
  • The chaining mode CXI_MECH_CHAIN_CCM is set as default and cannot be changed.
    Parameters
    nonceNonce (7-13 bytes) for initial crypt call
    adadditional authentication data.
  • On chunked operation additional authentication data should be given once on the first call and has to be absent on subsequent calls.
    Parameters
    datalenlength total length of the data that will be passed to the crypt() call(s) later
    maclenlength of the MAC (range 4-16), has to be set for initial and final crypt call

Member Function Documentation

◆ getEncoded()

MechanismParameter getEncoded ( void  )
Returns
Returns the encoded mechanism parameter.