f8041adf08232a9f3432b31e51896eefe37772cc
4 * \brief SHA-224 and SHA-256 cryptographic hash function
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: Apache-2.0
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * This file is part of mbed TLS (https://tls.mbed.org)
23 #ifndef MBEDTLS_SHA256_H
24 #define MBEDTLS_SHA256_H
26 #if !defined(MBEDTLS_CONFIG_FILE)
29 #include MBEDTLS_CONFIG_FILE
35 #if !defined(MBEDTLS_SHA256_ALT)
36 // Regular implementation
44 * \brief SHA-256 context structure
48 uint32_t total
[2]; /*!< number of bytes processed */
49 uint32_t state
[8]; /*!< intermediate digest state */
50 unsigned char buffer
[64]; /*!< data block being processed */
51 int is224
; /*!< 0 => SHA-256, else SHA-224 */
53 mbedtls_sha256_context
;
56 * \brief Initialize SHA-256 context
58 * \param ctx SHA-256 context to be initialized
60 void mbedtls_sha256_init( mbedtls_sha256_context
*ctx
);
63 * \brief Clear SHA-256 context
65 * \param ctx SHA-256 context to be cleared
67 void mbedtls_sha256_free( mbedtls_sha256_context
*ctx
);
70 * \brief Clone (the state of) a SHA-256 context
72 * \param dst The destination context
73 * \param src The context to be cloned
75 void mbedtls_sha256_clone( mbedtls_sha256_context
*dst
,
76 const mbedtls_sha256_context
*src
);
79 * \brief SHA-256 context setup
81 * \param ctx context to be initialized
82 * \param is224 0 = use SHA256, 1 = use SHA224
84 void mbedtls_sha256_starts( mbedtls_sha256_context
*ctx
, int is224
);
87 * \brief SHA-256 process buffer
89 * \param ctx SHA-256 context
90 * \param input buffer holding the data
91 * \param ilen length of the input data
93 void mbedtls_sha256_update( mbedtls_sha256_context
*ctx
, const unsigned char *input
,
97 * \brief SHA-256 final digest
99 * \param ctx SHA-256 context
100 * \param output SHA-224/256 checksum result
102 void mbedtls_sha256_finish( mbedtls_sha256_context
*ctx
, unsigned char output
[32] );
105 void mbedtls_sha256_process( mbedtls_sha256_context
*ctx
, const unsigned char data
[64] );
111 #else /* MBEDTLS_SHA256_ALT */
112 #include "sha256_alt.h"
113 #endif /* MBEDTLS_SHA256_ALT */
120 * \brief Output = SHA-256( input buffer )
122 * \param input buffer holding the data
123 * \param ilen length of the input data
124 * \param output SHA-224/256 checksum result
125 * \param is224 0 = use SHA256, 1 = use SHA224
127 void mbedtls_sha256( const unsigned char *input
, size_t ilen
,
128 unsigned char output
[32], int is224
);
131 * \brief Checkup routine
133 * \return 0 if successful, or 1 if the test failed
135 int mbedtls_sha256_self_test( int verbose
);
141 #endif /* mbedtls_sha256.h */