Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
sha256_alt.c
00001 /* 00002 * sha256_alt.c 00003 * 00004 * Copyright (C) 2018, Arm Limited, All Rights Reserved 00005 * SPDX-License-Identifier: Apache-2.0 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00008 * not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00015 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 * 00019 */ 00020 00021 #include "mbedtls/sha256.h" 00022 #if defined(MBEDTLS_SHA256_ALT) 00023 #include <string.h> 00024 #include "mbedtls/platform.h" 00025 00026 void mbedtls_sha256_init( mbedtls_sha256_context *ctx ) 00027 { 00028 memset( ctx, 0, sizeof( mbedtls_sha256_context ) ); 00029 } 00030 00031 void mbedtls_sha256_free( mbedtls_sha256_context *ctx ) 00032 { 00033 if( ctx == NULL ) 00034 return; 00035 CRYS_HASH_Free( &ctx->crys_hash_ctx ); 00036 memset( ctx, 0, sizeof( mbedtls_sha256_context ) ); 00037 } 00038 00039 void mbedtls_sha256_clone( mbedtls_sha256_context *dst, 00040 const mbedtls_sha256_context *src ) 00041 { 00042 memcpy( dst, src, sizeof( mbedtls_sha256_context ) ); 00043 } 00044 00045 00046 int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ) 00047 { 00048 if(CRYS_HASH_Init( &ctx->crys_hash_ctx, is224 ? 00049 CRYS_HASH_SHA224_mode : CRYS_HASH_SHA256_mode ) != CRYS_OK ) 00050 return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); 00051 return ( 0 ); 00052 } 00053 00054 int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, 00055 const unsigned char data[64] ) 00056 { 00057 return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ); 00058 } 00059 00060 int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, 00061 const unsigned char *input, 00062 size_t ilen ) 00063 { 00064 if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK ) 00065 return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); 00066 return ( 0 ); 00067 } 00068 00069 int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, 00070 unsigned char output[32] ) 00071 { 00072 CRYSError_t crys_err = CRYS_OK; 00073 CRYS_HASH_Result_t crys_result = {0}; 00074 crys_err = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result ); 00075 if( crys_err == CRYS_OK ) 00076 { 00077 memcpy( output, crys_result, 32 ); 00078 return ( 0 ); 00079 } 00080 else 00081 return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); 00082 } 00083 #endif //MBEDTLS_SHA256_ALT 00084
Generated on Tue Jul 12 2022 13:54:50 by
1.7.2