The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
sha2.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* @file sha2.h
5
* @brief SHA-256 (FIPS 180-4) in steps, for data that does not fit in
6
* memory at one time. the names are the ones of the BSD sha2.h.
7
* ginnOS has SHA-256 only, not SHA-384 or SHA-512.
8
*
9
* usage:
10
*
11
* SHA2_CTX ctx;
12
* SHA256Init(&ctx);
13
* SHA256Update(&ctx, part, part_length); // as many times as needed
14
* SHA256Final(digest, &ctx);
15
*
16
* for data in one buffer, sha256() in crypt.h does the three steps.
17
*/
18
19
#include <
stddef.h
>
20
#include <
stdint.h
>
21
22
#define SHA256_BLOCK_LENGTH 64
23
#define SHA256_DIGEST_LENGTH 32
24
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
25
26
/** the state of a SHA-256 calculation. its fields are private. */
27
typedef
struct
28
{
29
uint32_t
h
[8];
30
uint64_t
length
;
// bytes added
31
uint8_t
block
[
SHA256_BLOCK_LENGTH
];
32
size_t
used
;
// bytes in block
33
}
SHA2_CTX
;
34
35
/** start a new calculation in ctx. */
36
void
SHA256Init
(
SHA2_CTX
*ctx);
37
38
/** add length bytes of data. */
39
void
SHA256Update
(
SHA2_CTX
*ctx,
const
void
*data,
size_t
length);
40
41
/**
42
* finish the calculation and write the digest. ctx must get SHA256Init
43
* again before it is used for new data.
44
*/
45
void
SHA256Final
(
uint8_t
digest[
SHA256_DIGEST_LENGTH
],
SHA2_CTX
*ctx);
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uint8_t
unsigned char uint8_t
Definition
fb.h:18
stddef.h
NULL, size_t, ptrdiff_t, offsetof.
stdint.h
integer types of fixed width.
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
SHA256Update
void SHA256Update(SHA2_CTX *ctx, const void *data, size_t length)
add length bytes of data.
SHA256_DIGEST_LENGTH
#define SHA256_DIGEST_LENGTH
Definition
sha2.h:23
SHA256Init
void SHA256Init(SHA2_CTX *ctx)
start a new calculation in ctx.
SHA256Final
void SHA256Final(uint8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *ctx)
finish the calculation and write the digest.
SHA256_BLOCK_LENGTH
#define SHA256_BLOCK_LENGTH
Definition
sha2.h:22
SHA2_CTX
the state of a SHA-256 calculation.
Definition
sha2.h:28
SHA2_CTX::h
uint32_t h[8]
Definition
sha2.h:29
SHA2_CTX::length
uint64_t length
Definition
sha2.h:30
SHA2_CTX::block
uint8_t block[SHA256_BLOCK_LENGTH]
Definition
sha2.h:31
SHA2_CTX::used
size_t used
Definition
sha2.h:32
src
libc
include
sha2.h
Generated by
1.18.0