hmac - 2023.2 English

Vitis Libraries

Release Date
2023.2 English
#include "xf_security/hmac.hpp"
template <
    int dataW,
    int lW,
    int hshW,
    int keyLen,
    int blockSize,
    template< int iW, int ilW, int oW > class F
void hmac (
    hls::stream <ap_uint <dataW>>& keyStrm,
    hls::stream <ap_uint <dataW>>& msgStrm,
    hls::stream <ap_uint <lW>>& msgLenStrm,
    hls::stream <bool>& eLenStrm,
    hls::stream <ap_uint <hshW>>& hshStrm,
    hls::stream <bool>& eHshStrm

Compute HMAC value according to specified hash function and input data.

keyW, keyStrm, keyLenStrm, msgW, msgStrm, and msgLenStrm would be used as parameters or input for the hash function, so they need to align with the API of the hash function.

Hash function is wrapped to a template struct which must have a static function named hash .

Take md5 for example:

template <int msgW, int lW, int hshW> struct md5_wrapper { static void hash(hls::stream<ap_uint<msgW> >& msgStrm, hls::stream<lW>& lenStrm, hls::stream<bool>& eLenStrm, hls::stream<ap_uint<hshW> >& hshStrm, hls::stream<bool>& eHshStrm) { xf::security::md5(msgStrm, lenStrm, eLenStrm, hshStrm, eHshStrm); } };

then use hmac like this,

xf::security::hmac<32, 32, 64, 128, 64, md5_wrapper> (…);


dataW the width of input stream keyStrm and msgStrm.
lW the with of input msgLenstrm.
blockSize the block size (in bytes) of the underlying hash function (e.g. 64 bytes for md5 and SHA-1).
hshW the width of output stream hshStrm.
keyLen lenght of key (in bytes)
F a wrapper of hash function which must have a static fucntion named hash .
keyStrm input key stream.
msgStrm input meassge stream.
msgLenStrm the length stream of input message stream.
eLenStrm the end flag of length stream.
hshStrm output stream.
eHshStrm end flag of output stream hshStrm.