SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration

Detailed Description

HMAC keyed-hash message authentication code (in conjunction with: MD5,SHA1,SHA256,SHA384,SHA512)

Data Structures

struct  SharkSslHMACCtx
 HMAC. More...
 

Typedefs

typedef struct SharkSslHMACCtx SharkSslHMACCtx
 HMAC. More...
 

Functions

SHARKSSL_API int SharkSslHMACCtx_constructor (SharkSslHMACCtx *ctx, U8 hashID, const U8 *key, U16 keyLen)
 Initialize. More...
 
SHARKSSL_API int SharkSslHMACCtx_append (SharkSslHMACCtx *, const U8 *data, U32 len)
 append More...
 
SHARKSSL_API int SharkSslHMACCtx_finish (SharkSslHMACCtx *, U8 *HMAC)
 finish More...
 
SHARKSSL_API int sharkssl_HMAC (const U8 hashID, const U8 *data, U32 len, const U8 *key, U16 keyLen, U8 *digest)
 HMAC. More...
 

Typedef Documentation

◆ SharkSslHMACCtx

HMAC.

In PSA consumer builds, this context owns a volatile PSA key. Do not copy it. Finish and destructor release the key; call destructor if a message is abandoned. Consumer methods return zero on success and -1 on error.

Function Documentation

◆ sharkssl_HMAC()

int sharkssl_HMAC ( const U8  hashID,
const U8 *  data,
U32  len,
const U8 *  key,
U16  keyLen,
U8 *  digest 
)

HMAC.

Use a nonempty key and an enabled hash.

Parameters
hashIDthe hash function to be used, can be one of: SHARKSSL_HASHID_MD5, SHARKSSL_HASHID_SHA1, SHARKSSL_HASHID_SHA256, SHARKSSL_HASHID_SHA384, SHARKSSL_HASHID_SHA512
datapointer to the data to be hashed
lendata length in bytes
keypointer to the cryptographic key
keyLen'key' length
digestoutput HMAC

The PSA consumer additionally requires that hash/HMAC combination from its provider. The result is one full hash-length MAC; no truncation is performed.

Returns
int: 0 on success; -1 for an unsupported or disabled hashID, native temporary-allocation failure, or PSA argument/algorithm/provider failure. Discard the digest on failure.

◆ SharkSslHMACCtx_append()

int SharkSslHMACCtx_append ( SharkSslHMACCtx *  ctx,
const U8 *  data,
U32  len 
)

append

Parameters
ctxSharkSslHMACCtx *; required initialized, unfinished context.
dataconst U8 *; message bytes, borrowed for the call; required when len is nonzero.
lenU32; message length in bytes.
Returns
int: 0 on success; -1 for an unusable hash/context or a PSA provider failure.

◆ SharkSslHMACCtx_constructor()

int SharkSslHMACCtx_constructor ( SharkSslHMACCtx *  ctx,
U8  hashID,
const U8 *  key,
U16  keyLen 
)

Initialize.

The PSA context owns an imported volatile key.

Parameters
ctxUninitialized data of size sizeof(SharkSslHMACCtx).
hashIDthe hash function to be used, can be one of: SHARKSSL_HASHID_MD5, SHARKSSL_HASHID_SHA1, SHARKSSL_HASHID_SHA256, SHARKSSL_HASHID_SHA384, SHARKSSL_HASHID_SHA512
keypointer to the cryptographic key
keyLen'key' length

Finish it or call SharkSslHMACCtx_destructor before reusing the storage. The native context retains a derived key pad until cleared.

Returns
int: 0 on success; -1 for an unsupported hash, native temporary-allocation failure, or a PSA argument/provider failure.

◆ SharkSslHMACCtx_finish()

int SharkSslHMACCtx_finish ( SharkSslHMACCtx *  ctx,
U8 *  HMAC 
)

finish

Parameters
ctxSharkSslHMACCtx *; required active context. The PSA implementation also releases its operation and imported key; clear the native context with its destructor after use.
HMACU8 *; required output buffer sized to the selected hash digest (16, 20, 32, 48, or 64 bytes for the documented native hashes).
Returns
int: 0 on success; -1 for an unusable hash/context or a PSA computation/cleanup failure. Discard the output on failure.