Mbed OS Reference
Loading...
Searching...
No Matches
TARGET_Silicon_Labs/sha256_alt.h
Go to the documentation of this file.
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 * \brief CRYPTO hardware accelerated SHA-224 and SHA-256 cryptographic hash function.
26 * \{
27 ******************************************************************************/
28
29#if defined(MBEDTLS_SHA256_ALT)
30
31/* SiliconLabs CRYPTO hardware acceleration implementation */
32
33#include <stddef.h>
34#include <stdint.h>
35#include <stdbool.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/**
42 * \brief SHA-256 context structure
43 */
44typedef struct
45{
46 uint32_t state[8]; /*!< intermediate digest state */
47 uint32_t total[2]; /*!< number of bytes processed */
48 unsigned char buffer[64]; /*!< data block being processed */
49 bool is224; /*!< false => SHA-256, else SHA-224 */
50}
52
53/**
54 * \brief Initialize SHA-256 context
55 *
56 * \param ctx SHA-256 context to be initialized
57 */
59
60/**
61 * \brief Clear SHA-256 context
62 *
63 * \param ctx SHA-256 context to be cleared
64 */
66
67/**
68 * \brief Clone (the state of) a SHA-256 context
69 *
70 * \param dst The destination context
71 * \param src The context to be cloned
72 */
74 const mbedtls_sha256_context *src );
75
76/**
77 * \brief SHA-256 context setup
78 *
79 * \param ctx context to be initialized
80 * \param is224 0 = use SHA256, 1 = use SHA224
81 *
82 * \returns error code
83 */
85
86/**
87 * \brief SHA-256 process buffer
88 *
89 * \param ctx SHA-256 context
90 * \param input buffer holding the data
91 * \param ilen length of the input data
92 *
93 * \returns error code
94 */
95int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
96 size_t ilen );
97
98/**
99 * \brief SHA-256 final digest
100 *
101 * \param ctx SHA-256 context
102 * \param output SHA-224/256 checksum result
103 *
104 * \returns error code
105 */
106int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
107
108/* Internal use */
109int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );
110
111#if !defined(MBEDTLS_DEPRECATED_REMOVED)
112#if defined(MBEDTLS_DEPRECATED_WARNING)
113#define MBEDTLS_DEPRECATED __attribute__((deprecated))
114#else
115#define MBEDTLS_DEPRECATED
116#endif
117/**
118 * \brief This function starts a SHA-256 checksum calculation.
119 *
120 * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
121 *
122 * \param ctx The SHA-256 context to initialize.
123 * \param is224 Determines which function to use.
124 * <ul><li>0: Use SHA-256.</li>
125 * <li>1: Use SHA-224.</li></ul>
126 */
127MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
128 int is224 );
129
130/**
131 * \brief This function feeds an input buffer into an ongoing
132 * SHA-256 checksum calculation.
133 *
134 * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
135 *
136 * \param ctx The SHA-256 context to initialize.
137 * \param input The buffer holding the data.
138 * \param ilen The length of the input data.
139 */
140MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
141 const unsigned char *input,
142 size_t ilen );
143
144/**
145 * \brief This function finishes the SHA-256 operation, and writes
146 * the result to the output buffer.
147 *
148 * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
149 *
150 * \param ctx The SHA-256 context.
151 * \param output The SHA-224or SHA-256 checksum result.
152 */
153MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
154 unsigned char output[32] );
155
156/**
157 * \brief This function processes a single data block within
158 * the ongoing SHA-256 computation. This function is for
159 * internal use only.
160 *
161 * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0.
162 *
163 * \param ctx The SHA-256 context.
164 * \param data The buffer holding one block of data.
165 */
166MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
167 const unsigned char data[64] );
168
169#undef MBEDTLS_DEPRECATED
170#endif /* !MBEDTLS_DEPRECATED_REMOVED */
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* #if defined(MBEDTLS_SHA256_ALT) */
177
178/** \} */
179
180#endif /* #ifndef MBEDTLS_SHA256_ALT_H */
void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])
This function processes a single data block within the ongoing SHA-256 computation.
void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
This function finishes the SHA-256 operation, and writes the result to the output buffer.
void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-256 checksum calculation.
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
This function clears a SHA-256 context.
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
This function initializes a SHA-256 context.
int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])
This function processes a single data block within the ongoing SHA-256 computation.
void mbedtls_sha256_clone(mbedtls_sha256_context *dst, const mbedtls_sha256_context *src)
This function clones the state of a SHA-256 context.
int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32])
This function finishes the SHA-256 operation, and writes the result to the output buffer.
void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-256 checksum calculation.
The SHA-256 context structure.
Definition: sha256.h:65