TrustCore SDK Crypto Interface API reference  version 2.0
crypto_interface_aes_ctr.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_AESCTRInit (MOC_SYM(hwAccelDescr hwAccelCtx) AES_CTR_Ctx *pCtx, const ubyte *pKeyMaterial, sbyte4 keyLength, const ubyte pInitCounter[AES_BLOCK_SIZE])
 Populates an already created AES-CTR context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_CloneAESCTRCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 Clone a AES-CTR context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAESCTRCtx (MOC_SYM(hwAccelDescr hwAccelCtx) const ubyte *pKeyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-CTR context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateAesCtrCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKeyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-CTR context for ipSec specifications. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DeleteAESCTRCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ppCtx)
 Delete an AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAESCTR (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLength, sbyte4 encrypt, ubyte *pIv)
 This function is effectively a wrapper to CRYPTO_INTERFACE_DoAESCTREx. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAESCTREx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLength, sbyte4 encrypt, ubyte *pIv, sbyte4 limit)
 Encrypt or decrypt data using the provided AES counter mode context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAesCtrEx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLength, sbyte4 encrypt, ubyte *pIv)
 Encrypt or decrypt data for ipSec specifications using the provided AES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_FinalAesCtrEx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pOutput, sbyte4 *pBytesWritten)
 Finalizes the AES-CTR stream cipher operation on a buffer of data. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_GetCounterBlockAESCTR (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte pCounterBuffer[AES_BLOCK_SIZE])
 Extract the working IV from the AES-CTR context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_UpdateAesCtrEx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pInput, sbyte4 inputLen, ubyte *pOutput, sbyte4 *pBytesWritten)
 Perform the AES-CTR stream cipher operation on a buffer of data. More...
 

Detailed Description

Add details here.

crypto_interface_aes_ctr.h

Function Documentation

◆ CRYPTO_INTERFACE_AESCTRInit()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_AESCTRInit ( MOC_SYM(hwAccelDescr hwAccelCtx) AES_CTR_Ctx *  pCtx,
const ubyte *  pKeyMaterial,
sbyte4  keyLength,
const ubyte  pInitCounter[AES_BLOCK_SIZE] 
)

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

Parameters
pCtxAES counter mode context to populate
pKeyMaterialKey material to use for the cipher operation.
keyLengthLength in bytes of the key material, valid key lengths are {16, 24, 32}.
pInitCounterA 16 byte buffer that contains the counter to be used
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_CloneAESCTRCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_CloneAESCTRCtx ( 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_CreateAESCTRCtx()

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

Note it is the callers responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteAESCTRCtx. Once created, you can use this context as input to CRYPTO_INTERFACE_DoAESCTR or CRYPTO_INTERFACE_DoAESCTREx to encrypt or decrypt data. The last 16 bytes of the pKeyMaterial buffer are expected to be the counter.

Parameters
pKeyMaterialKey material to use for the cipher operation including the 16 byte counter.
keyLengthLength in bytes of the key material plus counter, valid values are {32, 40, 48}.
encryptunused variable
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_CreateAesCtrCtx()

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

This is analogous to CRYPTO_INTERFACE_CreateAESCTRCtx except that instead of the key being appended by the nonce, iv, and ctr, it just appended by the nonce. It is the callers responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteAESCTRCtx. Once created, you can use this context as input to CRYPTO_INTERFACE_DoAesCtrEx to encrypt or decrypt data.

Parameters
pKeyMaterialKey material to use for the cipher operation including the 4 byte nonce.
keyLengthLength in bytes of the key material plus nonce, valid values are {32, 40, 48}.
encryptunused variable
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_DeleteAESCTRCtx()

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

Applies to CTR mode only.

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

◆ CRYPTO_INTERFACE_DoAESCTR()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAESCTR ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pData,
sbyte4  dataLength,
sbyte4  encrypt,
ubyte *  pIv 
)
Parameters
pCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLengthLength in bytes of the data to process. Does not have to be a multiple of the AES block size (16).
encryptThis value is unused.
pIvThis function does not take an IV, therefore this value is ignored 16 bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_DoAESCTREx()

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

This function does not use an IV. This operation is in place, therefore pData will be overwritten with computed ciphertext.

Parameters
pCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLengthLength in bytes of the data to process. Does not have to be a multiple of the AES block size (16).
encryptThis value is unused.
pIvOptional. If provied the internal IV will be set to the 16 byte buffer and the stream offset will be set back to 0.
limitlimit specifies the last byte to increment. If AES_BLOCK_SIZE, all bytes will be incremented. If 0, no bytes will be incremented
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_DoAesCtrEx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoAesCtrEx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pData,
sbyte4  dataLength,
sbyte4  encrypt,
ubyte *  pIv 
)
Parameters
pCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLengthLength in bytes of the data to process. Does not have to be a multiple of the AES block size (16).
encryptThis value is unused.
pIvThe 8 byte iv to be used. The counter will be reset to [nonce || iv || 1 ]
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_FinalAesCtrEx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_FinalAesCtrEx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pOutput,
sbyte4 *  pBytesWritten 
)

This API should be used when the underlying implementation may return output of a differing length from that of the input and there may be leftover unprocessed bytes left to be encrypted or decryped.

Parameters
pCtxPointer to an instantiated BulkCtx of aesCTRCipherContext type.
pOutputBuffer to hold the resulting output. This must have enough space available for the expected output.
pBytesWrittenContents will be set to the number of bytes actually written to the output buffer.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_GetCounterBlockAESCTR()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_GetCounterBlockAESCTR ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte  pCounterBuffer[AES_BLOCK_SIZE] 
)

The buffer must be at least the size of an AES block size.

Parameters
pCtxContext to retrieve the IV from.
pCounterBufferBuffer to store the IV in.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_UpdateAesCtrEx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_UpdateAesCtrEx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pInput,
sbyte4  inputLen,
ubyte *  pOutput,
sbyte4 *  pBytesWritten 
)

This API should be used in place of CRYPTO_INTERFACE_DoAESCTR when the underlying implementation may return output of a differing length from that of the input (for example if only 16 byte blocks are returned).

Parameters
pCtxPointer to an instantiated BulkCtx of aesCTRCipherContext type.
pInputBuffer of the input plaintext or ciphertext.
inputLenThe length of the input buffer in bytes.
pOutputBuffer to hold the resulting output. This may be the same as the input buffer but must have enough space available for the expected output.
pBytesWrittenContents will be set to the number of bytes actually written to the output buffer.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.