![]() |
TrustCore SDK Crypto Interface API reference
version 2.0
|
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... | |
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
pCtx | A previously initialized context. |
pNonce | A buffer containing the nonce to be set. |
nonceLength | The length of pNonce in bytes. |
pCounter | A buffer containing the counter to be set. |
counterLength | The length of pCounter in bytes. |
OK
(0) if successful For invalid input a negative number error code definition from merrors.h is returned.chacha20.c
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 | ||
) |
pCtx | Pointer to the context to use for the AEAD cipher operation. |
pNonce | Pointer to the nonce for the ChaCha20 operation. |
noncelen | The length of pNonce in bytes. This must be 12. |
pAad | Pointer to the additional authenticated data for the Poly1305 operation. |
aadLen | The length of pAad in bytes. This may be zero. |
pData | Pointer to the data to be encrypted or decrypted. |
dataLen | The length of pData in bytes. |
verifyLen | The length of the tag to be created or verified in bytes. This must be 16. |
encrypt | Unused. The encrypt flag entered via CRYPTO_INTERFACE_ChaCha20Poly1305_createCtx will take precedence. |
OK
(0) if successful, otherwise a negative number error code from merrors.h 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
ctx | A previously created context. |
pNonce | Buffer that holds the nonce. |
nlen | The length of pNonce in bytes. This must be 8. |
pAdata | Buffer that holds the additional authenticated data. This buffer is unused in SSH. |
alen | The length of pAdata in bytes. Unused. |
pData | A buffer of data to be encrypted or decrypted. |
dlen | The length of pData in bytes. |
verifyLen | The length of the verification tag in bytes. This must be 16. |
encrypt | Enter one (or nonzero) for encryption and 0 for decryption. |
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.chacha20.c
MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_cloneCtx | ( | MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx | pCtx, |
BulkCtx * | ppNewCtx | ||
) |
pCtx | Pointer to an instantiated BulkCtx. |
ppNewCtx | Double pointer to the BulkCtx to be created and populated with the key data from the source key. |
OK
(0) if successful, otherwise a negative number error code from merrors.h. 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.
pKey | Key material used for the ChaCha20 Poly1305 AEAD operation. |
keyLen | The length of pKey in bytes. This must be 32 bytes. |
encrypt | Enter TRUE (or non-zero) for encryption and FALSE (or zero) for decryption. |
OK
(0) if successful, otherwise a negative number error code from merrors.h MOC_EXTERN MSTATUS CRYPTO_INTERFACE_ChaCha20Poly1305_deleteCtx | ( | MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx * | ppCtx | ) |
ppCtx | Pointer to the BulkCtx (ie ChaCha20Poly1305 context) to be deleted. |
OK
(0) if successful, otherwise a negative number error code from merrors.h 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.
pCtx | A pointer to a previously initialized context. |
pTag | A 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. |
tagLen | The length of the pTag buffer in bytes. |
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.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.
pCtx | A pointer to a previously initialized context. |
pAadData | A pointer to a byte array holding the AAD. |
aadDataLen | The length of the pAadData buffer in bytes. |
OK
(0) if successful; otherwise a negative number error code definition from merrors.h. 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.
pCtx | A pointer to a previously initialized context. |
pData | A pointer to a byte array holding the data. |
dataLen | The length of the pData buffer in bytes. |
OK
(0) if successful; otherwise a negative number error code definition from merrors.h. 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.
pCtx | A pointer to a previously initialized context. |
pNonce | A pointer to a byte array holding the 12 byte nonce. |
nonceLen | The length of the pNonce buffer in bytes. This must be 12. |
OK
(0) if successful; otherwise a negative number error code definition from merrors.h. 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.
pKey | Key material used for the cipher operation. This key is a concatenation of (key || counter || nonce). |
keyLen | Length, in bytes, of the key material. 32 bytes of key, 4 bytes of counter, 12 bytes of nonce. |
mode | Unused. |
OK
(0) if successful, otherwise a negative number error code from merrors.h MOC_EXTERN MSTATUS CRYPTO_INTERFACE_DeleteChaCha20Ctx | ( | MOC_SYM(hwAccelDescr hwAccelCtx) BulkCtx * | ppBulkCtx | ) |
ppBulkCtx | Pointer to the BulkCtx to be deleted. |
OK
(0) if successful, otherwise a negative number error code from merrors.h 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.
pBulkCtx | Context to use for the cipher operation. |
pData | Data to encrypt or decrypt. |
dataLen | Length, in bytes, of the data to process. |
mode | Unused. |
pIv | Optional. 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) |
OK
(0) if successful, otherwise a negative number error code from merrors.h