siphash.h
Functions
Name | |
---|---|
int | wc_InitSipHash(SipHash * siphash, const unsigned char * key, unsigned char outSz) This function initializes SipHash with a key for a MAC size. |
int | wc_SipHashUpdate(SipHash * siphash, const unsigned char * in, word32 inSz) Can be called to continually hash the provided byte array of length len. |
int | wc_SipHashFinal(SipHash * siphash, unsigned char * out, unsigned char outSz) Finalizes MACing of data. Result is placed into out. |
int | wc_SipHash(const unsigned char * key, const unsigned char * in, word32 inSz, unsigned char * out, unsigned char outSz) This function one-shots the data using SipHash to calculate a MAC based on the key. |
Functions Documentation
function wc_InitSipHash
int wc_InitSipHash(
SipHash * siphash,
const unsigned char * key,
unsigned char outSz
)
This function initializes SipHash with a key for a MAC size.
Parameters:
- siphash pointer to the SipHash structure to use for MACing
- key pointer to the 16-byte array
- outSz number of bytes to output as MAC
See:
Return:
- 0 Returned upon successfully initializing
- BAD_FUNC_ARG Returned when siphash or key is NULL
- BAD_FUNC_ARG Returned when outSz is neither 8 nor 16
Example
SipHash siphash[1];
unsigned char key[16] = { ... };
byte macSz = 8; // 8 or 16
if ((ret = wc_InitSipHash(siphash, key, macSz)) != 0) {
WOLFSSL_MSG("wc_InitSipHash failed");
}
else if ((ret = wc_SipHashUpdate(siphash, data, len)) != 0) {
WOLFSSL_MSG("wc_SipHashUpdate failed");
}
else if ((ret = wc_SipHashFinal(siphash, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHashFinal failed");
}
function wc_SipHashUpdate
int wc_SipHashUpdate(
SipHash * siphash,
const unsigned char * in,
word32 inSz
)
Can be called to continually hash the provided byte array of length len.
Parameters:
- siphash pointer to the SipHash structure to use for MACing
- in the data to be MACed
- inSz size of data to be MACed
See:
Return:
- 0 Returned upon successfully adding the data to the MAC
- BAD_FUNC_ARG Returned when siphash is NULL
- BAD_FUNC_ARG Returned when in is NULL and inSz is not zero
Example
SipHash siphash[1];
byte data[] = { Data to be MACed };
word32 len = sizeof(data);
if ((ret = wc_InitSipHash(siphash, key, macSz)) != 0) {
WOLFSSL_MSG("wc_InitSipHash failed");
}
else if ((ret = wc_SipHashUpdate(siphash, data, len)) != 0) {
WOLFSSL_MSG("wc_SipHashUpdate failed");
}
else if ((ret = wc_SipHashFinal(siphash, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHashFinal failed");
}
function wc_SipHashFinal
int wc_SipHashFinal(
SipHash * siphash,
unsigned char * out,
unsigned char outSz
)
Finalizes MACing of data. Result is placed into out.
Parameters:
- siphash pointer to the SipHash structure to use for MACing
- out Byte array to hold MAC value
- outSz number of bytes to output as MAC
See:
Return:
- 0 Returned upon successfully finalizing.
- BAD_FUNC_ARG Returned when siphash of out is NULL
- BAD_FUNC_ARG Returned when outSz is not the same as the initialized value
Example
SipHash siphash[1];
byte mac[8] = { ... }; // 8 or 16 bytes
byte macSz = sizeof(mac);
if ((ret = wc_InitSipHash(siphash, key, macSz)) != 0) {
WOLFSSL_MSG("wc_InitSipHash failed");
}
else if ((ret = wc_SipHashUpdate(siphash, data, len)) != 0) {
WOLFSSL_MSG("wc_SipHashUpdate failed");
}
else if ((ret = wc_SipHashFinal(siphash, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHashFinal failed");
}
function wc_SipHash
int wc_SipHash(
const unsigned char * key,
const unsigned char * in,
word32 inSz,
unsigned char * out,
unsigned char outSz
)
This function one-shots the data using SipHash to calculate a MAC based on the key.
Parameters:
- key pointer to the 16-byte array
- in the data to be MACed
- inSz size of data to be MACed
- out Byte array to hold MAC value
- outSz number of bytes to output as MAC
See:
Return:
- 0 Returned upon successfully MACing
- BAD_FUNC_ARG Returned when key or out is NULL
- BAD_FUNC_ARG Returned when in is NULL and inSz is not zero
- BAD_FUNC_ARG Returned when outSz is neither 8 nor 16
Example
unsigned char key[16] = { ... };
byte data[] = { Data to be MACed };
word32 len = sizeof(data);
byte mac[8] = { ... }; // 8 or 16 bytes
byte macSz = sizeof(mac);
if ((ret = wc_SipHash(key, data, len, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHash failed");
}
Source code
int wc_InitSipHash(SipHash* siphash, const unsigned char* key,
unsigned char outSz);
int wc_SipHashUpdate(SipHash* siphash, const unsigned char* in,
word32 inSz);
int wc_SipHashFinal(SipHash* siphash, unsigned char* out,
unsigned char outSz);
int wc_SipHash(const unsigned char* key, const unsigned char* in,
word32 inSz, unsigned char* out, unsigned char outSz);
Updated on 2024-12-04 at 01:16:56 +0000