My Project
Functions
Algorithms - ChaCha

Functions

int wc_Chacha_SetIV (ChaCha *ctx, const byte *inIv, word32 counter)
 This function sets the initialization vector (nonce) for a ChaCha object, initializing it for use as a cipher. It should be called after the key has been set, using wc_Chacha_SetKey. A difference nonce should be used for each round of encryption. More...
 
int wc_Chacha_Process (ChaCha *ctx, byte *cipher, const byte *plain, word32 msglen)
 This function processes the text from the buffer input, encrypts or decrypts it, and stores the result in the buffer output. More...
 
int wc_Chacha_SetKey (ChaCha *ctx, const byte *key, word32 keySz)
 This function sets the key for a ChaCha object, initializing it for use as a cipher. It should be called before setting the nonce with wc_Chacha_SetIV, and before using it for encryption with wc_Chacha_Process. More...
 

Detailed Description

Function Documentation

◆ wc_Chacha_Process()

int wc_Chacha_Process ( ChaCha *  ctx,
byte *  cipher,
const byte *  plain,
word32  msglen 
)

This function processes the text from the buffer input, encrypts or decrypts it, and stores the result in the buffer output.

Returns
0 Returned upon successfully encrypting or decrypting the input
BAD_FUNC_ARG returned if there is an error processing the ctx input argument
Parameters
ctxpointer to the ChaCha structure on which to set the iv
outputpointer to a buffer in which to store the output ciphertext or decrypted plaintext
inputpointer to the buffer containing the input plaintext to encrypt or the input ciphertext to decrypt
msglenlength of the message to encrypt or the ciphertext to decrypt

Example

ChaCha enc;
// initialize enc with wc_Chacha_SetKey and wc_Chacha_SetIV
byte plain[] = { // initialize plaintext };
byte cipher[sizeof(plain)];
if( wc_Chacha_Process(&enc, cipher, plain, sizeof(plain)) != 0) {
// error processing ChaCha cipher
}
See also
wc_Chacha_SetKey
wc_Chacha_Process

◆ wc_Chacha_SetIV()

int wc_Chacha_SetIV ( ChaCha *  ctx,
const byte *  inIv,
word32  counter 
)

This function sets the initialization vector (nonce) for a ChaCha object, initializing it for use as a cipher. It should be called after the key has been set, using wc_Chacha_SetKey. A difference nonce should be used for each round of encryption.

Returns
0 Returned upon successfully setting the initialization vector
BAD_FUNC_ARG returned if there is an error processing the ctx input argument
Parameters
ctxpointer to the ChaCha structure on which to set the iv
inIvpointer to a buffer containing the 12 byte initialization vector with which to initialize the ChaCha structure
counterthe value at which the block counter should start–usually zero.

Example

ChaCha enc;
// initialize enc with wc_Chacha_SetKey
byte iv[12];
// initialize iv
if( wc_Chacha_SetIV(&enc, iv, 0) != 0) {
// error initializing ChaCha structure
}
See also
wc_Chacha_SetKey
wc_Chacha_Process

◆ wc_Chacha_SetKey()

int wc_Chacha_SetKey ( ChaCha *  ctx,
const byte *  key,
word32  keySz 
)

This function sets the key for a ChaCha object, initializing it for use as a cipher. It should be called before setting the nonce with wc_Chacha_SetIV, and before using it for encryption with wc_Chacha_Process.

Returns
0 Returned upon successfully setting the key
BAD_FUNC_ARG returned if there is an error processing the ctx input argument or if the key is not 16 or 32 bytes long
Parameters
ctxpointer to the ChaCha structure in which to set the key
keypointer to a buffer containing the 16 or 32 byte key with which to initialize the ChaCha structure
keySzthe length of the key passed in

Example

ChaCha enc;
byte key[] = { // initialize key };
if( wc_Chacha_SetKey(&enc, key, sizeof(key)) != 0) {
// error initializing ChaCha structure
}
See also
wc_Chacha_SetIV
wc_Chacha_Process
wc_Chacha_SetKey
int wc_Chacha_SetKey(ChaCha *ctx, const byte *key, word32 keySz)
This function sets the key for a ChaCha object, initializing it for use as a cipher....
wc_Chacha_Process
int wc_Chacha_Process(ChaCha *ctx, byte *cipher, const byte *plain, word32 msglen)
This function processes the text from the buffer input, encrypts or decrypts it, and stores the resul...
wc_Chacha_SetIV
int wc_Chacha_SetIV(ChaCha *ctx, const byte *inIv, word32 counter)
This function sets the initialization vector (nonce) for a ChaCha object, initializing it for use as ...