Skip to content
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

STM32 hw entropy #2611

Merged
merged 7 commits into from
Oct 12, 2016
Merged

STM32 hw entropy #2611

merged 7 commits into from
Oct 12, 2016

Conversation

adustm
Copy link
Member

@adustm adustm commented Sep 2, 2016

Hello @0xc0170 and @screamerbg
This Pull Request is the completion of the HW entropy for STM32 platforms.
Every ST platform having a TrueRandomGenerator in the microcontroler is now available.

I performed the test bellow on NUCLEO_L476RG, NUCLEO_L073RZ, NUCLEO_L432KC and DISCO_L476VG
with IAR, ARM and GCC_ARM toolchains


#include "test_env.h"
#include "entropy_poll.h"

#define BUFF_SIZE       500
unsigned char myrndbuff[BUFF_SIZE]={0};
size_t *olen;

int main() {
    GREENTEA_SETUP(20, "default_auto");
    printf("MBED: st_rng_entropy\r\n");
    int ret = 0, i=0;
    bool result = false;
    size_t mysize=0;
    olen = &mysize;
    ret = mbedtls_hardware_poll( NULL, myrndbuff, BUFF_SIZE, olen );
    if (ret == 0 ) {
        printf("tls_ret_ok\n");
        printf("%i\n",(int)*olen);
        if (*olen == BUFF_SIZE) {
            printf("size ok\n");
            result = true;
            for (i=0;i<BUFF_SIZE;i++){unsigned char ch=myrndbuff[i];printf("%u\n",ch);}
        } else printf("size ko\n");
    } else printf("tls_ret_ko\n");
    printf("Test end\n");

  GREENTEA_TESTSUITE_RESULT(result);
}

@adustm
Copy link
Member Author

adustm commented Sep 5, 2016

Hello,
Something went wrong in the automatic tests. Could you let me know what it is ? I cannot see the results.
Kind regards
Armelle

@bridadan
Copy link
Contributor

bridadan commented Sep 6, 2016

@mazimkhan Looks like there was a failure with the uvisor tests, any idea what's going on here?

@sg- sg- added the needs: CI label Sep 9, 2016
@sg-
Copy link
Contributor

sg- commented Sep 9, 2016

@adustm I'd like to hold on this until the tests get merged. Should be soon. #2603

@adustm
Copy link
Member Author

adustm commented Sep 12, 2016

Hello @-sg,
I passed the tls test of #2603, as requested by @screamerbg
I hope you will be able to merge both soon.
Cheers
Armelle

@sg- sg- added needs: work and removed needs: CI labels Sep 16, 2016
@screamerbg
Copy link
Contributor

Bump @sg- @0xc0170

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 27, 2016

Bump @sg- @0xc0170

We have been working on adding TRNG HAL last days, the PR should be merged today, and this PR should be updated to use it (it require changes in mbedtls ). I can do that manually to bring this up to date if required.

we will keep you updated


/* Get Random byte */
for( uint32_t i = 0; i < len; i++ ){
rng_get_byte( output + i );
Copy link
Contributor

@0xc0170 0xc0170 Sep 27, 2016

Choose a reason for hiding this comment

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

One thing I noticed while reading reference manual for some STM32F4 RNG peripheral, once RNG is started, the first byte should be discarded. this is not done for any STM as I have seen so far.

@adustm
Copy link
Member Author

adustm commented Sep 27, 2016

Hello, It's been 2 weeks and I missed the target release 126...
Could you please merge this PR (as you already did with the previous one #2253 ) ? It is the exact same code for some other platforms

Kind regards
Armelle

@mazimkhan
Copy link

retest uvisor

1 similar comment
@mazimkhan
Copy link

retest uvisor

@sg-
Copy link
Contributor

sg- commented Sep 28, 2016

@adustm This needs to be updated to use TRGN in the device_has field per #2765

@adustm
Copy link
Member Author

adustm commented Sep 29, 2016

Hello,
I have updated this PR wrt to the changes from @0xc0170 (use device TRNG instead of the macro MBEDTLS_ENTROPY_ALT ) from #2765 .
I have passed again the test from the mbedtls self test used in #2603
I think this PR is now ready. Let me know if you agree.
Kind regards
Armelle

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 29, 2016

@adustm Thank you ! Got a question. in trng_init, shouldn't you read one byte to discard it (when you enable RNG peripheral)? I raised that question above, I recall it was specified in STM32F4 reference manual.

Looks fine to me otherwise.

@sg- Please review

@sg-
Copy link
Contributor

sg- commented Sep 30, 2016

@adustm Thank you ! Got a question. in trng_init, shouldn't you read one byte to discard it (when you enable RNG peripheral)? I raised that question above, I recall it was specified in STM32F4 reference manual.

@adustm bump.

@sg-
Copy link
Contributor

sg- commented Oct 3, 2016

@adustm bump.

@adustm
Copy link
Member Author

adustm commented Oct 4, 2016

Hello @sg-
I confirm the specification point. I have made some internal discussions, as I wanted this code to be part of the ST HAL init function, but it needs to be done by me.
I'll modify this PR and add the modification for every platforms.
Kind regards

@adustm
Copy link
Member Author

adustm commented Oct 4, 2016

... files have change of location... I'll update as soon as I can... I'll let you know
cheers

@adustm
Copy link
Member Author

adustm commented Oct 6, 2016

Hello @sg-
I think it is ready now .
Let me know !
Kind regards
Armelle

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 6, 2016

Thanks for handling that first number .

LGTM

@bridadan
Copy link
Contributor

bridadan commented Oct 6, 2016

/morph test

@mbed-bot
Copy link

mbed-bot commented Oct 6, 2016

Result: SUCCESS

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

/morph test

Output

mbed Build Number: 1067

All builds and test passed!

@bridadan
Copy link
Contributor

bridadan commented Oct 6, 2016

@0xc0170 Good to remove needs: works label?

@sg- sg- added needs: CI and removed needs: work labels Oct 7, 2016
@sg-
Copy link
Contributor

sg- commented Oct 7, 2016

@adustm target.json conflict to resolve :)

@adustm
Copy link
Member Author

adustm commented Oct 10, 2016

Hello @sg-, it's done.

"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"release_versions": ["2", "5"],
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
"release_versions": ["2", "5"]

Choose a reason for hiding this comment

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

Please put , after "release_versions": ["2", "5"]. It breaks the builds.

@sg-
Copy link
Contributor

sg- commented Oct 10, 2016

/morph test-nightly

@sg- sg- removed the needs: work label Oct 10, 2016
@mbed-bot
Copy link

Result: FAILURE

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

/morph test-nightly

@bridadan
Copy link
Contributor

Same deal, all failing tests are currently in the nightly 👍 LGTM

@sg- sg- merged commit f9ee683 into ARMmbed:master Oct 12, 2016
@adustm adustm deleted the STM32_entropy branch October 13, 2016 07:38
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.

7 participants