1
#pragma GCC system_header
3
* \file cipher_internal.h
5
* \brief Cipher wrappers.
7
* \author Adriaan de Jong <dejong@fox-it.com>
10
* Copyright The Mbed TLS Contributors
11
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13
* This file is provided under the Apache License 2.0, or the
14
* GNU General Public License v2.0 or later.
19
* Licensed under the Apache License, Version 2.0 (the "License"); you may
20
* not use this file except in compliance with the License.
21
* You may obtain a copy of the License at
23
* http://www.apache.org/licenses/LICENSE-2.0
25
* Unless required by applicable law or agreed to in writing, software
26
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
27
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
* See the License for the specific language governing permissions and
29
* limitations under the License.
34
* GNU General Public License v2.0 or later:
36
* This program is free software; you can redistribute it and/or modify
37
* it under the terms of the GNU General Public License as published by
38
* the Free Software Foundation; either version 2 of the License, or
39
* (at your option) any later version.
41
* This program is distributed in the hope that it will be useful,
42
* but WITHOUT ANY WARRANTY; without even the implied warranty of
43
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44
* GNU General Public License for more details.
46
* You should have received a copy of the GNU General Public License along
47
* with this program; if not, write to the Free Software Foundation, Inc.,
48
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
52
#ifndef MBEDTLS_CIPHER_WRAP_H
53
#define MBEDTLS_CIPHER_WRAP_H
55
#if !defined(MBEDTLS_CONFIG_FILE)
58
#include MBEDTLS_CONFIG_FILE
68
* Base cipher information. The non-mode specific functions and values.
70
struct mbedtls_cipher_base_t
72
/** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
73
mbedtls_cipher_id_t cipher;
75
/** Encrypt using ECB */
76
int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
77
const unsigned char *input, unsigned char *output );
79
#if defined(MBEDTLS_CIPHER_MODE_CBC)
80
/** Encrypt using CBC */
81
int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
82
unsigned char *iv, const unsigned char *input,
83
unsigned char *output );
86
#if defined(MBEDTLS_CIPHER_MODE_CFB)
87
/** Encrypt using CFB (Full length) */
88
int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
89
unsigned char *iv, const unsigned char *input,
90
unsigned char *output );
93
#if defined(MBEDTLS_CIPHER_MODE_OFB)
94
/** Encrypt using OFB (Full length) */
95
int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
97
const unsigned char *input,
98
unsigned char *output );
101
#if defined(MBEDTLS_CIPHER_MODE_CTR)
102
/** Encrypt using CTR */
103
int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
104
unsigned char *nonce_counter, unsigned char *stream_block,
105
const unsigned char *input, unsigned char *output );
108
#if defined(MBEDTLS_CIPHER_MODE_XTS)
109
/** Encrypt or decrypt using XTS. */
110
int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length,
111
const unsigned char data_unit[16],
112
const unsigned char *input, unsigned char *output );
115
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
116
/** Encrypt using STREAM */
117
int (*stream_func)( void *ctx, size_t length,
118
const unsigned char *input, unsigned char *output );
121
/** Set key for encryption purposes */
122
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
123
unsigned int key_bitlen );
125
/** Set key for decryption purposes */
126
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
127
unsigned int key_bitlen);
129
/** Allocate a new context */
130
void * (*ctx_alloc_func)( void );
132
/** Free the given context */
133
void (*ctx_free_func)( void *ctx );
139
mbedtls_cipher_type_t type;
140
const mbedtls_cipher_info_t *info;
141
} mbedtls_cipher_definition_t;
143
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
145
extern int mbedtls_cipher_supported[];
151
#endif /* MBEDTLS_CIPHER_WRAP_H */