3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
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.
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.
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/>.
22 * \email daniel.otte@rub.de
24 * \license GPLv3 or later
25 * \brief SHA-1 declaration.
34 /** \def SHA1_HASH_BITS
35 * definees the size of a SHA-1 hash in bits
38 /** \def SHA1_HASH_BYTES
39 * definees the size of a SHA-1 hash in bytes
42 /** \def SHA1_BLOCK_BITS
43 * definees the size of a SHA-1 input block in bits
46 /** \def SHA1_BLOCK_BYTES
47 * definees the size of a SHA-1 input block in bytes
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)
54 /** \typedef sha1_ctx_t
55 * \brief SHA-1 context type
57 * A vatiable of this type may hold the state of a SHA-1 hashing process
64 /** \typedef sha1_hash_t
65 * \brief hash value type
66 * A variable of this type may hold a SHA-1 hash value
68 typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
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
74 * \param state pointer to the SHA-1 context variable
76 void sha1_init(sha1_ctx_t *state);
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
82 * \param state pointer to the state variable to update
83 * \param block pointer to the message block to process
85 void sha1_nextBlock (sha1_ctx_t *state, const void* block);
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
95 void sha1_lastBlock (sha1_ctx_t *state, const void* block, uint16_t length_b);
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
103 void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state);
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
113 void sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b);