1
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
44
45
46
47
48
49
50
51
52
53
54
58
59
60
61
65
66
67
68
73
74
75
76
80
81
82
83
87
88
89
90
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
116
117
118
119
120
121
122
123
124
125
/* ... */
/* ... */
#ifndef MBEDTLS_CIPHER_WRAP_H
#define MBEDTLS_CIPHER_WRAP_H
#if !defined(MBEDTLS_CONFIG_FILE)
#include "config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#include "cipher.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ... */
struct mbedtls_cipher_base_t
{
mbedtls_cipher_id_t cipher;
int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
const unsigned char *input, unsigned char *output );
#if defined(MBEDTLS_CIPHER_MODE_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)
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
#if defined(MBEDTLS_CIPHER_MODE_OFB)
int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output );/* ... */
#endif
#if defined(MBEDTLS_CIPHER_MODE_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 );/* ... */
#endif
#if defined(MBEDTLS_CIPHER_MODE_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 );/* ... */
#endif
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
int (*stream_func)( void *ctx, size_t length,
const unsigned char *input, unsigned char *output );/* ... */
#endif
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
unsigned int key_bitlen );
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
unsigned int key_bitlen);
void * (*ctx_alloc_func)( void );
void (*ctx_free_func)( void *ctx );
...};
typedef struct
{
mbedtls_cipher_type_t type;
const mbedtls_cipher_info_t *info;
...} mbedtls_cipher_definition_t;
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
extern int mbedtls_cipher_supported[];
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif