libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
hash_common_f24.c
Go to the documentation of this file.
1/** @addtogroup hash_file HASH Peripheral API
2 *
3 * @ingroup peripheral_apis
4 *
5 * @author @htmlonly © @endhtmlonly 2013
6 * Mikhail Avkhimenia <mikhail@avkhimenia.net>
7 *
8 * This library supports the HASH processor in the STM32F2 and STM32F4
9 * series of ARM Cortex Microcontrollers by ST Microelectronics.
10 *
11 * LGPL License Terms @ref lgpl_license
12 * */
13
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * Copyright (C) 2013 Mikhail Avkhimenia <mikhail@avkhimenia.net>
18 *
19 * This library is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with this library. If not, see <http://www.gnu.org/licenses/>.
31 */
32
33/**@{*/
34
36
37/*---------------------------------------------------------------------------*/
38/** @brief HASH Set Mode
39
40Sets up the specified mode - either HASH or HMAC.
41
42@param[in] mode unsigned int8. Hash processor mode: @ref hash_mode
43*/
44
45void hash_set_mode(uint8_t mode)
46{
47 HASH_CR &= ~HASH_CR_MODE;
48 HASH_CR |= mode;
49}
50
51/*---------------------------------------------------------------------------*/
52/** @brief HASH Set Algorithm
53
54Sets up the specified algorithm - either MD5 or SHA1.
55
56@param[in] algorithm unsigned int8. Hash algorithm: @ref hash_algorithm
57*/
58
59void hash_set_algorithm(uint8_t algorithm)
60{
61 HASH_CR &= ~HASH_CR_ALGO;
62 HASH_CR |= algorithm;
63}
64
65/*---------------------------------------------------------------------------*/
66/** @brief HASH Set Data Type
67
68Sets up the specified data type: 32Bit, 16Bit, 8Bit, Bitstring.
69
70@param[in] datatype unsigned int8. Hash data type: @ref hash_data_type
71*/
72
73void hash_set_data_type(uint8_t datatype)
74{
75 HASH_CR &= ~HASH_CR_DATATYPE;
76 HASH_CR |= datatype;
77}
78
79/*---------------------------------------------------------------------------*/
80/** @brief HASH Set Key Length
81
82Sets up the specified key length: Long, Short.
83
84@param[in] keylength unsigned int8. Hash data type: @ref hash_key_length
85*/
86
87void hash_set_key_length(uint8_t keylength)
88{
89 HASH_CR &= ~HASH_CR_LKEY;
90 HASH_CR |= keylength;
91}
92
93/*---------------------------------------------------------------------------*/
94/** @brief HASH Set Last Word Valid Bits
95
96Specifies the number of valid bits in the last word.
97
98@param[in] validbits unsigned int8. Number of valid bits.
99*/
100
101void hash_set_last_word_valid_bits(uint8_t validbits)
102{
104 HASH_STR |= validbits;
105}
106
107/*---------------------------------------------------------------------------*/
108/** @brief HASH Init
109
110Initializes the HASH processor.
111
112*/
113
115{
117}
118
119/*---------------------------------------------------------------------------*/
120/** @brief HASH Add data
121
122Puts data into the HASH processor's queue.
123
124@param[in] data unsigned int32. Hash input data.
125*/
126
127void hash_add_data(uint32_t data)
128{
129 HASH_DIN = data;
130}
131
132/*---------------------------------------------------------------------------*/
133/** @brief HASH Digest
134
135Starts the processing of the last data block.
136
137*/
138
140{
142}
143
144/*---------------------------------------------------------------------------*/
145/** @brief HASH Get Hash Result
146
147Makes a copy of the resulting hash.
148
149@param[out] data unsigned int32. Hash 4\5 words long depending on the algorithm.
150*/
151
152void hash_get_result(uint32_t *data)
153{
154 data[0] = HASH_HR[0];
155 data[1] = HASH_HR[1];
156 data[2] = HASH_HR[2];
157 data[3] = HASH_HR[3];
158
160 data[4] = HASH_HR[4];
161 }
162}
163/**@}*/
164
#define HASH_ALGO_SHA1
#define HASH_STR_DCAL
#define HASH_DIN
#define HASH_CR_ALGO
#define HASH_STR_NBW
#define HASH_HR
#define HASH_STR
#define HASH_CR_INIT
#define HASH_CR
void hash_set_mode(uint8_t mode)
HASH Set Mode.
void hash_set_algorithm(uint8_t algorithm)
HASH Set Algorithm.
void hash_add_data(uint32_t data)
HASH Add data.
void hash_init()
HASH Init.
void hash_set_last_word_valid_bits(uint8_t validbits)
HASH Set Last Word Valid Bits.
void hash_digest()
HASH Digest.
void hash_get_result(uint32_t *data)
HASH Get Hash Result.
void hash_set_key_length(uint8_t keylength)
HASH Set Key Length.
void hash_set_data_type(uint8_t datatype)
HASH Set Data Type.