The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
sha2.h File Reference

SHA-256 (FIPS 180-4) in steps, for data that does not fit in memory at one time. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  SHA2_CTX
 the state of a SHA-256 calculation. More...

Macros

#define SHA256_BLOCK_LENGTH   64
#define SHA256_DIGEST_LENGTH   32
#define SHA256_DIGEST_STRING_LENGTH   (SHA256_DIGEST_LENGTH * 2 + 1)

Functions

void SHA256Init (SHA2_CTX *ctx)
 start a new calculation in ctx.
void SHA256Update (SHA2_CTX *ctx, const void *data, size_t length)
 add length bytes of data.
void SHA256Final (uint8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *ctx)
 finish the calculation and write the digest.

Detailed Description

SHA-256 (FIPS 180-4) in steps, for data that does not fit in memory at one time.

the names are the ones of the BSD sha2.h. ginnOS has SHA-256 only, not SHA-384 or SHA-512.

usage:

SHA2_CTX ctx;
SHA256Init(&ctx);
SHA256Update(&ctx, part, part_length); // as many times as needed
SHA256Final(digest, &ctx);

for data in one buffer, sha256() in crypt.h does the three steps.

Macro Definition Documentation

◆ SHA256_BLOCK_LENGTH

#define SHA256_BLOCK_LENGTH   64

◆ SHA256_DIGEST_LENGTH

#define SHA256_DIGEST_LENGTH   32

◆ SHA256_DIGEST_STRING_LENGTH

#define SHA256_DIGEST_STRING_LENGTH   (SHA256_DIGEST_LENGTH * 2 + 1)

Function Documentation

◆ SHA256Init()

void SHA256Init ( SHA2_CTX * ctx)

start a new calculation in ctx.

◆ SHA256Update()

void SHA256Update ( SHA2_CTX * ctx,
const void * data,
size_t length )

add length bytes of data.

◆ SHA256Final()

void SHA256Final ( uint8_t digest[SHA256_DIGEST_LENGTH],
SHA2_CTX * ctx )

finish the calculation and write the digest.

ctx must get SHA256Init again before it is used for new data.