mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-13 03:22:25 +03:00
.github
3rdparty
ChangeLog.d
cmake
configs
docs
doxygen
include
library
.gitignore
CMakeLists.txt
Makefile
aes.c
aesce.c
aesce.h
aesni.c
aesni.h
alignment.h
aria.c
asn1parse.c
asn1write.c
base64.c
base64_internal.h
bignum.c
bignum_core.c
bignum_core.h
bignum_mod.c
bignum_mod.h
bignum_mod_raw.c
bignum_mod_raw.h
bignum_mod_raw_invasive.h
block_cipher.c
block_cipher_internal.h
bn_mul.h
camellia.c
ccm.c
chacha20.c
chachapoly.c
check_crypto_config.h
cipher.c
cipher_wrap.c
cipher_wrap.h
cmac.c
common.h
constant_time.c
constant_time_impl.h
constant_time_internal.h
ctr.h
ctr_drbg.c
debug.c
des.c
dhm.c
ecdh.c
ecdsa.c
ecjpake.c
ecp.c
ecp_curves.c
ecp_curves_new.c
ecp_internal_alt.h
ecp_invasive.h
entropy.c
entropy_poll.c
entropy_poll.h
gcm.c
hkdf.c
hmac_drbg.c
lmots.c
lmots.h
lms.c
md.c
md5.c
md_psa.h
md_wrap.h
memory_buffer_alloc.c
mps_common.h
mps_error.h
mps_reader.c
mps_reader.h
mps_trace.c
mps_trace.h
net_sockets.c
nist_kw.c
oid.c
padlock.c
padlock.h
pem.c
pk.c
pk_internal.h
pk_wrap.c
pk_wrap.h
pkcs12.c
pkcs5.c
pkcs7.c
pkparse.c
pkwrite.c
pkwrite.h
platform.c
platform_util.c
poly1305.c
psa_crypto.c
psa_crypto_aead.c
psa_crypto_aead.h
psa_crypto_cipher.c
psa_crypto_cipher.h
psa_crypto_client.c
psa_crypto_core.h
psa_crypto_core_common.h
psa_crypto_driver_wrappers_no_static.h
psa_crypto_ecp.c
psa_crypto_ecp.h
psa_crypto_ffdh.c
psa_crypto_ffdh.h
psa_crypto_hash.c
psa_crypto_hash.h
psa_crypto_invasive.h
psa_crypto_its.h
psa_crypto_mac.c
psa_crypto_mac.h
psa_crypto_pake.c
psa_crypto_pake.h
psa_crypto_random_impl.h
psa_crypto_rsa.c
psa_crypto_rsa.h
psa_crypto_se.c
psa_crypto_se.h
psa_crypto_slot_management.c
psa_crypto_slot_management.h
psa_crypto_storage.c
psa_crypto_storage.h
psa_its_file.c
psa_util.c
psa_util_internal.h
ripemd160.c
rsa.c
rsa_alt_helpers.c
rsa_alt_helpers.h
rsa_internal.h
sha1.c
sha256.c
sha3.c
sha512.c
ssl_cache.c
ssl_ciphersuites.c
ssl_client.c
ssl_client.h
ssl_cookie.c
ssl_debug_helpers.h
ssl_misc.h
ssl_msg.c
ssl_ticket.c
ssl_tls.c
ssl_tls12_client.c
ssl_tls12_server.c
ssl_tls13_client.c
ssl_tls13_generic.c
ssl_tls13_invasive.h
ssl_tls13_keys.c
ssl_tls13_keys.h
ssl_tls13_server.c
threading.c
timing.c
version.c
x509.c
x509_create.c
x509_crl.c
x509_crt.c
x509_csr.c
x509write.c
x509write_crt.c
x509write_csr.c
programs
scripts
tests
visualc
.gitattributes
.gitignore
.globalrc
.mypy.ini
.pylintrc
.readthedocs.yaml
.travis.yml
.uncrustify.cfg
BRANCHES.md
BUGS.md
CMakeLists.txt
CONTRIBUTING.md
ChangeLog
DartConfiguration.tcl
LICENSE
Makefile
README.md
SECURITY.md
SUPPORT.md
dco.txt
Test data copied from existing test suites. Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
100 lines
3.3 KiB
C
100 lines
3.3 KiB
C
/**
|
|
* \file block_cipher_internal.h
|
|
*
|
|
* \brief Lightweight abstraction layer for block ciphers with 128 bit blocks,
|
|
* for use by the GCM and CCM modules.
|
|
*/
|
|
/*
|
|
* Copyright The Mbed TLS Contributors
|
|
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
|
*/
|
|
#ifndef MBEDTLS_BLOCK_CIPHER_INTERNAL_H
|
|
#define MBEDTLS_BLOCK_CIPHER_INTERNAL_H
|
|
|
|
#include "mbedtls/build_info.h"
|
|
|
|
#include "mbedtls/cipher.h"
|
|
|
|
#include "mbedtls/block_cipher.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* \brief Initialize the context.
|
|
* This must be the first API call before using the context.
|
|
*
|
|
* \param ctx The context to initialize.
|
|
*/
|
|
static inline void mbedtls_block_cipher_init(mbedtls_block_cipher_context_t *ctx)
|
|
{
|
|
memset(ctx, 0, sizeof(*ctx));
|
|
}
|
|
|
|
/**
|
|
* \brief Set the block cipher to use with this context.
|
|
* This must be called after mbedtls_block_cipher_init().
|
|
*
|
|
* \param ctx The context to set up.
|
|
* \param cipher_id The identifier of the cipher to use.
|
|
* This must be either AES, ARIA or Camellia.
|
|
* Warning: this is a ::mbedtls_cipher_id_t,
|
|
* not a ::mbedtls_block_cipher_id_t!
|
|
*
|
|
* \retval \c 0 on success.
|
|
* \retval #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if \p cipher_id was
|
|
* invalid.
|
|
*/
|
|
int mbedtls_block_cipher_setup(mbedtls_block_cipher_context_t *ctx,
|
|
mbedtls_cipher_id_t cipher_id);
|
|
|
|
/**
|
|
* \brief Set the key into the context.
|
|
*
|
|
* \param ctx The context to configure.
|
|
* \param key The buffer holding the key material.
|
|
* \param key_bitlen The size of the key in bits.
|
|
*
|
|
* \retval \c 0 on success.
|
|
* \retval #MBEDTLS_ERR_CIPHER_INVALID_CONTEXT if the context was not
|
|
* properly set up before calling this function.
|
|
* \retval One of #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH,
|
|
* #MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
* #MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA if \p key_bitlen is
|
|
* invalid.
|
|
*/
|
|
int mbedtls_block_cipher_setkey(mbedtls_block_cipher_context_t *ctx,
|
|
const unsigned char *key,
|
|
unsigned key_bitlen);
|
|
|
|
/**
|
|
* \brief Encrypt one block (16 bytes) with the configured key.
|
|
*
|
|
* \param ctx The context holding the key.
|
|
* \param input The buffer holding the input block. Must be 16 bytes.
|
|
* \param output The buffer to which the output block will be written.
|
|
* Must be writable and 16 bytes long.
|
|
* This must either not overlap with \p input, or be equal.
|
|
*
|
|
* \retval \c 0 on success.
|
|
* \retval #MBEDTLS_ERR_CIPHER_INVALID_CONTEXT if the context was not
|
|
* properly set up before calling this function.
|
|
* \retval Another negative value if encryption failed.
|
|
*/
|
|
int mbedtls_block_cipher_encrypt(mbedtls_block_cipher_context_t *ctx,
|
|
const unsigned char input[16],
|
|
unsigned char output[16]);
|
|
/**
|
|
* \brief Clear the context.
|
|
*
|
|
* \param ctx The context to clear.
|
|
*/
|
|
void mbedtls_block_cipher_free(mbedtls_block_cipher_context_t *ctx);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* MBEDTLS_BLOCK_CIPHER_INTERNAL_H */
|