Rate This Document
Findability
Accuracy
Completeness
Readability

RNG Interfaces for Obtaining Random Numbers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
struct wcrypto_rng_msg {
__u8 alg_type; /* Denoted by enum wcrypto_type */
__u8 op_type;/* Denoted by enum wcrypto_rng_op_type */
__u8 data_fmt; /* Data format, denoted by enum wd_buff_type */
__u8 result;/* Data format, denoted by WD error code */
__u8 *out; /* Result address */
__u8 *in; /* Input address */
__u32 out_bytes; /* output bytes */
__u32 in_bytes; /* input bytes */
__u64 usr_tag; /* user identifier */
};

enum wcrypto_rng_op_type {
WCRYPTO_RNG_INVALID,/* Invalid RNG operational type */
WCRYPTO_DRBG_RESEED,/* seed operation */
WCRYPTO_DRBG_GEN,/* deterministic random number generation */
WCRYPTO_TRNG_GEN, /* true random number generation */
};

struct wcrypto_rng_ctx_setup {
wcrypto_cb cb;
__u16 data_fmt; /* Data format, denoted by enum wd_buff_type */
enum wcrypto_type type;/* Please refer to the definition of enum */
enum wcrypto_cipher_alg calg;/* DRBG cipher algorithm */
enum wcrypto_cipher_mode cmode; /* DRBG cipher mode */
enum wcrypto_digest_alg dalg; /* DRBG digest algorithm */
enum wcrypto_digest_mode dmode; /* DRBG digest mode */
};

struct wcrypto_rng_op_data {
enum wcrypto_rng_op_type op_type;
__u32 status; /* Operation result status */
void *in;/* input */
void *out; /* output */
__u32 in_bytes; /* input bytes */
__u32 out_bytes; /* output bytes */
};

Prototype

void * wcrypto_create_rng_ctx(struct wd_queue *q, struct wcrypto_rng_ctx_setup *setup);

Function

Create an RNG context based on the WD queue.

Input Description

q: WD queue

setup: context creation input parameter

Output Description

None

Return Value Description

Context address.

NULL: failure

A non-NULL value: success

Usage Instruction

Multiple threads are supported.

Precautions

  

Prototype

int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag);

Function

Perform RNG operations based on the RNG context.

Input Description

ctx: RNG context

opdata: RNG operation parameters, including the input, output, and operation types

tag: user callback. If the value is NULL, the interface is a synchronous interface. Otherwise, the interface is an asynchronous interface.

Output Description

None

Return Value Description

0: success

Others: failure

Usage Instruction

One ctx supports only one thread.

Precautions

  

Prototype

int wcrypto_rng_poll(struct wd_queue *q, unsigned int num);

Function

Perform RNG poll operations based on the WD queue.

Input Description

q: WD RNG queue

num: 0 indicates that all response messages in queue q are received. A non-0 value indicates the number of response messages received in queue q.

Output Description

None

Return Value Description

A value greater than 0: number of the received response messages

0: No response message is received.

A negative value: poll error

Usage Instruction

One q supports only one thread.

Precautions

  

Prototype

void wcrypto_del_rng_ctx(void *ctx);

Function

Delete an RNG context.

Input Description

ctx: RNG context to be deleted

Output Description

None

Return Value Description

None

Usage Instruction

  

Precautions