RNG API#
Random number generation is a crucial component of cryptography, used to create keys and prevent attackers from predicting or replicating patterns in data. It is typically implemented using specialized algorithms or hardware.
Data Structures#
-
struct alc_rng_info_t#
Store info about RNG.
- Param ri_type:
Store info about type of RNG used
- Param ri_source:
Store info about source of RNG used
- Param ri_distrib:
Store info about distribution used for RNG
- Param ri_flagsStore:
info about algorithm used for RNG
-
struct alc_rng_handle_t#
Handle for maintaining session.
- Param rh_context:
pointer to the context of the rng
Functions#
-
alc_error_t alcp_rng_supported(const alc_rng_info_p pRngInfo)#
Query Library if the given configuration is supported.
This API needs to be called before any other API is called to know if RNG that is being request is supported or not
- Parameters:
pRngInfo – [in] Pointer to alc_rng_info_t structure
- Returns:
Error Code for the API called. If alc_error_t is not ALC_ERROR_NONE, an error has occurred and handle will be invalid for future operations
-
Uint64 alcp_rng_context_size(const alc_rng_info_p pRngInfo)#
Get the context/session size.
This API should be called before alcp_rng_request to identify the memory to be allocated for context
Note
User is expected to allocate for the session this function returns size to be allocated
- Parameters:
pRngInfo – [in] Pointer to RNG configuration
- Returns:
Uint64 Size of Rng Context
-
alc_error_t alcp_rng_request(const alc_rng_info_p pRngInfo, alc_rng_handle_p pRngHandle)#
Request an handle for given RNG configuration.
This API can be called after alcp_rng_supported and before alcp_rng_finish
Note
Requested algorithm may be first checked using alcp_rng_context_size and pHandle as allocated by user.
- Parameters:
pRngInfo – [in] Pointer to RNG configuration
pRngHandle – [out] Library populated session handle for future rng operations.
- Returns:
Error Code for the API called. If alc_error_t is not ALC_ERROR_NONE, an error has occurred and handle will be invalid for future operations
-
alc_error_t alcp_rng_gen_random(alc_rng_handle_p pRngHandle, Uint8 *pBuf, Uint64 size)#
Generate and fill buffer with random numbers.
This API can be called after alcp_rng_request and alcp_rng_init if hardware RNG requires it and before alcp_rng_finish
- Parameters:
pRngHandle – [in] Pointer to Handle
pBuf – [out] Pointer buffer that needs to be filled with random numbers
size – [in] size of pBuf
- Returns:
Error Code for the API called. If alc_error_t is not ALC_ERROR_NONE, an error has occurred and handle will be invalid for future operations
-
alc_error_t alcp_rng_init(alc_rng_handle_p pRngHandle)#
Initialize a random number generator.
This API can be called after alcp_rng_request and before alcp_rng_finish
Note
Some hardware RNGs require initialization
- Parameters:
pRngHandle – [in] Pointer to handle returned in alcp_rng_request()
- Returns:
Error Code for the API called. If alc_error_t is not ALC_ERROR_NONE, an error has occurred and handle will be invalid for future operations
-
alc_error_t alcp_rng_seed(alc_rng_handle_p pRngHandle, const Uint8 *seed, Uint64 size)#
Seed a PRNG or other if supported.
This API can be called after alcp_rng_request and alcp_rng_init if hardware RNG requires it. This API is called to reset data so should be called after alcp_rng_request and before alcp_rng_finish
- Parameters:
pRngHandle – [in] Pointer to user allocated handle
seed – [in] Pointer to seed
size – [in] Length of seed in bytes
- Returns:
Error Code for the API called. If alc_error_t is not ALC_ERROR_NONE, an error has occurred and handle will be invalid for future operations
-
alc_error_t alcp_rng_finish(alc_rng_handle_p pRngHandle)#
Complete a session.
This API is called to free resources so should be called to free the session
Note
Completes the session which was previously requested using alcp_rng_request
- Parameters:
pRngHandle – [in] Pointer to handle
- Returns:
Error Code for the API called. If alc_error_t is not ALC_ERROR_NONE, an error has occurred and handle will be invalid for future operations
Variables#
-
enum [anonymous] alc_rng_type_t#
Store info about type of RNG used.
-
enum [anonymous] alc_rng_source_t#
Store info about source of RNG used.
-
enum [anonymous] alc_rng_distrib_t#
Store info about distribution used for RNG.
-
enum _alc_rng_algo_flags alc_rng_algo_flags_t#
Store info about algorithm used for RNG.