My Project
Functions
ascon.h File Reference

Go to the source code of this file.

Functions

int wc_AsconHash256_Init (wc_AsconHash256 *a)
 This function initializes the ASCON context for hashing. More...
 
int wc_AsconHash256_Update (wc_AsconHash256 *a, const byte *data, word32 dataSz)
 This function updates the ASCON hash with the input data. More...
 
int wc_AsconHash256_Final (wc_AsconHash256 *a, byte *hash)
 This function finalizes the ASCON hash and produces the output. More...
 
wc_AsconAEAD128 * wc_AsconAEAD128_New (void)
 This function allocates and initializes a new Ascon AEAD context. More...
 
void wc_AsconAEAD128_Free (wc_AsconAEAD128 *a)
 This function frees the resources associated with the Ascon AEAD context. More...
 
int wc_AsconAEAD128_Init (wc_AsconAEAD128 *a)
 This function initializes an Ascon AEAD context. More...
 
void wc_AsconAEAD128_Clear (wc_AsconAEAD128 *a)
 This function deinitializes an Ascon AEAD context. It does not free the context. More...
 
int wc_AsconAEAD128_SetKey (wc_AsconAEAD128 *a, const byte *key)
 This function sets the key for the Ascon AEAD context. More...
 
int wc_AsconAEAD128_SetNonce (wc_AsconAEAD128 *a, const byte *nonce)
 This function sets the nonce for the Ascon AEAD context. More...
 
int wc_AsconAEAD128_SetAD (wc_AsconAEAD128 *a, const byte *ad, word32 adSz)
 This function sets the associated data for the Ascon AEAD context. More...
 
int wc_AsconAEAD128_EncryptUpdate (wc_AsconAEAD128 *a, byte *out, const byte *in, word32 inSz)
 This function encrypts a plaintext message using Ascon AEAD. The output is stored in the out buffer. The length of the output is equal to the length of the input. More...
 
int wc_AsconAEAD128_EncryptFinal (wc_AsconAEAD128 *a, byte *tag)
 This function finalizes the encryption process using Ascon AEAD and produces the authentication tag. More...
 
int wc_AsconAEAD128_DecryptUpdate (wc_AsconAEAD128 *a, byte *out, const byte *in, word32 inSz)
 This function updates the decryption process using Ascon AEAD. The output is stored in the out buffer. The length of the output is equal to the length of the input. More...
 
int wc_AsconAEAD128_DecryptFinal (wc_AsconAEAD128 *a, const byte *tag)
 This function finalizes the decryption process using Ascon AEAD and verifies the authentication tag. More...
 

Function Documentation

◆ wc_AsconAEAD128_Clear()

void wc_AsconAEAD128_Clear ( wc_AsconAEAD128 *  a)

This function deinitializes an Ascon AEAD context. It does not free the context.

Parameters
apointer to the Ascon AEAD context to deinitialize.

Example

AsconAead a;
if (wc_AsconAEAD128_Init(&a) != 0)
// handle error
void wc_AsconAEAD128_Clear(wc_AsconAEAD128 *a)
This function deinitializes an Ascon AEAD context. It does not free the context.
int wc_AsconAEAD128_Init(wc_AsconAEAD128 *a)
This function initializes an Ascon AEAD context.
See also
wc_AsconAeadEncrypt
wc_AsconAeadDecrypt

◆ wc_AsconAEAD128_DecryptFinal()

int wc_AsconAEAD128_DecryptFinal ( wc_AsconAEAD128 *  a,
const byte *  tag 
)

This function finalizes the decryption process using Ascon AEAD and verifies the authentication tag.

Returns
0 on success.
BAD_FUNC_ARG if the context or tag pointer is NULL.
BAD_STATE_E if the key, nonce, or additional data has not been set or the context was previously used for encryption.
ASCON_AUTH_E if the authentication tag does not match.
Parameters
apointer to the initialized Ascon AEAD context.
tagpointer to the buffer containing the authentication tag to verify

Example

wc_AsconAEAD128 a;
byte key[ASCON_AEAD128_KEY_SZ] = { ... };
byte nonce[ASCON_AEAD128_NONCE_SZ] = { ... };
byte ciphertext[CIPHER_TEXT_SIZE] = { ... };
byte plaintext[PLAIN_TEXT_SIZE];
byte tag[ASCON_AEAD128_TAG_SZ] = { ... };
if (wc_AsconAeadInit(&a) != 0)
// handle error
if (wc_AsconAEAD128_SetKey(&a, key) != 0)
// handle error
if (wc_AsconAEAD128_SetNonce(&a, nonce) != 0)
// handle error
if (wc_AsconAEAD128_SetAD(&a, ad, sizeof(ad)) != 0)
// handle error
if (wc_AsconAEAD128_DecryptUpdate(&a, plaintext, ciphertext,
sizeof(ciphertext)) != 0)
// handle error
if (wc_AsconAEAD128_DecryptFinal(&a, tag) != 0)
// handle error
int wc_AsconAEAD128_DecryptUpdate(wc_AsconAEAD128 *a, byte *out, const byte *in, word32 inSz)
This function updates the decryption process using Ascon AEAD. The output is stored in the out buffer...
int wc_AsconAEAD128_SetNonce(wc_AsconAEAD128 *a, const byte *nonce)
This function sets the nonce for the Ascon AEAD context.
int wc_AsconAEAD128_SetAD(wc_AsconAEAD128 *a, const byte *ad, word32 adSz)
This function sets the associated data for the Ascon AEAD context.
int wc_AsconAEAD128_DecryptFinal(wc_AsconAEAD128 *a, const byte *tag)
This function finalizes the decryption process using Ascon AEAD and verifies the authentication tag.
int wc_AsconAEAD128_SetKey(wc_AsconAEAD128 *a, const byte *key)
This function sets the key for the Ascon AEAD context.
See also
wc_AsconAEAD128_Init
wc_AsconAEAD128_SetKey
wc_AsconAEAD128_SetNonce
wc_AsconAEAD128_SetAD
wc_AsconAEAD128_DecryptUpdate
wc_AsconAEAD128_EncryptUpdate
wc_AsconAEAD128_EncryptFinal

◆ wc_AsconAEAD128_DecryptUpdate()

int wc_AsconAEAD128_DecryptUpdate ( wc_AsconAEAD128 *  a,
byte *  out,
const byte *  in,
word32  inSz 
)

This function updates the decryption process using Ascon AEAD. The output is stored in the out buffer. The length of the output is equal to the length of the input.

Returns
0 on success.
BAD_FUNC_ARG if the context or output pointer is NULL or the input is NULL while the input size is greater than 0.
BAD_STATE_E if the key, nonce, or additional data has not been set or the context was previously used for encryption.
Parameters
apointer to the initialized Ascon AEAD context.
outpointer to the output buffer to store the plaintext.
inpointer to the input buffer containing the ciphertext message.
inSzlength of the input buffer.

Example

wc_AsconAEAD128 a;
byte key[ASCON_AEAD128_KEY_SZ] = { ... };
byte nonce[ASCON_AEAD128_NONCE_SZ] = { ... };
byte ciphertext[CIPHER_TEXT_SIZE] = { ... };
byte plaintext[PLAIN_TEXT_SIZE];
byte tag[ASCON_AEAD128_TAG_SZ] = { ... };
if (wc_AsconAeadInit(&a) != 0)
// handle error
if (wc_AsconAEAD128_SetKey(&a, key) != 0)
// handle error
if (wc_AsconAEAD128_SetNonce(&a, nonce) != 0)
// handle error
if (wc_AsconAEAD128_SetAD(&a, ad, sizeof(ad)) != 0)
// handle error
if (wc_AsconAEAD128_DecryptUpdate(&a, plaintext, ciphertext,
sizeof(ciphertext)) != 0)
// handle error
if (wc_AsconAEAD128_DecryptFinal(&a, tag) != 0)
// handle error
See also
wc_AsconAEAD128_Init
wc_AsconAEAD128_SetKey
wc_AsconAEAD128_SetNonce
wc_AsconAEAD128_SetAD
wc_AsconAEAD128_EncryptUpdate
wc_AsconAEAD128_EncryptFinal
wc_AsconAEAD128_DecryptFinal

◆ wc_AsconAEAD128_EncryptFinal()

int wc_AsconAEAD128_EncryptFinal ( wc_AsconAEAD128 *  a,
byte *  tag 
)

This function finalizes the encryption process using Ascon AEAD and produces the authentication tag.

Returns
0 on success.
BAD_FUNC_ARG if the context or output pointer is NULL or the input is NULL while the input size is greater than 0.
BAD_STATE_E if the key, nonce, or additional data has not been set or the context was previously used for decryption.
Parameters
apointer to the initialized Ascon AEAD context.
tagpointer to the output buffer to store the authentication tag.

Example

wc_AsconAEAD128 a;
byte key[ASCON_AEAD128_KEY_SZ] = { ... };
byte nonce[ASCON_AEAD128_NONCE_SZ] = { ... };
byte plaintext[PLAIN_TEXT_SIZE] = { ... };
byte ciphertext[CIPHER_TEXT_SIZE];
byte tag[ASCON_AEAD128_TAG_SZ] = { ... };
if (wc_AsconAeadInit(&a) != 0)
// handle error
if (wc_AsconAEAD128_SetKey(&a, key) != 0)
// handle error
if (wc_AsconAEAD128_SetNonce(&a, nonce) != 0)
// handle error
if (wc_AsconAEAD128_SetAD(&a, ad, sizeof(ad)) != 0)
// handle error
if (wc_AsconAEAD128_EncryptUpdate(&a, ciphertext, plaintext,
sizeof(plaintext)) != 0)
// handle error
if (wc_AsconAEAD128_EncryptFinal(&a, tag) != 0)
// handle error
int wc_AsconAEAD128_EncryptFinal(wc_AsconAEAD128 *a, byte *tag)
This function finalizes the encryption process using Ascon AEAD and produces the authentication tag.
int wc_AsconAEAD128_EncryptUpdate(wc_AsconAEAD128 *a, byte *out, const byte *in, word32 inSz)
This function encrypts a plaintext message using Ascon AEAD. The output is stored in the out buffer....
See also
wc_AsconAEAD128_Init
wc_AsconAEAD128_SetKey
wc_AsconAEAD128_SetNonce
wc_AsconAEAD128_SetAD
wc_AsconAEAD128_EncryptUpdate
wc_AsconAEAD128_DecryptUpdate
wc_AsconAEAD128_DecryptFinal

◆ wc_AsconAEAD128_EncryptUpdate()

int wc_AsconAEAD128_EncryptUpdate ( wc_AsconAEAD128 *  a,
byte *  out,
const byte *  in,
word32  inSz 
)

This function encrypts a plaintext message using Ascon AEAD. The output is stored in the out buffer. The length of the output is equal to the length of the input.

Returns
0 on success.
BAD_FUNC_ARG if the context or output pointer is NULL or the input is NULL while the input size is greater than 0.
BAD_STATE_E if the key, nonce, or additional data has not been set or the context was previously used for decryption.
Parameters
apointer to the initialized Ascon AEAD context.
outpointer to the output buffer to store the ciphertext.
inpointer to the input buffer containing the plaintext message.
inSzlength of the input buffer.

Example

wc_AsconAEAD128 a;
byte key[ASCON_AEAD128_KEY_SZ] = { ... };
byte nonce[ASCON_AEAD128_NONCE_SZ] = { ... };
byte plaintext[PLAIN_TEXT_SIZE] = { ... };
byte ciphertext[CIPHER_TEXT_SIZE];
byte tag[ASCON_AEAD128_TAG_SZ] = { ... };
if (wc_AsconAeadInit(&a) != 0)
// handle error
if (wc_AsconAEAD128_SetKey(&a, key) != 0)
// handle error
if (wc_AsconAEAD128_SetNonce(&a, nonce) != 0)
// handle error
if (wc_AsconAEAD128_SetAD(&a, ad, sizeof(ad)) != 0)
// handle error
if (wc_AsconAEAD128_EncryptUpdate(&a, ciphertext, plaintext,
sizeof(plaintext)) != 0)
// handle error
if (wc_AsconAEAD128_EncryptFinal(&a, tag) != 0)
// handle error
See also
wc_AsconAeadInit
wc_AsconAEAD128_Clear
wc_AsconAEAD128_SetKey
wc_AsconAEAD128_SetNonce
wc_AsconAEAD128_SetAD
wc_AsconAEAD128_EncryptFinal
wc_AsconAEAD128_DecryptUpdate
wc_AsconAEAD128_DecryptFinal

◆ wc_AsconAEAD128_Free()

void wc_AsconAEAD128_Free ( wc_AsconAEAD128 *  a)

This function frees the resources associated with the Ascon AEAD context.

Parameters
apointer to the Ascon AEAD context to free.

Example

wc_AsconAEAD128* a = wc_AsconAEAD128_New();
if (a == NULL) {
// handle allocation error
}
// Use the context
wc_AsconAEAD128 * wc_AsconAEAD128_New(void)
This function allocates and initializes a new Ascon AEAD context.
void wc_AsconAEAD128_Free(wc_AsconAEAD128 *a)
This function frees the resources associated with the Ascon AEAD context.
See also
wc_AsconAEAD128_New

◆ wc_AsconAEAD128_Init()

int wc_AsconAEAD128_Init ( wc_AsconAEAD128 *  a)

This function initializes an Ascon AEAD context.

Returns
0 on success.
BAD_FUNC_ARG if the context or output pointer is NULL.
Parameters
apointer to the Ascon AEAD context to initialize.

Example

AsconAead a;
if (wc_AsconAEAD128_Init(&a) != 0)
// handle error
See also
wc_AsconAeadEncrypt
wc_AsconAeadDecrypt

◆ wc_AsconAEAD128_New()

wc_AsconAEAD128* wc_AsconAEAD128_New ( void  )

This function allocates and initializes a new Ascon AEAD context.

Returns
pointer to the newly allocated Ascon AEAD context
NULL on failure.

Example

wc_AsconAEAD128* a = wc_AsconAEAD128_New();
if (a == NULL) {
// handle allocation error
}
See also
wc_AsconAEAD128_Free

◆ wc_AsconAEAD128_SetAD()

int wc_AsconAEAD128_SetAD ( wc_AsconAEAD128 *  a,
const byte *  ad,
word32  adSz 
)

This function sets the associated data for the Ascon AEAD context.

Returns
0 on success.
BAD_FUNC_ARG if the context or associated data pointer is NULL.
BAD_STATE_E if the key or nonce has not been set.
Parameters
apointer to the initialized Ascon AEAD context.
adpointer to the associated data buffer.
adSzsize of the associated data buffer.

Example

wc_AsconAEAD128 a;
byte key[ASCON_AEAD128_KEY_SZ] = { ... };
byte nonce[ASCON_AEAD128_NONCE_SZ] = { ... };
byte ad[] = { ... };
if (wc_AsconAEAD128_Init(&a) != 0)
// handle error
if (wc_AsconAEAD128_SetKey(&a, key) != 0)
// handle error
if (wc_AsconAEAD128_SetNonce(&a, nonce) != 0)
// handle error
if (wc_AsconAEAD128_SetAD(&a, ad, sizeof(ad)) != 0)
// handle error
See also
wc_AsconAEAD128_Init
wc_AsconAEAD128_SetKey
wc_AsconAEAD128_SetNonce

◆ wc_AsconAEAD128_SetKey()

int wc_AsconAEAD128_SetKey ( wc_AsconAEAD128 *  a,
const byte *  key 
)

This function sets the key for the Ascon AEAD context.

Returns
0 on success.
BAD_FUNC_ARG if the context or key pointer is NULL.
BAD_STATE_E if the key has already been set.
Parameters
apointer to the initialized Ascon AEAD context.
keypointer to the key buffer of length ASCON_AEAD128_KEY_SZ.

Example

wc_AsconAEAD128 a;
byte key[ASCON_AEAD128_KEY_SZ] = { ... };
if (wc_AsconAEAD128_Init(&a) != 0)
// handle error
if (wc_AsconAEAD128_SetKey(&a, key) != 0)
// handle error
See also
wc_AsconAEAD128_Init
wc_AsconAEAD128_SetNonce
wc_AsconAEAD128_SetAD

◆ wc_AsconAEAD128_SetNonce()

int wc_AsconAEAD128_SetNonce ( wc_AsconAEAD128 *  a,
const byte *  nonce 
)

This function sets the nonce for the Ascon AEAD context.

Returns
0 on success.
BAD_FUNC_ARG if the context or nonce pointer is NULL.
BAD_STATE_E if the nonce has already been set.
Parameters
apointer to the initialized Ascon AEAD context.
noncepointer to the nonce buffer of length ASCON_AEAD128_NONCE_SZ.

Example

wc_AsconAEAD128 a;
byte nonce[ASCON_AEAD128_NONCE_SZ] = { ... };
if (wc_AsconAEAD128_Init(&a) != 0)
// handle error
if (wc_AsconAEAD128_SetNonce(&a, nonce) != 0)
// handle error
See also
wc_AsconAEAD128_Init
wc_AsconAEAD128_SetKey
wc_AsconAEAD128_SetAD

◆ wc_AsconHash256_Final()

int wc_AsconHash256_Final ( wc_AsconHash256 *  a,
byte *  hash 
)

This function finalizes the ASCON hash and produces the output.

Returns
0 on success.
BAD_FUNC_ARG if the context or output pointer is NULL.
Parameters
ctxpointer to the ASCON context.
outpointer to the output buffer.
outSzsize of the output buffer, should be at least ASCON_HASH256_SZ.

Example

wc_AsconHash256 a;
byte data[] = {0x01, 0x02, 0x03};
byte hash[ASCON_HASH256_SZ];
if (wc_AsconHash256_Init(&a) != 0)
// handle error
if (wc_AsconHash256_Update(&ctx, data, sizeof(data)) != 0)
// handle error
if (wc_AsconHash256_Final(&ctx, hash, sizeof(hash)) != 0)
// handle error
// hash contains the final hash
int wc_AsconHash256_Init(wc_AsconHash256 *a)
This function initializes the ASCON context for hashing.
int wc_AsconHash256_Update(wc_AsconHash256 *a, const byte *data, word32 dataSz)
This function updates the ASCON hash with the input data.
int wc_AsconHash256_Final(wc_AsconHash256 *a, byte *hash)
This function finalizes the ASCON hash and produces the output.
See also
wc_AsconHash256_Init
wc_AsconHash256_Update

◆ wc_AsconHash256_Init()

int wc_AsconHash256_Init ( wc_AsconHash256 *  a)

This function initializes the ASCON context for hashing.

Returns
0 on success.
BAD_FUNC_ARG if the context pointer is NULL.
Parameters
apointer to the ASCON context to initialize.

Example

wc_AsconHash256 a;
byte data[] = {0x01, 0x02, 0x03};
byte hash[ASCON_HASH256_SZ];
if (wc_AsconHash256_Init(&a) != 0)
// handle error
if (wc_AsconHash256_Update(&ctx, data, sizeof(data)) != 0)
// handle error
if (wc_AsconHash256_Final(&ctx, hash, sizeof(hash)) != 0)
// handle error
// hash contains the final hash
See also
wc_AsconHash256_Update
wc_AsconHash256_Final

◆ wc_AsconHash256_Update()

int wc_AsconHash256_Update ( wc_AsconHash256 *  a,
const byte *  data,
word32  dataSz 
)

This function updates the ASCON hash with the input data.

Returns
0 on success.
BAD_FUNC_ARG if the context or input pointer is NULL.
Parameters
ctxpointer to the ASCON context.
inpointer to the input data.
inSzsize of the input data.

Example

wc_AsconHash256 a;
byte data[] = {0x01, 0x02, 0x03};
byte hash[ASCON_HASH256_SZ];
if (wc_AsconHash256_Init(&a) != 0)
// handle error
if (wc_AsconHash256_Update(&ctx, data, sizeof(data)) != 0)
// handle error
if (wc_AsconHash256_Final(&ctx, hash, sizeof(hash)) != 0)
// handle error
// hash contains the final hash
See also
wc_AsconHash256_Init
wc_AsconHash256_Final