EVE 1.0
sha1.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011, Micael Hildenborg
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of Micael Hildenborg nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16  THIS SOFTWARE IS PROVIDED BY Micael Hildenborg ''AS IS'' AND ANY
17  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL Micael Hildenborg BE LIABLE FOR ANY
20  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef SHA1_DEFINED
29 #define SHA1_DEFINED
30 
31 /**
32  * \file
33  * \brief SHA1 implementation
34  *
35  */ /******************************************************************/
36 
37 /**
38  * \defgroup sha1 SHA1
39  * \ingroup security
40  * \{
41  */
42 
43 #define SHA1_HASH_LENGTH 20
44 
45 struct sha1_state_t {
46  unsigned char t[64];
47  unsigned int result[5];
48  int currentBlock;
49  int totalLength;
50 };
51 
52 /**
53 @param state the SHA-1 hasher instance
54 */
55 void sha1_init(struct sha1_state_t *state);
56 
57 /**
58 @param state the SHA-1 hasher instance
59 @param src points to any kind of data to be hashed.
60 @param bytelength the number of bytes to hash from the src pointer.
61 */
62 void sha1_calc(struct sha1_state_t *state, const void* src, int bytelength);
63 
64 /**
65 @param state the SHA-1 hasher instance
66 @param hash should point to a buffer of at least 20 bytes of size for storing the sha1 result in.
67 */
68 void sha1_commit(struct sha1_state_t *state, unsigned char* hash);
69 
70 /**
71 @param hash is 20 bytes of sha1 hash. This is the same data that is the result from the calc function.
72 @param hexstring should point to a buffer of at least 41 bytes of size for storing the hexadecimal representation of the hash. A zero will be written at position 40, so the buffer will be a valid zero ended string.
73 */
74 void sha1_toHexString(const unsigned char* hash, char* hexstring);
75 
76 /** \} */
77 
78 #endif // SHA1_DEFINED
void sha1_commit(struct sha1_state_t *state, unsigned char *hash)
void sha1_calc(struct sha1_state_t *state, const void *src, int bytelength)
void sha1_toHexString(const unsigned char *hash, char *hexstring)
void sha1_init(struct sha1_state_t *state)