The SHA2 family of hash functions. More...
#include "common.h"
Go to the source code of this file.
Data Structures | |
struct | qsc_sha256_state |
The SHA2-256 digest state array. More... | |
struct | qsc_sha384_state |
The SHA2-384 digest state array. More... | |
struct | qsc_sha512_state |
The SHA2-512 digest state array. More... | |
struct | qsc_hmac256_state |
The HMAC(SHA2-256) state array. More... | |
struct | qsc_hmac512_state |
The HMAC(SHA2-512) state array. More... | |
Functions | |
QSC_EXPORT_API void | qsc_sha256_compute (uint8_t *output, const uint8_t *message, size_t msglen) |
Process a message with SHA2-256 and return the hash code in the output byte array. | |
QSC_EXPORT_API void | qsc_sha256_dispose (qsc_sha256_state *ctx) |
Dispose of the SHA2-256 state. | |
QSC_EXPORT_API void | qsc_sha256_finalize (qsc_sha256_state *ctx, uint8_t *output) |
Finalize the message state and return the hash value in the output array. | |
QSC_EXPORT_API void | qsc_sha256_initialize (qsc_sha256_state *ctx) |
Initialize a SHA2-256 state structure. | |
QSC_EXPORT_API void | qsc_sha256_permute (uint32_t *output, const uint8_t *input) |
The SHA2-256 permutation function. | |
QSC_EXPORT_API void | qsc_sha256_update (qsc_sha256_state *ctx, const uint8_t *message, size_t msglen) |
Update SHA2-256 with message input. | |
QSC_EXPORT_API void | qsc_sha384_compute (uint8_t *output, const uint8_t *message, size_t msglen) |
Process a message with SHA2-384 and return the hash code in the output byte array. | |
QSC_EXPORT_API void | qsc_sha384_dispose (qsc_sha384_state *ctx) |
Dispose of the SHA2-384 state. | |
QSC_EXPORT_API void | qsc_sha384_finalize (qsc_sha384_state *ctx, uint8_t *output) |
Finalize the SHA2-384 state and return the hash value in the output array. | |
QSC_EXPORT_API void | qsc_sha384_initialize (qsc_sha384_state *ctx) |
Initialize a SHA2-384 state structure. | |
QSC_EXPORT_API void | qsc_sha384_update (qsc_sha384_state *ctx, const uint8_t *message, size_t msglen) |
Update SHA2-384 with message input. | |
QSC_EXPORT_API void | qsc_sha512_compute (uint8_t *output, const uint8_t *message, size_t msglen) |
Process a message with SHA2-512 and return the hash code in the output byte array. | |
QSC_EXPORT_API void | qsc_sha512_dispose (qsc_sha512_state *ctx) |
Dispose of the SHA2-512 state. | |
QSC_EXPORT_API void | qsc_sha512_finalize (qsc_sha512_state *ctx, uint8_t *output) |
Finalize the SHA2-512 state and return the hash value in the output array. | |
QSC_EXPORT_API void | qsc_sha512_initialize (qsc_sha512_state *ctx) |
Initialize a SHA2-512 state structure. | |
QSC_EXPORT_API void | qsc_sha512_permute (uint64_t *output, const uint8_t *input) |
The SHA2-512 permutation function. | |
QSC_EXPORT_API void | qsc_sha512_update (qsc_sha512_state *ctx, const uint8_t *message, size_t msglen) |
Update SHA2-512 with message input. | |
QSC_EXPORT_API void | qsc_hmac256_compute (uint8_t *output, const uint8_t *message, size_t msglen, const uint8_t *key, size_t keylen) |
Process a message with HMAC(SHA2-256) and return the MAC code in the output byte array. | |
QSC_EXPORT_API void | qsc_hmac256_dispose (qsc_hmac256_state *ctx) |
Dispose of the HMAC-256 state. | |
QSC_EXPORT_API void | qsc_hmac256_finalize (qsc_hmac256_state *ctx, uint8_t *output) |
Finalize the HMAC-256 state and return the MAC code in the output byte array. | |
QSC_EXPORT_API void | qsc_hmac256_initialize (qsc_hmac256_state *ctx, const uint8_t *key, size_t keylen) |
Initialize an HMAC-256 state structure with a key. | |
QSC_EXPORT_API void | qsc_hmac256_update (qsc_hmac256_state *ctx, const uint8_t *message, size_t msglen) |
Update HMAC-256 with message input. | |
QSC_EXPORT_API void | qsc_hmac512_compute (uint8_t *output, const uint8_t *message, size_t msglen, const uint8_t *key, size_t keylen) |
Process a message with HMAC(SHA2-512) and return the MAC code in the output byte array. | |
QSC_EXPORT_API void | qsc_hmac512_dispose (qsc_hmac512_state *ctx) |
Dispose of the HMAC-512 state. | |
QSC_EXPORT_API void | qsc_hmac512_finalize (qsc_hmac512_state *ctx, uint8_t *output) |
Finalize the HMAC-512 state and return the MAC code in the output byte array. | |
QSC_EXPORT_API void | qsc_hmac512_initialize (qsc_hmac512_state *ctx, const uint8_t *key, size_t keylen) |
Initialize an HMAC-512 state structure with a key. | |
QSC_EXPORT_API void | qsc_hmac512_update (qsc_hmac512_state *ctx, const uint8_t *message, size_t msglen) |
Update HMAC-512 with message input. | |
QSC_EXPORT_API void | qsc_hkdf256_expand (uint8_t *output, size_t otplen, const uint8_t *key, size_t keylen, const uint8_t *info, size_t infolen) |
Initialize an instance of HKDF(HMAC(SHA2-256)) and generate pseudo-random output. | |
QSC_EXPORT_API void | qsc_hkdf256_extract (uint8_t *output, size_t otplen, const uint8_t *key, size_t keylen, const uint8_t *salt, size_t saltlen) |
Extract a key from a combined key and salt input using HMAC(SHA2-256). | |
QSC_EXPORT_API void | qsc_hkdf512_expand (uint8_t *output, size_t otplen, const uint8_t *key, size_t keylen, const uint8_t *info, size_t infolen) |
Initialize an instance of HKDF(HMAC(SHA2-512)) and generate pseudo-random output. | |
QSC_EXPORT_API void | qsc_hkdf512_extract (uint8_t *output, size_t otplen, const uint8_t *key, size_t keylen, const uint8_t *salt, size_t saltlen) |
Extract a key from a combined key and salt input using HMAC(SHA2-512). | |
The SHA2 family of hash functions.
This header contains the public API and documentation for the SHA2 digest functions, HMAC, and HKDF implementations. It supports SHA2-256, SHA2-384, and SHA2-512 variants. The API includes both short-form functions (processing the complete message in one call) and long-form functions (initialize, update, finalize) for incremental processing.
Example for SHA2-512 using the long-form API:
QSC_EXPORT_API void qsc_hkdf256_expand | ( | uint8_t * | output, |
size_t | otplen, | ||
const uint8_t * | key, | ||
size_t | keylen, | ||
const uint8_t * | info, | ||
size_t | infolen ) |
Initialize an instance of HKDF(HMAC(SHA2-256)) and generate pseudo-random output.
output | [uint8_t*] The output pseudo-random byte array. |
otplen | [size_t] The output array length. |
key | [const uint8_t*] The HKDF key array. |
keylen | [size_t] The key array length. |
info | [const uint8_t*] The info array. |
infolen | [size_t] The info array length. |
QSC_EXPORT_API void qsc_hkdf256_extract | ( | uint8_t * | output, |
size_t | otplen, | ||
const uint8_t * | key, | ||
size_t | keylen, | ||
const uint8_t * | salt, | ||
size_t | saltlen ) |
Extract a key from a combined key and salt input using HMAC(SHA2-256).
output | [uint8_t*] The output pseudo-random byte array. |
otplen | [size_t] The output array length. |
key | [const uint8_t*] The HKDF key array. |
keylen | [size_t] The key array length. |
salt | [const uint8_t*] The salt array. |
saltlen | [size_t] The salt array length. |
QSC_EXPORT_API void qsc_hkdf512_expand | ( | uint8_t * | output, |
size_t | otplen, | ||
const uint8_t * | key, | ||
size_t | keylen, | ||
const uint8_t * | info, | ||
size_t | infolen ) |
Initialize an instance of HKDF(HMAC(SHA2-512)) and generate pseudo-random output.
output | [uint8_t*] The output pseudo-random byte array. |
otplen | [size_t] The output array length. |
key | [const uint8_t*] The HKDF key array. |
keylen | [size_t] The key array length. |
info | [const uint8_t*] The info array. |
infolen | [size_t] The info array length. |
QSC_EXPORT_API void qsc_hkdf512_extract | ( | uint8_t * | output, |
size_t | otplen, | ||
const uint8_t * | key, | ||
size_t | keylen, | ||
const uint8_t * | salt, | ||
size_t | saltlen ) |
Extract a key from a combined key and salt input using HMAC(SHA2-512).
output | [uint8_t*] The output pseudo-random byte array. |
otplen | [size_t] The output array length. |
key | [const uint8_t*] The HKDF key array. |
keylen | [size_t] The key array length. |
salt | [const uint8_t*] The salt array. |
saltlen | [size_t] The salt array length. |
QSC_EXPORT_API void qsc_hmac256_compute | ( | uint8_t * | output, |
const uint8_t * | message, | ||
size_t | msglen, | ||
const uint8_t * | key, | ||
size_t | keylen ) |
Process a message with HMAC(SHA2-256) and return the MAC code in the output byte array.
output | [uint8_t*] The output byte array; receives the MAC code. |
message | [const uint8_t*] The message input byte array. |
msglen | [size_t] The number of message bytes to process. |
key | [const uint8_t*] The secret key array. |
keylen | [size_t] The key array length. |
QSC_EXPORT_API void qsc_hmac256_dispose | ( | qsc_hmac256_state * | ctx | ) |
Dispose of the HMAC-256 state.
ctx | [qsc_hmac256_state*] Pointer to the MAC state structure. |
QSC_EXPORT_API void qsc_hmac256_finalize | ( | qsc_hmac256_state * | ctx, |
uint8_t * | output ) |
Finalize the HMAC-256 state and return the MAC code in the output byte array.
ctx | [qsc_hmac256_state*] Pointer to the MAC state structure; must be initialized. |
output | [uint8_t*] The output byte array; receives the MAC code. |
QSC_EXPORT_API void qsc_hmac256_initialize | ( | qsc_hmac256_state * | ctx, |
const uint8_t * | key, | ||
size_t | keylen ) |
Initialize an HMAC-256 state structure with a key.
ctx | [qsc_hmac256_state*] Pointer to the MAC state structure. |
key | [const uint8_t*] Pointer to the secret key array. |
keylen | [size_t] The key array length. |
QSC_EXPORT_API void qsc_hmac256_update | ( | qsc_hmac256_state * | ctx, |
const uint8_t * | message, | ||
size_t | msglen ) |
Update HMAC-256 with message input.
ctx | [qsc_hmac256_state*] Pointer to the MAC state structure. |
message | [const uint8_t*] The input message byte array. |
msglen | [size_t] The number of message bytes to process. |
QSC_EXPORT_API void qsc_hmac512_compute | ( | uint8_t * | output, |
const uint8_t * | message, | ||
size_t | msglen, | ||
const uint8_t * | key, | ||
size_t | keylen ) |
Process a message with HMAC(SHA2-512) and return the MAC code in the output byte array.
output | [uint8_t*] The output byte array; receives the MAC code. |
message | [const uint8_t*] The message input byte array. |
msglen | [size_t] The number of message bytes to process. |
key | [const uint8_t*] The secret key array. |
keylen | [size_t] The key array length. |
QSC_EXPORT_API void qsc_hmac512_dispose | ( | qsc_hmac512_state * | ctx | ) |
Dispose of the HMAC-512 state.
ctx | [qsc_hmac512_state*] Pointer to the MAC state structure. |
QSC_EXPORT_API void qsc_hmac512_finalize | ( | qsc_hmac512_state * | ctx, |
uint8_t * | output ) |
Finalize the HMAC-512 state and return the MAC code in the output byte array.
ctx | [qsc_hmac512_state*] Pointer to the MAC state structure; must be initialized. |
output | [uint8_t*] The output byte array; receives the MAC code. |
QSC_EXPORT_API void qsc_hmac512_initialize | ( | qsc_hmac512_state * | ctx, |
const uint8_t * | key, | ||
size_t | keylen ) |
Initialize an HMAC-512 state structure with a key.
ctx | [qsc_hmac512_state*] Pointer to the MAC state structure. |
key | [const uint8_t*] Pointer to the secret key array. |
keylen | [size_t] The key array length. |
QSC_EXPORT_API void qsc_hmac512_update | ( | qsc_hmac512_state * | ctx, |
const uint8_t * | message, | ||
size_t | msglen ) |
Update HMAC-512 with message input.
ctx | [qsc_hmac512_state*] Pointer to the MAC state structure. |
message | [const uint8_t*] The input message byte array. |
msglen | [size_t] The number of message bytes to process. |
QSC_EXPORT_API void qsc_sha256_compute | ( | uint8_t * | output, |
const uint8_t * | message, | ||
size_t | msglen ) |
Process a message with SHA2-256 and return the hash code in the output byte array.
output | [uint8_t*] The output byte array; receives the hash code. |
message | [const uint8_t*] The message input byte array. |
msglen | [size_t] The number of message bytes to process. |
QSC_EXPORT_API void qsc_sha256_dispose | ( | qsc_sha256_state * | ctx | ) |
Dispose of the SHA2-256 state.
ctx | [qsc_sha256_state*] Pointer to the cipher state structure. |
QSC_EXPORT_API void qsc_sha256_finalize | ( | qsc_sha256_state * | ctx, |
uint8_t * | output ) |
Finalize the message state and return the hash value in the output array.
ctx | [qsc_sha256_state*] Pointer to the function state; must be initialized. |
output | [uint8_t*] The output byte array; receives the hash code. |
QSC_EXPORT_API void qsc_sha256_initialize | ( | qsc_sha256_state * | ctx | ) |
Initialize a SHA2-256 state structure.
ctx | [qsc_sha256_state*] Pointer to the function state. |
QSC_EXPORT_API void qsc_sha256_permute | ( | uint32_t * | output, |
const uint8_t * | input ) |
The SHA2-256 permutation function.
Internal function: Called by protocol hash and generation functions, or in the construction of other external protocols. Absorbs a message and permutes the state array.
output | [uint32_t*] The function output; must be initialized. |
input | [const uint8_t*] The input message byte array. |
QSC_EXPORT_API void qsc_sha256_update | ( | qsc_sha256_state * | ctx, |
const uint8_t * | message, | ||
size_t | msglen ) |
Update SHA2-256 with message input.
ctx | [qsc_sha256_state*] Pointer to the function state. |
message | [const uint8_t*] The input message byte array. |
msglen | [size_t] The number of message bytes to process. |
QSC_EXPORT_API void qsc_sha384_compute | ( | uint8_t * | output, |
const uint8_t * | message, | ||
size_t | msglen ) |
Process a message with SHA2-384 and return the hash code in the output byte array.
output | [uint8_t*] The output byte array; receives the hash code. |
message | [const uint8_t*] The message input byte array. |
msglen | [size_t] The number of message bytes to process. |
QSC_EXPORT_API void qsc_sha384_dispose | ( | qsc_sha384_state * | ctx | ) |
Dispose of the SHA2-384 state.
ctx | [qsc_sha384_state*] Pointer to the cipher state structure. |
QSC_EXPORT_API void qsc_sha384_finalize | ( | qsc_sha384_state * | ctx, |
uint8_t * | output ) |
Finalize the SHA2-384 state and return the hash value in the output array.
ctx | [qsc_sha384_state*] Pointer to the function state; must be initialized. |
output | [uint8_t*] The output byte array; receives the hash code. |
QSC_EXPORT_API void qsc_sha384_initialize | ( | qsc_sha384_state * | ctx | ) |
Initialize a SHA2-384 state structure.
ctx | [qsc_sha384_state*] Pointer to the function state. |
QSC_EXPORT_API void qsc_sha384_update | ( | qsc_sha384_state * | ctx, |
const uint8_t * | message, | ||
size_t | msglen ) |
Update SHA2-384 with message input.
ctx | [qsc_sha384_state*] Pointer to the function state. |
message | [const uint8_t*] The input message byte array. |
msglen | [size_t] The number of message bytes to process. |
QSC_EXPORT_API void qsc_sha512_compute | ( | uint8_t * | output, |
const uint8_t * | message, | ||
size_t | msglen ) |
Process a message with SHA2-512 and return the hash code in the output byte array.
output | [uint8_t*] The output byte array; receives the hash code. |
message | [const uint8_t*] The message input byte array. |
msglen | [size_t] The number of message bytes to process. |
QSC_EXPORT_API void qsc_sha512_dispose | ( | qsc_sha512_state * | ctx | ) |
Dispose of the SHA2-512 state.
ctx | [qsc_sha512_state*] Pointer to the cipher state structure. |
QSC_EXPORT_API void qsc_sha512_finalize | ( | qsc_sha512_state * | ctx, |
uint8_t * | output ) |
Finalize the SHA2-512 state and return the hash value in the output array.
ctx | [qsc_sha512_state*] Pointer to the function state; must be initialized. |
output | [uint8_t*] The output byte array; receives the hash code. |
QSC_EXPORT_API void qsc_sha512_initialize | ( | qsc_sha512_state * | ctx | ) |
Initialize a SHA2-512 state structure.
ctx | [qsc_sha512_state*] Pointer to the function state. |
QSC_EXPORT_API void qsc_sha512_permute | ( | uint64_t * | output, |
const uint8_t * | input ) |
The SHA2-512 permutation function.
Internal function: Called by protocol hash and generation functions, or in the construction of other external protocols. Absorbs a message and permutes the state array.
output | [uint64_t*] The function output; must be initialized. |
input | [const uint8_t*] The input message byte array. |
QSC_EXPORT_API void qsc_sha512_update | ( | qsc_sha512_state * | ctx, |
const uint8_t * | message, | ||
size_t | msglen ) |
Update SHA2-512 with message input.
ctx | [qsc_sha512_state*] Pointer to the function state. |
message | [const uint8_t*] The input message byte array. |
msglen | [size_t] The number of message bytes to process. |