-
Notifications
You must be signed in to change notification settings - Fork 3k
NUCLEO_F756ZG / mbedTLS_SHA1 hw acceleration #3957
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
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It seems there are some memory leaks here
- user defined configuration should not be defined in mbedtls_device.h
|
||
|
||
#define MBEDTLS_SHA1_C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an application specific definition, and should be defined by the end user. Please remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll put that into targets.json
#ifndef MBEDTLS_DEVICE_H | ||
#define MBEDTLS_DEVICE_H | ||
|
||
#define MBEDTLS_AES_ALT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds alternative AES support, but this PR is for SHA1 only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as in PR for MD5. I based my PR on AES' one because I think it causes merge issues if I create new folders and new files with the same names in separate PRs, sorry for that.
#define MBEDTLS_AES_ALT | ||
#define MBEDTLS_SHA1_ALT | ||
|
||
#define MBEDTLS_SHA1_C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an application specific definition, and should be defined by the end user. Please remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll put that into targets.json
|
||
if (ilen <4) | ||
{ | ||
ctx->sbuf=malloc(ilen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a memory leak:
- where is this being released
- even if it is being released in an internal API, if a user is calling twice to mbedtls_sha1_update with size smaller than 4, the first allocated buffer will not be freed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for noticing this. I'll work on that
buf_len = ilen - modulus; | ||
HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, (uint8_t *)input, buf_len); | ||
ctx->sbuf_len=modulus; | ||
ctx->sbuf=malloc(ctx->sbuf_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a memory leak:
- where is this being released
- even if it is being released in an internal API, if a user is calling twice to mbedtls_sha1_update with size which modulus is not 4, the first allocated buffer will not be freed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for noticing this. I'll work on that
HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, (uint8_t *)input, ilen); | ||
else | ||
{ | ||
intermediate_buf=malloc(ilen+ctx->sbuf_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a memory leak - > where is it freed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for noticing this. I'll work on that
#if defined MBEDTLS_SHA1_ALT | ||
|
||
#include "mbedtls/platform.h" | ||
#include "mbedtls/config.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to include this file, as it should be included in the c file before this header file is included
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mbedtls/config.h not needed. Correct
|
||
#if defined MBEDTLS_SHA1_ALT | ||
|
||
#include "mbedtls/platform.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file needed to be included in this header file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is needed to avoid warnings that 'malloc' is declared implicitly. I move it to sha1_alt.c instead
* \param ilen length of the input data | ||
* \param output SHA-1 checksum result | ||
*/ | ||
void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to redefine this function, as it is defined in sha1.h
, outside the #ifdef MBEDTLS_SHA1_ALT
check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct
* | ||
* \return 0 if successful, or 1 if the test failed | ||
*/ | ||
int mbedtls_sha1_self_test( int verbose ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to redefine this function, as it is defined in sha1.h
, outside the #ifdef MBEDTLS_SHA1_ALT
check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct
Move include platform from sha1_alt.h to sha1_alt.c
@adustm Should this be moved against the workshop branch? |
Description
mbedtls_SHA1 hw acceleration for NUCLEO_F756ZG
Status
READY
Related PRs
** This PR needs #3954 + #3947 to be merged first**
Deploy notes
Notes regarding the deployment of this PR. These should note any
required changes in the build environment, tools, compilers, etc.
Steps to test or reproduce
same as in #3947