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

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

Go to the source code of this file.

Functions

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_CHACHA20_setNonceAndCounterSSH (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *pNonce, ubyte4 nonceLength, ubyte *pCounter, ubyte counterLength)
 Set values for the nonce and counter blocks for ChaCha20 context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_cipher (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pNonce, ubyte4 noncelen, ubyte *pAad, ubyte4 aadLen, ubyte *pData, ubyte4 dataLen, ubyte4 verifyLen, sbyte4 encrypt)
 Performs the ChaCha20 Poly1305 AEAD operation. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_cipherSSH (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx ctx, ubyte *pNonce, ubyte4 nlen, ubyte *pAdata, ubyte4 alen, ubyte *pData, ubyte4 dlen, ubyte4 verifyLen, sbyte4 encrypt)
 Performs the ChaCha20poly1305 AEAD algorithm as specified for SSH authentication protocol. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_cloneCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, BulkCtx *ppNewCtx)
 Clone a ChaCha20Poly1305 context. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_ChaCha20Poly1305_createCtx (MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *pKey, sbyte4 keyLen, sbyte4 encrypt)
 Create a new ChaCha20Poly1305 context for use in the ChaCha20 Poly1305 AEAD. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_deleteCtx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ppCtx)
 Deletes a ChaCha20Poly1305 context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_final (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pTag, ubyte4 tagLen)
 Finalizes a previously initialized context and computes or verifies the MAC. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_update_aad (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pAadData, ubyte4 aadDataLen)
 Updates a ChaCha20Ctx context with additional authenticated data. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_update_data (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pData, ubyte4 dataLen)
 Updates a ChaCha20Ctx context with data to be encrypted or decrypted. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_update_nonce (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pCtx, ubyte *pNonce, ubyte4 nonceLen)
 Adds the nonce value to a ChaCha20Ctx context data structure for use with the Poly1305 MAC algorithm. More...
 
MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateChaCha20Ctx (MOC_SYM(hwAccelDescr hwAccelCtx) const ubyte pKey[48], sbyte4 keyLen, sbyte4 mode)
 Create a new ChaCha20 context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DeleteChaCha20Ctx (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *ppBulkCtx)
 Delete a ChaCha20 context. More...
 
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoChaCha20 (MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx pBulkCtx, ubyte *pData, sbyte4 dataLen, sbyte4 mode, ubyte *pIv)
 Encrypt or decrypt data using the provided ChaCha20 context. More...
 

Detailed Description

Function Documentation

◆ CRYPTO_INTERFACE_CHACHA20_setNonceAndCounterSSH()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_CHACHA20_setNonceAndCounterSSH ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  ctx,
ubyte *  pNonce,
ubyte4  nonceLength,
ubyte *  pCounter,
ubyte  counterLength 
)

This function specifically is for ssh protocol, this function assumes an 8 byte counter and an 8 byte nonce.

Set values for the nonce and counter blocks for ChaCha20 context. This function specifically is for ssh protocol, this function assumes an 8 byte counter and an 8 byte nonce.

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

  • __ENABLE_MOCANA_CHACHA20__

chacha20.h

Parameters
pCtxA previously initialized context.
pNonceA buffer containing the nonce to be set.
nonceLengthThe length of pNonce in bytes.
pCounterA buffer containing the counter to be set.
counterLengthThe length of pCounter in bytes.
Returns
OK (0) if successful For invalid input a negative number error code definition from merrors.h is returned.

chacha20.c

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_cipher()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_cipher ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pNonce,
ubyte4  noncelen,
ubyte *  pAad,
ubyte4  aadLen,
ubyte *  pData,
ubyte4  dataLen,
ubyte4  verifyLen,
sbyte4  encrypt 
)
Parameters
pCtxPointer to the context to use for the AEAD cipher operation.
pNoncePointer to the nonce for the ChaCha20 operation.
noncelenThe length of pNonce in bytes. This must be 12.
pAadPointer to the additional authenticated data for the Poly1305 operation.
aadLenThe length of pAad in bytes. This may be zero.
pDataPointer to the data to be encrypted or decrypted.
dataLenThe length of pData in bytes.
verifyLenThe length of the tag to be created or verified in bytes. This must be 16.
encryptUnused. The encrypt flag entered via CRYPTO_INTERFACE_ChaCha20Poly1305_createCtx will take precedence.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_cipherSSH()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_cipherSSH ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  ctx,
ubyte *  pNonce,
ubyte4  nlen,
ubyte *  pAdata,
ubyte4  alen,
ubyte *  pData,
ubyte4  dlen,
ubyte4  verifyLen,
sbyte4  encrypt 
)

Performs the ChaCha20poly1305 AEAD algorithm as specified for SSH authentication protocol.

To enable this method, the following flags must be defined:

  • __ENABLE_MOCANA_CHACHA20__
  • __ENABLE_MOCANA_POLY1305__

chacha20.h

Parameters
ctxA previously created context.
pNonceBuffer that holds the nonce.
nlenThe length of pNonce in bytes. This must be 8.
pAdataBuffer that holds the additional authenticated data. This buffer is unused in SSH.
alenThe length of pAdata in bytes. Unused.
pDataA buffer of data to be encrypted or decrypted.
dlenThe length of pData in bytes.
verifyLenThe length of the verification tag in bytes. This must be 16.
encryptEnter one (or nonzero) for encryption and 0 for decryption.
Returns
OK (0) if successful including the tag being valid on decryption. For an invalid tag or invalid input a negative number error code definition from merrors.h is returned.
Warning
For authenticated decryption be sure to check the return code for OK before accepting that the decrypted data is authentic.

chacha20.c

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_cloneCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_cloneCtx ( 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_ChaCha20Poly1305_createCtx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_ChaCha20Poly1305_createCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) ubyte *  pKey,
sbyte4  keyLen,
sbyte4  encrypt 
)

Note: It is the caller's responsibility to free this object after use by calling CRYPTO_INTERFACE_ChaCha20Poly1305_deleteCtx. Once created, you may use this context as input to CRYPTO_INTERFACE_ChaCha20Poly1305_cipher API.

Parameters
pKeyKey material used for the ChaCha20 Poly1305 AEAD operation.
keyLenThe length of pKey in bytes. This must be 32 bytes.
encryptEnter TRUE (or non-zero) for encryption and FALSE (or zero) for decryption.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_deleteCtx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_deleteCtx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *  ppCtx)
Parameters
ppCtxPointer to the BulkCtx (ie ChaCha20Poly1305 context) to be deleted.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_final()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_final ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pTag,
ubyte4  tagLen 
)

Finalizes a previously initialized context. If the context was initialized for encryption then the generated Poly1305 tag will be placed in the buffer pTag. If the context was initialized for decryption, then pTag is an input parameter for the existing tag, which will then be verified.

There are no flag dependencies to enable this function.

Parameters
pCtxA pointer to a previously initialized context.
pTagA pointer to a byte array of data. This will hold the resulting tag if the context was initialized for encryption. If the context was initialized for decryption, then this is an input parameter for the existing tag, which will then be verified.
tagLenThe length of the pTag buffer in bytes.
Returns
OK (0) if successful including the tag being valid on decryption. For an invalid tag or invalid input a negative number error code definition from merrors.h is returned.
Warning
For authenticated decryption be sure to check the return code for OK before accepting that the decrypted data is authentic.

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_update_aad()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_update_aad ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pAadData,
ubyte4  aadDataLen 
)

Updates an initialized context with additional authenticated data (AAD). One may call update as many times as needed with portions of the AAD. All calls to CRYPTO_INTERFACE_ChaCha20Poly1305_update_aad must happen before calling CRYPTO_INTERFACE_ChaCha20Poly1305_update_data.

There are no flag dependencies to enable this function.

Parameters
pCtxA pointer to a previously initialized context.
pAadDataA pointer to a byte array holding the AAD.
aadDataLenThe length of the pAadData buffer in bytes.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_update_data()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_update_data ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pData,
ubyte4  dataLen 
)

Updates an initialized context with the data to be encrypted or decrypted. The encryption or decryption will happen in-place. One may call update as many times as needed with portions of the data.

There are no flag dependencies to enable this function.

Parameters
pCtxA pointer to a previously initialized context.
pDataA pointer to a byte array holding the data.
dataLenThe length of the pData buffer in bytes.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ CRYPTO_INTERFACE_ChaCha20Poly1305_update_nonce()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_update_nonce ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pCtx,
ubyte *  pNonce,
ubyte4  nonceLen 
)

Adds the nonce value to a ChaCha20Ctx context data structure for use with the Poly1305 MAC algorithm. The counter will be initialized to 0.

There are no flag dependencies to enable this function.

Parameters
pCtxA pointer to a previously initialized context.
pNonceA pointer to a byte array holding the 12 byte nonce.
nonceLenThe length of the pNonce buffer in bytes. This must be 12.
Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h.

◆ CRYPTO_INTERFACE_CreateChaCha20Ctx()

MOC_EXTERN BulkCtx CRYPTO_INTERFACE_CreateChaCha20Ctx ( MOC_SYM(hwAccelDescr hwAccelCtx) const ubyte  pKey[48],
sbyte4  keyLen,
sbyte4  mode 
)

Note: It is the caller's responsibility to free this object after use by calling CRYPTO_INTERFACE_DeleteChaCha20Ctx. Once created, you may use this context as input to CRYPTO_INTERFACE_DoChaCha20 to encrypt or decrypt data.

Parameters
pKeyKey material used for the cipher operation. This key is a concatenation of (key || counter || nonce).
keyLenLength, in bytes, of the key material. 32 bytes of key, 4 bytes of counter, 12 bytes of nonce.
modeUnused.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_DeleteChaCha20Ctx()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DeleteChaCha20Ctx ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx *  ppBulkCtx)
Parameters
ppBulkCtxPointer to the BulkCtx to be deleted.
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h

◆ CRYPTO_INTERFACE_DoChaCha20()

MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DoChaCha20 ( MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx  pBulkCtx,
ubyte *  pData,
sbyte4  dataLen,
sbyte4  mode,
ubyte *  pIv 
)

This function can be used to stream data so new data may be passed in on each subsequent call. Note: This operation is performed in-place, meaning that the pData buffer will contain the result.

Parameters
pBulkCtxContext to use for the cipher operation.
pDataData to encrypt or decrypt.
dataLenLength, in bytes, of the data to process.
modeUnused.
pIvOptional. If provided, it will be used as the counter and nonce in the creation of future blocks of key stream. The latest IV (ie counter and nonce) will then be written to this buffer. (nanocrypto mode only)
Returns
OK (0) if successful, otherwise a negative number error code from merrors.h