2011-01-06 15:37:30 +00:00
|
|
|
/**
|
2021-03-09 17:03:29 +00:00
|
|
|
* \file cipher_wrap.h
|
2014-05-01 11:03:14 +00:00
|
|
|
*
|
2011-01-06 15:37:30 +00:00
|
|
|
* \brief Cipher wrappers.
|
|
|
|
*
|
|
|
|
* \author Adriaan de Jong <dejong@fox-it.com>
|
2018-01-05 15:33:17 +00:00
|
|
|
*/
|
|
|
|
/*
|
2020-08-07 11:07:28 +00:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2015-09-04 12:21:07 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2011-01-06 15:37:30 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* 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
|
2011-01-06 15:37:30 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-01-06 15:37:30 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* 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.
|
2011-01-06 15:37:30 +00:00
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
#ifndef MBEDTLS_CIPHER_WRAP_H
|
|
|
|
#define MBEDTLS_CIPHER_WRAP_H
|
2011-01-06 15:37:30 +00:00
|
|
|
|
2021-05-27 09:25:03 +00:00
|
|
|
#include "mbedtls/build_info.h"
|
2015-02-13 14:12:07 +00:00
|
|
|
|
2019-07-04 19:01:14 +00:00
|
|
|
#include "mbedtls/cipher.h"
|
2011-01-06 15:37:30 +00:00
|
|
|
|
2018-11-09 16:47:20 +00:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
|
|
#include "psa/crypto.h"
|
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
|
|
|
|
2011-01-06 15:37:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-05-06 16:10:55 +00:00
|
|
|
/**
|
|
|
|
* Base cipher information. The non-mode specific functions and values.
|
|
|
|
*/
|
|
|
|
struct mbedtls_cipher_base_t
|
|
|
|
{
|
|
|
|
/** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
|
|
|
|
mbedtls_cipher_id_t cipher;
|
|
|
|
|
|
|
|
/** Encrypt using ECB */
|
|
|
|
int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
|
|
|
|
const unsigned char *input, unsigned char *output );
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
/** Encrypt using CBC */
|
|
|
|
int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
|
|
|
|
unsigned char *iv, const unsigned char *input,
|
|
|
|
unsigned char *output );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
/** Encrypt using CFB (Full length) */
|
|
|
|
int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
|
|
|
|
unsigned char *iv, const unsigned char *input,
|
|
|
|
unsigned char *output );
|
|
|
|
#endif
|
|
|
|
|
2018-04-22 21:58:07 +00:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_OFB)
|
|
|
|
/** Encrypt using OFB (Full length) */
|
|
|
|
int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
|
|
|
|
unsigned char *iv,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned char *output );
|
|
|
|
#endif
|
|
|
|
|
2015-05-06 16:10:55 +00:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
/** Encrypt using CTR */
|
|
|
|
int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
|
|
|
|
unsigned char *nonce_counter, unsigned char *stream_block,
|
|
|
|
const unsigned char *input, unsigned char *output );
|
2018-04-30 16:17:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
|
|
|
/** Encrypt or decrypt using XTS. */
|
|
|
|
int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length,
|
|
|
|
const unsigned char data_unit[16],
|
|
|
|
const unsigned char *input, unsigned char *output );
|
2015-05-06 16:10:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
|
|
|
/** Encrypt using STREAM */
|
|
|
|
int (*stream_func)( void *ctx, size_t length,
|
|
|
|
const unsigned char *input, unsigned char *output );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Set key for encryption purposes */
|
|
|
|
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
|
2015-06-18 13:28:12 +00:00
|
|
|
unsigned int key_bitlen );
|
2015-05-06 16:10:55 +00:00
|
|
|
|
|
|
|
/** Set key for decryption purposes */
|
|
|
|
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
|
2015-06-18 13:28:12 +00:00
|
|
|
unsigned int key_bitlen);
|
2015-05-06 16:10:55 +00:00
|
|
|
|
|
|
|
/** Allocate a new context */
|
|
|
|
void * (*ctx_alloc_func)( void );
|
|
|
|
|
|
|
|
/** Free the given context */
|
|
|
|
void (*ctx_free_func)( void *ctx );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-09-18 13:12:07 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_cipher_type_t type;
|
|
|
|
const mbedtls_cipher_info_t *info;
|
|
|
|
} mbedtls_cipher_definition_t;
|
2011-01-06 15:37:30 +00:00
|
|
|
|
2018-11-09 16:47:20 +00:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
2018-11-17 22:11:16 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
MBEDTLS_CIPHER_PSA_KEY_UNSET = 0,
|
2018-11-19 14:05:48 +00:00
|
|
|
MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */
|
|
|
|
/* use raw key material internally imported */
|
2019-05-27 12:53:19 +00:00
|
|
|
/* as a volatile key, and which hence need */
|
|
|
|
/* to destroy that key when the context is */
|
|
|
|
/* freed. */
|
2018-11-19 14:05:48 +00:00
|
|
|
MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts */
|
2019-05-27 12:53:19 +00:00
|
|
|
/* which use a key provided by the */
|
|
|
|
/* user, and which hence will not be */
|
|
|
|
/* destroyed when the context is freed. */
|
2018-11-17 22:11:16 +00:00
|
|
|
} mbedtls_cipher_psa_key_ownership;
|
|
|
|
|
2018-11-09 16:47:20 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2018-11-12 11:59:30 +00:00
|
|
|
psa_algorithm_t alg;
|
2020-08-04 07:51:30 +00:00
|
|
|
psa_key_id_t slot;
|
2018-11-17 22:11:16 +00:00
|
|
|
mbedtls_cipher_psa_key_ownership slot_state;
|
2018-11-09 16:47:20 +00:00
|
|
|
} mbedtls_cipher_context_psa;
|
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
|
2013-09-08 21:04:04 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
extern int mbedtls_cipher_supported[];
|
2012-02-06 16:45:10 +00:00
|
|
|
|
2011-01-06 15:37:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#endif /* MBEDTLS_CIPHER_WRAP_H */
|