Interfaces Related to RSA
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 43 44 45 46 47 48 49 50 51 52 53 54 | /* RSA message format of Warpdrive */ struct wcrypto_rsa_msg { __u8 alg_type:3;/* Denoted by enum wcrypto_type */ __u8 op_type:2;/* Denoted by enum wcrypto_rsa_op_type */ __u8 key_type:2;/* Denoted by enum wcrypto_rsa_key_type */ __u8 data_fmt:1; /* Data format, denoted by enum wd_buff_type */ __u8 result;/* Data format, denoted by WD error code */ __u16 in_bytes;/* Input data bytes */ __u16 out_bytes;/* Output data bytes */ __u16 key_bytes;/* Input key bytes */ __u8 *in;/* Input data VA, buf should be DMA buffer. */ __u8 *out;/* Output data VA pointer, should be DMA buffer */ __u8 *key;/* Input key VA pointer, should be DMA buffer */ __u64 usr_data;/* Input user tag, used for indentify data stream/user: struct wcrypto_cb_tag */ }; /* RSA operational types */ enum wcrypto_rsa_op_type { WCRYPTO_RSA_INVALID,/* invalid rsa operation */ WCRYPTO_RSA_SIGN,/* RSA sign */ WCRYPTO_RSA_VERIFY,/* RSA verify */ WCRYPTO_RSA_GENKEY,/* RSA key generation */ }; /* RSA key types */ enum wcrypto_rsa_key_type { WCRYPTO_RSA_INVALID_KEY, /* invalid rsa key type */ WCRYPTO_RSA_PUBKEY,/* rsa publick key type */ WCRYPTO_RSA_PRIKEY1,/* invalid rsa private common key type */ WCRYPTO_RSA_PRIKEY2, /* invalid rsa private CRT key type */ }; struct wcrypto_rsa_kg_in; /* rsa key generation input parameters */ struct wcrypto_rsa_kg_out;/* rsa key generation output parameters */ struct wcrypto_rsa_pubkey;/* rsa public key */ struct wcrypto_rsa_prikey;/* rsa private key */ /* RSA context setting up input parameters from user */ struct wcrypto_rsa_ctx_setup { wcrypto_cb cb;/* call back function from user */ __u16 data_fmt;/* data format denoted by enum wd_buff_type */ __u16 key_bits;/* RSA key bits */ bool is_crt;/* CRT mode or not */ struct wd_mm_br br;/* memory operations from user */ }; struct wcrypto_rsa_op_data { enum wcrypto_rsa_op_type op_type; /* rsa operation type */ int status; /* rsa operation status */ void *in; /* rsa operation input address, should be DMA-able */ void *out; /* rsa operation output address, should be DMA-able */ __u32 in_bytes;/* rsa operation input bytes */ __u32 out_bytes; /* rsa operation output bytes */ }; |
Prototype |
bool wcrypto_rsa_is_crt(void *ctx); |
|---|---|
Function |
Check whether an RSA context is in CRT mode. |
Input Description |
ctx: RSA context |
Output Description |
None |
Return Value Description |
True: CRT mode False: non-CRT mode |
Usage Instruction |
|
Precautions |
Prototype |
int wcrypto_rsa_key_bits(void *ctx); |
|---|---|
Function |
Obtain the width of the RSA context key (bits). |
Input Description |
ctx: RSA context |
Output Description |
None |
Return Value Description |
RSA key width (bits) |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_get_rsa_pubkey(void *ctx, struct wcrypto_rsa_pubkey **pubkey); |
|---|---|
Function |
Obtain the public key of the RSA context. |
Input Description |
ctx: RSA context pubkey: address of the public key pointer of RSA |
Output Description |
pubkey: address of the public key of RSA |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_get_rsa_prikey(void *ctx, struct wcrypto_rsa_prikey **prikey); |
|---|---|
Function |
Obtain the private key of the RSA context. |
Input Description |
ctx: RSA context prikey: address of the private key pointer of RSA |
Output Description |
prikey: address of the private key of RSA |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
int wcrypto_set_rsa_pubkey_params(void *ctx, struct wd_dtb *e, struct wd_dtb *n); |
|---|---|
Function |
Set the public key parameters of the RSA context. |
Input Description |
ctx: RSA context e: e parameter of RSA n: n parameter of RSA |
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_rsa_pubkey_params(struct wcrypto_rsa_pubkey *pbk, struct wd_dtb **e, struct wd_dtb **n); |
|---|---|
Function |
Obtain public key parameters using the RSA public key. |
Input Description |
pbk: RSA public key e: e parameter address pointer of RSA n: n parameter address pointer of RSA |
Output Description |
e: e parameter address of RSA n: n parameter address of RSA |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
int wcrypto_set_rsa_prikey_params(void *ctx, struct wd_dtb *d, struct wd_dtb *n); |
|---|---|
Function |
Set the private key parameters of the RSA context. |
Input Description |
ctx: RSA context d: d parameter of RSA n: n parameter of RSA |
Output Description |
None |
Return Value Description |
0: success -WD_EINVAL: failure (For details about error codes, see WD Message Error Code Interface.) |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_get_rsa_prikey_params(struct wcrypto_rsa_prikey *pvk, struct wd_dtb **d,struct wd_dtb **n); |
|---|---|
Function |
Obtain private key parameters using the RSA private key. |
Input Description |
pvk: RSA private key d: d parameter address pointer of RSA n: n parameter address pointer of RSA |
Output Description |
d: d parameter address of RSA n: n parameter address of RSA |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
int wcrypto_set_rsa_crt_prikey_params(void *ctx, struct wd_dtb *dq, struct wd_dtb *dp,struct wd_dtb *qinv, struct wd_dtb *q, struct wd_dtb *p); |
|---|---|
Function |
Set the private key CRT parameter of the RSA context. |
Input Description |
ctx: RSA context dq: dq parameter of RSA dp: dp parameter of RSA qinv: qinv parameter of RSA q: q parameter of RSA p: p parameter of RSA |
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_rsa_crt_prikey_params(struct wcrypto_rsa_prikey *pvk, struct wd_dtb **dq, struct wd_dtb **dp, struct wd_dtb **qinv, struct wd_dtb **q, struct wd_dtb **p); |
|---|---|
Function |
Obtain the CRT parameter using the RSA private key. |
Input Description |
pvk: RSA private key dq: dq parameter address pointer of RSA dp: dp parameter address pointer of RSA qinv: qinv parameter address pointer of RSA q: q parameter address pointer of RSA p: p parameter address pointer of RSA |
Output Description |
dq: dq parameter address of RSA dp: dp parameter address of RSA qinv: qinv parameter address of RSA q: q parameter address of RSA p: p parameter address of RSA |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
struct wcrypto_rsa_kg_in *wcrypto_new_kg_in(void *ctx, struct wd_dtb *e, struct wd_dtb *p, struct wd_dtb *q); |
|---|---|
Function |
Create an input parameter set of the RSA private key based on a specified ctx. |
Input Description |
ctx: RSA context e: e parameter of RSA q: q parameter of RSA p: p parameter of RSA |
Output Description |
None |
Return Value Description |
A non-NULL value: success NULL: failure |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_del_kg_in(void *ctx, struct wcrypto_rsa_kg_in *ki); |
|---|---|
Function |
Delete the input parameter set of the private key based on an RSA context. |
Input Description |
ctx: RSA context ki: input parameter set generated by the RSA key |
Output Description |
None |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_get_rsa_kg_in_params(struct wcrypto_rsa_kg_in *kin, struct wd_dtb *e, struct wd_dtb *q, struct wd_dtb *p); |
|---|---|
Function |
Generate an input parameter set based on the RSA key to obtain the input parameters. |
Input Description |
kin: input parameter set generated by the RSA key e: e parameter address of RSA q: q parameter address of RSA p: p parameter address of RSA |
Output Description |
e: e parameter of RSA q: q parameter of RSA p: p parameter of RSA |
Return Value Description |
None |
Usage Instruction |
Southbound API |
Precautions |
Prototype |
struct wcrypto_rsa_kg_out * wcrypto_new_kg_out(void *ctx); |
|---|---|
Function |
Create an output parameter set of the RSA private key based on a specified ctx. |
Input Description |
ctx: RSA context |
Output Description |
None |
Return Value Description |
A non-NULL value: success NULL: failure |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_del_kg_out(void *ctx, struct wcrypto_rsa_kg_out *kout); |
|---|---|
Function |
Delete the output parameter set of the RSA private key based on a specified ctx. |
Input Description |
ctx: RSA context kout: output parameter set generated by the RSA key |
Output Description |
None |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_get_rsa_kg_out_params(struct wcrypto_rsa_kg_out *kout, struct wd_dtb *d, struct wd_dtb *n); |
|---|---|
Function |
Generate an output parameter set based on the RSA key to obtain the output parameters. |
Input Description |
kout: output parameter set generated by the RSA key d: d parameter address of RSA n: n parameter address of RSA |
Output Description |
d: d parameter of RSA n: n parameter of RSA |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
void wcrypto_get_rsa_kg_out_crt_params(struct wcrypto_rsa_kg_out *kout, struct wd_dtb *qinv, struct wd_dtb *dq, struct wd_dtb *dp); |
|---|---|
Function |
Generate an output parameter set based on the RSA key in CRT mode to obtain the output parameters. |
Input Description |
kout: output parameter set generated by the RSA key qinv: qinv parameter address of RSA in CRT mode dq: dq parameter address of RSA in CRT mode dp: dp parameter address of RSA in CRT mode |
Output Description |
qinv: qinv parameter of RSA in CRT mode dq: dq parameter of RSA in CRT mode dp: dp parameter of RSA in CRT mode |
Return Value Description |
None |
Usage Instruction |
|
Precautions |
Prototype |
int wcrypto_rsa_kg_in_data(struct wcrypto_rsa_kg_in *ki, char **data); |
|---|---|
Function |
Generate an input parameter set based on the RSA key to obtain the data domain of the input parameters. |
Input Description |
ki: input parameter set generated by the RSA key |
Output Description |
data: data domain address of the input parameter set |
Return Value Description |
0: success Others: failure (For details about error codes, see WD Message Error Code Interface.) |
Usage Instruction |
Southbound API |
Precautions |
Prototype |
int wcrypto_rsa_kg_out_data(struct wcrypto_rsa_kg_out *ko, char **data); |
|---|---|
Function |
Generate an output parameter set based on the RSA key to obtain the data domain of the output parameters. |
Input Description |
ko: output parameter set generated by the RSA key |
Output Description |
data: data domain address of the output parameter set |
Return Value Description |
0: success Others: failure (For details about error codes, see WD Message Error Code Interface.) |
Usage Instruction |
Southbound API |
Precautions |
Prototype |
void * wcrypto_create_rsa_ctx(struct wd_queue *q, struct wcrypto_rsa_ctx_setup *setup); |
|---|---|
Function |
Create a context based on the WD queue that supports RSA. |
Input Description |
q: WD queue setup: context parameter set specified by the user |
Output Description |
None |
Return Value Description |
A non-NULL value: success NULL: failure |
Usage Instruction |
Multiple threads are supported. |
Precautions |
Prototype |
int wcrypto_do_rsa(void *ctx, struct wcrypto_rsa_op_data *opdata, void *tag); |
|---|---|
Function |
Perform RSA operations based on the RSA context. |
Input Description |
ctx: RSA context opdata: RSA 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 Other negative values: failure (-WD_VERIFY_ERR: RSA verification failure; -WD_HWDT_MISMATCH: input values do not match the data length, format, and alignment mode required by the hardware; -WD_SGL_ERR: SGL input error; -WD_HW_EACCESS: hardware unavailable, such as hardware reset; -WD_EINVAL: other errors) |
Usage Instruction |
One ctx supports only one thread. |
Precautions |
Prototype |
int wcrypto_rsa_poll(struct wd_queue *q, unsigned int num); |
|---|---|
Function |
Perform RSA poll operations based on the WD queue. |
Input Description |
q: WD RSA 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 (-WD_HW_EACCESS: hardware unavailable, such as hardware reset; -WD_EINVAL: other errors) |
Usage Instruction |
One q supports only one thread. |
Precautions |
For details about the status error code in the response message, see WD Message Error Code Interface. |
Prototype |
void wcrypto_del_rsa_ctx(void *ctx); |
|---|---|
Function |
Delete an RSA context. |
Input Description |
ctx: RSA context to be deleted |
Output Description |
None |
Return Value Description |
None |
Usage Instruction |
|
Precautions |