Skip to content

Fix bug in K64F trng_api.c #5550

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

Merged
merged 1 commit into from
Nov 30, 2017
Merged

Fix bug in K64F trng_api.c #5550

merged 1 commit into from
Nov 30, 2017

Conversation

sarahmarshy
Copy link
Contributor

@sarahmarshy sarahmarshy commented Nov 21, 2017

Description

K64F trng_get_byte function assumed memory for byte was zero initialized.

That means that this line would OR random data with data existing in memory. All values will eventually reach 255 if called many times.

Steps to test or reproduce

Use this test program to replicate the issue:

#include "mbed.h"

#define RANDOM_BUFF_SIZE 3                                                           /**< Random numbers buffer size. */

#include "hal/trng_api.h"

int main(void)
{
    uint32_t err_code;

    while (true)
    {
        trng_t trng_obj;
        trng_init(&trng_obj);
        uint8_t p_buff[RANDOM_BUFF_SIZE];
        size_t output_length;
        uint8_t length = trng_get_bytes(&trng_obj, p_buff, RANDOM_BUFF_SIZE, &output_length);
        printf("Random Vector:");
        for(uint8_t i = 0; i < RANDOM_BUFF_SIZE; i++)
        {
            printf(" %u",p_buff[i]);
        }
        printf("\r\n expected: %d length: %d",RANDOM_BUFF_SIZE, output_length);
        printf("\n\r");
        trng_free(&trng_obj);
        wait_ms(3000);
    }
}

@hanno-becker
Copy link

hanno-becker commented Nov 22, 2017

Thanks for spotting and fixing this!

@0xc0170 Could you also add @mazimkhan as a reviewer, please?

Copy link

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@mazimkhan mazimkhan left a comment

Choose a reason for hiding this comment

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

LGTM

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 24, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Nov 24, 2017

Build : SUCCESS

Build number : 590
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5550/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Nov 24, 2017

@mbed-ci
Copy link

mbed-ci commented Nov 24, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2017

/morph test

@mbed-ci
Copy link

mbed-ci commented Nov 27, 2017

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.

5 participants