Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_sha256.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
35
36#ifndef __NILOREA_SHA256__
37#define __NILOREA_SHA256__
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
47
48#include <stddef.h>
49#include <stdint.h>
50
52#define N_SHA256_LEN 32
54#define N_SHA256_HEX_LEN 65
55
57typedef struct N_SHA256 {
59 uint32_t state[8];
61 uint64_t length;
63 unsigned char block[64];
65 size_t used;
66} N_SHA256;
67
70void n_sha256_init(N_SHA256* ctx);
71
76void n_sha256_update(N_SHA256* ctx, const void* data, size_t len);
77
81void n_sha256_final(N_SHA256* ctx, unsigned char out[N_SHA256_LEN]);
82
87void n_sha256(const void* data, size_t len, unsigned char out[N_SHA256_LEN]);
88
93int n_sha256_file(const char* path, unsigned char out[N_SHA256_LEN]);
94
98void n_sha256_hex(const unsigned char digest[N_SHA256_LEN], char out[N_SHA256_HEX_LEN]);
99
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif /* __NILOREA_SHA256__ */
unsigned char block[64]
the block being filled
Definition n_sha256.h:63
uint32_t state[8]
the eight working words
Definition n_sha256.h:59
size_t used
how much of it is filled
Definition n_sha256.h:65
uint64_t length
bytes hashed so far
Definition n_sha256.h:61
void n_sha256_final(N_SHA256 *ctx, unsigned char out[32])
finish: the digest, the state left spent
Definition n_sha256.c:132
void n_sha256_init(N_SHA256 *ctx)
start a hash
Definition n_sha256.c:91
int n_sha256_file(const char *path, unsigned char out[32])
hash a file, read in pieces
Definition n_sha256.c:166
void n_sha256(const void *data, size_t len, unsigned char out[32])
hash one buffer
Definition n_sha256.c:158
#define N_SHA256_HEX_LEN
size of its lowercase hex form, terminator included
Definition n_sha256.h:54
void n_sha256_update(N_SHA256 *ctx, const void *data, size_t len)
feed bytes
Definition n_sha256.c:103
#define N_SHA256_LEN
size in bytes of a SHA-256 digest
Definition n_sha256.h:52
void n_sha256_hex(const unsigned char digest[32], char out[65])
a digest as lowercase hex
Definition n_sha256.c:195
a SHA-256 in progress: plain data, copyable to fork a hash
Definition n_sha256.h:57