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

native_simulator: ensure nsi_host_random() returns 64 bits of randomness #83428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xudongzheng
Copy link
Contributor

With native_sim/native/64, nsi_host_random() was only populating 31 of the 64 bits due to the 31-bit limit of the random() function.

To reproduce issue:

CONFIG_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_FAKE_ENTROPY_NATIVE_POSIX=y
#include <zephyr/logging/log.h>
#include <zephyr/random/random.h>

LOG_MODULE_REGISTER(hello);

int main(void) {
	uint8_t test[128];
	sys_csrand_get(test, sizeof(test));
	LOG_HEXDUMP_INF(test, sizeof(test), "test");
	return 0;
}

Output:

[00:00:00.000,000] <inf> hello: test
                                3b db 31 0f 00 00 00 00  cc b6 d5 47 00 00 00 00 |;.1..... ...G....
                                08 aa d2 15 00 00 00 00  e1 be 87 53 00 00 00 00 |........ ...S....
                                e4 7b 88 04 00 00 00 00  ae b1 9d 5f 00 00 00 00 |.{...... ..._....
                                e6 88 9e 4d 00 00 00 00  fb 2d 97 15 00 00 00 00 |...M.... .-......
                                50 16 f7 13 00 00 00 00  28 31 2f 70 00 00 00 00 |P....... (1/p....
                                c0 e6 44 39 00 00 00 00  e9 be 5f 25 00 00 00 00 |..D9.... .._%....
                                36 dc af 46 00 00 00 00  ef 48 d1 72 00 00 00 00 |6..F.... .H.r....
                                ed 48 03 3a 00 00 00 00  6d aa 0f 7e 00 00 00 00 |.H.:.... m..~....

@zephyrbot zephyrbot added the area: native port Host native arch port (native_sim) label Dec 28, 2024
@zephyrbot zephyrbot requested a review from aescolar December 28, 2024 02:43
With native_sim/native/64, nsi_host_random() was only populating
31 of the 64 bits due to the 31-bit limit of the random() function.

Signed-off-by: Xudong Zheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: native port Host native arch port (native_sim)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants