sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
hmac.h File Reference
#include <string>
#include <cstring>

Go to the source code of this file.

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

Function Documentation

◆ hmac() [1/2]

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

convenience function for std::string

Definition at line 84 of file hmac.h.

◆ hmac() [2/2]

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

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])

Definition at line 39 of file hmac.h.