mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
features/cryptocell/FEATURE_CRYPTOCELL310/sha512_alt.c@1:9db0e321a9f4, 2019-12-31 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 31 06:02:27 2019 +0000
- Revision:
- 1:9db0e321a9f4
updated based on mbed-os5.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 1:9db0e321a9f4 | 1 | /* |
kenjiArai | 1:9db0e321a9f4 | 2 | * sha512_alt.c |
kenjiArai | 1:9db0e321a9f4 | 3 | * |
kenjiArai | 1:9db0e321a9f4 | 4 | * Copyright (C) 2019, Arm Limited, All Rights Reserved |
kenjiArai | 1:9db0e321a9f4 | 5 | * SPDX-License-Identifier: Apache-2.0 |
kenjiArai | 1:9db0e321a9f4 | 6 | * |
kenjiArai | 1:9db0e321a9f4 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
kenjiArai | 1:9db0e321a9f4 | 8 | * not use this file except in compliance with the License. |
kenjiArai | 1:9db0e321a9f4 | 9 | * You may obtain a copy of the License at |
kenjiArai | 1:9db0e321a9f4 | 10 | * |
kenjiArai | 1:9db0e321a9f4 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 1:9db0e321a9f4 | 12 | * |
kenjiArai | 1:9db0e321a9f4 | 13 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 1:9db0e321a9f4 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
kenjiArai | 1:9db0e321a9f4 | 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 1:9db0e321a9f4 | 16 | * See the License for the specific language governing permissions and |
kenjiArai | 1:9db0e321a9f4 | 17 | * limitations under the License. |
kenjiArai | 1:9db0e321a9f4 | 18 | * |
kenjiArai | 1:9db0e321a9f4 | 19 | */ |
kenjiArai | 1:9db0e321a9f4 | 20 | |
kenjiArai | 1:9db0e321a9f4 | 21 | #include "mbedtls/sha512.h" |
kenjiArai | 1:9db0e321a9f4 | 22 | #if defined(MBEDTLS_SHA512_ALT) |
kenjiArai | 1:9db0e321a9f4 | 23 | #include <string.h> |
kenjiArai | 1:9db0e321a9f4 | 24 | #include "mbedtls/platform.h" |
kenjiArai | 1:9db0e321a9f4 | 25 | |
kenjiArai | 1:9db0e321a9f4 | 26 | void mbedtls_sha512_init( mbedtls_sha512_context *ctx ) |
kenjiArai | 1:9db0e321a9f4 | 27 | { |
kenjiArai | 1:9db0e321a9f4 | 28 | memset( ctx, 0, sizeof( mbedtls_sha512_context ) ); |
kenjiArai | 1:9db0e321a9f4 | 29 | } |
kenjiArai | 1:9db0e321a9f4 | 30 | |
kenjiArai | 1:9db0e321a9f4 | 31 | void mbedtls_sha512_free( mbedtls_sha512_context *ctx ) |
kenjiArai | 1:9db0e321a9f4 | 32 | { |
kenjiArai | 1:9db0e321a9f4 | 33 | if( ctx == NULL ) |
kenjiArai | 1:9db0e321a9f4 | 34 | return; |
kenjiArai | 1:9db0e321a9f4 | 35 | CRYS_HASH_Free( &ctx->crys_hash_ctx ); |
kenjiArai | 1:9db0e321a9f4 | 36 | memset( ctx, 0, sizeof( mbedtls_sha512_context ) ); |
kenjiArai | 1:9db0e321a9f4 | 37 | } |
kenjiArai | 1:9db0e321a9f4 | 38 | |
kenjiArai | 1:9db0e321a9f4 | 39 | void mbedtls_sha512_clone( mbedtls_sha512_context *dst, |
kenjiArai | 1:9db0e321a9f4 | 40 | const mbedtls_sha512_context *src ) |
kenjiArai | 1:9db0e321a9f4 | 41 | { |
kenjiArai | 1:9db0e321a9f4 | 42 | memcpy(dst,src,sizeof(mbedtls_sha512_context)); |
kenjiArai | 1:9db0e321a9f4 | 43 | } |
kenjiArai | 1:9db0e321a9f4 | 44 | |
kenjiArai | 1:9db0e321a9f4 | 45 | |
kenjiArai | 1:9db0e321a9f4 | 46 | int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 ) |
kenjiArai | 1:9db0e321a9f4 | 47 | { |
kenjiArai | 1:9db0e321a9f4 | 48 | if( is384 ) |
kenjiArai | 1:9db0e321a9f4 | 49 | return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ); |
kenjiArai | 1:9db0e321a9f4 | 50 | if( CRYS_HASH_Init( &ctx->crys_hash_ctx, CRYS_HASH_SHA512_mode ) != CRYS_OK ) |
kenjiArai | 1:9db0e321a9f4 | 51 | return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); |
kenjiArai | 1:9db0e321a9f4 | 52 | return ( 0 ); |
kenjiArai | 1:9db0e321a9f4 | 53 | } |
kenjiArai | 1:9db0e321a9f4 | 54 | |
kenjiArai | 1:9db0e321a9f4 | 55 | int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, |
kenjiArai | 1:9db0e321a9f4 | 56 | const unsigned char data[128] ) |
kenjiArai | 1:9db0e321a9f4 | 57 | { |
kenjiArai | 1:9db0e321a9f4 | 58 | return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ); |
kenjiArai | 1:9db0e321a9f4 | 59 | } |
kenjiArai | 1:9db0e321a9f4 | 60 | |
kenjiArai | 1:9db0e321a9f4 | 61 | int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, |
kenjiArai | 1:9db0e321a9f4 | 62 | const unsigned char *input, |
kenjiArai | 1:9db0e321a9f4 | 63 | size_t ilen ) |
kenjiArai | 1:9db0e321a9f4 | 64 | { |
kenjiArai | 1:9db0e321a9f4 | 65 | if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK ) |
kenjiArai | 1:9db0e321a9f4 | 66 | return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); |
kenjiArai | 1:9db0e321a9f4 | 67 | return ( 0 ); |
kenjiArai | 1:9db0e321a9f4 | 68 | } |
kenjiArai | 1:9db0e321a9f4 | 69 | |
kenjiArai | 1:9db0e321a9f4 | 70 | int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx, |
kenjiArai | 1:9db0e321a9f4 | 71 | unsigned char output[64] ) |
kenjiArai | 1:9db0e321a9f4 | 72 | { |
kenjiArai | 1:9db0e321a9f4 | 73 | CRYSError_t crys_err = CRYS_OK; |
kenjiArai | 1:9db0e321a9f4 | 74 | CRYS_HASH_Result_t crys_result = {0}; |
kenjiArai | 1:9db0e321a9f4 | 75 | crys_err = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result ); |
kenjiArai | 1:9db0e321a9f4 | 76 | if( crys_err == CRYS_OK ) |
kenjiArai | 1:9db0e321a9f4 | 77 | { |
kenjiArai | 1:9db0e321a9f4 | 78 | memcpy(output,crys_result,64); |
kenjiArai | 1:9db0e321a9f4 | 79 | return ( 0 ); |
kenjiArai | 1:9db0e321a9f4 | 80 | } |
kenjiArai | 1:9db0e321a9f4 | 81 | else |
kenjiArai | 1:9db0e321a9f4 | 82 | return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); |
kenjiArai | 1:9db0e321a9f4 | 83 | } |
kenjiArai | 1:9db0e321a9f4 | 84 | #endif //MBEDTLS_SHA512_ALT |