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 
23 /* This code is public-domain - it is based on libcrypt
24  * placed in the public domain by Wei Dai and other contributors. */
25 
26 #ifndef HASHES_SHA1_H
27 #define HASHES_SHA1_H
28 
29 #include <stdint.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 #define SHA1_DIGEST_LENGTH (20)
39 
43 #define SHA1_BLOCK_LENGTH (64)
44 
49 typedef struct {
51  uint32_t buffer[SHA1_BLOCK_LENGTH / sizeof(uint32_t)];
53  uint32_t state[SHA1_DIGEST_LENGTH / sizeof(uint32_t)];
55  uint32_t byte_count;
58  uint8_t buffer_offset;
60  uint8_t key_buffer[SHA1_BLOCK_LENGTH];
62  uint8_t inner_hash[SHA1_DIGEST_LENGTH];
63 } sha1_context;
64 
65 
71 void sha1_init(sha1_context *ctx);
72 
80 void sha1_update(sha1_context *ctx, const void *data, size_t len);
81 
89 void sha1_final(sha1_context *ctx, void *digest);
90 
98 void sha1(void *digest, const void *data, size_t len);
99 
107 void sha1_init_hmac(sha1_context *ctx, const void *key, size_t key_length);
108 
115 void sha1_final_hmac(sha1_context *ctx, void *digest);
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif /* HASHES_SHA1_H */
122 
SHA-1 algorithm context.
Definition: sha1.h:49
uint32_t byte_count
already processed bytes
Definition: sha1.h:55
void sha1(void *digest, const void *data, size_t len)
Calculate a SHA1 hash from the given data.
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.
#define SHA1_DIGEST_LENGTH
Length of SHA-1 digests in byte.
Definition: sha1.h:38
void sha1_init(sha1_context *ctx)
Initialize SHA-1 message digest context.
uint8_t buffer_offset
internal state variable to keep track if the buffer is filled before proceeding to hash this block ...
Definition: sha1.h:58
#define SHA1_BLOCK_LENGTH
Length of SHA-1 block in byte.
Definition: sha1.h:43
void sha1_init_hmac(sha1_context *ctx, const void *key, size_t key_length)
Initialize SHA-1 message digest context with MAC.
void sha1_final_hmac(sha1_context *ctx, void *digest)
Finalizes the SHA-1 message digest with MAC.
void sha1_final(sha1_context *ctx, void *digest)
Finalizes the SHA-1 message digest.