sha1.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Oliver Hahm <oliver.hahm@inria.fr>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
22 /* This code is public-domain - it is based on libcrypt
23  * placed in the public domain by Wei Dai and other contributors. */
24 
25 #include <stdint.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #define SHA1_DIGEST_LENGTH (20)
35 
39 #define SHA1_BLOCK_LENGTH (64)
40 
45 typedef struct {
47  uint32_t buffer[SHA1_BLOCK_LENGTH / sizeof(uint32_t)];
49  uint32_t state[SHA1_DIGEST_LENGTH / sizeof(uint32_t)];
51  uint32_t byte_count;
54  uint8_t buffer_offset;
56  uint8_t key_buffer[SHA1_BLOCK_LENGTH];
58  uint8_t inner_hash[SHA1_DIGEST_LENGTH];
59 } sha1_context;
60 
67 
75 void sha1_update(sha1_context *ctx, const void *data, size_t len);
76 
84 void sha1_final(sha1_context *ctx, void *digest);
85 
93 void sha1(void *digest, const void *data, size_t len);
94 
102 void sha1_init_hmac(sha1_context *ctx, const void *key, size_t key_length);
103 
110 void sha1_final_hmac(sha1_context *ctx, void *digest);
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
#define SHA1_BLOCK_LENGTH
Length of SHA-1 block in byte.
Definition: sha1.h:39
#define SHA1_DIGEST_LENGTH
Length of SHA-1 digests in byte.
Definition: sha1.h:34
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:45
uint32_t byte_count
already processed bytes
Definition: sha1.h:51
uint8_t buffer_offset
internal state variable to keep track if the buffer is filled before proceeding to hash this block
Definition: sha1.h:54