Skip to content

Commit 54d7d7e

Browse files
author
Seppo Takalo
authored
Merge pull request #10913 from RonEld/sha512_cc310_porting
Port CC 310 sha 512 driver
2 parents 6722d8c + 4cf3e1c commit 54d7d7e

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-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_CMAC_ALT
2930
#define MBEDTLS_ECDSA_VERIFY_ALT
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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
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)