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