Path: blob/master/thirdparty/mbedtls/library/block_cipher_internal.h
9898 views
/**1* \file block_cipher_internal.h2*3* \brief Lightweight abstraction layer for block ciphers with 128 bit blocks,4* for use by the GCM and CCM modules.5*/6/*7* Copyright The Mbed TLS Contributors8* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later9*/10#ifndef MBEDTLS_BLOCK_CIPHER_INTERNAL_H11#define MBEDTLS_BLOCK_CIPHER_INTERNAL_H1213#include "mbedtls/build_info.h"1415#include "mbedtls/cipher.h"1617#include "mbedtls/block_cipher.h"1819#ifdef __cplusplus20extern "C" {21#endif2223/**24* \brief Initialize the context.25* This must be the first API call before using the context.26*27* \param ctx The context to initialize.28*/29static inline void mbedtls_block_cipher_init(mbedtls_block_cipher_context_t *ctx)30{31memset(ctx, 0, sizeof(*ctx));32}3334/**35* \brief Set the block cipher to use with this context.36* This must be called after mbedtls_block_cipher_init().37*38* \param ctx The context to set up.39* \param cipher_id The identifier of the cipher to use.40* This must be either AES, ARIA or Camellia.41* Warning: this is a ::mbedtls_cipher_id_t,42* not a ::mbedtls_block_cipher_id_t!43*44* \retval \c 0 on success.45* \retval #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if \p cipher_id was46* invalid.47*/48int mbedtls_block_cipher_setup(mbedtls_block_cipher_context_t *ctx,49mbedtls_cipher_id_t cipher_id);5051/**52* \brief Set the key into the context.53*54* \param ctx The context to configure.55* \param key The buffer holding the key material.56* \param key_bitlen The size of the key in bits.57*58* \retval \c 0 on success.59* \retval #MBEDTLS_ERR_CIPHER_INVALID_CONTEXT if the context was not60* properly set up before calling this function.61* \retval One of #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH,62* #MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,63* #MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA if \p key_bitlen is64* invalid.65*/66int mbedtls_block_cipher_setkey(mbedtls_block_cipher_context_t *ctx,67const unsigned char *key,68unsigned key_bitlen);6970/**71* \brief Encrypt one block (16 bytes) with the configured key.72*73* \param ctx The context holding the key.74* \param input The buffer holding the input block. Must be 16 bytes.75* \param output The buffer to which the output block will be written.76* Must be writable and 16 bytes long.77* This must either not overlap with \p input, or be equal.78*79* \retval \c 0 on success.80* \retval #MBEDTLS_ERR_CIPHER_INVALID_CONTEXT if the context was not81* properly set up before calling this function.82* \retval Another negative value if encryption failed.83*/84int mbedtls_block_cipher_encrypt(mbedtls_block_cipher_context_t *ctx,85const unsigned char input[16],86unsigned char output[16]);87/**88* \brief Clear the context.89*90* \param ctx The context to clear.91*/92void mbedtls_block_cipher_free(mbedtls_block_cipher_context_t *ctx);9394#ifdef __cplusplus95}96#endif9798#endif /* MBEDTLS_BLOCK_CIPHER_INTERNAL_H */99100101