CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
hash Namespace Reference

Usage: std::string msg = "The quick brown fox jumps over the lazy dog"; std::string key = "key"; std::string md5hmac = hmac< MD5 >(msg, key); std::string sha1hmac = hmac< SHA1 >(msg, key); std::string sha2hmac = hmac<SHA256>(msg, key);. More...

Classes

class  CRC32
 compute CRC32 hash, based on Intel's Slicing-by-8 algorithm More...
class  Hash
 abstract base class More...
class  Keccak
 compute Keccak hash (designated SHA3) More...
class  MD5
 compute MD5 hash More...
class  SHA1
 compute SHA1 hash More...
class  SHA256
 compute SHA256 hash More...
class  SHA3
 compute SHA3 hash More...

Functions

template<typename HashMethod>
std::string hmac (const void *data, size_t numDataBytes, const void *key, size_t numKeyBytes)
 compute HMAC hash of data and key using MD5, SHA1 or SHA256
template<typename HashMethod>
std::string hmac (const std::string &data, const std::string &key)
 convenience function for std::string

Detailed Description

Usage: std::string msg = "The quick brown fox jumps over the lazy dog"; std::string key = "key"; std::string md5hmac = hmac< MD5 >(msg, key); std::string sha1hmac = hmac< SHA1 >(msg, key); std::string sha2hmac = hmac<SHA256>(msg, key);.

Note: To keep my code simple, HMAC computation currently needs the whole message at once. This is in contrast to the hashes MD5, SHA1, etc. where an add() method is available for incremental computation. You can use any hash for HMAC as long as it provides:

  • constant HashMethod::BlockSize (typically 64)
  • constant HashMethod::HashBytes (length of hash in bytes, e.g. 20 for SHA1)
  • HashMethod::add(buffer, bufferSize)
  • HashMethod::getHash(unsigned char buffer[HashMethod::BlockSize])

Function Documentation

◆ hmac() [1/2]

template<typename HashMethod>
std::string hash::hmac ( const std::string & data,
const std::string & key )

convenience function for std::string

Definition at line 88 of file hmac.h.

References hmac().

◆ hmac() [2/2]

template<typename HashMethod>
std::string hash::hmac ( const void * data,
size_t numDataBytes,
const void * key,
size_t numKeyBytes )

compute HMAC hash of data and key using MD5, SHA1 or SHA256

Definition at line 43 of file hmac.h.

Referenced by hmac().