Skip to content

Commit

Permalink
random: Rename random header
Browse files Browse the repository at this point in the history
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.

Rename it to random.h and get consistently with other
subsystems.

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
Flavio Ceolin authored and jhedberg committed Oct 10, 2023
1 parent c928e3b commit e7bd10a
Show file tree
Hide file tree
Showing 133 changed files with 225 additions and 206 deletions.
2 changes: 1 addition & 1 deletion drivers/entropy/entropy_mcux_caam.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <zephyr/device.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>

Expand Down
2 changes: 1 addition & 1 deletion drivers/entropy/entropy_mcux_css.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <zephyr/device.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/init.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

static int entropy_mcux_css_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/entropy/entropy_mcux_rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <zephyr/device.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/init.h>

#include "fsl_rng.h"
Expand Down
2 changes: 1 addition & 1 deletion drivers/entropy/entropy_mcux_rnga.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <zephyr/device.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/init.h>

#include "fsl_rnga.h"
Expand Down
2 changes: 1 addition & 1 deletion drivers/entropy/entropy_mcux_trng.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <zephyr/device.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/init.h>

#include "fsl_trng.h"
Expand Down
2 changes: 1 addition & 1 deletion drivers/entropy/entropy_rv32m1_trng.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <zephyr/device.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/init.h>

#include "fsl_trng.h"
Expand Down
2 changes: 1 addition & 1 deletion drivers/entropy/entropy_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/init.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/util.h>
Expand Down
2 changes: 1 addition & 1 deletion drivers/ethernet/eth.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define ZEPHYR_DRIVERS_ETHERNET_ETH_H_

#include <zephyr/types.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

/* helper macro to return mac address octet from local_mac_address prop */
#define NODE_MAC_ADDR_OCTET(node, n) DT_PROP_BY_IDX(node, local_mac_address, n)
Expand Down
2 changes: 1 addition & 1 deletion drivers/flash/flash_simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/stats/stats.h>
#include <string.h>

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_b91.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/net/ieee802154_radio.h>
#include <zephyr/irq.h>
#if defined(CONFIG_NET_L2_OPENTHREAD)
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_cc1200.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include <zephyr/sys/byteorder.h>
#include <string.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include <zephyr/drivers/spi.h>
#include <zephyr/drivers/gpio.h>
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(ieee802154_cc13xx_cc26xx);
#include <zephyr/net/ieee802154_radio.h>
#include <zephyr/net/ieee802154.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <string.h>
#include <zephyr/sys/sys_io.h>

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_cc13xx_cc26xx_subg.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(ieee802154_cc13xx_cc26xx_subg);
#include <zephyr/net/ieee802154.h>
#include <zephyr/net/ieee802154_radio.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/crc.h>
#include <zephyr/sys/sys_io.h>
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_cc2520.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include <zephyr/sys/byteorder.h>
#include <string.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include <zephyr/drivers/gpio.h>

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_dw1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LOG_MODULE_REGISTER(dw1000, LOG_LEVEL_INF);

#include <zephyr/sys/byteorder.h>
#include <string.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/debug/stack.h>
#include <math.h>

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_kw41z.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include "fsl_xcvr.h"

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_mcr20a.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include <zephyr/sys/byteorder.h>
#include <string.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/debug/stack.h>

#include <zephyr/drivers/gpio.h>
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_nrf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include <zephyr/sys/byteorder.h>
#include <string.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include <zephyr/net/ieee802154_radio.h>
#include <zephyr/irq.h>
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_rf2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include <zephyr/sys/byteorder.h>
#include <string.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/linker/sections.h>
#include <zephyr/sys/atomic.h>

Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_uart_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr/init.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include <zephyr/drivers/uart_pipe.h>
#include <zephyr/net/ieee802154_radio.h>
Expand Down
2 changes: 1 addition & 1 deletion drivers/modem/wncm14a2a.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
#include <zephyr/drivers/gpio.h>
#include <zephyr/device.h>
#include <zephyr/init.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include <zephyr/net/net_context.h>
#include <zephyr/net/net_if.h>
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LOG_MODULE_REGISTER(net_ppp, LOG_LEVEL);
#include <zephyr/sys/crc.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/drivers/console/uart_mux.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include "../../subsys/net/ip/net_stats.h"
#include "../../subsys/net/ip/net_private.h"
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/slip.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr/net/net_core.h>
#include <zephyr/net/dummy.h>
#include <zephyr/drivers/uart_pipe.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>

#include "slip.h"

Expand Down
77 changes: 3 additions & 74 deletions include/zephyr/random/rand32.h
Original file line number Diff line number Diff line change
@@ -1,86 +1,15 @@
/*
* Copyright (c) 2013-2014 Wind River Systems, Inc.
* Copyright (c) 2023 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Random number generator header file
*
* This header file declares prototypes for the kernel's random number
* generator APIs.
*
* Typically, a platform enables the appropriate source for the random
* number generation based on the hardware platform's capabilities or
* (for testing purposes only) enables the TEST_RANDOM_GENERATOR
* configuration option.
*/

#ifndef ZEPHYR_INCLUDE_RANDOM_RAND32_H_
#define ZEPHYR_INCLUDE_RANDOM_RAND32_H_

#include <zephyr/types.h>
#include <stddef.h>
#include <zephyr/kernel.h>

/**
* @brief Random Function APIs
* @defgroup random_api Random Function APIs
* @ingroup crypto
* @{
*/

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Return a 32-bit random value that should pass general
* randomness tests.
*
* @note The random value returned is not a cryptographically secure
* random number value.
*
* @return 32-bit random value.
*/
__syscall uint32_t sys_rand32_get(void);

/**
* @brief Fill the destination buffer with random data values that should
* pass general randomness tests.
*
* @note The random values returned are not considered cryptographically
* secure random number values.
*
* @param [out] dst destination buffer to fill with random data.
* @param len size of the destination buffer.
*
*/
__syscall void sys_rand_get(void *dst, size_t len);

/**
* @brief Fill the destination buffer with cryptographically secure
* random data values.
*
* @note If the random values requested do not need to be cryptographically
* secure then use sys_rand_get() instead.
*
* @param [out] dst destination buffer to fill.
* @param len size of the destination buffer.
*
* @return 0 if success, -EIO if entropy reseed error
*
*/
__syscall int sys_csrand_get(void *dst, size_t len);

#ifdef __cplusplus
}
#endif
#include <zephyr/random/random.h>

/**
* @}
*/
#warning "<zephyr/random/rand32.h> is deprecated, include <zephyr/random/random.h> instead"

#include <syscalls/rand32.h>
#endif /* ZEPHYR_INCLUDE_RANDOM_RAND32_H_ */
87 changes: 87 additions & 0 deletions include/zephyr/random/random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2013-2014 Wind River Systems, Inc.
* Copyright (c) 2023 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Random number generator header file
*
* This header file declares prototypes for the kernel's random number
* generator APIs.
*
* Typically, a platform enables the appropriate source for the random
* number generation based on the hardware platform's capabilities or
* (for testing purposes only) enables the TEST_RANDOM_GENERATOR
* configuration option.
*/

#ifndef ZEPHYR_INCLUDE_RANDOM_RANDOM_H_
#define ZEPHYR_INCLUDE_RANDOM_RANDOM_H_

#include <zephyr/types.h>
#include <stddef.h>
#include <zephyr/kernel.h>

/**
* @brief Random Function APIs
* @defgroup random_api Random Function APIs
* @ingroup crypto
* @{
*/

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Return a 32-bit random value that should pass general
* randomness tests.
*
* @note The random value returned is not a cryptographically secure
* random number value.
*
* @return 32-bit random value.
*/
__syscall uint32_t sys_rand32_get(void);

/**
* @brief Fill the destination buffer with random data values that should
* pass general randomness tests.
*
* @note The random values returned are not considered cryptographically
* secure random number values.
*
* @param [out] dst destination buffer to fill with random data.
* @param len size of the destination buffer.
*
*/
__syscall void sys_rand_get(void *dst, size_t len);

/**
* @brief Fill the destination buffer with cryptographically secure
* random data values.
*
* @note If the random values requested do not need to be cryptographically
* secure then use sys_rand_get() instead.
*
* @param [out] dst destination buffer to fill.
* @param len size of the destination buffer.
*
* @return 0 if success, -EIO if entropy reseed error
*
*/
__syscall int sys_csrand_get(void *dst, size_t len);

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#include <syscalls/random.h>
#endif /* ZEPHYR_INCLUDE_RANDOM_RANDOM_H_ */
2 changes: 1 addition & 1 deletion kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/debug/stack.h>
#include <zephyr/random/rand32.h>
#include <zephyr/random/random.h>
#include <zephyr/linker/sections.h>
#include <zephyr/toolchain.h>
#include <zephyr/kernel_structs.h>
Expand Down
Loading

0 comments on commit e7bd10a

Please sign in to comment.