CRYPTO API 参考
CRYPTO
-
typedef wm_hal_cryp_cfg_t wm_drv_cryp_cfg_t
-
wm_device_t *wm_drv_cryp_init(const char *dev_name)
Initialize CRYP driver, initialize resources shared by encryption and decryption algorithms such as RC4, AES, DES, and 3DES.
备注
This API must be called before all other CRYP API can be called
- 参数:
dev_name – CRYP device name
- 返回:
NULL: failed
others: CRYP driver device
-
int wm_drv_cryp_deinit(wm_device_t *dev)
Deinitialize CRYP driver.
- 参数:
dev – CRYP driver device
- 返回:
WM_ERR_SUCCESS: succeed
WM_ERR_INVALID_PARAM: invalid argument
others: failed
-
int wm_drv_rc4_init(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, const unsigned char *key, uint32_t keylen)
Fill the wm_drv_cryp_cfg_t structure pointed to by ctx with necessary data.
备注
The parameter ctx must be a structure which is allocated externally. And all of Context parameters in the initializing methods should be allocated externally too.
- 参数:
dev – [in] Pointer to the CRYP device structure.
ctx – [in] Pointer to the Cipher Context.
key – [in] Pointer to the key.
keylen – [in] the length of key.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_drv_aes_init(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, const unsigned char *iv, const unsigned char *key, uint32_t keylen, wm_gpsec_sub_mode_t sub_mode)
Fill the psCipherContext_t structure pointed to by ctx with necessary data.
- 参数:
dev – [in] Pointer to the CRYP device structure.
ctx – [in] Pointer to the Cipher Context.
iv – [in] Pointer to the iv.
key – [in] Pointer to the key.
keylen – [in] the length of key.
sub_mode – [in] DES/ 3DES Algorithm support ECB/CBC mode, AES Algorithm support ECB/CBC/CTR/MAC mode.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_drv_des_init(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, const unsigned char *iv, const unsigned char *key, uint32_t keylen, wm_gpsec_sub_mode_t sub_mode)
Fill the psCipherContext_t structure pointed to by ctx with necessary data.
- 参数:
dev – [in] Pointer to the CRYP device structure.
ctx – [in] Pointer to the Cipher Context.
iv – [in] Pointer to the iv.
key – [in] Pointer to the key.
keylen – [in] the length of key.
sub_mode – [in] DES/ 3DES Algorithm support ECB/CBC mode, AES Algorithm support ECB/CBC/CTR/MAC mode.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_drv_3des_init(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, const unsigned char *iv, const unsigned char *key, uint32_t keylen, wm_gpsec_sub_mode_t sub_mode)
Fill the psCipherContext_t structure pointed to by ctx with necessary data.
- 参数:
dev – [in] Pointer to the CRYP device structure.
ctx – [in] Pointer to the Cipher Context.
iv – [in] Pointer to the iv.
key – [in] Pointer to the key.
keylen – [in] the length of key.
sub_mode – [in] DES/ 3DES Algorithm support ECB/CBC mode, AES Algorithm support ECB/CBC/CTR/MAC mode.
- 返回:
WM_ERR_SUCCESS: succeed
others: failed
-
int wm_drv_rc4_encrypt_decrypt(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, unsigned char *in, unsigned char *out, uint32_t len)
This function encrypts or decrypts a variable length data stream according to RC4. The RC4 algorithm it generates a “keystream” which is simply XORed with the plaintext to produce the ciphertext stream. Decryption is exactly the same as encryption. This function also decrypts a variable length data stream according to RC4.
- 参数:
dev – [in] pointer to a wm_device_t structure.
ctx – [in] Pointer to the Cipher Context.
in – [in] Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
out – [in] Pointer to the resulting ciphertext data stream.
len – [in] Length of the input data stream in byte.
- 返回:
WM_ERR_SUCCESS: succeed
WM_ERR_INVALID_PARAM: invalid argument
Other error codes based on the encrypt/decrypt process
-
int wm_drv_aes_encrypt_decrypt(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, unsigned char *in, unsigned char *out, uint32_t len, wm_gpsec_encrypt_decrypt_sel_t enc_dec)
This function encrypts or decrypts a variable length data stream according to AES.
- 参数:
dev – [in] pointer to a wm_device_t structure.
ctx – [in] Pointer to the Cipher Context.
in – [in] Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
out – [in] Pointer to the resulting ciphertext data stream.
len – [in] Length of the input data stream in byte.
enc_dec – [in] The cryption way which indicates encryption or decryption.
- 返回:
WM_ERR_SUCCESS: succeed
WM_ERR_INVALID_PARAM: invalid argument
Other error codes based on the encrypt/decrypt process
-
int wm_drv_des_encrypt_decrypt(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, unsigned char *in, unsigned char *out, uint32_t len, wm_gpsec_encrypt_decrypt_sel_t enc_dec)
This function encrypts or decrypts a variable length data stream according to DES.
- 参数:
dev – [in] pointer to a wm_device_t structure.
ctx – [in] Pointer to the Cipher Context.
in – [in] Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
out – [in] Pointer to the resulting ciphertext data stream.
len – [in] Length of the input data stream in byte.
enc_dec – [in] The cryption way which indicates encryption or decryption.
- 返回:
WM_ERR_SUCCESS: succeed
WM_ERR_INVALID_PARAM: invalid argument
Other error codes based on the encrypt/decrypt process
-
int wm_drv_3des_encrypt_decrypt(wm_device_t *dev, wm_drv_cryp_cfg_t *ctx, unsigned char *in, unsigned char *out, uint32_t len, wm_gpsec_encrypt_decrypt_sel_t enc_dec)
This function encrypts or decrypts a variable length data stream according to 3DES.
- 参数:
dev – [in] pointer to a wm_device_t structure.
ctx – [in] Pointer to the Cipher Context.
in – [in] Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length.
out – [in] Pointer to the resulting ciphertext data stream.
len – [in] Length of the input data stream in byte.
enc_dec – [in] The cryption way which indicates encryption or decryption.
- 返回:
WM_ERR_SUCCESS: succeed
WM_ERR_INVALID_PARAM: invalid argument
Other error codes based on the encrypt/decrypt process