1 /**
2  * \file sha1.h
3  *
4  * \brief This file contains SHA-1 definitions and functions.
5  *
6  * The Secure Hash Algorithm 1 (SHA-1) cryptographic hash function is defined in
7  * <em>FIPS 180-4: Secure Hash Standard (SHS)</em>.
8  *
9  * \warning   SHA-1 is considered a weak message digest and its use constitutes
10  *            a security risk. We recommend considering stronger message
11  *            digests instead.
12  */
13 /*
14  *  Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
15  *  Copyright (C) 2019, STMicroelectronics, All Rights Reserved
16  *  SPDX-License-Identifier: Apache-2.0
17  *
18  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
19  *  not use this file except in compliance with the License.
20  *  You may obtain a copy of the License at
21  *
22  *  http://www.apache.org/licenses/LICENSE-2.0
23  *
24  *  Unless required by applicable law or agreed to in writing, software
25  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  *  See the License for the specific language governing permissions and
28  *  limitations under the License.
29  *
30  *  This file implements STMicroelectronics SHA1 API with HW services based
31  *  on mbed TLS API
32  */
33 
34 #ifndef MBEDTLS_SHA1_ALT_H
35 #define MBEDTLS_SHA1_ALT_H
36 
37 #if defined (MBEDTLS_SHA1_ALT)
38 #include "stm32hal.h"
39 
40 #define ST_SHA1_BLOCK_SIZE  ((size_t)  64)          /*!< HW handles 512 bits, ie 64 bytes */
41 #define ST_SHA1_EXTRA_BYTES ((size_t)  4)         /*!< One supplementary word on first block */
42 #define ST_SHA1_NB_HASH_REG ((uint32_t)57)          /*!< Number of HASH HW context Registers:
43                                                          CR + STR + IMR + CSR[54] */
44 
45 /**
46  * \brief          SHA-1 context structure
47  */
48 typedef struct mbedtls_sha1_context
49 {
50     HASH_HandleTypeDef hhash;                       /*!< Handle of HASH HAL */
51     uint8_t sbuf[ST_SHA1_BLOCK_SIZE + ST_SHA1_EXTRA_BYTES];
52                                                     /*!< Buffer to store input data
53                                                         (first block with its extra bytes,
54                                                          intermediate blocks,
55                                                          or last input block) */
56     uint8_t sbuf_len;                               /*!< Number of bytes stored in sbuf */
57     uint8_t ctx_save_regs[ST_SHA1_NB_HASH_REG*4];
58     uint8_t first;                                  /*!< Extra-bytes on first computed block */
59 }
60 mbedtls_sha1_context;
61 
62 
63 #endif /* MBEDTLS_SHA1_ALT */
64 
65 #endif /* MBEDTLS_SHA1_ALT_H */