Loading...
Searching...
No Matches
sha1.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Oliver Hahm <oliver.hahm@inria.fr>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
24
25/* This code is public-domain - it is based on libcrypt
26 * placed in the public domain by Wei Dai and other contributors. */
27
28#include <stdint.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
37#define SHA1_DIGEST_LENGTH (20)
38
42#define SHA1_BLOCK_LENGTH (64)
43
48typedef struct {
50 uint32_t buffer[SHA1_BLOCK_LENGTH / sizeof(uint32_t)];
52 uint32_t state[SHA1_DIGEST_LENGTH / sizeof(uint32_t)];
54 uint32_t byte_count;
63
70
78void sha1_update(sha1_context *ctx, const void *data, size_t len);
79
87void sha1_final(sha1_context *ctx, void *digest);
88
96void sha1(void *digest, const void *data, size_t len);
97
105void sha1_init_hmac(sha1_context *ctx, const void *key, size_t key_length);
106
113void sha1_final_hmac(sha1_context *ctx, void *digest);
114
115#ifdef __cplusplus
116}
117#endif
118
#define SHA1_BLOCK_LENGTH
Length of SHA-1 block in byte.
Definition sha1.h:42
#define SHA1_DIGEST_LENGTH
Length of SHA-1 digests in byte.
Definition sha1.h:37
void sha1_final_hmac(sha1_context *ctx, void *digest)
Finalizes the SHA-1 message digest with MAC.
void sha1_update(sha1_context *ctx, const void *data, size_t len)
Update the SHA-1 context with a portion of the message being hashed.
void sha1_init(sha1_context *ctx)
Initialize SHA-1 message digest context.
void sha1(void *digest, const void *data, size_t len)
Calculate a SHA1 hash from the given data.
void sha1_final(sha1_context *ctx, void *digest)
Finalizes the SHA-1 message digest.
void sha1_init_hmac(sha1_context *ctx, const void *key, size_t key_length)
Initialize SHA-1 message digest context with MAC.
SHA-1 algorithm context.
Definition sha1.h:48
uint8_t key_buffer[SHA1_BLOCK_LENGTH]
internal state of the key buffer
Definition sha1.h:59
uint32_t state[SHA1_DIGEST_LENGTH/sizeof(uint32_t)]
buffering current state of hashing
Definition sha1.h:52
uint32_t byte_count
already processed bytes
Definition sha1.h:54
uint32_t buffer[SHA1_BLOCK_LENGTH/sizeof(uint32_t)]
internal buffer
Definition sha1.h:50
uint8_t inner_hash[SHA1_DIGEST_LENGTH]
temporary buffer for the inner hashing
Definition sha1.h:61
uint8_t buffer_offset
internal state variable to keep track if the buffer is filled before proceeding to hash this block
Definition sha1.h:57