mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 17 23:23:45 2019 +0000
Revision:
0:5b88d5760320
mbed-os5 only for TYBLE16

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:5b88d5760320 1 /*
kenjiArai 0:5b88d5760320 2 * sha1_alt.c
kenjiArai 0:5b88d5760320 3 *
kenjiArai 0:5b88d5760320 4 * Copyright (C) 2018, Arm Limited, All Rights Reserved
kenjiArai 0:5b88d5760320 5 * SPDX-License-Identifier: Apache-2.0
kenjiArai 0:5b88d5760320 6 *
kenjiArai 0:5b88d5760320 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
kenjiArai 0:5b88d5760320 8 * not use this file except in compliance with the License.
kenjiArai 0:5b88d5760320 9 * You may obtain a copy of the License at
kenjiArai 0:5b88d5760320 10 *
kenjiArai 0:5b88d5760320 11 * http://www.apache.org/licenses/LICENSE-2.0
kenjiArai 0:5b88d5760320 12 *
kenjiArai 0:5b88d5760320 13 * Unless required by applicable law or agreed to in writing, software
kenjiArai 0:5b88d5760320 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
kenjiArai 0:5b88d5760320 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kenjiArai 0:5b88d5760320 16 * See the License for the specific language governing permissions and
kenjiArai 0:5b88d5760320 17 * limitations under the License.
kenjiArai 0:5b88d5760320 18 *
kenjiArai 0:5b88d5760320 19 */
kenjiArai 0:5b88d5760320 20
kenjiArai 0:5b88d5760320 21 #include "mbedtls/sha1.h"
kenjiArai 0:5b88d5760320 22 #if defined(MBEDTLS_SHA1_ALT)
kenjiArai 0:5b88d5760320 23 #include <string.h>
kenjiArai 0:5b88d5760320 24 #include "mbedtls/platform.h"
kenjiArai 0:5b88d5760320 25
kenjiArai 0:5b88d5760320 26 void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
kenjiArai 0:5b88d5760320 27 {
kenjiArai 0:5b88d5760320 28 memset( ctx, 0, sizeof( mbedtls_sha1_context ) );
kenjiArai 0:5b88d5760320 29 }
kenjiArai 0:5b88d5760320 30
kenjiArai 0:5b88d5760320 31 void mbedtls_sha1_free( mbedtls_sha1_context *ctx )
kenjiArai 0:5b88d5760320 32 {
kenjiArai 0:5b88d5760320 33 if( ctx == NULL )
kenjiArai 0:5b88d5760320 34 return;
kenjiArai 0:5b88d5760320 35
kenjiArai 0:5b88d5760320 36 CRYS_HASH_Free( &ctx->crys_hash_ctx );
kenjiArai 0:5b88d5760320 37
kenjiArai 0:5b88d5760320 38 memset( ctx, 0, sizeof( mbedtls_sha1_context ) );
kenjiArai 0:5b88d5760320 39 }
kenjiArai 0:5b88d5760320 40
kenjiArai 0:5b88d5760320 41 void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
kenjiArai 0:5b88d5760320 42 const mbedtls_sha1_context *src )
kenjiArai 0:5b88d5760320 43 {
kenjiArai 0:5b88d5760320 44 memcpy( dst, src, sizeof( mbedtls_sha1_context ) );
kenjiArai 0:5b88d5760320 45 }
kenjiArai 0:5b88d5760320 46
kenjiArai 0:5b88d5760320 47 int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
kenjiArai 0:5b88d5760320 48 {
kenjiArai 0:5b88d5760320 49 if( CRYS_HASH_Init( &ctx->crys_hash_ctx, CRYS_HASH_SHA1_mode ) != CRYS_OK )
kenjiArai 0:5b88d5760320 50 return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
kenjiArai 0:5b88d5760320 51 return ( 0 );
kenjiArai 0:5b88d5760320 52 }
kenjiArai 0:5b88d5760320 53
kenjiArai 0:5b88d5760320 54
kenjiArai 0:5b88d5760320 55 int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
kenjiArai 0:5b88d5760320 56 const unsigned char *input,
kenjiArai 0:5b88d5760320 57 size_t ilen )
kenjiArai 0:5b88d5760320 58 {
kenjiArai 0:5b88d5760320 59 if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK )
kenjiArai 0:5b88d5760320 60 return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
kenjiArai 0:5b88d5760320 61 return ( 0 );
kenjiArai 0:5b88d5760320 62 }
kenjiArai 0:5b88d5760320 63
kenjiArai 0:5b88d5760320 64 int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
kenjiArai 0:5b88d5760320 65 unsigned char output[20] )
kenjiArai 0:5b88d5760320 66 {
kenjiArai 0:5b88d5760320 67 CRYSError_t crys_err = CRYS_OK;
kenjiArai 0:5b88d5760320 68 CRYS_HASH_Result_t crys_result = {0};
kenjiArai 0:5b88d5760320 69 crys_err = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result );
kenjiArai 0:5b88d5760320 70 if( crys_err == CRYS_OK )
kenjiArai 0:5b88d5760320 71 {
kenjiArai 0:5b88d5760320 72 memcpy( output, crys_result, 20 );
kenjiArai 0:5b88d5760320 73 return ( 0 );
kenjiArai 0:5b88d5760320 74 }
kenjiArai 0:5b88d5760320 75 else
kenjiArai 0:5b88d5760320 76 return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
kenjiArai 0:5b88d5760320 77 }
kenjiArai 0:5b88d5760320 78
kenjiArai 0:5b88d5760320 79 int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
kenjiArai 0:5b88d5760320 80 const unsigned char data[64] )
kenjiArai 0:5b88d5760320 81 {
kenjiArai 0:5b88d5760320 82 return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
kenjiArai 0:5b88d5760320 83 }
kenjiArai 0:5b88d5760320 84 #endif //MBEDTLS_SHA1_ALT