TrustCore SDK Crypto Interface API reference  version 2.0
crypto_interface_aes.h File Reference

Cryptographic Interface header file for declaring AES functions. More...

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockDecrypt (aesCipherContext *pCtx, ubyte *pIv, ubyte *pInput, sbyte4 inputLen, ubyte *pOutBuffer, sbyte4 *pRetLength)
 Decrypt some data using the provided AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockDecryptEx (MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *pCtx, ubyte *pIv, ubyte *pInput, sbyte4 inputLen, ubyte *pOutBuffer, sbyte4 *pRetLength)
 Decrypt some data using the provided AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockEncrypt (aesCipherContext *pCtx, ubyte *pIv, ubyte *pInput, sbyte4 inputLen, ubyte *pOutBuffer, sbyte4 *pRetLength)
 Encrypt some data using the provided AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockEncryptEx (MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *pCtx, ubyte *pIv, ubyte *pInput, sbyte4 inputLen, ubyte *pOutBuffer, sbyte4 *pRetLength)
 Encrypt some data using the provided AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_clearKey (aesCipherContext *pCtx)
 Delete an AES context previously initialized with CRYPTO_INTERFACE_AESALGO_makeAesKey. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_makeAesKey (aesCipherContext *pCtx, sbyte4 keyLen, const ubyte *pKeyMaterial, sbyte4 encrypt, sbyte4 mode)
 Initialize a raw AES object for operation. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_makeAesKeyEx (MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *pCtx, sbyte4 keyLen, const ubyte *pKeyMaterial, sbyte4 encrypt, sbyte4 mode)
 Initialize a raw AES object for operation. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_CloneAESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 Clone a AES context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESCFB1Ctx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-CFB1 context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESCFBCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKeyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-CFB128 context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKeyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-CBC context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESECBCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKeyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-ECB context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESOFBCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKeyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-OFB context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DeleteAESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ppCtx)
 Delete an AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAES (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLength, sbyte4 encrypt, ubyte *pIv)
 Encrypt or decrypt data using the provided AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAESECB (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLength, sbyte4 encrypt)
 Same as CRYPTO_INTERFACE_DoAES but specifically for ECB mode. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAESEx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLength, sbyte4 encrypt, ubyte *pIv)
 Encrypt or decrypt data using the provided AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ResetAESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ppCtx)
 "Reset" an AES context by setting the "initialized" field within the aesCipherContext to 0. More...
 

Detailed Description

Add details here.

crypto_interface_aes.h

Function Documentation

◆ CRYPTO_INTERFACE_AESALGO_blockDecrypt()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockDecrypt ( aesCipherContext *  pCtx,
ubyte *  pIv,
ubyte *  pInput,
sbyte4  inputLen,
ubyte *  pOutBuffer,
sbyte4 *  pRetLength 
)
Parameters
pCtxThe context to use for this cipher operation.
pIvInitialization vector to use for this operation, optional for ECB mode. Must be 16 bytes for all other modes.
pInputData to decrypt.
inputLenLength in bytes of the input data, must be a multiple of the AES block size (16).
pOutBufferBuffer that will recieve the decrypted result, must be as large as the input data.
pRetLengthPointer to the sbyte4 which will recieve the length of the resulting plaintext.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_AESALGO_blockDecryptEx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockDecryptEx ( MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *  pCtx,
ubyte *  pIv,
ubyte *  pInput,
sbyte4  inputLen,
ubyte *  pOutBuffer,
sbyte4 *  pRetLength 
)
Parameters
pCtxThe context to use for this cipher operation.
pIvInitialization vector to use for this operation, optional for ECB mode. Must be 16 bytes for all other modes.
pInputData to decrypt.
inputLenLength in bytes of the input data, must be a multiple of the AES block size (16).
pOutBufferBuffer that will recieve the decrypted result, must be as large as the input data.
pRetLengthPointer to the sbyte4 which will recieve the length of the resulting plaintext.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_AESALGO_blockEncrypt()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockEncrypt ( aesCipherContext *  pCtx,
ubyte *  pIv,
ubyte *  pInput,
sbyte4  inputLen,
ubyte *  pOutBuffer,
sbyte4 *  pRetLength 
)
Parameters
pCtxThe context to use for this cipher operation.
pIvInitialization vector to use for this operation, optional for ECB mode. Must be 16 bytes for all other modes.
pInputData to encrypt.
inputLenLength in bytes of the input data, must be a multiple of the AES block size (16).
pOutBufferBuffer that will recieve the encrypted result, must be as large as the input data.
pRetLengthPointer to the sbyte4 which will recieve the length of the resulting ciphertext.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_AESALGO_blockEncryptEx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_blockEncryptEx ( MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *  pCtx,
ubyte *  pIv,
ubyte *  pInput,
sbyte4  inputLen,
ubyte *  pOutBuffer,
sbyte4 *  pRetLength 
)
Parameters
pCtxThe context to use for this cipher operation.
pIvInitialization vector to use for this operation, optional for ECB mode. Must be 16 bytes for all other modes.
pInputData to encrypt.
inputLenLength in bytes of the input data, must be a multiple of the AES block size (16).
pOutBufferBuffer that will recieve the encrypted result, must be as large as the input data.
pRetLengthPointer to the sbyte4 which will recieve the length of the resulting ciphertext.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_AESALGO_clearKey()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_clearKey ( aesCipherContext *  pCtx)

Note that this function frees the underlying context created by the crypto interface. Even though the aesCipherContext pointer was originally allocated by the caller, failing to call this function after use will result in a memory leak.

Parameters
pCtxPointer to an AES context previously created with CRYPTO_INTERFACE_AESALGO_makeAesKey.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_AESALGO_makeAesKey()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_makeAesKey ( aesCipherContext *  pCtx,
sbyte4  keyLen,
const ubyte *  pKeyMaterial,
sbyte4  encrypt,
sbyte4  mode 
)

Note that this should only be used when constructing a larger cryptographic scheme that requires an AES primitive. To use AES for encrypting/decrypting data in general, use one of the CRYPTO_INTERFACE_CreateAES*Ctx functions instead. It is the callers responsibility to delete this context after use by calling CRYPTO_INTERFACE_AESALGO_clearKey.

Parameters
pCtxPointer to a caller allocated AES context to be initialized.
keyLenLength in bytes of key material to use, must be one of {16,24,32}.
pKeyMaterialKey material to use for this operation.
encryptTRUE to encrypt, FALSE to decrypt.
modeThe AES mode of operation to use. Must be one of { MODE_ECB, MODE_CBC, MODE_CFB128, MODE_OFB }
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_AESALGO_makeAesKeyEx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESALGO_makeAesKeyEx ( MOC_SYM(hwAccelDescr hwAccelCtx) aesCipherContext *  pCtx,
sbyte4  keyLen,
const ubyte *  pKeyMaterial,
sbyte4  encrypt,
sbyte4  mode 
)

Note that this should only be used when constructing a larger cryptographic scheme that requires an AES primitive. To use AES for encrypting/decrypting data in general, use one of the CRYPTO_INTERFACE_CreateAES*Ctx functions instead. It is the callers responsibility to delete this context after use by calling CRYPTO_INTERFACE_AESALGO_clearKey.

Parameters
pCtxPointer to a caller allocated AES context to be initialized.
keyLenLength in bytes of key material to use, must be one of {16,24,32}.
pKeyMaterialKey material to use for this operation.
encryptTRUE to encrypt, FALSE to decrypt.
modeThe AES mode of operation to use. Must be one of { MODE_ECB, MODE_CBC, MODE_CFB128, MODE_OFB }
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_CloneAESCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_CloneAESCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
BulkCtx *  ppNewCtx 
)
Parameters
pCtxPointer to an instantiated BulkCtx.
ppNewCtxDouble pointer to the BulkCtx to be created and populated with the key data from the source key.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_CreateAESCFB1Ctx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESCFB1Ctx ( MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *  keyMaterial,
sbyte4  keyLength,
sbyte4  encrypt 
)

Note it is the callers responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteAESCtx. Once created, you can use this context as input to CRYPTO_INTERFACE_DoAES to encrypt or decrypt data.

Parameters
pKeyMaterialKey material to use for the cipher operation.
keyLengthLength in bytes of the key material, valid key lengths are {16, 24, 32}.
encryptTRUE to prepare this context for encryption, FALSE to prepare this context for decryption.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_CreateAESCFBCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESCFBCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *  pKeyMaterial,
sbyte4  keyLength,
sbyte4  encrypt 
)

Note it is the callers responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteAESCtx. Once created, you can use this context as input to CRYPTO_INTERFACE_DoAES to encrypt or decrypt data.

Parameters
pKeyMaterialKey material to use for the cipher operation.
keyLengthLength in bytes of the key material, valid key lengths are {16, 24, 32}.
encryptTRUE to prepare this context for encryption, FALSE to prepare this context for decryption.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_CreateAESCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *  pKeyMaterial,
sbyte4  keyLength,
sbyte4  encrypt 
)

Note it is the callers responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteAESCtx. Once created, you can use this context as input to CRYPTO_INTERFACE_DoAES to encrypt or decrypt data.

Parameters
pKeyMaterialKey material to use for the cipher operation.
keyLengthLength in bytes of the key material, valid key lengths are {16, 24, 32}.
encryptTRUE to prepare this context for encryption, FALSE to prepare this context for decryption.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_CreateAESECBCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESECBCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *  pKeyMaterial,
sbyte4  keyLength,
sbyte4  encrypt 
)

Note it is the callers responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteAESCtx. Once created, you can use this context as input to CRYPTO_INTERFACE_DoAESECB to encrypt or decrypt data.

Parameters
pKeyMaterialKey material to use for the cipher operation.
keyLengthLength in bytes of the key material, valid key lengths are {16, 24, 32}.
encryptTRUE to prepare this context for encryption, FALSE to prepare this context for decryption.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_CreateAESOFBCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESOFBCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *  pKeyMaterial,
sbyte4  keyLength,
sbyte4  encrypt 
)

Note it is the callers responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteAESCtx. Once created, you can use this context as input to CRYPTO_INTERFACE_DoAES to encrypt or decrypt data.

Parameters
pKeyMaterialKey material to use for the cipher operation.
keyLengthLength in bytes of the key material, valid key lengths are {16, 24, 32}.
encryptTRUE to prepare this context for encryption, FALSE to prepare this context for decryption.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_DeleteAESCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DeleteAESCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *  ppCtx)

Applies to CBC, CFB, and OFB modes.

Parameters
ppCtxPointer to the BulkCtx to be deleted.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_DoAES()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAES ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pData,
sbyte4  dataLength,
sbyte4  encrypt,
ubyte *  pIv 
)

Use this for AES contexts created with the CBC, CFB, or OFB modes. This function can be used to stream data, pass in the initialization vector on the first call, but note each subsequent call is not guaranteed to use the pIv field passed in. Please use CRYPTO_INTERFACE_DoAESEx if you wish to update the iv. Note that this operation is in place, so the pData buffer will contain the result.

Note that you must use ResetAESCtx to start a new cipher operation.

Parameters
pCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLengthLength in bytes of the data to process. Must be a multiple of the AES block size (16).
encryptTRUE to encrypt, FALSE to decrypt. Must match the value used during context creation.
pIvInitialization vector for the cipher operation. Must be exactly 16 bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_DoAESECB()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAESECB ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pData,
sbyte4  dataLength,
sbyte4  encrypt 
)

Note this function does not take an initialization vector as it is not used in ECB mode.

Parameters
pCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLengthLength in bytes of the data to process. Must be a multiple of the AES block size (16).
encryptTRUE to encrypt, FALSE to decrypt. Must match the value used during context creation.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_DoAESEx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAESEx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pData,
sbyte4  dataLength,
sbyte4  encrypt,
ubyte *  pIv 
)

Use this for AES contexts created with the CBC, CFB, or OFB modes. This function can be used to stream data, pass in the initialization vector on the first call then continue to pass in new data on each subsequent call. Note that this operation is in place, so the pData buffer will contain the result. This method will copy the working IV into the pIv parameter upon completion.

Note that you must use ResetAESCtx to start a new cipher operation.

Parameters
pCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLengthLength in bytes of the data to process. Must be a multiple of the AES block size (16).
encryptTRUE to encrypt, FALSE to decrypt. Must match the value used during context creation.
pIvInitialization vector for the cipher operation. Must be exactly 16 bytes. Will contain the working IV when the method finishes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_ResetAESCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ResetAESCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *  ppCtx)

This function is a helper whose purpose is to bridge the gap between the standard DoAES & CRYPTO_INTERFACE_DoAES. The standard DoAES function modifies parameter buffers in-place, whereas CI version makes an internal copy of the buffers to operate on. Therefore, calling this function will allow the user to re-use the same context for multiple buffers.

Parameters
ppCtxPointer to the BulkCtx to be reset.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.