Skip to content

Commit a060c7b

Browse files
Ron EldorRon Eldor
authored andcommitted
Port CC 310 sha512 driver
Port the cc310 SHA512 driver, even though it is sw implementation. Because the linker could not remove the cc310 sha512 implementation, there was duplicate implementation of SHA512, without enabling the sha512 alternative implementation.
1 parent 15b5b5d commit a060c7b

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

features/cryptocell/FEATURE_CRYPTOCELL310/mbedtls_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
2525
#define MBEDTLS_SHA1_ALT
2626
#define MBEDTLS_SHA256_ALT
27+
#define MBEDTLS_SHA512_ALT
2728
#define MBEDTLS_CCM_ALT
2829
#define MBEDTLS_ECDSA_VERIFY_ALT
2930
#define MBEDTLS_ECDSA_SIGN_ALT
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
32+
void mbedtls_sha512_free( mbedtls_sha512_context *ctx )
33+
{
34+
if( ctx == NULL )
35+
return;
36+
CRYS_HASH_Free( &ctx->crys_hash_ctx );
37+
memset( ctx, 0, sizeof( mbedtls_sha512_context ) );
38+
}
39+
40+
void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
41+
const mbedtls_sha512_context *src )
42+
{
43+
memcpy(dst,src,sizeof(mbedtls_sha512_context));
44+
}
45+
46+
47+
int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 )
48+
{
49+
if( is384 )
50+
return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
51+
if( CRYS_HASH_Init( &ctx->crys_hash_ctx, CRYS_HASH_SHA512_mode ) != CRYS_OK )
52+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
53+
return ( 0 );
54+
}
55+
56+
int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
57+
const unsigned char data[128] )
58+
{
59+
return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
60+
}
61+
62+
int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
63+
const unsigned char *input,
64+
size_t ilen )
65+
{
66+
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK )
67+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
68+
return ( 0 );
69+
}
70+
71+
int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
72+
unsigned char output[64] )
73+
{
74+
CRYSError_t crys_err = CRYS_OK;
75+
CRYS_HASH_Result_t crys_result = {0};
76+
crys_err = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result );
77+
if( crys_err == CRYS_OK )
78+
{
79+
memcpy(output,crys_result,64);
80+
return ( 0 );
81+
}
82+
else
83+
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
84+
}
85+
#endif //MBEDTLS_SHA512_ALT
86+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* sha512_alt.h
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+
#ifndef __SHA512_ALT__
22+
#define __SHA512_ALT__
23+
24+
#if defined(MBEDTLS_SHA512_ALT)
25+
26+
#include "crys_hash.h"
27+
28+
/**
29+
* \brief SHA-512 context structure
30+
*/
31+
typedef struct
32+
{
33+
CRYS_HASHUserContext_t crys_hash_ctx;
34+
} mbedtls_sha512_context;
35+
36+
#endif // MBEDTLS_SHA256_ALT__
37+
#endif //__SHA256_ALT__

0 commit comments

Comments
 (0)