API参考
载入中...
搜索中...
未找到
Crypt_eal_cipher

cipher suites 更多...

Crypt_eal_cipher 的协作图:

函数

bool CRYPT_EAL_CipherIsValidAlgId (CRYPT_CIPHER_AlgId id)
 Check whether the given symmetric algorithm ID is valid.
CRYPT_EAL_CipherCtx * CRYPT_EAL_CipherNewCtx (CRYPT_CIPHER_AlgId id)
 Generate symmetric encryption and decryption handles.
CRYPT_EAL_CipherCtx * CRYPT_EAL_ProviderCipherNewCtx (CRYPT_EAL_LibCtx *libCtx, int32_t algId, const char *attrName)
 Generate symmetric encryption and decryption handles in the providers
void CRYPT_EAL_CipherFreeCtx (CRYPT_EAL_CipherCtx *ctx)
 Release the symmetric encryption/decryption handle. Clear sensitive information before releasing the handle.
int32_t CRYPT_EAL_CipherInit (CRYPT_EAL_CipherCtx *ctx, const uint8_t *key, uint32_t keyLen, const uint8_t *iv, uint32_t ivLen, bool enc)
 Initialize the symmetric encryption/decryption handle. The key cannot be null. Except the ECB mode, other modes iv cannot be null.
void CRYPT_EAL_CipherDeinit (CRYPT_EAL_CipherCtx *ctx)
 Deinitialize the handle and restore the handle to the state, when the CRYPT_EAL_CipherNewCtx function is called.
int32_t CRYPT_EAL_CipherReinit (CRYPT_EAL_CipherCtx *ctx, uint8_t *iv, uint32_t ivLen)
int32_t CRYPT_EAL_CipherUpdate (CRYPT_EAL_CipherCtx *ctx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen)
int32_t CRYPT_EAL_CipherFinal (CRYPT_EAL_CipherCtx *ctx, uint8_t *out, uint32_t *outLen)
 Fill the data with the size of the block and output the encrypted data; the AEAD tag is obtained through CRYPT_EAL_CipherCtrl. For block encryption algorithms such as CBC and ECB, padding must be set, In XTS mode, final needs to be called to obtain the last two blocks.
int32_t CRYPT_EAL_CipherCtrl (CRYPT_EAL_CipherCtx *ctx, int32_t type, void *data, uint32_t len)
int32_t CRYPT_EAL_CipherSetPadding (CRYPT_EAL_CipherCtx *ctx, CRYPT_PaddingType type)
 Set the padding mode.
int32_t CRYPT_EAL_CipherGetPadding (CRYPT_EAL_CipherCtx *ctx)
 Obtain the padding type.
int32_t CRYPT_EAL_CipherGetInfo (CRYPT_CIPHER_AlgId id, int32_t type, uint32_t *infoValue)
 Obtain the type of an algorithm based on the algorithm ID.
int32_t CRYPT_EAL_CipherCopyCtx (CRYPT_EAL_CipherCtx *to, const CRYPT_EAL_CipherCtx *from)
 Copy the cipher context.
CRYPT_EAL_CipherCtx * CRYPT_EAL_CipherDupCtx (const CRYPT_EAL_CipherCtx *from)
 Dup the cipher context.

详细描述

cipher suites

函数说明

◆ CRYPT_EAL_CipherCopyCtx()

int32_t CRYPT_EAL_CipherCopyCtx ( CRYPT_EAL_CipherCtx * to,
const CRYPT_EAL_CipherCtx * from )

Copy the cipher context.

参数
to[IN] target cipher context.
from[IN] original cipher context.
返回值
CRYPT_SUCCESS,parametersare set successfully.
CRYPT_NULL_INPUT,theinput parameter is NULL. Other error codes see crypt_errno.h

◆ CRYPT_EAL_CipherCtrl()

int32_t CRYPT_EAL_CipherCtrl ( CRYPT_EAL_CipherCtx * ctx,
int32_t type,
void * data,
uint32_t len )

Set the mode ctx parameters in the CTX. parameter data type Length(len):number of data bytes CRYPT_CTRL_GET_IV uint8_t array The length of the IV depends on the corresponding algorithm, see the mapping in CRYPT_EAL_CipherInit CRYPT_CTRL_SET_AAD uint8_t array It is used only for AEAD calculation. The length is related to the corresponding AEAD algorithm. CRYPT_CTRL_GET_TAG uint8_t array It is used only for AEAD calculation. The length is the tagLen value set by the user. CRYPT_CTRL_SET_TAGLEN uint32_t length(len) 4 CRYPT_CTRL_SET_MSGLEN uint64_t length(len) 8 CRYPT_CTRL_SET_FEEDBACKSIZE uint32_t length(len) 4 CRYPT_CTRL_GET_FEEDBACKSIZE uint32_t pointer sizeof(*uint32_t) CRYPT_CTRL_GET_BLOCKSIZE uint32_t length(len) 4

注意
If the function is called by an external user and the error stack is concerned, it is recommended that BSL_ERR_ClearError() be called before this function is called.
参数
ctx[IN] Symmetric encryption/decryption handle
type[IN] Parameter type
data[IN/OUT] Input and output data
len[OUT] Data length
返回值
CRYPT_SUCCESS,success.error codes see the crypt_errno.h

◆ CRYPT_EAL_CipherDeinit()

void CRYPT_EAL_CipherDeinit ( CRYPT_EAL_CipherCtx * ctx)

Deinitialize the handle and restore the handle to the state, when the CRYPT_EAL_CipherNewCtx function is called.

注意
If the function is called by an external user and the error stack is concerned, you are advised to call BSL_ERR_ClearError() before calling this function.
参数
ctx[IN] Symmetric encryption/decryption handle

◆ CRYPT_EAL_CipherDupCtx()

CRYPT_EAL_CipherCtx * CRYPT_EAL_CipherDupCtx ( const CRYPT_EAL_CipherCtx * from)

Dup the cipher context.

参数
from[IN] original cipher context.
返回值
CRYPT_EAL_CipherCtx,ciphercontext pointer. NULL, if the operation fails.

◆ CRYPT_EAL_CipherFinal()

int32_t CRYPT_EAL_CipherFinal ( CRYPT_EAL_CipherCtx * ctx,
uint8_t * out,
uint32_t * outLen )

Fill the data with the size of the block and output the encrypted data; the AEAD tag is obtained through CRYPT_EAL_CipherCtrl. For block encryption algorithms such as CBC and ECB, padding must be set, In XTS mode, final needs to be called to obtain the last two blocks.

注意
If the function is called by an external user and the error stack is concerned, you are advised to call BSL_ERR_ClearError() before calling this function.
参数
ctx[IN] Symmetric encryption/decryption handle
out[OUT] Output the encrypted data
outLen[IN/OUT] Input: outLen >= blockSize Output: The output value for stream encryption is 0. If padding is set for CBC and ECB block encryption, the output value of outLen is blockSize. If the padding is not set for CBC and ECB block encryption and CTX contains cached data, an error is reported. If padding is not set for CBC and ECB block encryption, and no data is cached in the CTX, the output value of outLen is 0.
返回值
CRYPT_SUCCESS,success.Other error codes see the crypt_errno.h.

◆ CRYPT_EAL_CipherFreeCtx()

void CRYPT_EAL_CipherFreeCtx ( CRYPT_EAL_CipherCtx * ctx)

Release the symmetric encryption/decryption handle. Clear sensitive information before releasing the handle.

注意
If the function is called by an external user and the error stack is concerned, it is recommended that BSL_ERR_ClearError() be called before this function is called.
参数
ctx[IN] Symmetric encryption/decryption handle. The CTX is set null by the caller.

◆ CRYPT_EAL_CipherGetInfo()

int32_t CRYPT_EAL_CipherGetInfo ( CRYPT_CIPHER_AlgId id,
int32_t type,
uint32_t * infoValue )

Obtain the type of an algorithm based on the algorithm ID.

参数
id[IN] Symmetric algorithm ID.
type[IN] Attribute type to be obtained.
infoValue[OUT] Obtained attribute data.
返回值
CRYPT_SUCCESS,successOther error codes see crypt_errno.h

◆ CRYPT_EAL_CipherGetPadding()

int32_t CRYPT_EAL_CipherGetPadding ( CRYPT_EAL_CipherCtx * ctx)

Obtain the padding type.

参数
ctxSymmetric encryption/decryption handle
返回值
Returnmode

◆ CRYPT_EAL_CipherInit()

int32_t CRYPT_EAL_CipherInit ( CRYPT_EAL_CipherCtx * ctx,
const uint8_t * key,
uint32_t keyLen,
const uint8_t * iv,
uint32_t ivLen,
bool enc )

Initialize the symmetric encryption/decryption handle. The key cannot be null. Except the ECB mode, other modes iv cannot be null.

The length of iv must be the same as the block length (this requirement is not required in ECB mode). The block length can be obtained through CRYPT_CTRL_GET_BLOCKSIZE of CRYPT_EAL_CipherCtrl. CRYPT_EAL_CipherInit can be called repeatedly at any stage, resets the key and iv, and clears the cached data.

注意
If the function is called by an external user and the error stack is concerned, you are advised to call BSL_ERR_ClearError() before calling this function.
参数
ctx[IN] Symmetric encryption/decryption handle
key[IN] Key
keyLen[IN] Key length
iv[IN] Initialization vector
ivLen[IN] Initialize the vector length.
enc[IN] True: encryption; False: decryption
返回值
CRYPT_SUCCESS,success.For other error codes, see crypt_errno.h.

◆ CRYPT_EAL_CipherIsValidAlgId()

bool CRYPT_EAL_CipherIsValidAlgId ( CRYPT_CIPHER_AlgId id)

Check whether the given symmetric algorithm ID is valid.

注解
Not supported in provider mode.
参数
id[IN] Symmetric algorithm ID.
返回值
Valid,trueis returned. Invalid, false is returned.

◆ CRYPT_EAL_CipherNewCtx()

CRYPT_EAL_CipherCtx * CRYPT_EAL_CipherNewCtx ( CRYPT_CIPHER_AlgId id)

Generate symmetric encryption and decryption handles.

注意
If the function is called by an external user and the error stack is concerned, it is recommended that BSL_ERR_ClearError() be called before this function is called.
参数
id[IN] Symmetric encryption/decryption algorithm ID.
返回值
Successcipher ctx. Fails: NULL.

◆ CRYPT_EAL_CipherReinit()

int32_t CRYPT_EAL_CipherReinit ( CRYPT_EAL_CipherCtx * ctx,
uint8_t * iv,
uint32_t ivLen )

Re-initialize the handle, retain the key, reset the IV, and clear the cache and sensitive data. Except the ECB mode, other modes iv cannot be null. The setting of iv must be based on the corresponding algorithm ID. For details, see the mapping in CRYPT_EAL_CipherInit.

参数
ctx[IN] Symmetric encryption/decryption handle
iv[IN] Vector
ivLen[IN] Vector length

◆ CRYPT_EAL_CipherSetPadding()

int32_t CRYPT_EAL_CipherSetPadding ( CRYPT_EAL_CipherCtx * ctx,
CRYPT_PaddingType type )

Set the padding mode.

参数
ctxSymmetric encryption/decryption handle
typePadding type
返回值
CRYPT_SUCCESS,success.Error codes see crypt_errno.h

◆ CRYPT_EAL_CipherUpdate()

int32_t CRYPT_EAL_CipherUpdate ( CRYPT_EAL_CipherCtx * ctx,
const uint8_t * in,
uint32_t inLen,
uint8_t * out,
uint32_t * outLen )

Continuously enter encrypted and decrypted data. CRYPT_EAL_CipherUpdate should be used in conjunction with CRYPT_EAL_CipherFinal, after one or more calls to CRYPT_EAL_CipherUpdate, Call CRYPT_EAL_CipherFinal. With the exception of SM4_XTS mode, multiple calls to CRYPT_EAL_CipherUpdate and CRYPT_EAL_CipherFinal are not supported.

注意
If the function is called by an external user and the error stack is concerned, it is recommended that BSL_ERR_ClearError() be called before this function is called.
参数
ctx[IN] Symmetric encryption and decryption handle
in[IN] Continuously input data
inLen[IN] Length of continuously input data
out[OUT] Output data
outLen[IN/OUT] Input: For CBC and ECB block encryption, you are advised to set outLen > inLen + blockSize. For CTR and XTS stream encryption, you are advised to set outLen >= inLen. blockSize can be obtained by using CRYPT_CTRL_GET_BLOCKSIZE of CRYPT_EAL_CipherCtrl. Output: Length of the encrypted data. If the block encryption algorithm is used and the length of the last data to be processed is insufficient, the output value of outLen is 0. eg: CBC and ECB block encryption
  1. Encrypted data is input for the first time, and inLen is less than blockSize. In this case, the output value of outLen is 0.
  2. In the first input encrypted data length, inLen is an integer multiple of blockSize. In this case, outLen is equal to inLen.
  3. In the first input encrypted data length, inLen > blockSize and not an integer multiple of blockSize. In this case, outLen < inLen.
  4. Enter the encrypted data for multiple times. (inLen% blockSize) + cache (CTX cache data) >= blockSize. At this point outLen = (inlen / blockSize) * blockSize + blockSize CTR outLen equals inLen. In XTS mode, update reserves the last two blocks for final processing, If the total length of the input data plus the buffer is less than 32 blocks, the output is 0.
  1. When data is input for the first time, outLen = (inLen / 16 - 2) * 16.
  2. Enter the encrypted data for multiple times. At this time, outLen = ((inLen + cache) / 16 - 2) * 16. In SM4_XTS mode, after calling CRYPT_EAL_CipherUpdate, you need to use CRYPT_EAL_CipherInit or CRYPT_EAL_CipherReinit to reset the key or iv.
返回值
CRYPT_SUCCESS,success.Other error codes see the crypt_errno.h.

◆ CRYPT_EAL_ProviderCipherNewCtx()

CRYPT_EAL_CipherCtx * CRYPT_EAL_ProviderCipherNewCtx ( CRYPT_EAL_LibCtx * libCtx,
int32_t algId,
const char * attrName )

Generate symmetric encryption and decryption handles in the providers

参数
libCtx[IN] Library context
algId[IN] Symmetric encryption/decryption algorithm ID.
attrName[IN] Specify expected attribute values
返回值
Successcipher ctx. Fails: NULL.