SHA-2#
SHA-2 comes in six different variants (instantiations) …
SHA-224,
SHA-256,
SHA-384,
SHA-512,
SHA-512/224 (not supported by HACL), and
SHA-512/256 (not supported by HACL).
The number denotes the digest size, i.e., how many bits are produced by the hash function.
Note: While SHA-256
already denotes the hash function from the SHA-2 family that produces 256 bits of output,
it is sometimes called SHA2-256
to avoid confusion with SHA-1 and SHA-3.
API Reference#
One-Shot#
-
void Hacl_Hash_SHA2_hash_224(uint8_t *output, uint8_t *input, uint32_t input_len)#
Hash
input
, of leninput_len
, intooutput
, an array of 28 bytes.
-
void Hacl_Hash_SHA2_hash_256(uint8_t *output, uint8_t *input, uint32_t input_len)#
Hash
input
, of leninput_len
, intooutput
, an array of 32 bytes.
-
void Hacl_Hash_SHA2_hash_384(uint8_t *output, uint8_t *input, uint32_t input_len)#
Hash
input
, of leninput_len
, intooutput
, an array of 48 bytes.
-
void Hacl_Hash_SHA2_hash_512(uint8_t *output, uint8_t *input, uint32_t input_len)#
Hash
input
, of leninput_len
, intooutput
, an array of 64 bytes.
Example
This is an example how to use the SHA-2 one-shot API to digest a complete message.
The digest is written to the memory pointed to by digest and the caller is expected to allocate enough memory for the digest.
// This example uses SHA2-256.
//
const char* message = "Hello, World!";
uint32_t message_size = strlen(message);
// 256 Bit / 8 = 32 Byte
uint8_t digest[256 / 8];
Hacl_Hash_SHA2_hash_256((uint8_t*)message, message_size, digest);
Streaming#
Init
Warning
doxygentypedef: Cannot find typedef “Hacl_Streaming_SHA2_state_sha2_224” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygentypedef: Cannot find typedef “Hacl_Streaming_SHA2_state_sha2_256” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygentypedef: Cannot find typedef “Hacl_Streaming_SHA2_state_sha2_384” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygentypedef: Cannot find typedef “Hacl_Streaming_SHA2_state_sha2_512” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_create_in_224” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_create_in_256” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_create_in_384” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_create_in_512” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_init_224” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_init_256” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_init_384” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_init_512” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Update
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_update_224” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_update_256” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_update_384” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_update_512” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Finish
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_finish_224” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_finish_256” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_finish_384” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_finish_512” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_free_224” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_free_256” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_free_384” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/
Warning
doxygenfunction: Cannot find function “Hacl_Streaming_SHA2_free_512” in doxygen xml output for project “HACL Packages” from directory: ../../build/doxygen/xml/