]> git.cryptolib.org Git - arm-crypto-lib.git/blob - sha1/sha1.h
Adding Khazad
[arm-crypto-lib.git] / sha1 / sha1.h
1 /* sha1.h */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /**
20  * \file        sha1.h
21  * \author      Daniel Otte
22  * \email   daniel.otte@rub.de
23  * \date        2006-10-08
24  * \license GPLv3 or later
25  * \brief   SHA-1 declaration.
26  * \ingroup SHA-1
27  * 
28  */
29  
30 #ifndef SHA1_H_
31 #define SHA1_H_
32
33 #include <stdint.h>
34 /** \def SHA1_HASH_BITS
35  * definees the size of a SHA-1 hash in bits 
36  */
37
38 /** \def SHA1_HASH_BYTES
39  * definees the size of a SHA-1 hash in bytes 
40  */
41
42 /** \def SHA1_BLOCK_BITS
43  * definees the size of a SHA-1 input block in bits 
44  */
45
46 /** \def SHA1_BLOCK_BYTES
47  * definees the size of a SHA-1 input block in bytes 
48  */
49 #define SHA1_HASH_BITS  160
50 #define SHA1_HASH_BYTES (SHA1_HASH_BITS/8)
51 #define SHA1_BLOCK_BITS 512
52 #define SHA1_BLOCK_BYTES (SHA1_BLOCK_BITS/8)
53
54 /** \typedef sha1_ctx_t
55  * \brief SHA-1 context type
56  * 
57  * A vatiable of this type may hold the state of a SHA-1 hashing process
58  */
59 typedef struct {
60         uint32_t h[5];
61         uint64_t length;
62 } sha1_ctx_t;
63
64 /** \typedef sha1_hash_t
65  * \brief hash value type
66  * A variable of this type may hold a SHA-1 hash value 
67  */
68 typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
69
70 /** \fn sha1_init(sha1_ctx_t *state)
71  * \brief initializes a SHA-1 context
72  * This function sets a ::sha1_ctx_t variable to the initialization vector
73  * for SHA-1 hashing.
74  * \param state pointer to the SHA-1 context variable
75  */
76 void sha1_init(sha1_ctx_t *state);
77
78 /** \fn sha1_nextBlock(sha1_ctx_t *state, const void* block)
79  *  \brief process one input block
80  * This function processes one input block and updates the hash context 
81  * accordingly
82  * \param state pointer to the state variable to update
83  * \param block pointer to the message block to process
84  */
85 void sha1_nextBlock (sha1_ctx_t *state, const void* block);
86
87 /** \fn sha1_lastBlock(sha1_ctx_t *state, const void* block, uint16_t length_b)
88  * \brief processes the given block and finalizes the context
89  * This function processes the last block in a SHA-1 hashing process.
90  * The block should have a maximum length of a single input block.
91  * \param state pointer to the state variable to update and finalize
92  * \param block pointer to themessage block to process
93  * \param length_b length of the message block in bits  
94  */
95 void sha1_lastBlock (sha1_ctx_t *state, const void* block, uint16_t length_b);
96
97 /** \fn sha1_ctx2hash(sha1_hash_t *dest, sha1_ctx_t *state)
98  * \brief convert a state variable into an actual hash value
99  * Writes the hash value corresponding to the state to the memory pointed by dest.
100  * \param dest pointer to the hash value destination
101  * \param state pointer to the hash context
102  */ 
103 void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state);
104
105 /** \fn sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b)
106  * \brief hashing a message which in located entirely in RAM
107  * This function automatically hashes a message which is entirely in RAM with
108  * the SHA-1 hashing algorithm.
109  * \param dest pointer to the hash value destination
110  * \param msg  pointer to the message which should be hashed
111  * \param length_b length of the message in bits
112  */ 
113 void sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b);
114
115
116
117 #endif /*SHA1_H_*/