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

Add TRNG API test #7057

Merged
merged 16 commits into from
Sep 26, 2018
Merged

Add TRNG API test #7057

merged 16 commits into from
Sep 26, 2018

Conversation

theamirocohen
Copy link
Contributor

Use TRNG api to construct different buffers and try to compress them, If the random data is not really random, the test will be able to compress it.
We also check that after device reset when we use TRNG the API will create different data.

We do use lzf lib to compress the random buffer, the library should be checked for copyrights violation by @ChiefBureaucraticOfficer , all files are documented and under the lzflib library.

[ ] Fix
[ ] Refactor
[ ] New target
[x] Feature
[ ] Breaking change

else
{
printf("compression for concatenated buffer after reset was unsuccessful");
TEST_ASSERT(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be ASSERT with msg (then printf not needed). I think this entire if can be turned into one assert.

Similar to: TEST_ASSERT_TRUE_MSG(compr_res < buffer_len , "failed......msg....here")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the test contains several parts I wanted the user to have a clear view of the progress, the assert message is only shown when the test fails.

(unsigned char **)htab);

if (comp_res >= BUFFER_LEN)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you fix formatting (follow mbed OS code style) , this one ({) should be attached

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for that, all formatting will be fixed

@@ -0,0 +1,16 @@
#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

license header missing in some files (please review), not only this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for that, all license header will be added.

@0xc0170
Copy link
Contributor

0xc0170 commented May 30, 2018

From the changes, looks like mbed tls and strorage teams should review this PR?

@ghost
Copy link

ghost commented May 30, 2018

This appears to have a GPL on it. @0xc0170

@0xc0170 0xc0170 requested a review from a user May 30, 2018 13:01
@ghost ghost added the do not merge label May 30, 2018
@theamirocohen
Copy link
Contributor Author

@ARMmbed/mbed-os-storage
@ARMmbed/mbed-os-tls
Hope you can help review PR

@ghost
Copy link

ghost commented May 30, 2018

GPL is still present in this PR. We cannot integrate GPL code with Mbed OS.

@theamirocohen
Copy link
Contributor Author

Compression lib was changed to pithy (with BSD license)

@theamirocohen
Copy link
Contributor Author

@dannybenor

@simonbutcher
Copy link
Contributor

You need @ARMmbed/mbed-os-crypto to review this, not @ARMmbed/mbed-os-tls!

As seems to be common these days, we may be duplicating work, and I believe the Crypto team were planning on providing their own statistical measurement of the TRNG.

cc: @Patater, @yanesca

@adbridge adbridge requested a review from a team June 4, 2018 13:55
@cmonr cmonr dismissed 0xc0170’s stale review June 4, 2018 15:57

License headers added.

@cmonr
Copy link
Contributor

cmonr commented Jun 18, 2018

@ARMmbed/mbed-os-crypto Mind reviewing?

@cmonr cmonr removed the request for review from a user June 18, 2018 23:17
@yanesca
Copy link
Contributor

yanesca commented Jun 19, 2018

@cmonr We'll review it shortly! Could you please add the "TLS" label to the PR?

yanesca
yanesca previously approved these changes Jun 22, 2018
Copy link
Contributor

@yanesca yanesca 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!

@mohammad1603 will be giving a review too and we need his approval before merging.

@cmonr
Copy link
Contributor

cmonr commented Jun 22, 2018

Thansk for the heads up @yanesca

Copy link
Contributor

@mohammad1603 mohammad1603 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, some minor issues

"""
This script is the host script for trng test sequence, it send the
step signaling sequence and receive and transmit data to the device after
reset if necesarry (default lading and storing while reseting the device
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: lading -> loading

This script is the host script for trng test sequence, it send the
step signaling sequence and receive and transmit data to the device after
reset if necesarry (default lading and storing while reseting the device
is NVstore, in case NVstore isn't enabled we'll use current infrastructure,
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you mean "device is NVstore" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"default lading and storing while reseting the device is NVstore", the device is the device used for testing, the NVstore is one way of storing and loading data


wait_for_communication = yield

if self.reset == False:
Copy link
Contributor

Choose a reason for hiding this comment

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

do you expect the device to reset after step1 (dummy message) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, If not an error will occur.

return BASE64_INVALID_PARAMETER;
}

if ((base64 >= 'A') && (base64 <= 'Z'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Style (minor): mixed style of using {.

if (a){
xx;
}

AND

if (a)
{ xx;  }

}

*writePtr = 0;
while (( string[currPos] != 0 ) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

i think you should switch between the first two conditions - the current code can cause an out of bounds access.
in case the string doesn't end with 0 you can see this behavior.
should be:

while (( currPos < stringMaxSize ) &&
( string[currPos] != 0 ) &&
( writePtr  <  bufferEnd ) &&
( !isEndOfString )) {

( !isEndOfString )) {
uint8_t val;

if (string[currPos] == 0 || currPos >= stringMaxSize)
Copy link
Contributor

Choose a reason for hiding this comment

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

in the while you validate this, you can avoid this checks (they will always be true)

// Check if additional bytes should have been processed but buffer isn't sufficient.
if (( result == BASE64_SUCCESS ) &&
( !isEndOfString ) &&
( string[currPos] != '=' ) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

if currPos == stringMaxSize this can be a problem as above

/*
* The test is based on the assumption that trng will generate random data, random so
* there will not be any similar patterns in it, that kind of data will be impossible to
* compress, if compression will acuur the test will result in failure.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: acuur -> occur

Copy link

@dannybenor dannybenor left a comment

Choose a reason for hiding this comment

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

Before approving this PR, TPIP must be approved by Aaron

@cmonr
Copy link
Contributor

cmonr commented Jun 25, 2018

@dannybenor TPIP?

@ghost
Copy link

ghost commented Jun 25, 2018

@cmonr - TPIP == Third Party IP. This looks to be BSD, which is compatible. I'll run it past legal for a TPIP review just to be sure.

@cmonr
Copy link
Contributor

cmonr commented Jul 5, 2018

@ChiefBureaucraticOfficer Is this good to progress?

@theamirocohen
Copy link
Contributor Author

Hi @0xc0170 ,
In internal checks we see that K22 is running properly, the fail might have been a statistical issue, where the string did have a similarity and compressed.
Any how @yossi2le added tests prints so we could track any error if it will fail again.
Can we run morph build again please.
Thanks!

@cmonr
Copy link
Contributor

cmonr commented Sep 12, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Sep 12, 2018

@cmonr
Copy link
Contributor

cmonr commented Sep 12, 2018

Oh, I feel silly. This needed to have been a build, not a re-test.

/morph build

@mbed-ci
Copy link

mbed-ci commented Sep 12, 2018

Build : SUCCESS

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

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Sep 13, 2018

@NirSonnenschein
Copy link
Contributor

/morph build

@mbed-ci
Copy link

mbed-ci commented Sep 16, 2018

Build : SUCCESS

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

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Sep 16, 2018

@NirSonnenschein
Copy link
Contributor

TRNG test seem to fail on K22F. @theamirocohen please take a look.

@mbed-ci
Copy link

mbed-ci commented Sep 16, 2018

@cmonr
Copy link
Contributor

cmonr commented Sep 25, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Sep 25, 2018

Build : SUCCESS

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

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Sep 25, 2018

@mbed-ci
Copy link

mbed-ci commented Sep 26, 2018

@cmonr
Copy link
Contributor

cmonr commented Sep 26, 2018

sigh

It looks like failure was an intermittent network issue.

/morph test

@mbed-ci
Copy link

mbed-ci commented Sep 26, 2018

@0xc0170 0xc0170 merged commit a0a9b54 into ARMmbed:master Sep 26, 2018
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.