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

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

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_Clone3DESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 Copy a TDES context previously created with CRYPTO_INTERFACE_Create3DESCtx. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_Create2Key3DESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKeyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new Triple DES (TDES) context with two keys. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_Create3DESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKeyMaterial, sbyte4 keyLen, sbyte4 encrypt)
 Create a new Triple DES (TDES) context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_Delete3DESCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *pCtx)
 Delete a TDES context previously created with CRYPTO_INTERFACE_Create3DESCtx. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_Do3DES (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLen, sbyte4 encrypt, ubyte *pIv)
 Encrypt or decrypt data using the provided TDES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_Do3DESEx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, sbyte4 dataLen, sbyte4 encrypt, ubyte *pIv)
 Encrypt or decrypt data using the provided TDES context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_clearKey (ctx3des *pCtx)
 Delete a TDES-ECB context previously initialized with CRYPTO_INTERFACE_THREE_DES_initKey. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_cloneCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 Copy a TDES context previously created with CRYPTO_INTERFACE_THREE_DES_createCtx. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_THREE_DES_create2KeyCtx (ubyte *pKeyMaterial, sbyte4 keyLen, sbyte4 encrypt)
 Create a new Triple DES (TDES) 2-key context for ECB mode. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_THREE_DES_createCtx (ubyte *pKeyMaterial, sbyte4 keyLen, sbyte4 encrypt)
 Create a new Triple DES (TDES) context for ECB mode. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_decipher (ctx3des *pCtx, ubyte *pSrc, ubyte *pDest, ubyte4 numBytes)
 Perform a raw TDES-ECB decrypt. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_deleteCtx (BulkCtx *pCtx)
 Delete a TDES context previously created with CRYPTO_INTERFACE_THREE_DES_createCtx. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_encipher (ctx3des *pCtx, ubyte *pSrc, ubyte *pDest, ubyte4 numBytes)
 Perform a raw TDES-ECB encrypt. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_initKey (ctx3des *pCtx, const ubyte *pKey, sbyte4 keyLen)
 Initialize a raw TDES-ECB object for operation. More...
 

Detailed Description

Function Documentation

◆ CRYPTO_INTERFACE_Clone3DESCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_Clone3DESCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
BulkCtx *  ppNewCtx 
)
Parameters
pSrcPointer to a BulkCtx returned by CRYPTO_INTERFACE_Create3DESCtx.
pDestDouble 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_Create2Key3DESCtx()

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

A final (third) key will be a copy of the first key. This function will allocate and return a new TDES context to be used with CRYPTO_INTERFACE_Do3DES. It is the callers responsibility to free this context after use by calling CRYPTO_INTERFACE_Delete3DESCtx.

Parameters
pKeyMaterialThe key material to use for this context creation.
keyLenLength in bytes of the key material, must be exactly 16 bytes.
encryptTRUE to prepare this object for encryption or FALSE to prepare this object for decryption.
Returns
NULL on error, otherwise a pointer to a TDES context.

◆ CRYPTO_INTERFACE_Create3DESCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_Create3DESCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *  pKeyMaterial,
sbyte4  keyLen,
sbyte4  encrypt 
)

This function will allocate and return a new TDES context to be used with CRYPTO_INTERFACE_Do3DES. It is the callers responsibility to free this context after use by calling CRYPTO_INTERFACE_Delete3DESCtx.

Parameters
pKeyMaterialThe key material to use for this context creation.
keyLenLength in bytes of the key material, must be exactly 24 bytes.
encryptTRUE to prepare this object for encryption or FALSE to prepare this object for decryption.
Returns
NULL on error, otherwise a pointer to a TDES context.

◆ CRYPTO_INTERFACE_Delete3DESCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_Delete3DESCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *  pCtx)
Parameters
pCtxPointer to a BulkCtx returned by CRYPTO_INTERFACE_Create3DESCtx.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_Do3DES()

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

This function uses a TDES context previously created with CRYPTO_INTERFACE_Create3DESCtx to encrypt or decrypt the provided data in CBC mode. 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 this method is not guaranteed to use the pIv field on each subsequent call. If you need to replace the iv then use CRYPTO_INTERFACE_Do3DESEx instead. Note also the operation is in place, so the pData buffer will contain the result.

Note that you can NOT reuse a TDES context to start a new cipher operation. Ensure that each object is used for only one encrypt or decrypt operation, you must create a new object to start a new cipher operation.

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

◆ CRYPTO_INTERFACE_Do3DESEx()

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

This function uses a TDES context previously created with CRYPTO_INTERFACE_Create3DESCtx to encrypt or decrypt the provided data in CBC mode. This function can be used to stream data, pass in the initialization vector on the first call then continue to pass in new data and the updated iv on each subsequent call. Unlike CRYPTO_INTERFACE_Do3DES this method will use the pIV field and update it upon completion of the method. Note that this operation is in place, so the pData buffer will contain the result.

Note that you can NOT reuse a TDES context to start a new cipher operation. Ensure that each object is used for only one encrypt or decrypt operation, you must create a new object to start a new cipher operation.

Parameters
pCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLenLength in bytes of the data to process. Must be a multiple of the TDES block size (8).
encryptTRUE to encrypt, FALSE to decrypt. Must match the value used in CRYPTO_INTERFACE_Create3DESCtx.
pIvInitialization vector for the cipher operation. Must be exactly 8 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_THREE_DES_clearKey()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_clearKey ( ctx3des *  pCtx)

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

Parameters
pCtxPointer to a TDES-ECB context previously created with CRYPTO_INTERFACE_THREE_DES_initKey.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_THREE_DES_cloneCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_cloneCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
BulkCtx *  ppNewCtx 
)
Parameters
pSrcPointer to a BulkCtx returned by CRYPTO_INTERFACE_THREE_DES_createCtx.
pDestDouble 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_THREE_DES_create2KeyCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_THREE_DES_create2KeyCtx ( ubyte *  pKeyMaterial,
sbyte4  keyLen,
sbyte4  encrypt 
)

This function will allocate and return a new TDES context to be used with CRYPTO_INTERFACE_THREE_DES_encipher/decipher. It will internally call CRYPTO_INTERFACE_THREE_DES_initKey. It is the callers responsibility to free this context after use by calling CRYPTO_INTERFACE_THREE_DES_deleteCtx.

Parameters
pKeyMaterialThe key material to use for this context creation.
keyLenLength in bytes of the key material, must be exactly 16 bytes.
encryptingored.
Returns
NULL on error, otherwise a pointer to a TDES context.

◆ CRYPTO_INTERFACE_THREE_DES_createCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_THREE_DES_createCtx ( ubyte *  pKeyMaterial,
sbyte4  keyLen,
sbyte4  encrypt 
)

This function will allocate and return a new TDES context to be used with CRYPTO_INTERFACE_THREE_DES_encipher/decipher. It will internally call CRYPTO_INTERFACE_THREE_DES_initKey. It is the callers responsibility to free this context after use by calling CRYPTO_INTERFACE_THREE_DES_deleteCtx.

Parameters
pKeyMaterialThe key material to use for this context creation.
keyLenLength in bytes of the key material, must be exactly 24 bytes.
encryptingored.
Returns
NULL on error, otherwise a pointer to a TDES context.

◆ CRYPTO_INTERFACE_THREE_DES_decipher()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_decipher ( ctx3des *  pCtx,
ubyte *  pSrc,
ubyte *  pDest,
ubyte4  numBytes 
)
Parameters
pCtxTDES context previously initialized with CRYPTO_INTERFACE_THREE_DES_initKey to use to decrypt.
pSrcData to decrypt.
pDestBuffer that will recieve the decrypted result.
numBytesNumber of bytes to decrypt, must be a multiple of 8.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_THREE_DES_deleteCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_deleteCtx ( BulkCtx *  pCtx)

This will internally call CRYPTO_INTERFACE_THREE_DES_clearKey.

Parameters
pCtxPointer to a BulkCtx returned by CRYPTO_INTERFACE_THREE_DES_createCtx.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_THREE_DES_encipher()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_encipher ( ctx3des *  pCtx,
ubyte *  pSrc,
ubyte *  pDest,
ubyte4  numBytes 
)
Parameters
pCtxTDES context previously initialized with CRYPTO_INTERFACE_THREE_DES_initKey to use to encrypt.
pSrcData to encrypt.
pDestBuffer that will recieve the encrypted result.
numBytesNumber of bytes to encrypt, must be a multiple of 8.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.

◆ CRYPTO_INTERFACE_THREE_DES_initKey()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_THREE_DES_initKey ( ctx3des *  pCtx,
const ubyte *  pKey,
sbyte4  keyLen 
)

Note that this should only be used when constructing a larger cryptographic scheme that requires a TDES-ECB primitive. It is the callers responsibility to delete this context after use by calling CRYPTO_INTERFACE_THREE_DES_clearKey.

Parameters
pCtxPointer to a caller allocated TDES-ECB context to be initialized.
pKeyKey material to use for this operation.
keyLenLength in bytes of key material to use, must be exactly 24 bytes.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h.