mbed TLS v2.16.7
sha256.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
11  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
12  *
13  * This file is provided under the Apache License 2.0, or the
14  * GNU General Public License v2.0 or later.
15  *
16  * **********
17  * Apache License 2.0:
18  *
19  * Licensed under the Apache License, Version 2.0 (the "License"); you may
20  * not use this file except in compliance with the License.
21  * You may obtain a copy of the License at
22  *
23  * http://www.apache.org/licenses/LICENSE-2.0
24  *
25  * Unless required by applicable law or agreed to in writing, software
26  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
27  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28  * See the License for the specific language governing permissions and
29  * limitations under the License.
30  *
31  * **********
32  *
33  * **********
34  * GNU General Public License v2.0 or later:
35  *
36  * This program is free software; you can redistribute it and/or modify
37  * it under the terms of the GNU General Public License as published by
38  * the Free Software Foundation; either version 2 of the License, or
39  * (at your option) any later version.
40  *
41  * This program is distributed in the hope that it will be useful,
42  * but WITHOUT ANY WARRANTY; without even the implied warranty of
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44  * GNU General Public License for more details.
45  *
46  * You should have received a copy of the GNU General Public License along
47  * with this program; if not, write to the Free Software Foundation, Inc.,
48  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
49  *
50  * **********
51  *
52  * This file is part of Mbed TLS (https://tls.mbed.org)
53  */
54 #ifndef MBEDTLS_SHA256_H
55 #define MBEDTLS_SHA256_H
56 
57 #if !defined(MBEDTLS_CONFIG_FILE)
58 #include "config.h"
59 #else
60 #include MBEDTLS_CONFIG_FILE
61 #endif
62 
63 #include <stddef.h>
64 #include <stdint.h>
65 
66 /* MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED is deprecated and should not be used. */
67 #define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037
68 #define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 #if !defined(MBEDTLS_SHA256_ALT)
75 // Regular implementation
76 //
77 
85 typedef struct mbedtls_sha256_context
86 {
87  uint32_t total[2];
88  uint32_t state[8];
89  unsigned char buffer[64];
90  int is224;
92 }
94 
95 #else /* MBEDTLS_SHA256_ALT */
96 #include "sha256_alt.h"
97 #endif /* MBEDTLS_SHA256_ALT */
98 
105 
114 
122  const mbedtls_sha256_context *src );
123 
136 
151  const unsigned char *input,
152  size_t ilen );
153 
167  unsigned char output[32] );
168 
182  const unsigned char data[64] );
183 
184 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
185 #if defined(MBEDTLS_DEPRECATED_WARNING)
186 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
187 #else
188 #define MBEDTLS_DEPRECATED
189 #endif
190 
201  int is224 );
202 
216  const unsigned char *input,
217  size_t ilen );
218 
231  unsigned char output[32] );
232 
245  const unsigned char data[64] );
246 
247 #undef MBEDTLS_DEPRECATED
248 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
249 
268 int mbedtls_sha256_ret( const unsigned char *input,
269  size_t ilen,
270  unsigned char output[32],
271  int is224 );
272 
273 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
274 #if defined(MBEDTLS_DEPRECATED_WARNING)
275 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
276 #else
277 #define MBEDTLS_DEPRECATED
278 #endif
279 
300 MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
301  size_t ilen,
302  unsigned char output[32],
303  int is224 );
304 
305 #undef MBEDTLS_DEPRECATED
306 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
307 
308 #if defined(MBEDTLS_SELF_TEST)
309 
316 int mbedtls_sha256_self_test( int verbose );
317 
318 #endif /* MBEDTLS_SELF_TEST */
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 
324 #endif /* mbedtls_sha256.h */
mbedtls_sha256_free
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
This function clears a SHA-256 context.
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: sha256.h:277
mbedtls_sha256_process
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....
mbedtls_sha256_context::state
uint32_t state[8]
Definition: sha256.h:88
mbedtls_sha256_context::is224
int is224
Definition: sha256.h:90
mbedtls_internal_sha256_process
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....
mbedtls_sha256_context
struct mbedtls_sha256_context mbedtls_sha256_context
The SHA-256 context structure.
mbedtls_sha256_context::buffer
unsigned char buffer[64]
Definition: sha256.h:89
mbedtls_sha256_update_ret
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.
mbedtls_sha256_finish
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.
mbedtls_sha256_self_test
int mbedtls_sha256_self_test(int verbose)
The SHA-224 and SHA-256 checkup routine.
mbedtls_sha256_starts
MBEDTLS_DEPRECATED void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
mbedtls_sha256_clone
void mbedtls_sha256_clone(mbedtls_sha256_context *dst, const mbedtls_sha256_context *src)
This function clones the state of a SHA-256 context.
mbedtls_sha256_context
The SHA-256 context structure.
Definition: sha256.h:86
mbedtls_sha256_update
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.
config.h
Configuration options (set of defines)
mbedtls_sha256_init
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
This function initializes a SHA-256 context.
mbedtls_sha256_context::total
uint32_t total[2]
Definition: sha256.h:87
mbedtls_sha256_ret
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.
mbedtls_sha256
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.
mbedtls_sha256_starts_ret
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
mbedtls_sha256_finish_ret
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.