-
Notifications
You must be signed in to change notification settings - Fork 3k
LPC546XX: Add TRNG support #6221
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
{ | ||
} | ||
|
||
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) |
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.
Please suppress unused argument compiler warning for obj
.
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.
@mmahadevan108 Could you address that comment, too, when you're fixing the zeroization below?
ARM Internal Ref: IOTSSL-2111 |
RNG_GetRandomData(); | ||
} | ||
} | ||
|
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.
Please reliably zeroize data
before returning to avoid leakage of entropy on the stack.
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.
I will zeroize data and update this commit
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.
@mmahadevan108 Please zeroize data
reliably, i.e. avoiding compiler-optimizations to remove it. For example, you could do *((volatile uint32_t*) &data)=0
at the end of the function (it's not necessary to do the clearing in every iteration).
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.
At the time the while
loop ends data
contains a 32bit random number that has been skipped. Is it something we need to zeroize?
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.
@mazimkhan Yes, it is zeroized before returning from the function, isn't it?
output[idx++] = (data >> (i * 8)) & 0xFF; | ||
} | ||
|
||
/* Skip next 32 random numbers for better entropy */ |
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.
How is that guaranteeing better entropy? Is there some known correlation between subsequent bytes returned from the RNG?
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 done per what is recommended in the reference manual.
To constitute one 128 bit number, a 32 bit random number is read, then the next 32
numbers are read but not used. The next 32 bit number is read and used and so on. Thus
32 32-bit random numbers are skipped between two 32-bit numbers that are used.
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.
The code doesn't implement this but instead skips 32*32 bits per 32 bits of entropy. Could you correct that, to avoid unnecessary workload in the device?
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.
For every 32 bit random number read, it is recommended that the next 32 32-bit random numbers are skipped. This is what the code is doing.
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.
I should have read that properly - apologies, my fault!
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.
The stack variable holding the most recent 32 bits of entropy should be reliably zeroized before returning from trng_get_bytes
.
066430a
to
c12c72d
Compare
PR has been updated per review comments |
/morph build |
@hanno-arm Mind doing a re-review? |
Build : FAILUREBuild number : 1355 |
From one of the error files:
|
I don't see this build error. The fsl_rng.h file is available under the LPC546XX/drivers folder. |
c12c72d
to
0eb06fe
Compare
@cmonr I updated the PR to fix the build error seen on LPC54114. |
4a48754
to
76c8a1b
Compare
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 good to me.
@mazimkhan Could you re-review this PR? It has changed slightly since your last approval. |
/morph build |
Build : SUCCESSBuild number : 1644 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 1276 |
Test : FAILUREBuild number : 1433 |
NRF52 Flash cache test issue... |
Test : SUCCESSBuild number : 1442 |
Anything needed for this PR? |
@mmahadevan108 We're waiting on a resolution on a GitHub issue that's affecting pr-head. Once it's resolved, we'll relaunch pr-head and hopefully merge this PR in. |
Green 🎊 PR head was fixed |
I'll rerun CI to get the latest results /morph build |
Build : SUCCESSBuild number : 1771 Triggering tests/morph test |
Exporter Build : FAILUREBuild number : 1411 |
ಠ_ಠ /morph export-build |
Test : SUCCESSBuild number : 1581 |
Exporter Build : SUCCESSBuild number : 1419 |
LPC546XX: Add TRNG support
| LPC546XX-ARM | LPC546XX | mbed-os-tests-mbedtls-multi |
Crypto: sha256_multi | 1 | 0 | OK
| 0.82 |
| LPC546XX-ARM | LPC546XX | mbed-os-tests-mbedtls-multi |
Crypto: sha256_split | 1 | 0 | OK
| 0.28 |
| LPC546XX-ARM | LPC546XX | mbed-os-tests-mbedtls-selftest |
mbedtls_entropy_self_test | 1 | 0 | OK
| 0.12 |
| LPC546XX-ARM | LPC546XX | mbed-os-tests-mbedtls-selftest |
mbedtls_sha256_self_test | 1 | 0 | OK
| 0.98 |
| LPC546XX-ARM | LPC546XX | mbed-os-tests-mbedtls-selftest |
mbedtls_sha512_self_test | 1 | 0 | OK
| 2.1 |