Mistake on this page?
Report an issue in GitHub or email us
TARGET_Silicon_Labs/sha256_alt.h
1 /**
2  * \file sha256_alt.h
3  *
4  * \brief SHA-224 and SHA-256 cryptographic hash function
5  *
6  * Copyright (C) 2015-2016, Silicon Labs, http://www.silabs.com
7  * SPDX-License-Identifier: Apache-2.0
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License"); you may
10  * not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 #ifndef MBEDTLS_SHA256_ALT_H
22 #define MBEDTLS_SHA256_ALT_H
23 
24 /***************************************************************************//**
25  * \addtogroup sl_crypto
26  * \{
27  ******************************************************************************/
28 
29 /***************************************************************************//**
30  * \addtogroup sl_crypto_sha256 SHA-224 and SHA-256 cryptographic hash function
31  * \brief CRYPTO hardware accelerated SHA-224 and SHA-256 cryptographic hash function.
32  * \{
33  ******************************************************************************/
34 
35 #if defined(MBEDTLS_SHA256_ALT)
36 
37 /* SiliconLabs CRYPTO hardware acceleration implementation */
38 
39 #include <stddef.h>
40 #include <stdint.h>
41 #include <stdbool.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /**
48  * \brief SHA-256 context structure
49  */
50 typedef struct
51 {
52  uint32_t state[8]; /*!< intermediate digest state */
53  uint32_t total[2]; /*!< number of bytes processed */
54  unsigned char buffer[64]; /*!< data block being processed */
55  bool is224; /*!< false => SHA-256, else SHA-224 */
56 }
57 mbedtls_sha256_context;
58 
59 /**
60  * \brief Initialize SHA-256 context
61  *
62  * \param ctx SHA-256 context to be initialized
63  */
64 void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
65 
66 /**
67  * \brief Clear SHA-256 context
68  *
69  * \param ctx SHA-256 context to be cleared
70  */
71 void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
72 
73 /**
74  * \brief Clone (the state of) a SHA-256 context
75  *
76  * \param dst The destination context
77  * \param src The context to be cloned
78  */
79 void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
80  const mbedtls_sha256_context *src );
81 
82 /**
83  * \brief SHA-256 context setup
84  *
85  * \param ctx context to be initialized
86  * \param is224 0 = use SHA256, 1 = use SHA224
87  *
88  * \returns error code
89  */
90 int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
91 
92 /**
93  * \brief SHA-256 process buffer
94  *
95  * \param ctx SHA-256 context
96  * \param input buffer holding the data
97  * \param ilen length of the input data
98  *
99  * \returns error code
100  */
101 int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
102  size_t ilen );
103 
104 /**
105  * \brief SHA-256 final digest
106  *
107  * \param ctx SHA-256 context
108  * \param output SHA-224/256 checksum result
109  *
110  * \returns error code
111  */
112 int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
113 
114 /* Internal use */
115 int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );
116 
117 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
118 #if defined(MBEDTLS_DEPRECATED_WARNING)
119 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
120 #else
121 #define MBEDTLS_DEPRECATED
122 #endif
123 /**
124  * \brief This function starts a SHA-256 checksum calculation.
125  *
126  * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
127  *
128  * \param ctx The SHA-256 context to initialize.
129  * \param is224 Determines which function to use.
130  * <ul><li>0: Use SHA-256.</li>
131  * <li>1: Use SHA-224.</li></ul>
132  */
133 MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
134  int is224 );
135 
136 /**
137  * \brief This function feeds an input buffer into an ongoing
138  * SHA-256 checksum calculation.
139  *
140  * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
141  *
142  * \param ctx The SHA-256 context to initialize.
143  * \param input The buffer holding the data.
144  * \param ilen The length of the input data.
145  */
146 MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
147  const unsigned char *input,
148  size_t ilen );
149 
150 /**
151  * \brief This function finishes the SHA-256 operation, and writes
152  * the result to the output buffer.
153  *
154  * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
155  *
156  * \param ctx The SHA-256 context.
157  * \param output The SHA-224or SHA-256 checksum result.
158  */
159 MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
160  unsigned char output[32] );
161 
162 /**
163  * \brief This function processes a single data block within
164  * the ongoing SHA-256 computation. This function is for
165  * internal use only.
166  *
167  * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0.
168  *
169  * \param ctx The SHA-256 context.
170  * \param data The buffer holding one block of data.
171  */
172 MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
173  const unsigned char data[64] );
174 
175 #undef MBEDTLS_DEPRECATED
176 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif /* #if defined(MBEDTLS_SHA256_ALT) */
183 
184 /** \} (end addtogroup sl_crypto_sha256) */
185 /** \} (end addtogroup sl_crypto) */
186 
187 #endif /* #ifndef MBEDTLS_SHA256_ALT_H */
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.