Rate This Document
Findability
Accuracy
Completeness
Readability

Interfaces Related to DH

 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
38
39
40
41
42
struct wcrypto_dh_msg {
__u8 alg_type:3;/* Denoted by enum wcrypto_type */
__u8 op_type:2;/* Denoted by enum wcrypto_dh_op_type */
__u8 data_fmt:1; /* Data format, denoted by enum wd_buff_type */
__u8 is_g2:2;/* g2 mode of phase 1 */
__u8 result;/* Data format, denoted by WD error code */
__u16 key_bytes;/* Key size */
__u8 *x_p; /* This is Xa and p data in order. Should be DMA buffer */
__u8 *g; /* This is PV also at phase 2. Should be DMA buffer*/
__u8 *out; /* Result address, should be DMA buffer */
__u16 xbytes; /* parameter Xa size */
__u16 pbytes; /* parameter p size */
__u16 gbytes; /* parameter g size */
__u16 out_bytes; /* output parameter size */
__u64 usr_data; /* user identifier: struct wcrypto_cb_tag */
};

enum wcrypto_dh_op_type {
WCRYPTO_DH_INVALID, /* invalid DH operation */
WCRYPTO_DH_PHASE1,/* Phase1 DH key generate */
WCRYPTO_DH_PHASE2,/* Phase2 DH key compute */
};

struct wcrypto_dh_ctx_setup {
wcrypto_cb cb; /* call back function from user */
__u16 data_fmt; /* data format denoted by enum wd_buff_type */
__u16 key_bits;/* DH key bites */
bool is_g2; /* is g2 mode or not */
struct wd_mm_br br; /* memory operations from user */
};

struct wcrypto_dh_op_data {
void *x_p; /* x and p, should be DMA buffer */
void *pv;/* it is g, but it is PV at phase 2, should be DMA buffer */
void *pri;/* phase 1&&2 output, should be DMA buffer */
__u16 pri_bytes;/* output bytes */
__u16 pbytes; /* p bytes */
__u16 xbytes; /* x bytes */
__u16 pvbytes; /* pv bytes */
enum wcrypto_dh_op_type op_type; /* operational type */
__u32 status;/* output status  */
};

Prototype

bool wcrypto_dh_is_g2(void *ctx);

Function

Check whether a DH context is in G2 mode.

Input Description

ctx: DH context

Output Description

None

Return Value Description

True: G2 mode

False: non-G2 mode

Usage Instruction

  

Precautions

  

Prototype

int wcrypto_dh_key_bits(void *ctx);

Function

Obtain the width of the DH context key (bits).

Input Description

ctx: DH context

Output Description

None

Return Value Description

Width of the DH context key (768, 1024, 1536, 2048, 3072, or 4096 bits)

Usage Instruction

  

Precautions

  

Prototype

void * wcrypto_create_dh_ctx(struct wd_queue *q, struct wcrypto_dh_ctx_setup *setup);

Function

Create a DH 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_dh(void *ctx, struct wcrypto_dh_op_data *opdata, void *tag);

Function

Perform DH operations based on the DH context.

Input Description

ctx: DH context

opdata: DH 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 (For details about error codes, see WD Message Error Code Interface.)

Usage Instruction

One ctx supports only one thread.

Precautions

  

Prototype

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

Function

Perform DH poll operations based on the WD queue.

Input Description

q: WD DH 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_dh_ctx(void *ctx);

Function

Delete a DH context.

Input Description

ctx: DH context to be deleted

Output Description

None

Return Value Description

None

Usage Instruction

  

Precautions

  

Prototype

int wcrypto_set_dh_g(void *ctx, struct wd_dtb *g);

Function

Set the g parameter of the DH context.

Input Description

ctx: DH context

g: g parameter of DH

Output Description

None

Return Value Description

0: success

Others: failure (For details about error codes, see WD Message Error Code Interface.)

Usage Instruction

  

Precautions

  

Prototype

void wcrypto_get_dh_g(void *ctx, struct wd_dtb **g);

Function

Obtain the g parameter based on the DH context.

Input Description

ctx: DH context

g: g parameter address of DH

Output Description

None

Return Value Description

None

Usage Instruction

  

Precautions