comparison sha1.h @ 0:8705acff2494

lots of stuff
author Matt Johnston <matt@ucc.asn.au>
date Sat, 01 Jun 2013 01:38:42 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8705acff2494
1 /* sha1.h */
2 /*
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2008 Daniel Otte ([email protected])
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 [email protected]
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 /*
69 typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
70 */
71
72 /** \fn sha1_init(sha1_ctx_t *state)
73 * \brief initializes a SHA-1 context
74 * This function sets a ::sha1_ctx_t variable to the initialization vector
75 * for SHA-1 hashing.
76 * \param state pointer to the SHA-1 context variable
77 */
78 void sha1_init(sha1_ctx_t *state);
79
80 /** \fn sha1_nextBlock(sha1_ctx_t *state, const void* block)
81 * \brief process one input block
82 * This function processes one input block and updates the hash context
83 * accordingly
84 * \param state pointer to the state variable to update
85 * \param block pointer to the message block to process
86 */
87 void sha1_nextBlock (sha1_ctx_t *state, const void* block);
88
89 /** \fn sha1_lastBlock(sha1_ctx_t *state, const void* block, uint16_t length_b)
90 * \brief processes the given block and finalizes the context
91 * This function processes the last block in a SHA-1 hashing process.
92 * The block should have a maximum length of a single input block.
93 * \param state pointer to the state variable to update and finalize
94 * \param block pointer to themessage block to process
95 * \param length_b length of the message block in bits
96 */
97 void sha1_lastBlock (sha1_ctx_t *state, const void* block, uint16_t length_b);
98
99 /** \fn sha1_ctx2hash(sha1_hash_t *dest, sha1_ctx_t *state)
100 * \brief convert a state variable into an actual hash value
101 * Writes the hash value corresponding to the state to the memory pointed by dest.
102 * \param dest pointer to the hash value destination
103 * \param state pointer to the hash context
104 */
105 void sha1_ctx2hash (void *dest, sha1_ctx_t *state);
106
107 /** \fn sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b)
108 * \brief hashing a message which in located entirely in RAM
109 * This function automatically hashes a message which is entirely in RAM with
110 * the SHA-1 hashing algorithm.
111 * \param dest pointer to the hash value destination
112 * \param msg pointer to the message which should be hashed
113 * \param length_b length of the message in bits
114 */
115 void sha1(void *dest, const void* msg, uint32_t length_b);
116
117
118
119 #endif /*SHA1_H_*/