ReactOS 0.4.16-dev-927-g467dec4
|
This file contains ChaCha20 definitions and functions. More...
Go to the source code of this file.
Classes | |
struct | mbedtls_chacha20_context |
Macros | |
#define | MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051 |
#define | MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053 |
#define | MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055 |
Typedefs | |
typedef struct mbedtls_chacha20_context | mbedtls_chacha20_context |
Functions | |
void | mbedtls_chacha20_init (mbedtls_chacha20_context *ctx) |
This function initializes the specified ChaCha20 context. | |
void | mbedtls_chacha20_free (mbedtls_chacha20_context *ctx) |
This function releases and clears the specified ChaCha20 context. | |
int | mbedtls_chacha20_setkey (mbedtls_chacha20_context *ctx, const unsigned char key[32]) |
This function sets the encryption/decryption key. | |
int | mbedtls_chacha20_starts (mbedtls_chacha20_context *ctx, const unsigned char nonce[12], uint32_t counter) |
This function sets the nonce and initial counter value. | |
int | mbedtls_chacha20_update (mbedtls_chacha20_context *ctx, size_t size, const unsigned char *input, unsigned char *output) |
This function encrypts or decrypts data. | |
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) |
This function encrypts or decrypts data with ChaCha20 and the given key and nonce. | |
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.
Definition in file chacha20.h.
#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051 |
Invalid input parameter(s).
Definition at line 71 of file chacha20.h.
#define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053 |
Feature not available. For example, s part of the API is not implemented.
Definition at line 75 of file chacha20.h.
#define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055 |
Chacha20 hardware accelerator failed.
Definition at line 79 of file chacha20.h.
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 | ||
) |
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.
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. void mbedtls_chacha20_free | ( | mbedtls_chacha20_context * | ctx | ) |
void 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 . |
int mbedtls_chacha20_setkey | ( | mbedtls_chacha20_context * | ctx, |
const unsigned char | key[32] | ||
) |
This function sets the encryption/decryption key.
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. int mbedtls_chacha20_starts | ( | mbedtls_chacha20_context * | ctx, |
const unsigned char | nonce[12], | ||
uint32_t | counter | ||
) |
This function sets the nonce and initial counter value.
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. int 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.
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.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.