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 
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
31 extern "C" {
32 #endif
33 
37 #define SHA1_DIGEST_LENGTH (20)
38 
42 #define SHA1_BLOCK_LENGTH (64)
43 
48 typedef 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;
57  uint8_t buffer_offset;
59  uint8_t key_buffer[SHA1_BLOCK_LENGTH];
61  uint8_t inner_hash[SHA1_DIGEST_LENGTH];
62 } sha1_context;
63 
70 
78 void sha1_update(sha1_context *ctx, const void *data, size_t len);
79 
87 void sha1_final(sha1_context *ctx, void *digest);
88 
96 void sha1(void *digest, const void *data, size_t len);
97 
105 void sha1_init_hmac(sha1_context *ctx, const void *key, size_t key_length);
106 
113 void 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
uint32_t byte_count
already processed bytes
Definition: sha1.h:54
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