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

Header file for the NanoCrypto AES-CTR API. More...

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS AESCTRInit (MOC_SYM(hwAccelDescr hwAccelCtx) AES_CTR_Ctx *aesCtrCtx, const ubyte *keyMaterial, sbyte4 keyLength, const ubyte initCounter[AES_BLOCK_SIZE])
 Prepare the key schedule for an existing AES-CTR context. More...
 
MOC_EXTERN MSTATUS CloneAESCTRCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 Clone a AES-CTR context. More...
 
MOC_EXTERN BulkCtx CreateAESCTRCtx (MOC_SYM(hwAccelDescr hwAccelCtx) const ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-CTR context data structure and prepare the key schedule. More...
 
MOC_EXTERN BulkCtx CreateAesCtrCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *keyMaterial, sbyte4 keyLength, sbyte4 encrypt)
 Create a new AES-CTR context data structure and prepare the key schedule for using with IPsec Encapsulating Security Payload. More...
 
MOC_EXTERN MSTATUS DeleteAESCTRCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ctx)
 Delete AES-CTR context data structure. More...
 
MOC_EXTERN MSTATUS DoAESCTR (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
 AES-CTR encrypt or decrypt a data buffer. More...
 
MOC_EXTERN MSTATUS DoAesCtr (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
 AES-CTR encrypt or decrypt a data buffer. More...
 
MOC_EXTERN MSTATUS DoAESCTREx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv, sbyte4 limit)
 AES-CTR encrypt or decrypt a data buffer. More...
 
MOC_EXTERN MSTATUS DoAesCtrEx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *data, sbyte4 dataLength, sbyte4 encrypt, ubyte *iv)
 AES-CTR encrypt or decrypt a data buffer. More...
 
MOC_EXTERN MSTATUS GetCounterBlockAESCTR (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte pCounterBuffer[AES_BLOCK_SIZE])
 AES-CTR get current counter block used in given context. More...
 

Detailed Description

Header file for the NanoCrypto AES-CTR API.

Function Documentation

◆ AESCTRInit()

MOC_EXTERN MSTATUS AESCTRInit ( MOC_SYM(hwAccelDescr hwAccelCtx) AES_CTR_Ctx *  aesCtrCtx,
const ubyte *  keyMaterial,
sbyte4  keyLength,
const ubyte  initCounter[AES_BLOCK_SIZE] 
)

There are no flag dependencies to enable this function.

aes_ctr.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.
aesCtrCtxPointer to an existing AES-CTR context.
keyMaterialKey material plus counter block.
keyLengthNumber of octets for AES key plus a fixed length counter block (AES_BLOCK_SIZE). Valid key lengths are: AES-CTR-128(16 + 16 = 32 octets), AES-CTR-192(40 octets), and AES-CTR-256 (48 octets).
initCounterThe initial counter block to use for this operation.
Returns
NULL if any error; otherwise pointer to created AES-CTR context.

Confirm that this function appears properly in the output; it's in question given the compiler-controlled declarations.

aes_ctr.h

◆ CloneAESCTRCtx()

MOC_EXTERN MSTATUS 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.

◆ CreateAESCTRCtx()

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

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

FIPS Approved
check-green.gif
Suite B Algorithm
x-red.gif
Flowchart AES-CTR

The AES-CTR context is an opaque data structure that holds information such as key length, key schedule, counter block, and mode of operation. To avoid memory leaks, your application code must call the DeleteAESCTRCtx function after completing AES-related operations (because the AES-CTR 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 subsequent AES function calls.

There are no flag dependencies to enable this function.

aes_ctr.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.
keyMaterialKey material plus counter block.
keyLengthNumber of octets for AES key plus a fixed length counter block (AES_BLOCK_SIZE). Valid key lengths are: AES-CTR-128(16 + 16 = 32 octets), AES-CTR-192(40 octets), and AES-CTR-256 (48 octets).
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 AES-CTR context.

Confirm that this function appears properly in the output; it's in question given the compiler-controlled declarations.

aes_ctr.h

◆ CreateAesCtrCtx()

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

This function creates and returns a context data structure for AES operations, and prepares the key schedule (intermediate key material). This is the first function your application calls when performing AES-CTR operations (encryption or decryption). Your application uses the returned structure in subsequent DoAesCtr() or DoAesCtrEx() function calls. Counter block must be initialized to one. Key material pointer must have 4 octet nonce following key.

FIPS Approved
check-green.gif
Suite B Algorithm
x-red.gif
Flowchart AES-CTR

The AES-CTR context is an opaque data structure that holds information such as key length, key schedule, counter block, and mode of operation. To avoid memory leaks, your application code must call the DeleteAESCTRCtx function after completing AES-related operations (because the AES-CTR 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 subsequent AES function calls.

There are no flag dependencies to enable this function.

aes_ctr.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.
keyMaterialKey material plus nonce blocks.
keyLengthNumber of octets for AES key plus a fixed length counter block (AES_BLOCK_SIZE). Valid key lengths are: AES-CTR-128(16 + 4 = 20 octets), AES-CTR-192(28 octets), and AES-CTR-256 (36 octets).
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 AES-CTR context.

Confirm that this function appears properly in the output; it's in question given the compiler-controlled declarations.

aes_ctr.h

◆ DeleteAESCTRCtx()

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

This function deletes an AES-CTR context previously created by CreateAESCTRCtx(). To avoid memory leaks, your application must call this function after completing AES-CTR related operations for a given context.

FIPS Approved
check-green.gif
Suite B Algorithm
x-red.gif
Flowchart AES-CTR

There are no flag dependencies to enable this function.

aes_ctr.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 AES-CTR 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.

aes_ctr.h

◆ DoAESCTR()

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

This function AES-CTR encrypts or decrypts a data buffer. Before calling this function, your application must call the CreateAESCTRCtx() function to dynamically create a valid AES-CTR context. For RFC 3686 usage, the IV should be NULL. If the IV parameter is not NULL, the contents of the IV are copied to counter block context within AES-CTR context. The internal counter block is incremented for each block that is encrypted/decrypted. AES in CTR mode does not require that the submitted data buffer be an even multiple of the AES block size (128 bits). Therefore, no padding is required, which makes this mode compatible with stream data.

FIPS Approved
check-green.gif
Suite B Algorithm
x-red.gif
Flowchart AES-CTR

There are no flag dependencies to enable this function.

aes_ctr.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
ctxAES-CTR context, previously created by CreateAESCTRCtx().
dataData to be encrypted or decrypted.
dataLengthNumber of octets of data to encrypt or decrypt (data).
encryptTRUE to encrypt the data; FALSE to decrypt the data.
ivUsually NULL, optionally used to pass in a new counter block of AES_BLOCK_SIZE.
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.

aes_ctr.h

◆ DoAesCtr()

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

This function AES-CTR encrypts or decrypts a data buffer. Before calling this function, your application must call the CreateAESCTRCtx() function to dynamically create a valid AES-CTR context. IV parameter must not be null, and must be at least 8 octets long. Note only first 8 bytes will be used. Counter block is incremented for each block that is encrypted/decrypted. AES in CTR mode does not require that the submitted data buffer be an even multiple of the AES block size (128 bits). Therefore, no padding is required, which makes this mode compatible with stream data.

FIPS Approved
check-green.gif
Suite B Algorithm
x-red.gif
Flowchart AES-CTR

There are no flag dependencies to enable this function.

aes_ctr.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
ctxAES-CTR context, previously created by CreateAesCtrCtx().
dataData to be encrypted or decrypted.
dataLengthNumber of octets of data to encrypt or decrypt (data).
encryptTRUE to encrypt the data; FALSE to decrypt the data.
ivMust be 8 octets, will not override nonce or counter.
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.

aes_ctr.h

◆ DoAESCTREx()

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

This function AES-CTR encrypts or decrypts a data buffer. Before calling this function, your application must call the CreateAESCTRCtx() function to dynamically create a valid AES-CTR context. For RFC 3686 usage, the IV should be NULL. If the IV parameter is not NULL, the contents of the IV are copied to counter block context within AES-CTR context. The internal counter block is incremented for each block that is encrypted/decrypted. AES in CTR mode does not require that the submitted data buffer be an even multiple of the AES block size (128 bits). Therefore, no padding is required, which makes this mode compatible with stream data.

FIPS Approved
check-green.gif
Suite B Algorithm
x-red.gif
Flowchart AES-CTR

There are no flag dependencies to enable this function.

aes_ctr.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
ctxAES-CTR context, previously created by CreateAESCTRCtx().
dataData to be encrypted or decrypted.
dataLengthNumber of octets of data to encrypt or decrypt (data).
encryptTRUE to encrypt the data; FALSE to decrypt the data.
ivUsually NULL, optionally used to pass in a new counter block of AES_BLOCK_SIZE.
limitSpecifies the last byte to increment -> AES_BLOCK_SIZE -> all bytes will be incremented 0 -> no bytes will be incremented
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.

aes_ctr.h

◆ DoAesCtrEx()

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

This function AES-CTR encrypts or decrypts a data buffer. Before calling this function, your application must call the CreateAESCTRCtx() function to dynamically create a valid AES-CTR context. IV parameter must not be null, and must be at least 8 octets long. Note only first 8 bytes will be used. Counter will be reset to 1 and offset will be reset to 0 before encrypt/derypt operation. AES in CTR mode does not require that the submitted data buffer be an even multiple of the AES block size (128 bits). Therefore, no padding is required, which makes this mode compatible with stream data.

FIPS Approved
check-green.gif
Suite B Algorithm
x-red.gif
Flowchart AES-CTR

There are no flag dependencies to enable this function.

aes_ctr.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
ctxAES-CTR context, previously created by CreateAesCtrCtx().
dataData to be encrypted or decrypted.
dataLengthNumber of octets of data to encrypt or decrypt (data).
encryptTRUE to encrypt the data; FALSE to decrypt the data.
ivMust be 8 octets, will not override nonce or counter.
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.

aes_ctr.h

◆ GetCounterBlockAESCTR()

MOC_EXTERN MSTATUS GetCounterBlockAESCTR ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  ctx,
ubyte  pCounterBuffer[AES_BLOCK_SIZE] 
)

This function takes an AES-CTR context, and writes the current counter block used to the given buffer, pCounterBuffer.

There are no flag dependencies to enable this function.

aes_ctr.h

Parameters
hwAccelCtxIf a hardware acceleration flag is defined, this macro expands to an additional parameter, "hwAccelDescr hwAccelCtx". Otherwise, this macro resolves to nothing.
ctxAES-CTR context, previously created by CreateAESCTRCtx().
pCounterBufferPointer to buffer that will store the counter block data.
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.

aes_ctr.h