mbed TLS v2.7.0
sha256.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
8  * SPDX-License-Identifier: Apache-2.0
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * This file is part of Mbed TLS (https://tls.mbed.org)
23  */
24 #ifndef MBEDTLS_SHA256_H
25 #define MBEDTLS_SHA256_H
26 
27 #if !defined(MBEDTLS_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include MBEDTLS_CONFIG_FILE
31 #endif
32 
33 #include <stddef.h>
34 #include <stdint.h>
35 
36 #define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037
38 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
39  !defined(inline) && !defined(__cplusplus)
40 #define inline __inline
41 #endif
42 #if !defined(MBEDTLS_SHA256_ALT)
43 // Regular implementation
44 //
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
57 typedef struct
58 {
59  uint32_t total[2];
60  uint32_t state[8];
61  unsigned char buffer[64];
62  int is224;
65 }
67 
74 
81 
89  const mbedtls_sha256_context *src );
90 
103 
115  const unsigned char *input,
116  size_t ilen );
117 
128  unsigned char output[32] );
129 
141  const unsigned char data[64] );
142 
143 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
144 #if defined(MBEDTLS_DEPRECATED_WARNING)
145 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
146 #else
147 #define MBEDTLS_DEPRECATED
148 #endif
149 
161  int is224 )
162 {
163  mbedtls_sha256_starts_ret( ctx, is224 );
164 }
165 
178  const unsigned char *input,
179  size_t ilen )
180 {
181  mbedtls_sha256_update_ret( ctx, input, ilen );
182 }
183 
195  unsigned char output[32] )
196 {
197  mbedtls_sha256_finish_ret( ctx, output );
198 }
199 
212  const unsigned char data[64] )
213 {
214  mbedtls_internal_sha256_process( ctx, data );
215 }
216 
217 #undef MBEDTLS_DEPRECATED
218 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 #else /* MBEDTLS_SHA256_ALT */
224 #include "sha256_alt.h"
225 #endif /* MBEDTLS_SHA256_ALT */
226 
227 #ifdef __cplusplus
228 extern "C" {
229 #endif
230 
248 int mbedtls_sha256_ret( const unsigned char *input,
249  size_t ilen,
250  unsigned char output[32],
251  int is224 );
252 
253 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
254 #if defined(MBEDTLS_DEPRECATED_WARNING)
255 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
256 #else
257 #define MBEDTLS_DEPRECATED
258 #endif
259 
280  const unsigned char *input,
281  size_t ilen,
282  unsigned char output[32],
283  int is224 )
284 {
285  mbedtls_sha256_ret( input, ilen, output, is224 );
286 }
287 
288 #undef MBEDTLS_DEPRECATED
289 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
290 
296 int mbedtls_sha256_self_test( int verbose );
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif /* mbedtls_sha256.h */
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. This function is for internal use only.
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
This function initializes a SHA-256 context.
#define MBEDTLS_DEPRECATED
Definition: aes.h:361
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. ...
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
This function clears a SHA-256 context.
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
Configuration options (set of defines)
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...
static MBEDTLS_DEPRECATED void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-256 checksum calculation.
Definition: sha256.h:159
The SHA-256 context structure.
Definition: sha256.h:57
static MBEDTLS_DEPRECATED void mbedtls_sha256(const unsigned char *input, size_t ilen, unsigned char output[32], int is224)
This function calculates the SHA-224 or SHA-256 checksum of a buffer.
Definition: sha256.h:279
static MBEDTLS_DEPRECATED 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. This function is for internal use only.
Definition: sha256.h:210
int mbedtls_sha256_ret(const unsigned char *input, size_t ilen, unsigned char output[32], int is224)
This function calculates the SHA-224 or SHA-256 checksum of a buffer.
static MBEDTLS_DEPRECATED 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...
Definition: sha256.h:193
static MBEDTLS_DEPRECATED 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. ...
Definition: sha256.h:176
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_self_test(int verbose)
The SHA-224 and SHA-256 checkup routine.