proxmark3/common/mbedtls/cipher_internal.h

151 lines
4.8 KiB
C
Raw Normal View History

2018-11-08 00:05:02 +08:00
/**
* \file cipher_internal.h
*
* \brief Cipher wrappers.
*
* \author Adriaan de Jong <dejong@fox-it.com>
*/
/*
2021-05-14 15:53:00 +08:00
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
2018-11-08 00:05:02 +08:00
*
2021-05-14 15:53:00 +08: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
2018-11-08 00:05:02 +08:00
*
2021-05-14 15:53:00 +08:00
* http://www.apache.org/licenses/LICENSE-2.0
2018-11-08 00:05:02 +08:00
*
2021-05-14 15:53:00 +08: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.
2018-11-08 00:05:02 +08:00
*/
#ifndef MBEDTLS_CIPHER_WRAP_H
#define MBEDTLS_CIPHER_WRAP_H
#if !defined(MBEDTLS_CONFIG_FILE)
2021-05-14 15:53:00 +08:00
#include "mbedtls/config.h"
2018-11-08 00:05:02 +08:00
#else
#include MBEDTLS_CONFIG_FILE
#endif
2021-05-14 15:53:00 +08:00
#include "mbedtls/cipher.h"
#if defined(MBEDTLS_USE_PSA_CRYPTO)
#include "psa/crypto.h"
#endif /* MBEDTLS_USE_PSA_CRYPTO */
2018-11-08 00:05:02 +08:00
#ifdef __cplusplus
extern "C" {
#endif
/**
* Base cipher information. The non-mode specific functions and values.
*/
2021-05-14 15:53:00 +08:00
struct mbedtls_cipher_base_t
{
2018-11-08 00:05:02 +08:00
/** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
mbedtls_cipher_id_t cipher;
/** Encrypt using ECB */
2021-05-14 15:53:00 +08:00
int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
const unsigned char *input, unsigned char *output );
2018-11-08 00:05:02 +08:00
#if defined(MBEDTLS_CIPHER_MODE_CBC)
/** Encrypt using CBC */
2021-05-14 15:53:00 +08:00
int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
unsigned char *iv, const unsigned char *input,
unsigned char *output );
2018-11-08 00:05:02 +08:00
#endif
#if defined(MBEDTLS_CIPHER_MODE_CFB)
/** Encrypt using CFB (Full length) */
2021-05-14 15:53:00 +08:00
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 );
2018-11-08 00:05:02 +08:00
#endif
#if defined(MBEDTLS_CIPHER_MODE_OFB)
/** Encrypt using OFB (Full length) */
2021-05-14 15:53:00 +08:00
int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output );
2018-11-08 00:05:02 +08:00
#endif
#if defined(MBEDTLS_CIPHER_MODE_CTR)
/** Encrypt using CTR */
2021-05-14 15:53:00 +08:00
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-11-08 00:05:02 +08:00
#endif
#if defined(MBEDTLS_CIPHER_MODE_XTS)
/** Encrypt or decrypt using XTS. */
2021-05-14 15:53:00 +08:00
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 );
2018-11-08 00:05:02 +08:00
#endif
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
/** Encrypt using STREAM */
2021-05-14 15:53:00 +08:00
int (*stream_func)( void *ctx, size_t length,
const unsigned char *input, unsigned char *output );
2018-11-08 00:05:02 +08:00
#endif
/** Set key for encryption purposes */
2021-05-14 15:53:00 +08:00
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
unsigned int key_bitlen );
2018-11-08 00:05:02 +08:00
/** Set key for decryption purposes */
2021-05-14 15:53:00 +08:00
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
unsigned int key_bitlen);
2018-11-08 00:05:02 +08:00
/** Allocate a new context */
2021-05-14 15:53:00 +08:00
void * (*ctx_alloc_func)( void );
2018-11-08 00:05:02 +08:00
/** Free the given context */
2021-05-14 15:53:00 +08:00
void (*ctx_free_func)( void *ctx );
2018-11-08 00:05:02 +08:00
};
2021-05-14 15:53:00 +08:00
typedef struct
{
2018-11-08 00:05:02 +08:00
mbedtls_cipher_type_t type;
const mbedtls_cipher_info_t *info;
} mbedtls_cipher_definition_t;
2021-05-14 15:53:00 +08:00
#if defined(MBEDTLS_USE_PSA_CRYPTO)
typedef enum
{
MBEDTLS_CIPHER_PSA_KEY_UNSET = 0,
MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */
/* use raw key material internally imported */
/* as a volatile key, and which hence need */
/* to destroy that key when the context is */
/* freed. */
MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts */
/* which use a key provided by the */
/* user, and which hence will not be */
/* destroyed when the context is freed. */
} mbedtls_cipher_psa_key_ownership;
typedef struct
{
psa_algorithm_t alg;
psa_key_id_t slot;
mbedtls_cipher_psa_key_ownership slot_state;
} mbedtls_cipher_context_psa;
#endif /* MBEDTLS_USE_PSA_CRYPTO */
2018-11-08 00:05:02 +08:00
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
extern int mbedtls_cipher_supported[];
#ifdef __cplusplus
}
#endif
#endif /* MBEDTLS_CIPHER_WRAP_H */