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.
sha1_alt.c
00001 /* 00002 * sha1_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/sha1.h" 00022 #if defined(MBEDTLS_SHA1_ALT) 00023 #include <string.h> 00024 00025 void mbedtls_sha1_init( mbedtls_sha1_context *ctx ) 00026 { 00027 memset( ctx, 0, sizeof( mbedtls_sha1_context ) ); 00028 00029 } 00030 00031 void mbedtls_sha1_free( mbedtls_sha1_context *ctx ) 00032 { 00033 if( ctx == NULL ) 00034 return; 00035 00036 CRYS_HASH_Free( &ctx->crys_hash_ctx ); 00037 00038 memset( ctx, 0, sizeof( mbedtls_sha1_context ) ); 00039 } 00040 00041 void mbedtls_sha1_clone( mbedtls_sha1_context *dst, 00042 const mbedtls_sha1_context *src ) 00043 { 00044 memcpy( dst, src, sizeof( mbedtls_sha1_context ) ); 00045 } 00046 00047 int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx ) 00048 { 00049 if( CRYS_HASH_Init( &ctx->crys_hash_ctx, CRYS_HASH_SHA1_mode ) != CRYS_OK ) 00050 return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED ); 00051 return ( 0 ); 00052 } 00053 00054 00055 int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, 00056 const unsigned char *input, 00057 size_t ilen ) 00058 { 00059 if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK ) 00060 return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED ); 00061 return ( 0 ); 00062 } 00063 00064 int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, 00065 unsigned char output[20] ) 00066 { 00067 CRYSError_t CrysErr = CRYS_OK; 00068 CRYS_HASH_Result_t crys_result = {0}; 00069 CrysErr = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result ); 00070 if( CrysErr == CRYS_OK ) 00071 { 00072 memcpy( output, crys_result, 20 ); 00073 return ( 0 ); 00074 } 00075 else 00076 return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED ); 00077 } 00078 00079 int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, 00080 const unsigned char data[64] ) 00081 { 00082 if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)data, 64 ) != CRYS_OK ) 00083 return ( MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED ); 00084 return ( 0 ); 00085 } 00086 #endif //MBEDTLS_SHA1_ALT
Generated on Tue Jul 12 2022 12:45:45 by
