diff options
author | Mark Horvath <mark.horvath@arm.com> | 2021-03-12 10:22:27 +0100 |
---|---|---|
committer | Anton Komlev <Anton.Komlev@arm.com> | 2021-06-21 22:11:31 +0200 |
commit | ed119d4a89861494d084cd0add30f57b5ccc0221 (patch) | |
tree | 8d6848b76a8850a364040c9e4157c6496187b610 /lib | |
parent | 91d9f7403cb476539b74cc06de82483977daf3a0 (diff) | |
download | trusted-firmware-m-ed119d4a89861494d084cd0add30f57b5ccc0221.tar.gz |
CC312: Hash chunking implemented
CC312 has a limitation that the maximum size of a data block to be
hashed is 0xFFFF. To overcome this limitation the hash of big input
buffers is calculated with more calls to CC312, passing only a smaller
part of the input at a time.
Signed-off-by: Mark Horvath <mark.horvath@arm.com>
Change-Id: Idb7a0c997bbe66b57d63f5d646cf6fdabd2ee179
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/mbedtls_hash_common.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/mbedtls_hash_common.c b/lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/mbedtls_hash_common.c index bb4c85fad5..733f9e0eb2 100644 --- a/lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/mbedtls_hash_common.c +++ b/lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/mbedtls_hash_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2001-2021, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -10,6 +10,9 @@ #include "sha1_alt.h" #include "sha256_alt.h" +/* CC312 DMA limits the amount of data can be hashed at once. */ +#define MAX_HASH_CHUNK_SIZE 0xffff + /* In CC312, DMA (i.e. for hash module input ) needs access to physical and continues memory. In order to assure the DMA can access the residue data saved in the hashCtx, it is being to copied to a local @@ -197,9 +200,21 @@ int mbedtls_sha_update_internal( void *ctx, const unsigned char *input, size_t i //printf("TEST12, hash err = 1\n"); return( 1 ); } + + while (ilen > MAX_HASH_CHUNK_SIZE) { + ret = mbedtls_hashUpdate(ctx, (uint8_t *)input, MAX_HASH_CHUNK_SIZE); + + ilen -= MAX_HASH_CHUNK_SIZE; + input += MAX_HASH_CHUNK_SIZE; + + if (CC_OK != ret) { + CC_PAL_LOG_ERR("mbedtls_hashUpdate failed, ret = %d\n", ret); + return( 1 ); + } + } + ret = mbedtls_hashUpdate(ctx, (uint8_t *)input, ilen); - if( CC_OK != ret) - { + if (CC_OK != ret) { CC_PAL_LOG_ERR("mbedtls_hashUpdate failed, ret = %d\n", ret); return( 1 ); } |