Interfaces Related to Cipher
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 55 56 | /* Cipher message format of Warpdrive */ struct wcrypto_cipher_msg { __u8 alg_type:4;/* Denoted by enum wcrypto_alg_type */ __u8 alg:4;/* Denoted by enum wcrypto_cipher_alg*/ __u8 op_type:4;/* Denoted by enum wcrypto_cipher_op_type */ __u8 mode:4;/* Denoted by enum wcrypto_cipher_mode */ __u8 data_fmt;/* Data format, denoted by enum wd_buff_type */ __u8 result;/* Data format, denoted by WD error code */ __u16 key_bytes;/* Key bytes */ __u16 iv_bytes;/* IV bytes */ __u32 in_bytes;/* Input data bytes */ __u32 out_bytes;/* Output data bytes */ __u8 *key;/* Input key VA pointer, should be DMA buffer */ __u8 *iv;/* Input IV VA pointer, should be DMA buffer */ __u8 *in;/* Input data VA pointer, should be DMA buffer */ __u8 *out;/* Output data VA pointer, should be DMA buffer */ __u64 usr_data;/* user identifier: for example, can be struct wcrypto_cb_tag */ }; enum wcrypto_cipher_op_type { WCRYPTO_CIPHER_ENCRYPTION, WCRYPTO_CIPHER_DECRYPTION, }; enum wcrypto_cipher_alg { WCRYPTO_CIPHER_SM4, WCRYPTO_CIPHER_AES, WCRYPTO_CIPHER_DES, WCRYPTO_CIPHER_3DES, }; enum wcrypto_cipher_mode { WCRYPTO_CIPHER_ECB, WCRYPTO_CIPHER_CBC, WCRYPTO_CIPHER_CTR, WCRYPTO_CIPHER_XTS, }; struct wcrypto_cipher_ctx_setup { wcrypto_cb cb;/* call back function from user */ enum wcrypto_cipher_alg alg;/* cipher algorithm type */ enum wcrypto_cipher_mode mode;/* cipher algorithm mode */ struct wd_mm_br br;/* memory operations from user */ __u16 data_fmt;/* data format denoted by enum wd_buff_type */ }; struct wcrypto_cipher_op_data { enum wcrypto_cipher_op_type op_type;/* cipher operation type */ int status;/* cipher operation status */ void *in;/* cipher operation input address */ void *out;/* cipher operation output address * void *iv;/* cipher operation iv address * __u32 in_bytes;/* cipher operation input bytes */ __u32 out_bytes;/* cipher operation output bytes */ __u32 iv_bytes;/* cipher operation iv bytes */ void *priv;/* private information */ }; |
Prototype |
void *wcrypto_create_cipher_ctx(struct wd_queue *q, struct wcrypto_cipher_ctx_setup *setup); |
|---|---|
Function |
Create a symmetric encryption and decryption algorithm 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_set_cipher_key(void *ctx, __u8 *key, __u16 key_len); |
|---|---|
Function |
Set the key information required by cipher to the cipher context. |
Input Description |
ctx: symmetric encryption and decryption algorithm context key: input key pointer address of cipher key_len: length of the cipher input key |
Output Description |
None |
Return Value Description |
0: success Others: failure |
Usage Instruction |
|
Precautions |
Prototype |
int wcrypto_do_cipher(void *ctx, struct wcrypto_cipher_op_data *opdata, void *tag); |
|---|---|
Function |
Perform symmetric encryption and decryption based on the cipher context. |
Input Description |
ctx: Cipher context opdata: cipher 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_cipher_poll(struct wd_queue *q, unsigned int num); |
|---|---|
Function |
Perform cipher poll operations based on the WD queue. |
Input Description |
q: WD 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_cipher_ctx(void *ctx); |
|---|---|
Function |
Delete a cipher context. |
Input Description |
ctx: cipher context to be deleted |
Output Description |
None |
Return Value Description |
None |
Usage Instruction |
|
Precautions |