-
Notifications
You must be signed in to change notification settings - Fork 3k
Nuvoton: Re-implement TRNG HAL with TRNG H/W #11650
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
Nuvoton: Re-implement TRNG HAL with TRNG H/W #11650
Conversation
@ccli8, thank you for your changes. |
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.
@Patater please review
"TRNG initialization counter would overflow"); | ||
} | ||
core_util_atomic_incr_u16(&trng_init_counter, 1); | ||
if (trng_init_counter == 1) { |
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.
Re-reading the counter isn't atomic - you need to look at the return value of the increment function.
if (trng_init_counter == 1) { | |
if (core_util_atomic_incr_u16(&trng_init_counter, 1) == 1) { |
Although here you're inside a critical section anyway, meaning you don't need the atomic increment at all, you can just do ++trng_init_counter
.
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.
Fixed
switch(id) | ||
{ | ||
case CURVE_P_192: | ||
p32[ 0] = 0x00000000; |
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 really a code-size win over just memcpy
ing from the const ECC_CURVE
table?
Even if it is, I suspect you could get an equivalent saving by just changing the char Ea[144]
etc members to const char *Ea
, which removes the need to store zero-padding.
(Beyond that, why store in hex rather than binary anyway?)
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 above code is for XOM (execute-only ROM). On mbed-os, it is disabled (XOM_SUPPORT
== 0).
Beyond that, why store in hex rather than binary anyway?
The curve definition source is in hex form. No further conversion.
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 above code is for XOM (execute-only ROM).
Okay, not relevant here, but a bit puzzled. Maybe there's something I'm missing.
If you're having problems with not being able to access const
data in execute-only ROM, there's something wrong with your memory map and/or linker/compiler setup. Execute-only ROM shouldn't be breaking basic concepts like being able to access const
data objects.
If really necessary in some environment, the build should be placing read-only data regions in RAM via the linker map.
Edit: oh, is that the point? You're having to resort to putting const data objects in RAM, which makes the other form work, but use a lot of RAM? So this form forces ROM use via code instead, even if clunky?
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.
@kjbracey-arm Why const
data not place in normal ROM? This is security consideration. The major purpose of XOM is non-readable. If XOM code references const
data in another ROM, compromising the ROM means compromising the XOM indirectly.
Anyway, XOM is not used on mbed-os, so just ignore it.
6800f29
to
cd63c09
Compare
Make modifications:
|
I have searched for some documentation and these were the best I could find: These have very limited information on the TRNGs in these targets. Where can I find more information on these TRNGs? |
@yanesca Sorry about that. Detailed spec is not open. However, you can find register definition in:
|
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.
LGTM
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.
One question otherwise looks fine to me
static uint16_t trng_init_counter = 0U; | ||
|
||
/* Mutex for synchronizing access to TRNG H/W */ | ||
static SingletonPtr<PlatformMutex> trng_mutex; |
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 needed? Because the upper layer takes care of this - HAL does not by default.
I assume this TRNG is just one peripheral so this is not taking care of sync in HAL layer when there are multiple users of this peripheral, there's just one trng hal? Or this is connected to secure/non secure thus this lock is needed.
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.
@0xc0170 Yes. It is unnecessary. mbedtls_mutex has done. Removed it.
Re-implement __PC() by replacing BSP assembly with toolchain built-in.
Related targets: - NU_PFM_M2351_* - NUMAKER_IOT_M263A
cd63c09
to
0bb8034
Compare
Make modifications:
|
Targets supporting TRNG H/W: - NU_PFM_M2351_* - NUMAKER_IOT_M263A
Update for change of TRNG security attribute
0bb8034
to
8161386
Compare
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
This PR is conclusion of #11176 (comment) and tries to re-implement TRNG HAL with TRNG H/W on targets which support it.
Support targets:
@cyliangtw
Related PR
#11176 (comment)
Pull request type
Reviewers
@kjbracey-arm @yanesca