New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUCLEO_F439ZI/mbedtls: add SHA1 hw_acceleration #4157

Merged
merged 13 commits into from Jun 26, 2017

Conversation

Projects
None yet
10 participants
@adustm
Member

adustm commented Apr 11, 2017

Description

Enable SHA1 for STM32F439ZI
Enable HW acceleration for SHA1 algorithm on STM32F439ZI
is PR #3947 on another branch

Status

READY

Steps to test or reproduce

To test this feature, you have to modify TESTS/mbedtls/selfttest/main.cpp in order to call sha1 self test:
add:
#include "mbedtls/sha1.h"
then

#if defined(MBEDTLS_SHA1_C)
MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_sha1_self_test)
#endif

then

#if defined(MBEDTLS_SHA1_C)
    Case("mbedtls_sha1_self_test", mbedtls_sha1_self_test_test_case),
#endif
@adustm

This comment has been minimized.

Member

adustm commented Apr 11, 2017

@0xc0170 0xc0170 requested review from yanesca and RonEld Apr 12, 2017

@RonEld

added same comments as #4156
In fact, the subject of this PR is misleading. The subject is SHA1 HW acceleration, but the content is MD5 HW ac celeration. Please check the mistake

#define MBEDTLS_MD5_C

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

Please remove

*/
void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
{
HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)input, ilen);

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

what if ilen < 64?
Don't you need some accumulation buffer like in the SHA1 use case? Is this done in HAL_HASH_MD5_Accumulate?

{
__HAL_HASH_START_DIGEST();
HAL_HASH_MD5_Finish(&ctx->hhash_md5, output, 10);

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

why 10? Is this hex value?

#if defined(MBEDTLS_MD5_ALT)
#include "mbedtls/platform.h"
#include "mbedtls/config.h"

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

is this include needed? isn't it already included in md5.h and md5.c before the inclusion of md5_alt.h?
Please check what header files inclusions are needed in this header files, and what should be moved to md5_alt.c file

*/
typedef struct
{
uint32_t total[2]; /*!< number of bytes processed */

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

where is this referenced?

typedef struct
{
uint32_t total[2]; /*!< number of bytes processed */
uint32_t state[4]; /*!< intermediate digest state */

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

where is this referenced?

{
uint32_t total[2]; /*!< number of bytes processed */
uint32_t state[4]; /*!< intermediate digest state */
unsigned char buffer[64]; /*!< data block being processed */

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

where is this referenced?

#endif
#ifdef __cplusplus
extern "C" {

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

can be removed

#endif
#ifdef __cplusplus
}

This comment has been minimized.

@RonEld

RonEld Apr 12, 2017

Contributor

can be removed

@adustm adustm force-pushed the adustm:STM_sha1_F439ZI branch from c80fa0a May 18, 2017

@adustm

This comment has been minimized.

Member

adustm commented May 18, 2017

Hello,
Sorry for the mixup between md5 and sha1 branches. I've now fixed it (back to SHA1 code).

@RonEld

RonEld approved these changes May 23, 2017

one additional, minor, comment. After that, It's approved from my side

features/mbedtls/targets/TARGET_STM/sha1_alt.h Outdated
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
/* Internal use */
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );

This comment has been minimized.

@RonEld

RonEld May 23, 2017

Contributor

change 64 to MBEDTLS_SHA1_BLOCK_SIZE.

This comment has been minimized.

@adustm
features/mbedtls/targets/TARGET_STM/sha1_alt.c Outdated
mbedtls_sha1_process(ctx, ctx->sbuf);
// now process every input as long as it is %4 bytes
size_t iter = currentlen / 4;
HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, (uint8_t *)(input+MBEDTLS_SHA1_BLOCK_SIZE-ctx->sbuf_len), (iter*4));

This comment has been minimized.

@RonEld

RonEld May 23, 2017

Contributor

same comment as in the SHA256:
Please verify how HAL_HASH_SHA1_Accumulate will behave if iter = 0

This comment has been minimized.

@adustm

adustm May 23, 2017

Member

Hello @RonEld ,
It will call HASH_WriteData in stm32f4xx_hal_hash.c line 225

for(buffercounter = 0U; buffercounter < Size; buffercounter+=4U)
 {
   HASH->DIN = *(uint32_t*)inputaddr;
   inputaddr+=4U;
 }

It will do nothing in case the Size is =0 (tested for the 3 toolchains GCC_ARM / IAR / ARM)

@RonEld

RonEld approved these changes May 23, 2017

@adustm

This comment has been minimized.

Member

adustm commented May 23, 2017

Hello @yanesca, you have been added as a reviewer by @0xc0170 .
Could you also review this PR, please ?

Thanks in advance,
Armelle

@andresag01

This comment has been minimized.

Contributor

andresag01 commented May 24, 2017

This is equivalent to #4162 and I have already reviewed that one.

@adustm adustm force-pushed the adustm:STM_sha1_F439ZI branch Jun 2, 2017

@adustm

This comment has been minimized.

Member

adustm commented Jun 2, 2017

Hello @gilles-peskine-arm @andresag01 ,
I have reworked this branch to allow multiple context.
Let me know if you think it's ok.
Kind regards

@gilles-peskine-arm

Looks good overall, see my comments in PR #4162

@andresag01

@adustm: Many thanks for considering our comments and reworking. This PR is is very similar to #4160, please refer to my most recent comments there.

@adustm

This comment has been minimized.

Member

adustm commented Jun 12, 2017

Hello,
@yanesca @andresag01 , could you approve this PR or is there anything missing ?

@0xc0170 do you know what is failing in the Cam-CI uvisor Build & Test script ?
Kind regards
Armelle

@sg-

This comment has been minimized.

Member

sg- commented Jun 15, 2017

Given all the approvals and that mbed TLS 2.5 is part of master can this PR be rebased on master?

@sg- sg- changed the base branch from mbed-os-workshop-17q2 to master Jun 15, 2017

@adustm adustm changed the base branch from master to mbed-os-workshop-17q2 Jun 16, 2017

@adustm adustm force-pushed the adustm:STM_sha1_F439ZI branch to e63912f Jun 16, 2017

@adustm adustm changed the base branch from mbed-os-workshop-17q2 to master Jun 16, 2017

@adustm

This comment has been minimized.

Member

adustm commented Jun 16, 2017

Hello
Approvals are ok, rebase is done.
Kind regards

@adustm

This comment has been minimized.

Member

adustm commented Jun 19, 2017

Hello, the scripts are still running after 3 days, I guess it should be executed again ?

Thanks in advance
Armelle

@theotherjimmy

This comment has been minimized.

Contributor

theotherjimmy commented Jun 19, 2017

Bumping CI by closing then opening.

@theotherjimmy

This comment has been minimized.

Contributor

theotherjimmy commented Jun 19, 2017

retest uvisor

1 similar comment
@adbridge

This comment has been minimized.

Contributor

adbridge commented Jun 19, 2017

retest uvisor

@adustm

This comment has been minimized.

Member

adustm commented Jun 22, 2017

bump ?

@adbridge

This comment has been minimized.

Contributor

adbridge commented Jun 23, 2017

/morph test

@mbed-bot

This comment has been minimized.

mbed-bot commented Jun 23, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 621

Test failed!

@adustm

This comment has been minimized.

Member

adustm commented Jun 23, 2017

Hello @adbridge
My PR has nothing to do with rtos on the failing device. Could you check the results, please ?
Kind regards
Armelle
cc @screamerbg

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Jun 26, 2017

/morph test

@mbed-bot

This comment has been minimized.

mbed-bot commented Jun 26, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 636

All builds and test passed!

@theotherjimmy theotherjimmy merged commit 0a2a48c into ARMmbed:master Jun 26, 2017

4 checks passed

Cam-CI uvisor Build & Test Success
Details
ci/morph-test Job has completed
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@adustm

This comment has been minimized.

Member

adustm commented Jun 27, 2017

👍

@adustm adustm deleted the adustm:STM_sha1_F439ZI branch Oct 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment