chacha20.h
mbedtls/private_access.h
mbedtls/build_info.h
stdint.h
stddef.h
chachapoly.h
chachapoly_alt.h
mbedtls/build_info.h
chacha20.h
mbedtls/check_config.h
mbedtls/config_adjust_legacy_crypto.h
mbedtls/config_adjust_psa_from_legacy.h
mbedtls/config_adjust_psa_superset_legacy.h
mbedtls/config_adjust_ssl.h
mbedtls/config_adjust_x509.h
mbedtls/config_psa.h
mbedtls/mbedtls_config.h
mbedtls/private_access.h
psa/crypto_adjust_auto_enabled.h
psa/crypto_adjust_config_dependencies.h
psa/crypto_adjust_config_key_pair_types.h
psa/crypto_adjust_config_synonyms.h
psa/crypto_legacy.h
limits.h
stddef.h
stdint.h
chacha20.h
chachapoly.h
debug.h
net_sockets.h
oid.h
pk.h
pkcs7.h
psa_util.h
ssl.h
ssl_cache.h
ssl_ciphersuites.h
ssl_cookie.h
ssl_ticket.h
x509.h
x509_crl.h
x509_crt.h
x509_csr.h
crypto.h
crypto_builtin_composites.h
crypto_driver_contexts_composites.h
crypto_struct.h
chachapoly_alt.h
mbedtls_chacha20_context
MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA
-0x0051

Invalid input parameter(s).

struct mbedtls_chacha20_context typedef struct mbedtls_chacha20_context mbedtls_chacha20_context mbedtls_chacha20_context
void void mbedtls_chacha20_init (mbedtls_chacha20_context *ctx) mbedtls_chacha20_init mbedtls_chacha20_context * ctx

This function initializes the specified ChaCha20 context.

It must be the first API called before using the context. It is usually followed by calls to \c mbedtls_chacha20_setkey() and \c mbedtls_chacha20_starts(), then one or more calls to to \c mbedtls_chacha20_update(), and finally to \c mbedtls_chacha20_free().

ctx

The ChaCha20 context to initialize. This must not be `NULL`.

void void mbedtls_chacha20_free (mbedtls_chacha20_context *ctx) mbedtls_chacha20_free mbedtls_chacha20_context * ctx

This function releases and clears the specified ChaCha20 context.

ctx

The ChaCha20 context to clear. This may be `NULL`, in which case this function is a no-op. If it is not `NULL`, it must point to an initialized context.

int int mbedtls_chacha20_setkey (mbedtls_chacha20_context *ctx, const unsigned char key[32]) mbedtls_chacha20_setkey mbedtls_chacha20_context * ctx const unsigned char key [32]

This function sets the encryption/decryption key.

After using this function, you must also call `mbedtls_chacha20_starts()` to set a nonce before you start encrypting/decrypting data with `mbedtls_chacha_update()`.

ctx

The ChaCha20 context to which the key should be bound. It must be initialized.

key

The encryption/decryption key. This must be `32` Bytes in length.

`0` on success.

MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or key is NULL.

int int mbedtls_chacha20_starts (mbedtls_chacha20_context *ctx, const unsigned char nonce[12], uint32_t counter) mbedtls_chacha20_starts mbedtls_chacha20_context * ctx const unsigned char nonce [12] uint32_t counter

This function sets the nonce and initial counter value.

A ChaCha20 context can be re-used with the same key by calling this function to change the nonce.

You must never use the same nonce twice with the same key. This would void any confidentiality guarantees for the messages encrypted with the same nonce and key.

ctx

The ChaCha20 context to which the nonce should be bound. It must be initialized and bound to a key.

nonce

The nonce. This must be `12` Bytes in size.

counter

The initial counter value. This is usually `0`.

`0` on success.

MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or nonce is NULL.

int int mbedtls_chacha20_update (mbedtls_chacha20_context *ctx, size_t size, const unsigned char *input, unsigned char *output) mbedtls_chacha20_update mbedtls_chacha20_context * ctx size_t size const unsigned char * input unsigned char * output

This function encrypts or decrypts data.

Since ChaCha20 is a stream cipher, the same operation is used for encrypting and decrypting data.

The `input` and `output` pointers must either be equal or point to non-overlapping buffers.

`mbedtls_chacha20_setkey()` and `mbedtls_chacha20_starts()` must be called at least once to setup the context before this function can be called.

This function can be called multiple times in a row in order to encrypt of decrypt data piecewise with the same key and nonce.

ctx

The ChaCha20 context to use for encryption or decryption. It must be initialized and bound to a key and nonce.

size

The length of the input data in Bytes.

input

The buffer holding the input data. This pointer can be `NULL` if `size == 0`.

output

The buffer holding the output data. This must be able to hold `size` Bytes. This pointer can be `NULL` if `size == 0`.

`0` on success.

A negative error code on failure.

int int mbedtls_chacha20_crypt (const unsigned char key[32], const unsigned char nonce[12], uint32_t counter, size_t size, const unsigned char *input, unsigned char *output) mbedtls_chacha20_crypt const unsigned char key [32] const unsigned char nonce [12] uint32_t counter size_t size const unsigned char * input unsigned char * output

This function encrypts or decrypts data with ChaCha20 and the given key and nonce.

Since ChaCha20 is a stream cipher, the same operation is used for encrypting and decrypting data.

You must never use the same (key, nonce) pair more than once. This would void any confidentiality guarantees for the messages encrypted with the same nonce and key.

The `input` and `output` pointers must either be equal or point to non-overlapping buffers.

key

The encryption/decryption key. This must be `32` Bytes in length.

nonce

The nonce. This must be `12` Bytes in size.

counter

The initial counter value. This is usually `0`.

size

The length of the input data in Bytes.

input

The buffer holding the input data. This pointer can be `NULL` if `size == 0`.

output

The buffer holding the output data. This must be able to hold `size` Bytes. This pointer can be `NULL` if `size == 0`.

`0` on success.

A negative error code on failure.

int int mbedtls_chacha20_self_test (int verbose) mbedtls_chacha20_self_test int verbose

The ChaCha20 checkup routine.

`0` on success.

`1` on failure.

This file contains ChaCha20 definitions and functions.

ChaCha20 is a stream cipher that can encrypt and decrypt information. ChaCha was created by Daniel Bernstein as a variant of its Salsa cipher https://cr.yp.to/chacha/chacha-20080128.pdf ChaCha20 is the variant with 20 rounds, that was also standardized in RFC 7539.

Daniel King damaki.gh@gmail.com

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */

    #ifndefMBEDTLS_CHACHA20_H
    #defineMBEDTLS_CHACHA20_H
    #include"mbedtls/private_access.h"

    #include"mbedtls/build_info.h"

    #include<stdint.h>
    #include<stddef.h>

    #defineMBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA-0x0051

    #ifdef__cplusplus
    extern"C"{
    #endif

    #if!defined(MBEDTLS_CHACHA20_ALT)

    typedefstructmbedtls_chacha20_context{
    uint32_tMBEDTLS_PRIVATE(state)[16];
    uint8_tMBEDTLS_PRIVATE(keystream8)[64];
    size_tMBEDTLS_PRIVATE(keystream_bytes_used);
    }
    mbedtls_chacha20_context;

    #else/*MBEDTLS_CHACHA20_ALT*/
    #include"chacha20_alt.h"
    #endif/*MBEDTLS_CHACHA20_ALT*/

    voidmbedtls_chacha20_init(mbedtls_chacha20_context*ctx);

    voidmbedtls_chacha20_free(mbedtls_chacha20_context*ctx);

    intmbedtls_chacha20_setkey(mbedtls_chacha20_context*ctx,
    constunsignedcharkey[32]);

    intmbedtls_chacha20_starts(mbedtls_chacha20_context*ctx,
    constunsignedcharnonce[12],
    uint32_tcounter);

    intmbedtls_chacha20_update(mbedtls_chacha20_context*ctx,
    size_tsize,
    constunsignedchar*input,
    unsignedchar*output);

    intmbedtls_chacha20_crypt(constunsignedcharkey[32],
    constunsignedcharnonce[12],
    uint32_tcounter,
    size_tsize,
    constunsignedchar*input,
    unsignedchar*output);

    #ifdefined(MBEDTLS_SELF_TEST)
    intmbedtls_chacha20_self_test(intverbose);
    #endif/*MBEDTLS_SELF_TEST*/

    #ifdef__cplusplus
    }
    #endif

    #endif/*MBEDTLS_CHACHA20_H*/