Skip to content

NUCLEO_F439ZI/mbedtls: add SHA1 hw_acceleration #3947

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

Closed
wants to merge 68 commits into from

Conversation

adustm
Copy link
Member

@adustm adustm commented Mar 16, 2017

Description

Enable SHA1 for STM32F439ZI
Enable HW acceleration for SHA1 algorithm on STM32F439ZI

Status

READY

Migrations

If this PR changes any APIs or behaviors, give a short description of what API users should do when this PR is merged.

YES | NO

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



#define MBEDTLS_SHA1_C
Copy link
Contributor

@LMESTM LMESTM Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is MBEDTLS_SHA1_C defined here (and MBEDTLS_AES_C) was not ?
maybe add a small comment that explain what it is defined for

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LMESTM ,
This define is supposed to be located in features\mbedtls\inc\mbedtls\config.h.
It would enable the SHA1 module for every targets, thus adding code size for everyone.

I have chosen to add the SHA1 enablement in this target only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok clear - thanks

Copy link
Contributor

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
I only asked few questions for my own understanding


void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
{
memset( ctx, 0, sizeof( mbedtls_sha1_context ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using memset here and not zeroize as defined above ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will do it

const mbedtls_sha1_context *src )
{
*dst = *src;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is safe for all toolchains and compilers options (no warnings?)
or would we need a copy ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a copy-paste from the original mbedtls/src/sha1.c
As we are replacing the complete module, we had to import every function that is declared inside #if !defined(MBEDTLS_SHA1_ALT) in the original sha1.c file.

unsigned char *sbuf;
unsigned char sbuf_len;
HASH_HandleTypeDef hhash_sha1;
int flag; /* flag to manage buffer constraint of crypto Hw */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to explicit how flag is used (what 0 means / what 1 means)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I will add a comment

@adustm
Copy link
Member Author

adustm commented Mar 16, 2017

+-------------------+---------------+------------------------+-----------------------------+--------+--------+--------+--------------------+
| target            | platform_name | test suite             | test case                   | passed | failed | result | elapsed_time (sec) |
+-------------------+---------------+------------------------+-----------------------------+--------+--------+--------+--------------------+
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_aes_self_test       | 1      | 0      | OK     | 0.56               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_base64_self_test    | 1      | 0      | OK     | 0.12               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_ccm_self_test       | 1      | 0      | OK     | 0.11               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_ctr_drbg_self_test  | 1      | 0      | OK     | 0.12               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_ecp_self_test       | 1      | 0      | OK     | 2.79               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_entropy_self_test   | 1      | 0      | OK     | 0.08               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_gcm_self_test       | 1      | 0      | OK     | 2.6                |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_hmac_drbg_self_test | 1      | 0      | OK     | 0.13               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_mpi_self_test       | 1      | 0      | OK     | 0.26               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_rsa_self_test       | 1      | 0      | OK     | 0.46               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_sha1_self_test      | 1      | 0      | OK     | 0.14               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_sha256_self_test    | 1      | 0      | OK     | 0.79               |
| NUCLEO_F439ZI-IAR | NUCLEO_F439ZI | tests-mbedtls-selftest | mbedtls_sha512_self_test    | 1      | 0      | OK     | 1.7                |
+-------------------+---------------+------------------------+-----------------------------+--------+--------+--------+--------------------+

@adustm
Copy link
Member Author

adustm commented Mar 20, 2017

Hi @LMESTM
I answered your questions and updated the code.
Cheers

@0xc0170 0xc0170 requested a review from simonbutcher March 20, 2017 12:28
@adustm adustm changed the title NUCLEO_F429ZI/mbedtls: add SHA1 hw_acceleration NUCLEO_F439ZI/mbedtls: add SHA1 hw_acceleration Mar 23, 2017
asmellby and others added 22 commits March 27, 2017 11:44
* Make memory sections configurable in linker files
* Dynamically determine vector location in flash for NVIC relocation
* Advertise bootloader support in targets.json
When using ARM Compiler 5, the RTX config hard-coded the heap and stack
sizes to specific values. This prevented the RTX HAL from dynamically
allocating unused memory as heap space.

Specifically, the HEAP_START define prevents this logic in RTX_CM_lib.h
from activating. The rest of the defines are also set in that header,
and should be removed from here.
The header is already included inside of flash_api.h if the target
uses CMSIS flash algos. If it doesn't, the file shouldn't be included,
since it doesn't exist.
* Using PinName as bitfield doesn't work without warnings, since NC
  needs all 32 bits to be represented.
* lp_ticker should not be freed when interrupt is disabled, since this
  will kill the timebase.
Signed-off-by: Mahadevan Mahesh <[email protected]>
*** Is alpha ***

I added options to tools/arm_pack_manager/pack_manager.py and
tools/flash_algo/extract.py to allow a user to specify a single pack on
disk to add to the cache. The syntax is as follows:
 - python tools/arm_pack_manager/pack_manager.py add-local-pack <local-pack>
 - cd tools/flash_algo; python extract.py --local-pack <local-pack>

Both of these methods will add your pack to the index and copy the pack
file into the location that arm_pack_manager would have placed it if it
was downloaded from the internet.
GetSector has been rewritten
@adustm adustm force-pushed the STM_sha1_F439ZI branch from 5d7a908 to c292c76 Compare April 4, 2017 14:53
@adustm
Copy link
Member Author

adustm commented Apr 4, 2017

rebase done

@adustm
Copy link
Member Author

adustm commented Apr 10, 2017

Hello @0xc0170
Could you let me know what wen wrong here ?
Armelle

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 10, 2017

Could you let me know what wen wrong here ?

I restarted the job, as it did not produce any valuable report (was restarted this morning by us).

sg- added 3 commits April 10, 2017 10:36
K64F: Add MMCAU driver needed for mbedtls
…spi_sdcard

[NRF52840]: enabled SdBlockDevice capability
@sg-
Copy link
Contributor

sg- commented Apr 10, 2017

@adustm Can this be moved against the workshop branch?

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

Successfully merging this pull request may close these issues.

10 participants