chachapoly.h
Go to the documentation of this file.
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBEDTLS_CHACHAPOLY_H
#define MBEDTLS_CHACHAPOLY_H
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
/* for shared error codes */
#include "mbedtls/poly1305.h"
#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054
#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
MBEDTLS_CHACHAPOLY_ENCRYPT,
MBEDTLS_CHACHAPOLY_DECRYPT
}
mbedtls_chachapoly_mode_t;
#if !defined(MBEDTLS_CHACHAPOLY_ALT)
#include "mbedtls/chacha20.h"
typedef struct mbedtls_chachapoly_context
{
mbedtls_chacha20_context chacha20_ctx;
mbedtls_poly1305_context poly1305_ctx;
uint64_t aad_len;
uint64_t ciphertext_len;
int state;
mbedtls_chachapoly_mode_t mode;
}
mbedtls_chachapoly_context;
#else /* !MBEDTLS_CHACHAPOLY_ALT */
#include "chachapoly_alt.h"
#endif /* !MBEDTLS_CHACHAPOLY_ALT */
void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
const unsigned char key[32] );
int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
const unsigned char nonce[12],
mbedtls_chachapoly_mode_t mode );
int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
const unsigned char *aad,
size_t aad_len );
int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
size_t len,
const unsigned char *input,
unsigned char *output );
int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
unsigned char mac[16] );
int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
size_t length,
const unsigned char nonce[12],
const unsigned char *aad,
size_t aad_len,
const unsigned char *input,
unsigned char *output,
unsigned char tag[16] );
int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
size_t length,
const unsigned char nonce[12],
const unsigned char *aad,
size_t aad_len,
const unsigned char tag[16],
const unsigned char *input,
unsigned char *output );
#if defined(MBEDTLS_SELF_TEST)
int mbedtls_chachapoly_self_test( int verbose );
#endif /* MBEDTLS_SELF_TEST */
#ifdef __cplusplus
}
#endif
#endif /* MBEDTLS_CHACHAPOLY_H */
chacha20.h
This file contains ChaCha20 definitions and functions.
mbedtls_chachapoly_finish
int mbedtls_chachapoly_finish(mbedtls_chachapoly_context *ctx, unsigned char mac[16])
This function finished the ChaCha20-Poly1305 operation and generates the MAC (authentication tag).
mbedtls_chachapoly_context
struct mbedtls_chachapoly_context mbedtls_chachapoly_context
mbedtls_chachapoly_init
void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx)
This function initializes the specified ChaCha20-Poly1305 context.
mbedtls_chachapoly_starts
int mbedtls_chachapoly_starts(mbedtls_chachapoly_context *ctx, const unsigned char nonce[12], mbedtls_chachapoly_mode_t mode)
This function starts a ChaCha20-Poly1305 encryption or decryption operation.
mbedtls_chachapoly_setkey
int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx, const unsigned char key[32])
This function sets the ChaCha20-Poly1305 symmetric encryption key.
mbedtls_chachapoly_update
int mbedtls_chachapoly_update(mbedtls_chachapoly_context *ctx, size_t len, const unsigned char *input, unsigned char *output)
Thus function feeds data to be encrypted or decrypted into an on-going ChaCha20-Poly1305 operation.
mbedtls_chachapoly_free
void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx)
This function releases and clears the specified ChaCha20-Poly1305 context.
mbedtls_chachapoly_encrypt_and_tag
int mbedtls_chachapoly_encrypt_and_tag(mbedtls_chachapoly_context *ctx, size_t length, const unsigned char nonce[12], const unsigned char *aad, size_t aad_len, const unsigned char *input, unsigned char *output, unsigned char tag[16])
This function performs a complete ChaCha20-Poly1305 authenticated encryption with the previously-set ...
mbedtls_chachapoly_self_test
int mbedtls_chachapoly_self_test(int verbose)
The ChaCha20-Poly1305 checkup routine.
mbedtls_chachapoly_mode_t
mbedtls_chachapoly_mode_t
Definition: chachapoly.h:54
MBEDTLS_CHACHAPOLY_ENCRYPT
@ MBEDTLS_CHACHAPOLY_ENCRYPT
Definition: chachapoly.h:55
MBEDTLS_CHACHAPOLY_DECRYPT
@ MBEDTLS_CHACHAPOLY_DECRYPT
Definition: chachapoly.h:56
mbedtls_chachapoly_auth_decrypt
int mbedtls_chachapoly_auth_decrypt(mbedtls_chachapoly_context *ctx, size_t length, const unsigned char nonce[12], const unsigned char *aad, size_t aad_len, const unsigned char tag[16], const unsigned char *input, unsigned char *output)
This function performs a complete ChaCha20-Poly1305 authenticated decryption with the previously-set ...
mbedtls_chachapoly_update_aad
int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context *ctx, const unsigned char *aad, size_t aad_len)
This function feeds additional data to be authenticated into an ongoing ChaCha20-Poly1305 operation.
config.h
Configuration options (set of defines)
poly1305.h
This file contains Poly1305 definitions and functions.
mbedtls_chacha20_context
Definition: chacha20.h:64
mbedtls_chachapoly_context
Definition: chachapoly.h:65
mbedtls_chachapoly_context::chacha20_ctx
mbedtls_chacha20_context chacha20_ctx
Definition: chachapoly.h:66
mbedtls_chachapoly_context::poly1305_ctx
mbedtls_poly1305_context poly1305_ctx
Definition: chachapoly.h:67
mbedtls_chachapoly_context::ciphertext_len
uint64_t ciphertext_len
Definition: chachapoly.h:69
mbedtls_chachapoly_context::aad_len
uint64_t aad_len
Definition: chachapoly.h:68
mbedtls_chachapoly_context::mode
mbedtls_chachapoly_mode_t mode
Definition: chachapoly.h:71
mbedtls_chachapoly_context::state
int state
Definition: chachapoly.h:70
mbedtls_poly1305_context
Definition: poly1305.h:64