User | Revision | Line number | New contents of line |
Simon Cooksey |
0:fb7af294d5d9
|
1
|
/**
|
Simon Cooksey |
0:fb7af294d5d9
|
2
|
* \file cipher_internal.h
|
Simon Cooksey |
0:fb7af294d5d9
|
3
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
4
|
* \brief Cipher wrappers.
|
Simon Cooksey |
0:fb7af294d5d9
|
5
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
6
|
* \author Adriaan de Jong <dejong@fox-it.com>
|
Simon Cooksey |
0:fb7af294d5d9
|
7
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
8
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
Simon Cooksey |
0:fb7af294d5d9
|
9
|
* SPDX-License-Identifier: Apache-2.0
|
Simon Cooksey |
0:fb7af294d5d9
|
10
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
11
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
Simon Cooksey |
0:fb7af294d5d9
|
12
|
* not use this file except in compliance with the License.
|
Simon Cooksey |
0:fb7af294d5d9
|
13
|
* You may obtain a copy of the License at
|
Simon Cooksey |
0:fb7af294d5d9
|
14
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
15
|
* http://www.apache.org/licenses/LICENSE-2.0
|
Simon Cooksey |
0:fb7af294d5d9
|
16
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
17
|
* Unless required by applicable law or agreed to in writing, software
|
Simon Cooksey |
0:fb7af294d5d9
|
18
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
Simon Cooksey |
0:fb7af294d5d9
|
19
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
Simon Cooksey |
0:fb7af294d5d9
|
20
|
* See the License for the specific language governing permissions and
|
Simon Cooksey |
0:fb7af294d5d9
|
21
|
* limitations under the License.
|
Simon Cooksey |
0:fb7af294d5d9
|
22
|
*
|
Simon Cooksey |
0:fb7af294d5d9
|
23
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
Simon Cooksey |
0:fb7af294d5d9
|
24
|
*/
|
Simon Cooksey |
0:fb7af294d5d9
|
25
|
#ifndef MBEDTLS_CIPHER_WRAP_H
|
Simon Cooksey |
0:fb7af294d5d9
|
26
|
#define MBEDTLS_CIPHER_WRAP_H
|
Simon Cooksey |
0:fb7af294d5d9
|
27
|
|
Simon Cooksey |
0:fb7af294d5d9
|
28
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
Simon Cooksey |
0:fb7af294d5d9
|
29
|
#include "config.h"
|
Simon Cooksey |
0:fb7af294d5d9
|
30
|
#else
|
Simon Cooksey |
0:fb7af294d5d9
|
31
|
#include MBEDTLS_CONFIG_FILE
|
Simon Cooksey |
0:fb7af294d5d9
|
32
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
33
|
|
Simon Cooksey |
0:fb7af294d5d9
|
34
|
#include "cipher.h"
|
Simon Cooksey |
0:fb7af294d5d9
|
35
|
|
Simon Cooksey |
0:fb7af294d5d9
|
36
|
#ifdef __cplusplus
|
Simon Cooksey |
0:fb7af294d5d9
|
37
|
extern "C" {
|
Simon Cooksey |
0:fb7af294d5d9
|
38
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
39
|
|
Simon Cooksey |
0:fb7af294d5d9
|
40
|
/**
|
Simon Cooksey |
0:fb7af294d5d9
|
41
|
* Base cipher information. The non-mode specific functions and values.
|
Simon Cooksey |
0:fb7af294d5d9
|
42
|
*/
|
Simon Cooksey |
0:fb7af294d5d9
|
43
|
struct mbedtls_cipher_base_t
|
Simon Cooksey |
0:fb7af294d5d9
|
44
|
{
|
Simon Cooksey |
0:fb7af294d5d9
|
45
|
/** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
|
Simon Cooksey |
0:fb7af294d5d9
|
46
|
mbedtls_cipher_id_t cipher;
|
Simon Cooksey |
0:fb7af294d5d9
|
47
|
|
Simon Cooksey |
0:fb7af294d5d9
|
48
|
/** Encrypt using ECB */
|
Simon Cooksey |
0:fb7af294d5d9
|
49
|
int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
|
Simon Cooksey |
0:fb7af294d5d9
|
50
|
const unsigned char *input, unsigned char *output );
|
Simon Cooksey |
0:fb7af294d5d9
|
51
|
|
Simon Cooksey |
0:fb7af294d5d9
|
52
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
Simon Cooksey |
0:fb7af294d5d9
|
53
|
/** Encrypt using CBC */
|
Simon Cooksey |
0:fb7af294d5d9
|
54
|
int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
|
Simon Cooksey |
0:fb7af294d5d9
|
55
|
unsigned char *iv, const unsigned char *input,
|
Simon Cooksey |
0:fb7af294d5d9
|
56
|
unsigned char *output );
|
Simon Cooksey |
0:fb7af294d5d9
|
57
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
58
|
|
Simon Cooksey |
0:fb7af294d5d9
|
59
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
Simon Cooksey |
0:fb7af294d5d9
|
60
|
/** Encrypt using CFB (Full length) */
|
Simon Cooksey |
0:fb7af294d5d9
|
61
|
int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
|
Simon Cooksey |
0:fb7af294d5d9
|
62
|
unsigned char *iv, const unsigned char *input,
|
Simon Cooksey |
0:fb7af294d5d9
|
63
|
unsigned char *output );
|
Simon Cooksey |
0:fb7af294d5d9
|
64
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
65
|
|
Simon Cooksey |
0:fb7af294d5d9
|
66
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
Simon Cooksey |
0:fb7af294d5d9
|
67
|
/** Encrypt using CTR */
|
Simon Cooksey |
0:fb7af294d5d9
|
68
|
int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
|
Simon Cooksey |
0:fb7af294d5d9
|
69
|
unsigned char *nonce_counter, unsigned char *stream_block,
|
Simon Cooksey |
0:fb7af294d5d9
|
70
|
const unsigned char *input, unsigned char *output );
|
Simon Cooksey |
0:fb7af294d5d9
|
71
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
72
|
|
Simon Cooksey |
0:fb7af294d5d9
|
73
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
Simon Cooksey |
0:fb7af294d5d9
|
74
|
/** Encrypt using STREAM */
|
Simon Cooksey |
0:fb7af294d5d9
|
75
|
int (*stream_func)( void *ctx, size_t length,
|
Simon Cooksey |
0:fb7af294d5d9
|
76
|
const unsigned char *input, unsigned char *output );
|
Simon Cooksey |
0:fb7af294d5d9
|
77
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
78
|
|
Simon Cooksey |
0:fb7af294d5d9
|
79
|
/** Set key for encryption purposes */
|
Simon Cooksey |
0:fb7af294d5d9
|
80
|
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
|
Simon Cooksey |
0:fb7af294d5d9
|
81
|
unsigned int key_bitlen );
|
Simon Cooksey |
0:fb7af294d5d9
|
82
|
|
Simon Cooksey |
0:fb7af294d5d9
|
83
|
/** Set key for decryption purposes */
|
Simon Cooksey |
0:fb7af294d5d9
|
84
|
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
|
Simon Cooksey |
0:fb7af294d5d9
|
85
|
unsigned int key_bitlen);
|
Simon Cooksey |
0:fb7af294d5d9
|
86
|
|
Simon Cooksey |
0:fb7af294d5d9
|
87
|
/** Allocate a new context */
|
Simon Cooksey |
0:fb7af294d5d9
|
88
|
void * (*ctx_alloc_func)( void );
|
Simon Cooksey |
0:fb7af294d5d9
|
89
|
|
Simon Cooksey |
0:fb7af294d5d9
|
90
|
/** Free the given context */
|
Simon Cooksey |
0:fb7af294d5d9
|
91
|
void (*ctx_free_func)( void *ctx );
|
Simon Cooksey |
0:fb7af294d5d9
|
92
|
|
Simon Cooksey |
0:fb7af294d5d9
|
93
|
};
|
Simon Cooksey |
0:fb7af294d5d9
|
94
|
|
Simon Cooksey |
0:fb7af294d5d9
|
95
|
typedef struct
|
Simon Cooksey |
0:fb7af294d5d9
|
96
|
{
|
Simon Cooksey |
0:fb7af294d5d9
|
97
|
mbedtls_cipher_type_t type;
|
Simon Cooksey |
0:fb7af294d5d9
|
98
|
const mbedtls_cipher_info_t *info;
|
Simon Cooksey |
0:fb7af294d5d9
|
99
|
} mbedtls_cipher_definition_t;
|
Simon Cooksey |
0:fb7af294d5d9
|
100
|
|
Simon Cooksey |
0:fb7af294d5d9
|
101
|
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
|
Simon Cooksey |
0:fb7af294d5d9
|
102
|
|
Simon Cooksey |
0:fb7af294d5d9
|
103
|
extern int mbedtls_cipher_supported[];
|
Simon Cooksey |
0:fb7af294d5d9
|
104
|
|
Simon Cooksey |
0:fb7af294d5d9
|
105
|
#ifdef __cplusplus
|
Simon Cooksey |
0:fb7af294d5d9
|
106
|
}
|
Simon Cooksey |
0:fb7af294d5d9
|
107
|
#endif
|
Simon Cooksey |
0:fb7af294d5d9
|
108
|
|
Simon Cooksey |
0:fb7af294d5d9
|
109
|
#endif /* MBEDTLS_CIPHER_WRAP_H */
|