CryptoSys API  6.22.1
Public Types | Public Member Functions | Static Public Member Functions | List of all members
crsysapi::Mac Class Reference

Message authentication code (MAC) functions. More...

Public Types

enum class  Alg
 Message Authentication Code (MAC) Algorithm
More...
 

Public Member Functions

int AddData (bvec_t data)
 Adds a chunk of data in a byte array to be digested by the Mac object. More...
 
int AddData (std::string s)
 Adds a chunk of data in a string to be digested by the Mac object. More...
 
bvec_t Final ()
 Computes final MAC value for the Mac object. More...
 
bool Init (bvec_t key, Alg alg)
 Initialises the Mac object ready for repeated incremental operations. More...
 

Static Public Member Functions

static bvec_t BytesFromBytes (const bvec_t &data, const bvec_t &key, Alg alg=Alg::HmacSha1)
 Computes MAC value in byte format from byte input. More...
 
static std::string HexFromBytes (const bvec_t &data, const bvec_t &key, Alg alg=Alg::HmacSha1)
 Computes MAC value in hex-encoded format from byte input. More...
 
static std::string HexFromHex (const std::string &dataHex, const std::string &keyHex, Alg alg=Alg::HmacSha1)
 Computes MAC value in hex-encoded format from hex-encoded input. More...
 
static std::string HexFromString (const std::string &s, const bvec_t &key, Alg alg=Alg::HmacSha1)
 Computes MAC value in hex-encoded format from string input. More...
 

Detailed Description

Message authentication code (MAC) functions.

Member Enumeration Documentation

◆ Alg

enum crsysapi::Mac::Alg
strong

Message Authentication Code (MAC) Algorithm

Enumerator
HmacSha1 

HMAC-SHA-1.

HmacSha224 

HMAC-SHA-224.

HmacSha256 

HMAC-SHA-256.

HmacSha384 

HMAC-SHA-384.

HmacSha512 

HMAC-SHA-512.

HmacSha3_224 

HMAC-SHA-3-224.

HmacSha3_256 

HMAC-SHA-3-256.

HmacSha3_384 

HMAC-SHA-3-384.

HmacSha3_512 

HMAC-SHA-3-512.

HmacMd5 

HMAC-MD5.

HmacRipemd160 

HMAC-RIPEMD160

CmacTdea 

CMAC-TDEA (CMAC-DES-EDE)

CmacAes128 

CMAC-AES-128

CmacAes192 

CMAC-AES-192

CmacAes256 

CMAC-AES-256

Poly1305 

Poly1305.

Kmac128 

KMAC128 with a fixed-length output of 256 bits (32 bytes)

Kmac256 

KMAC256 with a fixed-length output of 512 bits (64 bytes)

Member Function Documentation

◆ AddData() [1/2]

int crsysapi::Mac::AddData ( bvec_t  data)

Adds a chunk of data in a byte array to be digested by the Mac object.

Parameters
dataData to add
Returns
0 on success or nonzero, see Err::ErrorLookup
Exceptions
std::runtime_errorif object is not valid.

◆ AddData() [2/2]

int crsysapi::Mac::AddData ( std::string  s)

Adds a chunk of data in a string to be digested by the Mac object.

Parameters
sData to add
Returns
0 on success or nonzero, see Err::ErrorLookup
Exceptions
std::runtime_errorif object is not valid.

◆ BytesFromBytes()

static bvec_t crsysapi::Mac::BytesFromBytes ( const bvec_t data,
const bvec_t key,
Alg  alg = Alg::HmacSha1 
)
static

Computes MAC value in byte format from byte input.

Parameters
dataMessage to be signed in byte array
keyKey in byte array
algMAC algorithm to be used
Returns
MAC in byte format

◆ Final()

bvec_t crsysapi::Mac::Final ( )

Computes final MAC value for the Mac object.

Returns
Digest value in a byte array.
Remarks
This operation delivers the final result of Add operations since the Mac::Init operation. Once called, the Mac object is no longer invalid. Use Mac::Init to start again.
Exceptions
std::runtime_errorif object is not valid.

◆ HexFromBytes()

static std::string crsysapi::Mac::HexFromBytes ( const bvec_t data,
const bvec_t key,
Alg  alg = Alg::HmacSha1 
)
static

Computes MAC value in hex-encoded format from byte input.

Parameters
dataMessage to be signed in byte array
keyKey in byte array
algMAC algorithm to be used
Returns
MAC in hex-encoded format

◆ HexFromHex()

static std::string crsysapi::Mac::HexFromHex ( const std::string &  dataHex,
const std::string &  keyHex,
Alg  alg = Alg::HmacSha1 
)
static

Computes MAC value in hex-encoded format from hex-encoded input.

Parameters
dataHexMessage to be signed in hex-encoded format
keyHexKey in hex-encoded format
algMAC algorithm to be used
Returns
MAC in hex-encoded format

◆ HexFromString()

static std::string crsysapi::Mac::HexFromString ( const std::string &  s,
const bvec_t key,
Alg  alg = Alg::HmacSha1 
)
static

Computes MAC value in hex-encoded format from string input.

Parameters
sMessage to be signed as a string
keyKey in byte array
algMAC algorithm to be used
Returns
MAC in hex-encoded format

◆ Init()

bool crsysapi::Mac::Init ( bvec_t  key,
Alg  alg 
)

Initialises the Mac object ready for repeated incremental operations.

Parameters
keyKey in byte array.
algMac algorithm to be used
Returns
True if successful.
Remarks
Only the HMAC-SHA-1 and HMAC-SHA-2 families of MAC algorithms are currently supported in object mode.
Exceptions
std::runtime_errorif algorithm is not supported.
Copyright © 2001-24 D.I. Management Services Pty Limited ABN 78 083 210 584 Australia. All rights reserved. <www.di-mgt.com.au> <www.cryptosys.net>. Generated on Sat Jan 6 2024 18:00:07 by Doxygen 1.9.1.