1 /** 2 * \file sha256.h 3 * 4 * \brief SHA-224 and SHA-256 cryptographic hash function 5 * 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 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 * This file is part of mbed TLS (https://tls.mbed.org) 22 */ 23 #ifndef MBEDTLS_SHA256_ALT_H 24 #define MBEDTLS_SHA256_ALT_H 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #include "sec_crypto_sha.h" 31 32 33 /** 34 * \brief SHA-256 context structure 35 */ 36 37 typedef struct 38 { 39 #if defined(CONFIG_TEE_SHA256) 40 uint8_t ctx[224+8]; 41 #endif 42 sc_sha_t sc_sha; 43 sc_sha_context_t sc_ctx; 44 } 45 mbedtls_sha256_context; 46 47 /** 48 * \brief Initialize SHA-256 context 49 * 50 * \param ctx SHA-256 context to be initialized 51 */ 52 void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); 53 54 /** 55 * \brief Clear SHA-256 context 56 * 57 * \param ctx SHA-256 context to be cleared 58 */ 59 void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); 60 61 /** 62 * \brief Clone (the state of) a SHA-256 context 63 * 64 * \param dst The destination context 65 * \param src The context to be cloned 66 */ 67 void mbedtls_sha256_clone( mbedtls_sha256_context *dst, 68 const mbedtls_sha256_context *src ); 69 70 /** 71 * \brief SHA-256 context setup 72 * 73 * \param ctx context to be initialized 74 * \param is224 0 = use SHA256, 1 = use SHA224 75 */ 76 int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ); 77 78 /** 79 * \brief SHA-256 process buffer 80 * 81 * \param ctx SHA-256 context 82 * \param input buffer holding the data 83 * \param ilen length of the input data 84 */ 85 int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input, 86 size_t ilen ); 87 88 /** 89 * \brief SHA-256 final digest 90 * 91 * \param ctx SHA-256 context 92 * \param output SHA-224/256 checksum result 93 */ 94 int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] ); 95 96 /* Internal use */ 97 void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] ); 98 99 int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, 100 const unsigned char data[64] ); 101 102 #ifdef __cplusplus 103 } 104 #endif 105 106 #endif /* mbedtls_sha256.h */ 107