libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
hash_common_f24.h
Go to the documentation of this file.
1/** @addtogroup hash_defines
2 *
3 * @author @htmlonly © @endhtmlonly 2013
4 * Mikhail Avkhimenia <mikhail@avkhimenia.net>
5 *
6 */
7/*
8 * This file is part of the libopencm3 project.
9 *
10 * Copyright (C) 2013 Mikhail Avkhimenia <mikhail@avkhimenia.net>
11 *
12 * This library is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26/**@{*/
27
28/** @cond */
29#ifdef LIBOPENCM3_HASH_H
30/** @endcond */
31#ifndef LIBOPENCM3_HASH_COMMON_F24_H
32#define LIBOPENCM3_HASH_COMMON_F24_H
33
34/* --- Convenience macros -------------------------------------------------- */
35
36/****************************************************************************/
37/** @defgroup hash_reg_base HASH register base addresses
38@ingroup STM32F_hash_defines
39
40@{*/
41#define HASH_BASE (PERIPH_BASE_AHB2 + 0x60400)
42#define HASH HASH_BASE
43/**@}*/
44
45/* --- HASH registers ------------------------------------------------------ */
46
47/* HASH control register (HASH_CR) */
48#define HASH_CR MMIO32(HASH + 0x00)
49
50/* HASH data input register (HASH_DIR) */
51#define HASH_DIN MMIO32(HASH + 0x04)
52
53/* HASH start register (HASH_STR) */
54#define HASH_STR MMIO32(HASH + 0x08)
55
56/* HASH digest registers (HASH_HR[5]) */
57#define HASH_HR (&MMIO32(HASH + 0x0C)) /* x5 */
58
59/* HASH interrupt enable register (HASH_IMR) */
60#define HASH_IMR MMIO32(HASH + 0x20)
61
62/* HASH status register (HASH_SR) */
63#define HASH_SR MMIO32(HASH + 0x28)
64
65/* HASH context swap registers (HASH_CSR[51]) */
66#define HASH_CSR (&MMIO32(HASH + 0xF8)) /* x51 */
67
68/* --- HASH_CR values ------------------------------------------------------ */
69
70/* INIT: Initialize message digest calculation */
71#define HASH_CR_INIT (1 << 2)
72
73/* DMAE: DMA enable */
74#define HASH_CR_DMAE (1 << 3)
75
76/* DATATYPE: Data type selection */
77/****************************************************************************/
78/** @defgroup hash_data_type HASH Data Type
79@ingroup hash_defines
80
81@{*/
82#define HASH_DATA_32BIT (0 << 4)
83#define HASH_DATA_16BIT (1 << 4)
84#define HASH_DATA_8BIT (2 << 4)
85#define HASH_DATA_BITSTRING (3 << 4)
86/**@}*/
87#define HASH_CR_DATATYPE (3 << 4)
88
89/* MODE: Mode selection */
90/****************************************************************************/
91/** @defgroup hash_mode HASH Mode
92@ingroup hash_defines
93
94@{*/
95#define HASH_MODE_HASH (0 << 6)
96#define HASH_MODE_HMAC (1 << 6)
97/**@}*/
98#define HASH_CR_MODE (1 << 6)
99
100/* ALGO: Algorithm selection */
101/****************************************************************************/
102/** @defgroup hash_algorithm HASH Algorithm
103@ingroup hash_defines
104
105@{*/
106#define HASH_ALGO_SHA1 (0 << 7)
107#define HASH_ALGO_MD5 (1 << 7)
108/**@}*/
109#define HASH_CR_ALGO (1 << 7)
110
111/* NBW: Number of words already pushed */
112#define HASH_CR_NBW (15 << 8)
113
114/* DINNE: DIN(Data input register) not empty */
115#define HASH_CR_DINNE (1 << 12)
116
117/* LKEY: Long key selection */
118/****************************************************************************/
119/** @defgroup hash_key_length HASH Key length
120@ingroup hash_defines
121
122@{*/
123#define HASH_KEY_SHORT (0 << 16)
124#define HASH_KEY_LONG (1 << 16)
125/**@}*/
126#define HASH_CR_LKEY (1 << 16)
127
128/* --- HASH_STR values ----------------------------------------------------- */
129
130/* NBLW: Number of valid bits in the last word of the message in the bit string
131 */
132#define HASH_STR_NBW (31 << 0)
133
134/* DCAL: Digest calculation */
135#define HASH_STR_DCAL (1 << 8)
136
137/* --- HASH_IMR values ----------------------------------------------------- */
138
139/* DINIE: Data input interrupt enable */
140#define HASH_IMR_DINIE (1 << 0)
141
142/* DCIE: Digest calculation completion interrupt enable */
143#define HASH_IMR_DCIE (1 << 1)
144
145/* --- HASH_SR values ------------------------------------------------------ */
146
147/* DINIS: Data input interrupt status */
148#define HASH_SR_DINIS (1 << 0)
149
150/* DCIS: Digest calculation completion interrupt status */
151#define HASH_SR_DCIS (1 << 1)
152
153/* DMAS: DMA Status */
154#define HASH_SR_DMAS (1 << 2)
155
156/* BUSY: Busy bit */
157#define HASH_SR_BUSY (1 << 3)
158
159/* --- HASH function prototypes -------------------------------------------- */
160
162
163void hash_set_mode(uint8_t mode);
164void hash_set_algorithm(uint8_t algorithm);
165void hash_set_data_type(uint8_t datatype);
166void hash_set_key_length(uint8_t keylength);
167void hash_set_last_word_valid_bits(uint8_t validbits);
168void hash_init(void);
169void hash_add_data(uint32_t data);
170void hash_digest(void);
171void hash_get_result(uint32_t *data);
172
174/**@}*/
175#endif
176/** @cond */
177#else
178#warning "hash_common_f24.h should not be included explicitly, only via hash.h"
179#endif
180/** @endcond */
181
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
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_set_last_word_valid_bits(uint8_t validbits)
HASH Set Last Word Valid Bits.
void hash_init(void)
HASH Init.
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.
void hash_digest(void)
HASH Digest.