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