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

Header file for the NanoCrypto Blowfish API. More...

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS CloneBlowfishCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 Clones a Blowfish context. More...
 
MOC_EXTERN BulkCtx CreateBlowfishCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Get a new Blowfish context data structure (for operations using a Blowfish key) and prepare the key schedule. More...
 
MOC_EXTERN MSTATUS DeleteBlowfishCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
 Delete Blowfish context data structure. More...
 
MOC_EXTERN MSTATUS DoBlowfish (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
 Blowfish-encrypt or Blowfish-decrypt a data buffer. More...
 

Detailed Description

Header file for the NanoCrypto Blowfish API.

Function Documentation

◆ CloneBlowfishCtx()

MOC_EXTERN MSTATUS CloneBlowfishCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
BulkCtx *  ppNewCtx 
)

Clones a Blowfish context. Be sure to free the new contex with a call to DeleteBlowfishCtx.

To enable this function, the following flag must be defined:

  • __ENABLE_BLOWFISH_CIPHERS__

blowfish.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
pCtxSource Blowfish context.
ppNewCtxWill point to the newly allocated copy of the source context.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.

blowfish.h

◆ CreateBlowfishCtx()

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

This function creates and returns a context data structure for Blowfish operations, and prepares the key schedule (intermediate key material). This is the first function your application calls when performing Blowfish operations (encryption or decryption). Your application uses the returned structure in subsequent DoBlowfish() function calls.

FIPS Approved
x-red.gif
Suite B Algorithm
x-red.gif
Flowchart Blowfish

The Blowfish context is an opaque data structure that holds information such as Blowfish context and key. To avoid memory leaks, your application code must call the DeleteBlowfishCtx() function after completing Blowfish operations (because the Blowfish context is dynamically allocated by this function during context creation).

Warning
If NULL is returned for the context pointer, you cannot use it as input to any subsequent DoBlowfish() function calls.

To enable this function, the following flag must be defined:

  • __ENABLE_BLOWFISH_CIPHERS__

blowfish.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing. But... what does the user specify? In the 5.3.1 docs, we just said that this was "Reserved for future use." Ditto this for all aes_ccm.{c,h} functions.
pKeyMaterialBlowfish key to use for encryption or decryption.
keyLengthNumber of bytes in the Blowfish key; must be a valid Blowfish key length (expected value is 16 bytes).
encryptTRUE to prepare the key schedule for encryption; FALSE to prepare the key schedule for decryption.
Returns
NULL if any error; otherwise pointer to created Blowfish context.

blowfish.h

◆ DeleteBlowfishCtx()

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

This function deletes a Blowfish context data structure previously created by CreateBlowfishCtx(). To avoid memory leaks, your application must call this function after completing Blowfish-related operations for a given context.

FIPS Approved
x-red.gif
Suite B Algorithm
x-red.gif
Flowchart Blowfish

To enable this function, the following flag must be defined:

  • __ENABLE_BLOWFISH_CIPHERS__

blowfish.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
ctxPointer to Blowfish context to delete.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.

blowfish.h

◆ DoBlowfish()

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

This function Blowfish-encrypts or Blowfish-decrypts a data buffer in CBC mode. Before calling this function, your application must call the CreateBlowfishCtx() function to dynamically create a valid Blowfish context.

FIPS Approved
x-red.gif
Suite B Algorithm
x-red.gif
Flowchart Blowfish

To enable this function, the following flag must be defined:

  • __ENABLE_BLOWFISH_CIPHERS__

blowfish.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
ctxBlowfish context, previously created by CreateBlowfishCtx().
dataData to encrypt or decrypt.
dataLengthNumber of bytes of data to encrypt or decrypt (data).
encryptTRUE to encrypt the data; FALSE to decrypt the data.
ivUnique IV for the Blowfish operation (encryption or decryption).
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.

blowfish.h