TrustCore SDK NanoCrypto API reference  version 7.0
cast128.h File Reference

Header file for the NanoCrypto Cast128 APIs. More...

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS CAST128_decryptBlock (cast128_ctx *pCtx, ubyte inblock[], ubyte outblock[])
 Decrypts a block of ciphertext. More...
 
MOC_EXTERN MSTATUS CAST128_encryptBlock (cast128_ctx *pCtx, ubyte inblock[], ubyte outblock[])
 Encrypts a block of plaintext. More...
 
MOC_EXTERN MSTATUS CAST128_initKey (cast128_ctx *pCtx, const ubyte *pKey, sbyte4 keyLen)
 Initializes a cast128 context with a key. More...
 
MOC_EXTERN BulkCtx CreateCast128Ctx (MOC_SYM(hwAccelDescr hwAccelCtx) const ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Allocates and initalizes a new cast128 context. More...
 
MOC_EXTERN MSTATUS DeleteCast128Ctx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
 Deletes a cast128 context. More...
 
MOC_EXTERN MSTATUS DoCast128 (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
 Performs cast128 in CBC mode on a buffer of data. More...
 

Detailed Description

This file contains the NanoCrypto Cast128 API methods.

To enable this file's methods define the following flag:

  • __ENABLE_CAST128_CIPHER__

cast128.h

Function Documentation

◆ CAST128_decryptBlock()

MOC_EXTERN MSTATUS CAST128_decryptBlock ( cast128_ctx *  pCtx,
ubyte  inblock[],
ubyte  outblock[] 
)

Decrypts a block of ciphertext.

To enable this file's methods define the following flag:

  • __ENABLE_CAST128_CIPHER__
Parameters
pCtxPointer to a previously initialized context.
inblockBuffer of the input 8 byte block of ciphertext.
outblockBuffer that will hold the resulting 8 byte block of plaintext.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

cast128.h

◆ CAST128_encryptBlock()

MOC_EXTERN MSTATUS CAST128_encryptBlock ( cast128_ctx *  pCtx,
ubyte  inblock[],
ubyte  outblock[] 
)

Encrypts a block of plaintext.

To enable this file's methods define the following flag:

  • __ENABLE_CAST128_CIPHER__
Parameters
pCtxPointer to a previously initialized context.
inblockBuffer of the input 8 byte block of plaintext.
outblockBuffer that will hold the resulting 8 byte block of ciphertext.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

cast128.h

◆ CAST128_initKey()

MOC_EXTERN MSTATUS CAST128_initKey ( cast128_ctx *  pCtx,
const ubyte *  pKey,
sbyte4  keyLen 
)

Initializes a cast128 context with a key.

To enable this file's methods define the following flag:

  • __ENABLE_CAST128_CIPHER__
Parameters
pCtxPointer to a context to be initialized with a key.
pKeyBuffer holding the input key.
keyLenThe length of the key in bytes.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

cast128.h

◆ CreateCast128Ctx()

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

Allocates and initalizes a new cast128 context with an input key.

To enable this file's methods define the following flag:

  • __ENABLE_CAST128_CIPHER__
Parameters
keyMaterialBuffer holding the input key material.
keyLengthThe length of the input key in bytes.
encryptUnused.
Returns
If successful, pointer to a new cast128 context cast as a BulkCtx. Otherwise NULL is returned.

cast128.h

◆ DeleteCast128Ctx()

MOC_EXTERN MSTATUS DeleteCast128Ctx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *  ctx)

Deletes and frees memory allocated for a cast128 context.

To enable this file's methods define the following flag:

  • __ENABLE_CAST128_CIPHER__
Parameters
ctxPointer to the location of the context to be deleted.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

cast128.h

◆ DoCast128()

MOC_EXTERN MSTATUS DoCast128 ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  ctx,
ubyte *  data,
sbyte4  dataLength,
sbyte4  encrypt,
ubyte *  iv 
)

Performs cast128 in CBC mode to encrypt or decrypt a buffer of data. The length of this data must be a multiple of the cast block size of 8 bytes. This method may be called as many times as necessary and the initialization vector will be updated in-place.

To enable this file's methods define the following flag:

  • __ENABLE_CAST128_CIPHER__
Parameters
ctxPointer to a previously created context.
dataA buffer holding the data to be encrypted or decrypted. This will be encrypted or decrypted in-place.
dataLengthThe length of the data in bytes. This must be a multiple of 8.
encryptPass TRUE (1) for encryption and FALSE (0) for decryption.
ivThe 8 byte initialization vector. This will be updated in place to the iv for the next input block.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

cast128.h