SHA-2
Single-part SHA-256 example
#define MESSAGE ((const unsigned char *) "test")
#define MESSAGE_LEN 4
unsigned char out[crypto_hash_sha256_BYTES];
crypto_hash_sha256(out, MESSAGE, MESSAGE_LEN);Multi-part SHA-256 example
#define MESSAGE_PART1 \
((const unsigned char *) "Arbitrary data to hash")
#define MESSAGE_PART1_LEN 22
#define MESSAGE_PART2 \
((const unsigned char *) "is longer than expected")
#define MESSAGE_PART2_LEN 23
unsigned char out[crypto_hash_sha256_BYTES];
crypto_hash_sha256_state state;
crypto_hash_sha256_init(&state);
crypto_hash_sha256_update(&state, MESSAGE_PART1, MESSAGE_PART1_LEN);
crypto_hash_sha256_update(&state, MESSAGE_PART2, MESSAGE_PART2_LEN);
crypto_hash_sha256_final(&state, out);Usage
SHA-256
SHA-512
Notes
Constants
Data types
Last updated