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
69 typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
71 /** \fn sha1_init(sha1_ctx_t *state)
72 * \brief initializes a SHA-1 context
73 * This function sets a ::sha1_ctx_t variable to the initialization vector
75 * \param state pointer to the SHA-1 context variable
77 void sha1_init(sha1_ctx_t *state);
79 /** \fn sha1_nextBlock(sha1_ctx_t *state, const void* block)
80 * \brief process one input block
81 * This function processes one input block and updates the hash context
83 * \param state pointer to the state variable to update
84 * \param block pointer to the message block to process
86 void sha1_nextBlock (sha1_ctx_t *state, const void* block);
88 /** \fn sha1_lastBlock(sha1_ctx_t *state, const void* block, uint16_t length_b)
89 * \brief processes the given block and finalizes the context
90 * This function processes the last block in a SHA-1 hashing process.
91 * The block should have a maximum length of a single input block.
92 * \param state pointer to the state variable to update and finalize
93 * \param block pointer to themessage block to process
94 * \param length_b length of the message block in bits
96 void sha1_lastBlock (sha1_ctx_t *state, const void* block, uint16_t length_b);
98 /** \fn sha1_ctx2hash(sha1_hash_t *dest, sha1_ctx_t *state)
99 * \brief convert a state variable into an actual hash value
100 * Writes the hash value corresponding to the state to the memory pointed by dest.
101 * \param dest pointer to the hash value destination
102 * \param state pointer to the hash context
104 void sha1_ctx2hash (void *dest, sha1_ctx_t *state);
106 /** \fn sha1(sha1_hash_t *dest, const void* msg, uint32_t length_b)
107 * \brief hashing a message which in located entirely in RAM
108 * This function automatically hashes a message which is entirely in RAM with
109 * the SHA-1 hashing algorithm.
110 * \param dest pointer to the hash value destination
111 * \param msg pointer to the message which should be hashed
112 * \param length_b length of the message in bits
114 void sha1(void *dest, const void* msg, uint32_t length_b);