Skip to content

Port the network stack to use the randombytes RTOS API rather than having each compartment re-implement rand(). - #121

Merged
davidchisnall merged 1 commit into
CHERIoT-Platform:mainfrom
resistor:rand
Aug 25, 2026
Merged

Port the network stack to use the randombytes RTOS API rather than having each compartment re-implement rand().#121
davidchisnall merged 1 commit into
CHERIoT-Platform:mainfrom
resistor:rand

Conversation

@resistor

Copy link
Copy Markdown
Member

No description provided.

@resistor
resistor marked this pull request as ready for review August 18, 2026 15:38
@resistor
resistor force-pushed the rand branch 4 times, most recently from e8ff670 to e9d6eef Compare August 19, 2026 14:45

@davidchisnall davidchisnall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left one comment but it applies across the rest.

I’m not sure when we can merge this. We try hard to avoid the requirement to version bump the RTOS and network stack at the same time, but these all use the helper that was added to the RTOS yesterday, so merging this means anyone using this needs to have yesterday’s RTOS or newer. The helper means that we can’t just gate this on the existence of the randombytes.h header and fall back to the old version.

Once we merge this, we’ll have a flag day. We should delete all of the old compatibility code in other places at the same time.

Comment thread lib/dns/dns.cc Outdated
// Prepare the query answer buffer and ID for the new query.
memset(&queryResult, 0, sizeof(NetworkAddress));
queryID = rand();
if (!randombytes(queryID))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Our style recommends using explicit != 0, rather than relying on implicit conversion to bool, to make it clear that the return is not Boolean.

It might be better to return the error code that randombytes returns, rather than -EAGAIN. For example, if this returns a not-enough-stack / trusted stack error then the caller can’t just retry and expect success in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@resistor

Copy link
Copy Markdown
Member Author

Once we merge this, we’ll have a flag day. We should delete all of the old compatibility code in other places at the same time.

Actually, I came up with some concepts trickery to allow this network stack to re-define the wrappers if they're not available from the RTOS. That should let us avoid a flag day.

@davidchisnall
davidchisnall merged commit 28cfb98 into CHERIoT-Platform:main Aug 25, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants