Modified mbed TLS headers for AES functionality only to reduce build size
Dependents: BLE_Gateway_Linker_fix BLE_Gateway
Fork of mbedtls by
source/cipher_wrap.c@1:24750b9ad5ef, 2016-01-22 (annotated)
- Committer:
- Christopher Haster
- Date:
- Fri Jan 22 16:44:49 2016 -0600
- Revision:
- 1:24750b9ad5ef
Initial move of mbedtls to mercurial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
1:24750b9ad5ef | 1 | /** |
Christopher Haster |
1:24750b9ad5ef | 2 | * \file cipher_wrap.c |
Christopher Haster |
1:24750b9ad5ef | 3 | * |
Christopher Haster |
1:24750b9ad5ef | 4 | * \brief Generic cipher wrapper for mbed TLS |
Christopher Haster |
1:24750b9ad5ef | 5 | * |
Christopher Haster |
1:24750b9ad5ef | 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
Christopher Haster |
1:24750b9ad5ef | 7 | * |
Christopher Haster |
1:24750b9ad5ef | 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Christopher Haster |
1:24750b9ad5ef | 9 | * SPDX-License-Identifier: Apache-2.0 |
Christopher Haster |
1:24750b9ad5ef | 10 | * |
Christopher Haster |
1:24750b9ad5ef | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Christopher Haster |
1:24750b9ad5ef | 12 | * not use this file except in compliance with the License. |
Christopher Haster |
1:24750b9ad5ef | 13 | * You may obtain a copy of the License at |
Christopher Haster |
1:24750b9ad5ef | 14 | * |
Christopher Haster |
1:24750b9ad5ef | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
1:24750b9ad5ef | 16 | * |
Christopher Haster |
1:24750b9ad5ef | 17 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
1:24750b9ad5ef | 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Christopher Haster |
1:24750b9ad5ef | 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
1:24750b9ad5ef | 20 | * See the License for the specific language governing permissions and |
Christopher Haster |
1:24750b9ad5ef | 21 | * limitations under the License. |
Christopher Haster |
1:24750b9ad5ef | 22 | * |
Christopher Haster |
1:24750b9ad5ef | 23 | * This file is part of mbed TLS (https://tls.mbed.org) |
Christopher Haster |
1:24750b9ad5ef | 24 | */ |
Christopher Haster |
1:24750b9ad5ef | 25 | |
Christopher Haster |
1:24750b9ad5ef | 26 | #if !defined(MBEDTLS_CONFIG_FILE) |
Christopher Haster |
1:24750b9ad5ef | 27 | #include "mbedtls/config.h" |
Christopher Haster |
1:24750b9ad5ef | 28 | #else |
Christopher Haster |
1:24750b9ad5ef | 29 | #include MBEDTLS_CONFIG_FILE |
Christopher Haster |
1:24750b9ad5ef | 30 | #endif |
Christopher Haster |
1:24750b9ad5ef | 31 | |
Christopher Haster |
1:24750b9ad5ef | 32 | #if defined(MBEDTLS_CIPHER_C) |
Christopher Haster |
1:24750b9ad5ef | 33 | |
Christopher Haster |
1:24750b9ad5ef | 34 | #include "mbedtls/cipher_internal.h" |
Christopher Haster |
1:24750b9ad5ef | 35 | |
Christopher Haster |
1:24750b9ad5ef | 36 | #if defined(MBEDTLS_AES_C) |
Christopher Haster |
1:24750b9ad5ef | 37 | #include "mbedtls/aes.h" |
Christopher Haster |
1:24750b9ad5ef | 38 | #endif |
Christopher Haster |
1:24750b9ad5ef | 39 | |
Christopher Haster |
1:24750b9ad5ef | 40 | #if defined(MBEDTLS_ARC4_C) |
Christopher Haster |
1:24750b9ad5ef | 41 | #include "mbedtls/arc4.h" |
Christopher Haster |
1:24750b9ad5ef | 42 | #endif |
Christopher Haster |
1:24750b9ad5ef | 43 | |
Christopher Haster |
1:24750b9ad5ef | 44 | #if defined(MBEDTLS_CAMELLIA_C) |
Christopher Haster |
1:24750b9ad5ef | 45 | #include "mbedtls/camellia.h" |
Christopher Haster |
1:24750b9ad5ef | 46 | #endif |
Christopher Haster |
1:24750b9ad5ef | 47 | |
Christopher Haster |
1:24750b9ad5ef | 48 | #if defined(MBEDTLS_DES_C) |
Christopher Haster |
1:24750b9ad5ef | 49 | #include "mbedtls/des.h" |
Christopher Haster |
1:24750b9ad5ef | 50 | #endif |
Christopher Haster |
1:24750b9ad5ef | 51 | |
Christopher Haster |
1:24750b9ad5ef | 52 | #if defined(MBEDTLS_BLOWFISH_C) |
Christopher Haster |
1:24750b9ad5ef | 53 | #include "mbedtls/blowfish.h" |
Christopher Haster |
1:24750b9ad5ef | 54 | #endif |
Christopher Haster |
1:24750b9ad5ef | 55 | |
Christopher Haster |
1:24750b9ad5ef | 56 | #if defined(MBEDTLS_GCM_C) |
Christopher Haster |
1:24750b9ad5ef | 57 | #include "mbedtls/gcm.h" |
Christopher Haster |
1:24750b9ad5ef | 58 | #endif |
Christopher Haster |
1:24750b9ad5ef | 59 | |
Christopher Haster |
1:24750b9ad5ef | 60 | #if defined(MBEDTLS_CCM_C) |
Christopher Haster |
1:24750b9ad5ef | 61 | #include "mbedtls/ccm.h" |
Christopher Haster |
1:24750b9ad5ef | 62 | #endif |
Christopher Haster |
1:24750b9ad5ef | 63 | |
Christopher Haster |
1:24750b9ad5ef | 64 | #if defined(MBEDTLS_CIPHER_NULL_CIPHER) |
Christopher Haster |
1:24750b9ad5ef | 65 | #include <string.h> |
Christopher Haster |
1:24750b9ad5ef | 66 | #endif |
Christopher Haster |
1:24750b9ad5ef | 67 | |
Christopher Haster |
1:24750b9ad5ef | 68 | #if defined(MBEDTLS_PLATFORM_C) |
Christopher Haster |
1:24750b9ad5ef | 69 | #include "mbedtls/platform.h" |
Christopher Haster |
1:24750b9ad5ef | 70 | #else |
Christopher Haster |
1:24750b9ad5ef | 71 | #include <stdlib.h> |
Christopher Haster |
1:24750b9ad5ef | 72 | #define mbedtls_calloc calloc |
Christopher Haster |
1:24750b9ad5ef | 73 | #define mbedtls_free free |
Christopher Haster |
1:24750b9ad5ef | 74 | #endif |
Christopher Haster |
1:24750b9ad5ef | 75 | |
Christopher Haster |
1:24750b9ad5ef | 76 | #if defined(MBEDTLS_GCM_C) |
Christopher Haster |
1:24750b9ad5ef | 77 | /* shared by all GCM ciphers */ |
Christopher Haster |
1:24750b9ad5ef | 78 | static void *gcm_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 79 | { |
Christopher Haster |
1:24750b9ad5ef | 80 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 81 | |
Christopher Haster |
1:24750b9ad5ef | 82 | if( ctx != NULL ) |
Christopher Haster |
1:24750b9ad5ef | 83 | mbedtls_gcm_init( (mbedtls_gcm_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 84 | |
Christopher Haster |
1:24750b9ad5ef | 85 | return( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 86 | } |
Christopher Haster |
1:24750b9ad5ef | 87 | |
Christopher Haster |
1:24750b9ad5ef | 88 | static void gcm_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 89 | { |
Christopher Haster |
1:24750b9ad5ef | 90 | mbedtls_gcm_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 91 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 92 | } |
Christopher Haster |
1:24750b9ad5ef | 93 | #endif /* MBEDTLS_GCM_C */ |
Christopher Haster |
1:24750b9ad5ef | 94 | |
Christopher Haster |
1:24750b9ad5ef | 95 | #if defined(MBEDTLS_CCM_C) |
Christopher Haster |
1:24750b9ad5ef | 96 | /* shared by all CCM ciphers */ |
Christopher Haster |
1:24750b9ad5ef | 97 | static void *ccm_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 98 | { |
Christopher Haster |
1:24750b9ad5ef | 99 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 100 | |
Christopher Haster |
1:24750b9ad5ef | 101 | if( ctx != NULL ) |
Christopher Haster |
1:24750b9ad5ef | 102 | mbedtls_ccm_init( (mbedtls_ccm_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 103 | |
Christopher Haster |
1:24750b9ad5ef | 104 | return( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 105 | } |
Christopher Haster |
1:24750b9ad5ef | 106 | |
Christopher Haster |
1:24750b9ad5ef | 107 | static void ccm_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 108 | { |
Christopher Haster |
1:24750b9ad5ef | 109 | mbedtls_ccm_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 110 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 111 | } |
Christopher Haster |
1:24750b9ad5ef | 112 | #endif /* MBEDTLS_CCM_C */ |
Christopher Haster |
1:24750b9ad5ef | 113 | |
Christopher Haster |
1:24750b9ad5ef | 114 | #if defined(MBEDTLS_AES_C) |
Christopher Haster |
1:24750b9ad5ef | 115 | |
Christopher Haster |
1:24750b9ad5ef | 116 | static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 117 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 118 | { |
Christopher Haster |
1:24750b9ad5ef | 119 | return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 120 | } |
Christopher Haster |
1:24750b9ad5ef | 121 | |
Christopher Haster |
1:24750b9ad5ef | 122 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 123 | static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length, |
Christopher Haster |
1:24750b9ad5ef | 124 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 125 | { |
Christopher Haster |
1:24750b9ad5ef | 126 | return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input, |
Christopher Haster |
1:24750b9ad5ef | 127 | output ); |
Christopher Haster |
1:24750b9ad5ef | 128 | } |
Christopher Haster |
1:24750b9ad5ef | 129 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 130 | |
Christopher Haster |
1:24750b9ad5ef | 131 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 132 | static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 133 | size_t length, size_t *iv_off, unsigned char *iv, |
Christopher Haster |
1:24750b9ad5ef | 134 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 135 | { |
Christopher Haster |
1:24750b9ad5ef | 136 | return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv, |
Christopher Haster |
1:24750b9ad5ef | 137 | input, output ); |
Christopher Haster |
1:24750b9ad5ef | 138 | } |
Christopher Haster |
1:24750b9ad5ef | 139 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Christopher Haster |
1:24750b9ad5ef | 140 | |
Christopher Haster |
1:24750b9ad5ef | 141 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 142 | static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
Christopher Haster |
1:24750b9ad5ef | 143 | unsigned char *nonce_counter, unsigned char *stream_block, |
Christopher Haster |
1:24750b9ad5ef | 144 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 145 | { |
Christopher Haster |
1:24750b9ad5ef | 146 | return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter, |
Christopher Haster |
1:24750b9ad5ef | 147 | stream_block, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 148 | } |
Christopher Haster |
1:24750b9ad5ef | 149 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Christopher Haster |
1:24750b9ad5ef | 150 | |
Christopher Haster |
1:24750b9ad5ef | 151 | static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 152 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 153 | { |
Christopher Haster |
1:24750b9ad5ef | 154 | return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 155 | } |
Christopher Haster |
1:24750b9ad5ef | 156 | |
Christopher Haster |
1:24750b9ad5ef | 157 | static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 158 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 159 | { |
Christopher Haster |
1:24750b9ad5ef | 160 | return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 161 | } |
Christopher Haster |
1:24750b9ad5ef | 162 | |
Christopher Haster |
1:24750b9ad5ef | 163 | static void * aes_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 164 | { |
Christopher Haster |
1:24750b9ad5ef | 165 | mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 166 | |
Christopher Haster |
1:24750b9ad5ef | 167 | if( aes == NULL ) |
Christopher Haster |
1:24750b9ad5ef | 168 | return( NULL ); |
Christopher Haster |
1:24750b9ad5ef | 169 | |
Christopher Haster |
1:24750b9ad5ef | 170 | mbedtls_aes_init( aes ); |
Christopher Haster |
1:24750b9ad5ef | 171 | |
Christopher Haster |
1:24750b9ad5ef | 172 | return( aes ); |
Christopher Haster |
1:24750b9ad5ef | 173 | } |
Christopher Haster |
1:24750b9ad5ef | 174 | |
Christopher Haster |
1:24750b9ad5ef | 175 | static void aes_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 176 | { |
Christopher Haster |
1:24750b9ad5ef | 177 | mbedtls_aes_free( (mbedtls_aes_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 178 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 179 | } |
Christopher Haster |
1:24750b9ad5ef | 180 | |
Christopher Haster |
1:24750b9ad5ef | 181 | static const mbedtls_cipher_base_t aes_info = { |
Christopher Haster |
1:24750b9ad5ef | 182 | MBEDTLS_CIPHER_ID_AES, |
Christopher Haster |
1:24750b9ad5ef | 183 | aes_crypt_ecb_wrap, |
Christopher Haster |
1:24750b9ad5ef | 184 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 185 | aes_crypt_cbc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 186 | #endif |
Christopher Haster |
1:24750b9ad5ef | 187 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 188 | aes_crypt_cfb128_wrap, |
Christopher Haster |
1:24750b9ad5ef | 189 | #endif |
Christopher Haster |
1:24750b9ad5ef | 190 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 191 | aes_crypt_ctr_wrap, |
Christopher Haster |
1:24750b9ad5ef | 192 | #endif |
Christopher Haster |
1:24750b9ad5ef | 193 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 194 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 195 | #endif |
Christopher Haster |
1:24750b9ad5ef | 196 | aes_setkey_enc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 197 | aes_setkey_dec_wrap, |
Christopher Haster |
1:24750b9ad5ef | 198 | aes_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 199 | aes_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 200 | }; |
Christopher Haster |
1:24750b9ad5ef | 201 | |
Christopher Haster |
1:24750b9ad5ef | 202 | static const mbedtls_cipher_info_t aes_128_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 203 | MBEDTLS_CIPHER_AES_128_ECB, |
Christopher Haster |
1:24750b9ad5ef | 204 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 205 | 128, |
Christopher Haster |
1:24750b9ad5ef | 206 | "AES-128-ECB", |
Christopher Haster |
1:24750b9ad5ef | 207 | 16, |
Christopher Haster |
1:24750b9ad5ef | 208 | 0, |
Christopher Haster |
1:24750b9ad5ef | 209 | 16, |
Christopher Haster |
1:24750b9ad5ef | 210 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 211 | }; |
Christopher Haster |
1:24750b9ad5ef | 212 | |
Christopher Haster |
1:24750b9ad5ef | 213 | static const mbedtls_cipher_info_t aes_192_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 214 | MBEDTLS_CIPHER_AES_192_ECB, |
Christopher Haster |
1:24750b9ad5ef | 215 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 216 | 192, |
Christopher Haster |
1:24750b9ad5ef | 217 | "AES-192-ECB", |
Christopher Haster |
1:24750b9ad5ef | 218 | 16, |
Christopher Haster |
1:24750b9ad5ef | 219 | 0, |
Christopher Haster |
1:24750b9ad5ef | 220 | 16, |
Christopher Haster |
1:24750b9ad5ef | 221 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 222 | }; |
Christopher Haster |
1:24750b9ad5ef | 223 | |
Christopher Haster |
1:24750b9ad5ef | 224 | static const mbedtls_cipher_info_t aes_256_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 225 | MBEDTLS_CIPHER_AES_256_ECB, |
Christopher Haster |
1:24750b9ad5ef | 226 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 227 | 256, |
Christopher Haster |
1:24750b9ad5ef | 228 | "AES-256-ECB", |
Christopher Haster |
1:24750b9ad5ef | 229 | 16, |
Christopher Haster |
1:24750b9ad5ef | 230 | 0, |
Christopher Haster |
1:24750b9ad5ef | 231 | 16, |
Christopher Haster |
1:24750b9ad5ef | 232 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 233 | }; |
Christopher Haster |
1:24750b9ad5ef | 234 | |
Christopher Haster |
1:24750b9ad5ef | 235 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 236 | static const mbedtls_cipher_info_t aes_128_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 237 | MBEDTLS_CIPHER_AES_128_CBC, |
Christopher Haster |
1:24750b9ad5ef | 238 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 239 | 128, |
Christopher Haster |
1:24750b9ad5ef | 240 | "AES-128-CBC", |
Christopher Haster |
1:24750b9ad5ef | 241 | 16, |
Christopher Haster |
1:24750b9ad5ef | 242 | 0, |
Christopher Haster |
1:24750b9ad5ef | 243 | 16, |
Christopher Haster |
1:24750b9ad5ef | 244 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 245 | }; |
Christopher Haster |
1:24750b9ad5ef | 246 | |
Christopher Haster |
1:24750b9ad5ef | 247 | static const mbedtls_cipher_info_t aes_192_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 248 | MBEDTLS_CIPHER_AES_192_CBC, |
Christopher Haster |
1:24750b9ad5ef | 249 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 250 | 192, |
Christopher Haster |
1:24750b9ad5ef | 251 | "AES-192-CBC", |
Christopher Haster |
1:24750b9ad5ef | 252 | 16, |
Christopher Haster |
1:24750b9ad5ef | 253 | 0, |
Christopher Haster |
1:24750b9ad5ef | 254 | 16, |
Christopher Haster |
1:24750b9ad5ef | 255 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 256 | }; |
Christopher Haster |
1:24750b9ad5ef | 257 | |
Christopher Haster |
1:24750b9ad5ef | 258 | static const mbedtls_cipher_info_t aes_256_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 259 | MBEDTLS_CIPHER_AES_256_CBC, |
Christopher Haster |
1:24750b9ad5ef | 260 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 261 | 256, |
Christopher Haster |
1:24750b9ad5ef | 262 | "AES-256-CBC", |
Christopher Haster |
1:24750b9ad5ef | 263 | 16, |
Christopher Haster |
1:24750b9ad5ef | 264 | 0, |
Christopher Haster |
1:24750b9ad5ef | 265 | 16, |
Christopher Haster |
1:24750b9ad5ef | 266 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 267 | }; |
Christopher Haster |
1:24750b9ad5ef | 268 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 269 | |
Christopher Haster |
1:24750b9ad5ef | 270 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 271 | static const mbedtls_cipher_info_t aes_128_cfb128_info = { |
Christopher Haster |
1:24750b9ad5ef | 272 | MBEDTLS_CIPHER_AES_128_CFB128, |
Christopher Haster |
1:24750b9ad5ef | 273 | MBEDTLS_MODE_CFB, |
Christopher Haster |
1:24750b9ad5ef | 274 | 128, |
Christopher Haster |
1:24750b9ad5ef | 275 | "AES-128-CFB128", |
Christopher Haster |
1:24750b9ad5ef | 276 | 16, |
Christopher Haster |
1:24750b9ad5ef | 277 | 0, |
Christopher Haster |
1:24750b9ad5ef | 278 | 16, |
Christopher Haster |
1:24750b9ad5ef | 279 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 280 | }; |
Christopher Haster |
1:24750b9ad5ef | 281 | |
Christopher Haster |
1:24750b9ad5ef | 282 | static const mbedtls_cipher_info_t aes_192_cfb128_info = { |
Christopher Haster |
1:24750b9ad5ef | 283 | MBEDTLS_CIPHER_AES_192_CFB128, |
Christopher Haster |
1:24750b9ad5ef | 284 | MBEDTLS_MODE_CFB, |
Christopher Haster |
1:24750b9ad5ef | 285 | 192, |
Christopher Haster |
1:24750b9ad5ef | 286 | "AES-192-CFB128", |
Christopher Haster |
1:24750b9ad5ef | 287 | 16, |
Christopher Haster |
1:24750b9ad5ef | 288 | 0, |
Christopher Haster |
1:24750b9ad5ef | 289 | 16, |
Christopher Haster |
1:24750b9ad5ef | 290 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 291 | }; |
Christopher Haster |
1:24750b9ad5ef | 292 | |
Christopher Haster |
1:24750b9ad5ef | 293 | static const mbedtls_cipher_info_t aes_256_cfb128_info = { |
Christopher Haster |
1:24750b9ad5ef | 294 | MBEDTLS_CIPHER_AES_256_CFB128, |
Christopher Haster |
1:24750b9ad5ef | 295 | MBEDTLS_MODE_CFB, |
Christopher Haster |
1:24750b9ad5ef | 296 | 256, |
Christopher Haster |
1:24750b9ad5ef | 297 | "AES-256-CFB128", |
Christopher Haster |
1:24750b9ad5ef | 298 | 16, |
Christopher Haster |
1:24750b9ad5ef | 299 | 0, |
Christopher Haster |
1:24750b9ad5ef | 300 | 16, |
Christopher Haster |
1:24750b9ad5ef | 301 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 302 | }; |
Christopher Haster |
1:24750b9ad5ef | 303 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Christopher Haster |
1:24750b9ad5ef | 304 | |
Christopher Haster |
1:24750b9ad5ef | 305 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 306 | static const mbedtls_cipher_info_t aes_128_ctr_info = { |
Christopher Haster |
1:24750b9ad5ef | 307 | MBEDTLS_CIPHER_AES_128_CTR, |
Christopher Haster |
1:24750b9ad5ef | 308 | MBEDTLS_MODE_CTR, |
Christopher Haster |
1:24750b9ad5ef | 309 | 128, |
Christopher Haster |
1:24750b9ad5ef | 310 | "AES-128-CTR", |
Christopher Haster |
1:24750b9ad5ef | 311 | 16, |
Christopher Haster |
1:24750b9ad5ef | 312 | 0, |
Christopher Haster |
1:24750b9ad5ef | 313 | 16, |
Christopher Haster |
1:24750b9ad5ef | 314 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 315 | }; |
Christopher Haster |
1:24750b9ad5ef | 316 | |
Christopher Haster |
1:24750b9ad5ef | 317 | static const mbedtls_cipher_info_t aes_192_ctr_info = { |
Christopher Haster |
1:24750b9ad5ef | 318 | MBEDTLS_CIPHER_AES_192_CTR, |
Christopher Haster |
1:24750b9ad5ef | 319 | MBEDTLS_MODE_CTR, |
Christopher Haster |
1:24750b9ad5ef | 320 | 192, |
Christopher Haster |
1:24750b9ad5ef | 321 | "AES-192-CTR", |
Christopher Haster |
1:24750b9ad5ef | 322 | 16, |
Christopher Haster |
1:24750b9ad5ef | 323 | 0, |
Christopher Haster |
1:24750b9ad5ef | 324 | 16, |
Christopher Haster |
1:24750b9ad5ef | 325 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 326 | }; |
Christopher Haster |
1:24750b9ad5ef | 327 | |
Christopher Haster |
1:24750b9ad5ef | 328 | static const mbedtls_cipher_info_t aes_256_ctr_info = { |
Christopher Haster |
1:24750b9ad5ef | 329 | MBEDTLS_CIPHER_AES_256_CTR, |
Christopher Haster |
1:24750b9ad5ef | 330 | MBEDTLS_MODE_CTR, |
Christopher Haster |
1:24750b9ad5ef | 331 | 256, |
Christopher Haster |
1:24750b9ad5ef | 332 | "AES-256-CTR", |
Christopher Haster |
1:24750b9ad5ef | 333 | 16, |
Christopher Haster |
1:24750b9ad5ef | 334 | 0, |
Christopher Haster |
1:24750b9ad5ef | 335 | 16, |
Christopher Haster |
1:24750b9ad5ef | 336 | &aes_info |
Christopher Haster |
1:24750b9ad5ef | 337 | }; |
Christopher Haster |
1:24750b9ad5ef | 338 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Christopher Haster |
1:24750b9ad5ef | 339 | |
Christopher Haster |
1:24750b9ad5ef | 340 | #if defined(MBEDTLS_GCM_C) |
Christopher Haster |
1:24750b9ad5ef | 341 | static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 342 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 343 | { |
Christopher Haster |
1:24750b9ad5ef | 344 | return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES, |
Christopher Haster |
1:24750b9ad5ef | 345 | key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 346 | } |
Christopher Haster |
1:24750b9ad5ef | 347 | |
Christopher Haster |
1:24750b9ad5ef | 348 | static const mbedtls_cipher_base_t gcm_aes_info = { |
Christopher Haster |
1:24750b9ad5ef | 349 | MBEDTLS_CIPHER_ID_AES, |
Christopher Haster |
1:24750b9ad5ef | 350 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 351 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 352 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 353 | #endif |
Christopher Haster |
1:24750b9ad5ef | 354 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 355 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 356 | #endif |
Christopher Haster |
1:24750b9ad5ef | 357 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 358 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 359 | #endif |
Christopher Haster |
1:24750b9ad5ef | 360 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 361 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 362 | #endif |
Christopher Haster |
1:24750b9ad5ef | 363 | gcm_aes_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 364 | gcm_aes_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 365 | gcm_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 366 | gcm_ctx_free, |
Christopher Haster |
1:24750b9ad5ef | 367 | }; |
Christopher Haster |
1:24750b9ad5ef | 368 | |
Christopher Haster |
1:24750b9ad5ef | 369 | static const mbedtls_cipher_info_t aes_128_gcm_info = { |
Christopher Haster |
1:24750b9ad5ef | 370 | MBEDTLS_CIPHER_AES_128_GCM, |
Christopher Haster |
1:24750b9ad5ef | 371 | MBEDTLS_MODE_GCM, |
Christopher Haster |
1:24750b9ad5ef | 372 | 128, |
Christopher Haster |
1:24750b9ad5ef | 373 | "AES-128-GCM", |
Christopher Haster |
1:24750b9ad5ef | 374 | 12, |
Christopher Haster |
1:24750b9ad5ef | 375 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 376 | 16, |
Christopher Haster |
1:24750b9ad5ef | 377 | &gcm_aes_info |
Christopher Haster |
1:24750b9ad5ef | 378 | }; |
Christopher Haster |
1:24750b9ad5ef | 379 | |
Christopher Haster |
1:24750b9ad5ef | 380 | static const mbedtls_cipher_info_t aes_192_gcm_info = { |
Christopher Haster |
1:24750b9ad5ef | 381 | MBEDTLS_CIPHER_AES_192_GCM, |
Christopher Haster |
1:24750b9ad5ef | 382 | MBEDTLS_MODE_GCM, |
Christopher Haster |
1:24750b9ad5ef | 383 | 192, |
Christopher Haster |
1:24750b9ad5ef | 384 | "AES-192-GCM", |
Christopher Haster |
1:24750b9ad5ef | 385 | 12, |
Christopher Haster |
1:24750b9ad5ef | 386 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 387 | 16, |
Christopher Haster |
1:24750b9ad5ef | 388 | &gcm_aes_info |
Christopher Haster |
1:24750b9ad5ef | 389 | }; |
Christopher Haster |
1:24750b9ad5ef | 390 | |
Christopher Haster |
1:24750b9ad5ef | 391 | static const mbedtls_cipher_info_t aes_256_gcm_info = { |
Christopher Haster |
1:24750b9ad5ef | 392 | MBEDTLS_CIPHER_AES_256_GCM, |
Christopher Haster |
1:24750b9ad5ef | 393 | MBEDTLS_MODE_GCM, |
Christopher Haster |
1:24750b9ad5ef | 394 | 256, |
Christopher Haster |
1:24750b9ad5ef | 395 | "AES-256-GCM", |
Christopher Haster |
1:24750b9ad5ef | 396 | 12, |
Christopher Haster |
1:24750b9ad5ef | 397 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 398 | 16, |
Christopher Haster |
1:24750b9ad5ef | 399 | &gcm_aes_info |
Christopher Haster |
1:24750b9ad5ef | 400 | }; |
Christopher Haster |
1:24750b9ad5ef | 401 | #endif /* MBEDTLS_GCM_C */ |
Christopher Haster |
1:24750b9ad5ef | 402 | |
Christopher Haster |
1:24750b9ad5ef | 403 | #if defined(MBEDTLS_CCM_C) |
Christopher Haster |
1:24750b9ad5ef | 404 | static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 405 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 406 | { |
Christopher Haster |
1:24750b9ad5ef | 407 | return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES, |
Christopher Haster |
1:24750b9ad5ef | 408 | key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 409 | } |
Christopher Haster |
1:24750b9ad5ef | 410 | |
Christopher Haster |
1:24750b9ad5ef | 411 | static const mbedtls_cipher_base_t ccm_aes_info = { |
Christopher Haster |
1:24750b9ad5ef | 412 | MBEDTLS_CIPHER_ID_AES, |
Christopher Haster |
1:24750b9ad5ef | 413 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 414 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 415 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 416 | #endif |
Christopher Haster |
1:24750b9ad5ef | 417 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 418 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 419 | #endif |
Christopher Haster |
1:24750b9ad5ef | 420 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 421 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 422 | #endif |
Christopher Haster |
1:24750b9ad5ef | 423 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 424 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 425 | #endif |
Christopher Haster |
1:24750b9ad5ef | 426 | ccm_aes_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 427 | ccm_aes_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 428 | ccm_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 429 | ccm_ctx_free, |
Christopher Haster |
1:24750b9ad5ef | 430 | }; |
Christopher Haster |
1:24750b9ad5ef | 431 | |
Christopher Haster |
1:24750b9ad5ef | 432 | static const mbedtls_cipher_info_t aes_128_ccm_info = { |
Christopher Haster |
1:24750b9ad5ef | 433 | MBEDTLS_CIPHER_AES_128_CCM, |
Christopher Haster |
1:24750b9ad5ef | 434 | MBEDTLS_MODE_CCM, |
Christopher Haster |
1:24750b9ad5ef | 435 | 128, |
Christopher Haster |
1:24750b9ad5ef | 436 | "AES-128-CCM", |
Christopher Haster |
1:24750b9ad5ef | 437 | 12, |
Christopher Haster |
1:24750b9ad5ef | 438 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 439 | 16, |
Christopher Haster |
1:24750b9ad5ef | 440 | &ccm_aes_info |
Christopher Haster |
1:24750b9ad5ef | 441 | }; |
Christopher Haster |
1:24750b9ad5ef | 442 | |
Christopher Haster |
1:24750b9ad5ef | 443 | static const mbedtls_cipher_info_t aes_192_ccm_info = { |
Christopher Haster |
1:24750b9ad5ef | 444 | MBEDTLS_CIPHER_AES_192_CCM, |
Christopher Haster |
1:24750b9ad5ef | 445 | MBEDTLS_MODE_CCM, |
Christopher Haster |
1:24750b9ad5ef | 446 | 192, |
Christopher Haster |
1:24750b9ad5ef | 447 | "AES-192-CCM", |
Christopher Haster |
1:24750b9ad5ef | 448 | 12, |
Christopher Haster |
1:24750b9ad5ef | 449 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 450 | 16, |
Christopher Haster |
1:24750b9ad5ef | 451 | &ccm_aes_info |
Christopher Haster |
1:24750b9ad5ef | 452 | }; |
Christopher Haster |
1:24750b9ad5ef | 453 | |
Christopher Haster |
1:24750b9ad5ef | 454 | static const mbedtls_cipher_info_t aes_256_ccm_info = { |
Christopher Haster |
1:24750b9ad5ef | 455 | MBEDTLS_CIPHER_AES_256_CCM, |
Christopher Haster |
1:24750b9ad5ef | 456 | MBEDTLS_MODE_CCM, |
Christopher Haster |
1:24750b9ad5ef | 457 | 256, |
Christopher Haster |
1:24750b9ad5ef | 458 | "AES-256-CCM", |
Christopher Haster |
1:24750b9ad5ef | 459 | 12, |
Christopher Haster |
1:24750b9ad5ef | 460 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 461 | 16, |
Christopher Haster |
1:24750b9ad5ef | 462 | &ccm_aes_info |
Christopher Haster |
1:24750b9ad5ef | 463 | }; |
Christopher Haster |
1:24750b9ad5ef | 464 | #endif /* MBEDTLS_CCM_C */ |
Christopher Haster |
1:24750b9ad5ef | 465 | |
Christopher Haster |
1:24750b9ad5ef | 466 | #endif /* MBEDTLS_AES_C */ |
Christopher Haster |
1:24750b9ad5ef | 467 | |
Christopher Haster |
1:24750b9ad5ef | 468 | #if defined(MBEDTLS_CAMELLIA_C) |
Christopher Haster |
1:24750b9ad5ef | 469 | |
Christopher Haster |
1:24750b9ad5ef | 470 | static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 471 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 472 | { |
Christopher Haster |
1:24750b9ad5ef | 473 | return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input, |
Christopher Haster |
1:24750b9ad5ef | 474 | output ); |
Christopher Haster |
1:24750b9ad5ef | 475 | } |
Christopher Haster |
1:24750b9ad5ef | 476 | |
Christopher Haster |
1:24750b9ad5ef | 477 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 478 | static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 479 | size_t length, unsigned char *iv, |
Christopher Haster |
1:24750b9ad5ef | 480 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 481 | { |
Christopher Haster |
1:24750b9ad5ef | 482 | return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv, |
Christopher Haster |
1:24750b9ad5ef | 483 | input, output ); |
Christopher Haster |
1:24750b9ad5ef | 484 | } |
Christopher Haster |
1:24750b9ad5ef | 485 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 486 | |
Christopher Haster |
1:24750b9ad5ef | 487 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 488 | static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 489 | size_t length, size_t *iv_off, unsigned char *iv, |
Christopher Haster |
1:24750b9ad5ef | 490 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 491 | { |
Christopher Haster |
1:24750b9ad5ef | 492 | return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length, |
Christopher Haster |
1:24750b9ad5ef | 493 | iv_off, iv, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 494 | } |
Christopher Haster |
1:24750b9ad5ef | 495 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Christopher Haster |
1:24750b9ad5ef | 496 | |
Christopher Haster |
1:24750b9ad5ef | 497 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 498 | static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
Christopher Haster |
1:24750b9ad5ef | 499 | unsigned char *nonce_counter, unsigned char *stream_block, |
Christopher Haster |
1:24750b9ad5ef | 500 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 501 | { |
Christopher Haster |
1:24750b9ad5ef | 502 | return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off, |
Christopher Haster |
1:24750b9ad5ef | 503 | nonce_counter, stream_block, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 504 | } |
Christopher Haster |
1:24750b9ad5ef | 505 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Christopher Haster |
1:24750b9ad5ef | 506 | |
Christopher Haster |
1:24750b9ad5ef | 507 | static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 508 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 509 | { |
Christopher Haster |
1:24750b9ad5ef | 510 | return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 511 | } |
Christopher Haster |
1:24750b9ad5ef | 512 | |
Christopher Haster |
1:24750b9ad5ef | 513 | static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 514 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 515 | { |
Christopher Haster |
1:24750b9ad5ef | 516 | return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 517 | } |
Christopher Haster |
1:24750b9ad5ef | 518 | |
Christopher Haster |
1:24750b9ad5ef | 519 | static void * camellia_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 520 | { |
Christopher Haster |
1:24750b9ad5ef | 521 | mbedtls_camellia_context *ctx; |
Christopher Haster |
1:24750b9ad5ef | 522 | ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 523 | |
Christopher Haster |
1:24750b9ad5ef | 524 | if( ctx == NULL ) |
Christopher Haster |
1:24750b9ad5ef | 525 | return( NULL ); |
Christopher Haster |
1:24750b9ad5ef | 526 | |
Christopher Haster |
1:24750b9ad5ef | 527 | mbedtls_camellia_init( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 528 | |
Christopher Haster |
1:24750b9ad5ef | 529 | return( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 530 | } |
Christopher Haster |
1:24750b9ad5ef | 531 | |
Christopher Haster |
1:24750b9ad5ef | 532 | static void camellia_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 533 | { |
Christopher Haster |
1:24750b9ad5ef | 534 | mbedtls_camellia_free( (mbedtls_camellia_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 535 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 536 | } |
Christopher Haster |
1:24750b9ad5ef | 537 | |
Christopher Haster |
1:24750b9ad5ef | 538 | static const mbedtls_cipher_base_t camellia_info = { |
Christopher Haster |
1:24750b9ad5ef | 539 | MBEDTLS_CIPHER_ID_CAMELLIA, |
Christopher Haster |
1:24750b9ad5ef | 540 | camellia_crypt_ecb_wrap, |
Christopher Haster |
1:24750b9ad5ef | 541 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 542 | camellia_crypt_cbc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 543 | #endif |
Christopher Haster |
1:24750b9ad5ef | 544 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 545 | camellia_crypt_cfb128_wrap, |
Christopher Haster |
1:24750b9ad5ef | 546 | #endif |
Christopher Haster |
1:24750b9ad5ef | 547 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 548 | camellia_crypt_ctr_wrap, |
Christopher Haster |
1:24750b9ad5ef | 549 | #endif |
Christopher Haster |
1:24750b9ad5ef | 550 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 551 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 552 | #endif |
Christopher Haster |
1:24750b9ad5ef | 553 | camellia_setkey_enc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 554 | camellia_setkey_dec_wrap, |
Christopher Haster |
1:24750b9ad5ef | 555 | camellia_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 556 | camellia_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 557 | }; |
Christopher Haster |
1:24750b9ad5ef | 558 | |
Christopher Haster |
1:24750b9ad5ef | 559 | static const mbedtls_cipher_info_t camellia_128_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 560 | MBEDTLS_CIPHER_CAMELLIA_128_ECB, |
Christopher Haster |
1:24750b9ad5ef | 561 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 562 | 128, |
Christopher Haster |
1:24750b9ad5ef | 563 | "CAMELLIA-128-ECB", |
Christopher Haster |
1:24750b9ad5ef | 564 | 16, |
Christopher Haster |
1:24750b9ad5ef | 565 | 0, |
Christopher Haster |
1:24750b9ad5ef | 566 | 16, |
Christopher Haster |
1:24750b9ad5ef | 567 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 568 | }; |
Christopher Haster |
1:24750b9ad5ef | 569 | |
Christopher Haster |
1:24750b9ad5ef | 570 | static const mbedtls_cipher_info_t camellia_192_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 571 | MBEDTLS_CIPHER_CAMELLIA_192_ECB, |
Christopher Haster |
1:24750b9ad5ef | 572 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 573 | 192, |
Christopher Haster |
1:24750b9ad5ef | 574 | "CAMELLIA-192-ECB", |
Christopher Haster |
1:24750b9ad5ef | 575 | 16, |
Christopher Haster |
1:24750b9ad5ef | 576 | 0, |
Christopher Haster |
1:24750b9ad5ef | 577 | 16, |
Christopher Haster |
1:24750b9ad5ef | 578 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 579 | }; |
Christopher Haster |
1:24750b9ad5ef | 580 | |
Christopher Haster |
1:24750b9ad5ef | 581 | static const mbedtls_cipher_info_t camellia_256_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 582 | MBEDTLS_CIPHER_CAMELLIA_256_ECB, |
Christopher Haster |
1:24750b9ad5ef | 583 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 584 | 256, |
Christopher Haster |
1:24750b9ad5ef | 585 | "CAMELLIA-256-ECB", |
Christopher Haster |
1:24750b9ad5ef | 586 | 16, |
Christopher Haster |
1:24750b9ad5ef | 587 | 0, |
Christopher Haster |
1:24750b9ad5ef | 588 | 16, |
Christopher Haster |
1:24750b9ad5ef | 589 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 590 | }; |
Christopher Haster |
1:24750b9ad5ef | 591 | |
Christopher Haster |
1:24750b9ad5ef | 592 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 593 | static const mbedtls_cipher_info_t camellia_128_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 594 | MBEDTLS_CIPHER_CAMELLIA_128_CBC, |
Christopher Haster |
1:24750b9ad5ef | 595 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 596 | 128, |
Christopher Haster |
1:24750b9ad5ef | 597 | "CAMELLIA-128-CBC", |
Christopher Haster |
1:24750b9ad5ef | 598 | 16, |
Christopher Haster |
1:24750b9ad5ef | 599 | 0, |
Christopher Haster |
1:24750b9ad5ef | 600 | 16, |
Christopher Haster |
1:24750b9ad5ef | 601 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 602 | }; |
Christopher Haster |
1:24750b9ad5ef | 603 | |
Christopher Haster |
1:24750b9ad5ef | 604 | static const mbedtls_cipher_info_t camellia_192_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 605 | MBEDTLS_CIPHER_CAMELLIA_192_CBC, |
Christopher Haster |
1:24750b9ad5ef | 606 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 607 | 192, |
Christopher Haster |
1:24750b9ad5ef | 608 | "CAMELLIA-192-CBC", |
Christopher Haster |
1:24750b9ad5ef | 609 | 16, |
Christopher Haster |
1:24750b9ad5ef | 610 | 0, |
Christopher Haster |
1:24750b9ad5ef | 611 | 16, |
Christopher Haster |
1:24750b9ad5ef | 612 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 613 | }; |
Christopher Haster |
1:24750b9ad5ef | 614 | |
Christopher Haster |
1:24750b9ad5ef | 615 | static const mbedtls_cipher_info_t camellia_256_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 616 | MBEDTLS_CIPHER_CAMELLIA_256_CBC, |
Christopher Haster |
1:24750b9ad5ef | 617 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 618 | 256, |
Christopher Haster |
1:24750b9ad5ef | 619 | "CAMELLIA-256-CBC", |
Christopher Haster |
1:24750b9ad5ef | 620 | 16, |
Christopher Haster |
1:24750b9ad5ef | 621 | 0, |
Christopher Haster |
1:24750b9ad5ef | 622 | 16, |
Christopher Haster |
1:24750b9ad5ef | 623 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 624 | }; |
Christopher Haster |
1:24750b9ad5ef | 625 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 626 | |
Christopher Haster |
1:24750b9ad5ef | 627 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 628 | static const mbedtls_cipher_info_t camellia_128_cfb128_info = { |
Christopher Haster |
1:24750b9ad5ef | 629 | MBEDTLS_CIPHER_CAMELLIA_128_CFB128, |
Christopher Haster |
1:24750b9ad5ef | 630 | MBEDTLS_MODE_CFB, |
Christopher Haster |
1:24750b9ad5ef | 631 | 128, |
Christopher Haster |
1:24750b9ad5ef | 632 | "CAMELLIA-128-CFB128", |
Christopher Haster |
1:24750b9ad5ef | 633 | 16, |
Christopher Haster |
1:24750b9ad5ef | 634 | 0, |
Christopher Haster |
1:24750b9ad5ef | 635 | 16, |
Christopher Haster |
1:24750b9ad5ef | 636 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 637 | }; |
Christopher Haster |
1:24750b9ad5ef | 638 | |
Christopher Haster |
1:24750b9ad5ef | 639 | static const mbedtls_cipher_info_t camellia_192_cfb128_info = { |
Christopher Haster |
1:24750b9ad5ef | 640 | MBEDTLS_CIPHER_CAMELLIA_192_CFB128, |
Christopher Haster |
1:24750b9ad5ef | 641 | MBEDTLS_MODE_CFB, |
Christopher Haster |
1:24750b9ad5ef | 642 | 192, |
Christopher Haster |
1:24750b9ad5ef | 643 | "CAMELLIA-192-CFB128", |
Christopher Haster |
1:24750b9ad5ef | 644 | 16, |
Christopher Haster |
1:24750b9ad5ef | 645 | 0, |
Christopher Haster |
1:24750b9ad5ef | 646 | 16, |
Christopher Haster |
1:24750b9ad5ef | 647 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 648 | }; |
Christopher Haster |
1:24750b9ad5ef | 649 | |
Christopher Haster |
1:24750b9ad5ef | 650 | static const mbedtls_cipher_info_t camellia_256_cfb128_info = { |
Christopher Haster |
1:24750b9ad5ef | 651 | MBEDTLS_CIPHER_CAMELLIA_256_CFB128, |
Christopher Haster |
1:24750b9ad5ef | 652 | MBEDTLS_MODE_CFB, |
Christopher Haster |
1:24750b9ad5ef | 653 | 256, |
Christopher Haster |
1:24750b9ad5ef | 654 | "CAMELLIA-256-CFB128", |
Christopher Haster |
1:24750b9ad5ef | 655 | 16, |
Christopher Haster |
1:24750b9ad5ef | 656 | 0, |
Christopher Haster |
1:24750b9ad5ef | 657 | 16, |
Christopher Haster |
1:24750b9ad5ef | 658 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 659 | }; |
Christopher Haster |
1:24750b9ad5ef | 660 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Christopher Haster |
1:24750b9ad5ef | 661 | |
Christopher Haster |
1:24750b9ad5ef | 662 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 663 | static const mbedtls_cipher_info_t camellia_128_ctr_info = { |
Christopher Haster |
1:24750b9ad5ef | 664 | MBEDTLS_CIPHER_CAMELLIA_128_CTR, |
Christopher Haster |
1:24750b9ad5ef | 665 | MBEDTLS_MODE_CTR, |
Christopher Haster |
1:24750b9ad5ef | 666 | 128, |
Christopher Haster |
1:24750b9ad5ef | 667 | "CAMELLIA-128-CTR", |
Christopher Haster |
1:24750b9ad5ef | 668 | 16, |
Christopher Haster |
1:24750b9ad5ef | 669 | 0, |
Christopher Haster |
1:24750b9ad5ef | 670 | 16, |
Christopher Haster |
1:24750b9ad5ef | 671 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 672 | }; |
Christopher Haster |
1:24750b9ad5ef | 673 | |
Christopher Haster |
1:24750b9ad5ef | 674 | static const mbedtls_cipher_info_t camellia_192_ctr_info = { |
Christopher Haster |
1:24750b9ad5ef | 675 | MBEDTLS_CIPHER_CAMELLIA_192_CTR, |
Christopher Haster |
1:24750b9ad5ef | 676 | MBEDTLS_MODE_CTR, |
Christopher Haster |
1:24750b9ad5ef | 677 | 192, |
Christopher Haster |
1:24750b9ad5ef | 678 | "CAMELLIA-192-CTR", |
Christopher Haster |
1:24750b9ad5ef | 679 | 16, |
Christopher Haster |
1:24750b9ad5ef | 680 | 0, |
Christopher Haster |
1:24750b9ad5ef | 681 | 16, |
Christopher Haster |
1:24750b9ad5ef | 682 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 683 | }; |
Christopher Haster |
1:24750b9ad5ef | 684 | |
Christopher Haster |
1:24750b9ad5ef | 685 | static const mbedtls_cipher_info_t camellia_256_ctr_info = { |
Christopher Haster |
1:24750b9ad5ef | 686 | MBEDTLS_CIPHER_CAMELLIA_256_CTR, |
Christopher Haster |
1:24750b9ad5ef | 687 | MBEDTLS_MODE_CTR, |
Christopher Haster |
1:24750b9ad5ef | 688 | 256, |
Christopher Haster |
1:24750b9ad5ef | 689 | "CAMELLIA-256-CTR", |
Christopher Haster |
1:24750b9ad5ef | 690 | 16, |
Christopher Haster |
1:24750b9ad5ef | 691 | 0, |
Christopher Haster |
1:24750b9ad5ef | 692 | 16, |
Christopher Haster |
1:24750b9ad5ef | 693 | &camellia_info |
Christopher Haster |
1:24750b9ad5ef | 694 | }; |
Christopher Haster |
1:24750b9ad5ef | 695 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Christopher Haster |
1:24750b9ad5ef | 696 | |
Christopher Haster |
1:24750b9ad5ef | 697 | #if defined(MBEDTLS_GCM_C) |
Christopher Haster |
1:24750b9ad5ef | 698 | static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 699 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 700 | { |
Christopher Haster |
1:24750b9ad5ef | 701 | return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA, |
Christopher Haster |
1:24750b9ad5ef | 702 | key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 703 | } |
Christopher Haster |
1:24750b9ad5ef | 704 | |
Christopher Haster |
1:24750b9ad5ef | 705 | static const mbedtls_cipher_base_t gcm_camellia_info = { |
Christopher Haster |
1:24750b9ad5ef | 706 | MBEDTLS_CIPHER_ID_CAMELLIA, |
Christopher Haster |
1:24750b9ad5ef | 707 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 708 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 709 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 710 | #endif |
Christopher Haster |
1:24750b9ad5ef | 711 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 712 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 713 | #endif |
Christopher Haster |
1:24750b9ad5ef | 714 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 715 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 716 | #endif |
Christopher Haster |
1:24750b9ad5ef | 717 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 718 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 719 | #endif |
Christopher Haster |
1:24750b9ad5ef | 720 | gcm_camellia_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 721 | gcm_camellia_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 722 | gcm_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 723 | gcm_ctx_free, |
Christopher Haster |
1:24750b9ad5ef | 724 | }; |
Christopher Haster |
1:24750b9ad5ef | 725 | |
Christopher Haster |
1:24750b9ad5ef | 726 | static const mbedtls_cipher_info_t camellia_128_gcm_info = { |
Christopher Haster |
1:24750b9ad5ef | 727 | MBEDTLS_CIPHER_CAMELLIA_128_GCM, |
Christopher Haster |
1:24750b9ad5ef | 728 | MBEDTLS_MODE_GCM, |
Christopher Haster |
1:24750b9ad5ef | 729 | 128, |
Christopher Haster |
1:24750b9ad5ef | 730 | "CAMELLIA-128-GCM", |
Christopher Haster |
1:24750b9ad5ef | 731 | 12, |
Christopher Haster |
1:24750b9ad5ef | 732 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 733 | 16, |
Christopher Haster |
1:24750b9ad5ef | 734 | &gcm_camellia_info |
Christopher Haster |
1:24750b9ad5ef | 735 | }; |
Christopher Haster |
1:24750b9ad5ef | 736 | |
Christopher Haster |
1:24750b9ad5ef | 737 | static const mbedtls_cipher_info_t camellia_192_gcm_info = { |
Christopher Haster |
1:24750b9ad5ef | 738 | MBEDTLS_CIPHER_CAMELLIA_192_GCM, |
Christopher Haster |
1:24750b9ad5ef | 739 | MBEDTLS_MODE_GCM, |
Christopher Haster |
1:24750b9ad5ef | 740 | 192, |
Christopher Haster |
1:24750b9ad5ef | 741 | "CAMELLIA-192-GCM", |
Christopher Haster |
1:24750b9ad5ef | 742 | 12, |
Christopher Haster |
1:24750b9ad5ef | 743 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 744 | 16, |
Christopher Haster |
1:24750b9ad5ef | 745 | &gcm_camellia_info |
Christopher Haster |
1:24750b9ad5ef | 746 | }; |
Christopher Haster |
1:24750b9ad5ef | 747 | |
Christopher Haster |
1:24750b9ad5ef | 748 | static const mbedtls_cipher_info_t camellia_256_gcm_info = { |
Christopher Haster |
1:24750b9ad5ef | 749 | MBEDTLS_CIPHER_CAMELLIA_256_GCM, |
Christopher Haster |
1:24750b9ad5ef | 750 | MBEDTLS_MODE_GCM, |
Christopher Haster |
1:24750b9ad5ef | 751 | 256, |
Christopher Haster |
1:24750b9ad5ef | 752 | "CAMELLIA-256-GCM", |
Christopher Haster |
1:24750b9ad5ef | 753 | 12, |
Christopher Haster |
1:24750b9ad5ef | 754 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 755 | 16, |
Christopher Haster |
1:24750b9ad5ef | 756 | &gcm_camellia_info |
Christopher Haster |
1:24750b9ad5ef | 757 | }; |
Christopher Haster |
1:24750b9ad5ef | 758 | #endif /* MBEDTLS_GCM_C */ |
Christopher Haster |
1:24750b9ad5ef | 759 | |
Christopher Haster |
1:24750b9ad5ef | 760 | #if defined(MBEDTLS_CCM_C) |
Christopher Haster |
1:24750b9ad5ef | 761 | static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 762 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 763 | { |
Christopher Haster |
1:24750b9ad5ef | 764 | return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA, |
Christopher Haster |
1:24750b9ad5ef | 765 | key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 766 | } |
Christopher Haster |
1:24750b9ad5ef | 767 | |
Christopher Haster |
1:24750b9ad5ef | 768 | static const mbedtls_cipher_base_t ccm_camellia_info = { |
Christopher Haster |
1:24750b9ad5ef | 769 | MBEDTLS_CIPHER_ID_CAMELLIA, |
Christopher Haster |
1:24750b9ad5ef | 770 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 771 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 772 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 773 | #endif |
Christopher Haster |
1:24750b9ad5ef | 774 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 775 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 776 | #endif |
Christopher Haster |
1:24750b9ad5ef | 777 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 778 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 779 | #endif |
Christopher Haster |
1:24750b9ad5ef | 780 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 781 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 782 | #endif |
Christopher Haster |
1:24750b9ad5ef | 783 | ccm_camellia_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 784 | ccm_camellia_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 785 | ccm_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 786 | ccm_ctx_free, |
Christopher Haster |
1:24750b9ad5ef | 787 | }; |
Christopher Haster |
1:24750b9ad5ef | 788 | |
Christopher Haster |
1:24750b9ad5ef | 789 | static const mbedtls_cipher_info_t camellia_128_ccm_info = { |
Christopher Haster |
1:24750b9ad5ef | 790 | MBEDTLS_CIPHER_CAMELLIA_128_CCM, |
Christopher Haster |
1:24750b9ad5ef | 791 | MBEDTLS_MODE_CCM, |
Christopher Haster |
1:24750b9ad5ef | 792 | 128, |
Christopher Haster |
1:24750b9ad5ef | 793 | "CAMELLIA-128-CCM", |
Christopher Haster |
1:24750b9ad5ef | 794 | 12, |
Christopher Haster |
1:24750b9ad5ef | 795 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 796 | 16, |
Christopher Haster |
1:24750b9ad5ef | 797 | &ccm_camellia_info |
Christopher Haster |
1:24750b9ad5ef | 798 | }; |
Christopher Haster |
1:24750b9ad5ef | 799 | |
Christopher Haster |
1:24750b9ad5ef | 800 | static const mbedtls_cipher_info_t camellia_192_ccm_info = { |
Christopher Haster |
1:24750b9ad5ef | 801 | MBEDTLS_CIPHER_CAMELLIA_192_CCM, |
Christopher Haster |
1:24750b9ad5ef | 802 | MBEDTLS_MODE_CCM, |
Christopher Haster |
1:24750b9ad5ef | 803 | 192, |
Christopher Haster |
1:24750b9ad5ef | 804 | "CAMELLIA-192-CCM", |
Christopher Haster |
1:24750b9ad5ef | 805 | 12, |
Christopher Haster |
1:24750b9ad5ef | 806 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 807 | 16, |
Christopher Haster |
1:24750b9ad5ef | 808 | &ccm_camellia_info |
Christopher Haster |
1:24750b9ad5ef | 809 | }; |
Christopher Haster |
1:24750b9ad5ef | 810 | |
Christopher Haster |
1:24750b9ad5ef | 811 | static const mbedtls_cipher_info_t camellia_256_ccm_info = { |
Christopher Haster |
1:24750b9ad5ef | 812 | MBEDTLS_CIPHER_CAMELLIA_256_CCM, |
Christopher Haster |
1:24750b9ad5ef | 813 | MBEDTLS_MODE_CCM, |
Christopher Haster |
1:24750b9ad5ef | 814 | 256, |
Christopher Haster |
1:24750b9ad5ef | 815 | "CAMELLIA-256-CCM", |
Christopher Haster |
1:24750b9ad5ef | 816 | 12, |
Christopher Haster |
1:24750b9ad5ef | 817 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
Christopher Haster |
1:24750b9ad5ef | 818 | 16, |
Christopher Haster |
1:24750b9ad5ef | 819 | &ccm_camellia_info |
Christopher Haster |
1:24750b9ad5ef | 820 | }; |
Christopher Haster |
1:24750b9ad5ef | 821 | #endif /* MBEDTLS_CCM_C */ |
Christopher Haster |
1:24750b9ad5ef | 822 | |
Christopher Haster |
1:24750b9ad5ef | 823 | #endif /* MBEDTLS_CAMELLIA_C */ |
Christopher Haster |
1:24750b9ad5ef | 824 | |
Christopher Haster |
1:24750b9ad5ef | 825 | #if defined(MBEDTLS_DES_C) |
Christopher Haster |
1:24750b9ad5ef | 826 | |
Christopher Haster |
1:24750b9ad5ef | 827 | static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 828 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 829 | { |
Christopher Haster |
1:24750b9ad5ef | 830 | ((void) operation); |
Christopher Haster |
1:24750b9ad5ef | 831 | return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 832 | } |
Christopher Haster |
1:24750b9ad5ef | 833 | |
Christopher Haster |
1:24750b9ad5ef | 834 | static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 835 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 836 | { |
Christopher Haster |
1:24750b9ad5ef | 837 | ((void) operation); |
Christopher Haster |
1:24750b9ad5ef | 838 | return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 839 | } |
Christopher Haster |
1:24750b9ad5ef | 840 | |
Christopher Haster |
1:24750b9ad5ef | 841 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 842 | static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length, |
Christopher Haster |
1:24750b9ad5ef | 843 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 844 | { |
Christopher Haster |
1:24750b9ad5ef | 845 | return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input, |
Christopher Haster |
1:24750b9ad5ef | 846 | output ); |
Christopher Haster |
1:24750b9ad5ef | 847 | } |
Christopher Haster |
1:24750b9ad5ef | 848 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 849 | |
Christopher Haster |
1:24750b9ad5ef | 850 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 851 | static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length, |
Christopher Haster |
1:24750b9ad5ef | 852 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 853 | { |
Christopher Haster |
1:24750b9ad5ef | 854 | return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input, |
Christopher Haster |
1:24750b9ad5ef | 855 | output ); |
Christopher Haster |
1:24750b9ad5ef | 856 | } |
Christopher Haster |
1:24750b9ad5ef | 857 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 858 | |
Christopher Haster |
1:24750b9ad5ef | 859 | static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 860 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 861 | { |
Christopher Haster |
1:24750b9ad5ef | 862 | ((void) key_bitlen); |
Christopher Haster |
1:24750b9ad5ef | 863 | |
Christopher Haster |
1:24750b9ad5ef | 864 | return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key ); |
Christopher Haster |
1:24750b9ad5ef | 865 | } |
Christopher Haster |
1:24750b9ad5ef | 866 | |
Christopher Haster |
1:24750b9ad5ef | 867 | static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 868 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 869 | { |
Christopher Haster |
1:24750b9ad5ef | 870 | ((void) key_bitlen); |
Christopher Haster |
1:24750b9ad5ef | 871 | |
Christopher Haster |
1:24750b9ad5ef | 872 | return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key ); |
Christopher Haster |
1:24750b9ad5ef | 873 | } |
Christopher Haster |
1:24750b9ad5ef | 874 | |
Christopher Haster |
1:24750b9ad5ef | 875 | static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 876 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 877 | { |
Christopher Haster |
1:24750b9ad5ef | 878 | ((void) key_bitlen); |
Christopher Haster |
1:24750b9ad5ef | 879 | |
Christopher Haster |
1:24750b9ad5ef | 880 | return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key ); |
Christopher Haster |
1:24750b9ad5ef | 881 | } |
Christopher Haster |
1:24750b9ad5ef | 882 | |
Christopher Haster |
1:24750b9ad5ef | 883 | static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 884 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 885 | { |
Christopher Haster |
1:24750b9ad5ef | 886 | ((void) key_bitlen); |
Christopher Haster |
1:24750b9ad5ef | 887 | |
Christopher Haster |
1:24750b9ad5ef | 888 | return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key ); |
Christopher Haster |
1:24750b9ad5ef | 889 | } |
Christopher Haster |
1:24750b9ad5ef | 890 | |
Christopher Haster |
1:24750b9ad5ef | 891 | static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 892 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 893 | { |
Christopher Haster |
1:24750b9ad5ef | 894 | ((void) key_bitlen); |
Christopher Haster |
1:24750b9ad5ef | 895 | |
Christopher Haster |
1:24750b9ad5ef | 896 | return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key ); |
Christopher Haster |
1:24750b9ad5ef | 897 | } |
Christopher Haster |
1:24750b9ad5ef | 898 | |
Christopher Haster |
1:24750b9ad5ef | 899 | static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 900 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 901 | { |
Christopher Haster |
1:24750b9ad5ef | 902 | ((void) key_bitlen); |
Christopher Haster |
1:24750b9ad5ef | 903 | |
Christopher Haster |
1:24750b9ad5ef | 904 | return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key ); |
Christopher Haster |
1:24750b9ad5ef | 905 | } |
Christopher Haster |
1:24750b9ad5ef | 906 | |
Christopher Haster |
1:24750b9ad5ef | 907 | static void * des_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 908 | { |
Christopher Haster |
1:24750b9ad5ef | 909 | mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 910 | |
Christopher Haster |
1:24750b9ad5ef | 911 | if( des == NULL ) |
Christopher Haster |
1:24750b9ad5ef | 912 | return( NULL ); |
Christopher Haster |
1:24750b9ad5ef | 913 | |
Christopher Haster |
1:24750b9ad5ef | 914 | mbedtls_des_init( des ); |
Christopher Haster |
1:24750b9ad5ef | 915 | |
Christopher Haster |
1:24750b9ad5ef | 916 | return( des ); |
Christopher Haster |
1:24750b9ad5ef | 917 | } |
Christopher Haster |
1:24750b9ad5ef | 918 | |
Christopher Haster |
1:24750b9ad5ef | 919 | static void des_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 920 | { |
Christopher Haster |
1:24750b9ad5ef | 921 | mbedtls_des_free( (mbedtls_des_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 922 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 923 | } |
Christopher Haster |
1:24750b9ad5ef | 924 | |
Christopher Haster |
1:24750b9ad5ef | 925 | static void * des3_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 926 | { |
Christopher Haster |
1:24750b9ad5ef | 927 | mbedtls_des3_context *des3; |
Christopher Haster |
1:24750b9ad5ef | 928 | des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 929 | |
Christopher Haster |
1:24750b9ad5ef | 930 | if( des3 == NULL ) |
Christopher Haster |
1:24750b9ad5ef | 931 | return( NULL ); |
Christopher Haster |
1:24750b9ad5ef | 932 | |
Christopher Haster |
1:24750b9ad5ef | 933 | mbedtls_des3_init( des3 ); |
Christopher Haster |
1:24750b9ad5ef | 934 | |
Christopher Haster |
1:24750b9ad5ef | 935 | return( des3 ); |
Christopher Haster |
1:24750b9ad5ef | 936 | } |
Christopher Haster |
1:24750b9ad5ef | 937 | |
Christopher Haster |
1:24750b9ad5ef | 938 | static void des3_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 939 | { |
Christopher Haster |
1:24750b9ad5ef | 940 | mbedtls_des3_free( (mbedtls_des3_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 941 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 942 | } |
Christopher Haster |
1:24750b9ad5ef | 943 | |
Christopher Haster |
1:24750b9ad5ef | 944 | static const mbedtls_cipher_base_t des_info = { |
Christopher Haster |
1:24750b9ad5ef | 945 | MBEDTLS_CIPHER_ID_DES, |
Christopher Haster |
1:24750b9ad5ef | 946 | des_crypt_ecb_wrap, |
Christopher Haster |
1:24750b9ad5ef | 947 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 948 | des_crypt_cbc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 949 | #endif |
Christopher Haster |
1:24750b9ad5ef | 950 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 951 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 952 | #endif |
Christopher Haster |
1:24750b9ad5ef | 953 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 954 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 955 | #endif |
Christopher Haster |
1:24750b9ad5ef | 956 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 957 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 958 | #endif |
Christopher Haster |
1:24750b9ad5ef | 959 | des_setkey_enc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 960 | des_setkey_dec_wrap, |
Christopher Haster |
1:24750b9ad5ef | 961 | des_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 962 | des_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 963 | }; |
Christopher Haster |
1:24750b9ad5ef | 964 | |
Christopher Haster |
1:24750b9ad5ef | 965 | static const mbedtls_cipher_info_t des_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 966 | MBEDTLS_CIPHER_DES_ECB, |
Christopher Haster |
1:24750b9ad5ef | 967 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 968 | MBEDTLS_KEY_LENGTH_DES, |
Christopher Haster |
1:24750b9ad5ef | 969 | "DES-ECB", |
Christopher Haster |
1:24750b9ad5ef | 970 | 8, |
Christopher Haster |
1:24750b9ad5ef | 971 | 0, |
Christopher Haster |
1:24750b9ad5ef | 972 | 8, |
Christopher Haster |
1:24750b9ad5ef | 973 | &des_info |
Christopher Haster |
1:24750b9ad5ef | 974 | }; |
Christopher Haster |
1:24750b9ad5ef | 975 | |
Christopher Haster |
1:24750b9ad5ef | 976 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 977 | static const mbedtls_cipher_info_t des_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 978 | MBEDTLS_CIPHER_DES_CBC, |
Christopher Haster |
1:24750b9ad5ef | 979 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 980 | MBEDTLS_KEY_LENGTH_DES, |
Christopher Haster |
1:24750b9ad5ef | 981 | "DES-CBC", |
Christopher Haster |
1:24750b9ad5ef | 982 | 8, |
Christopher Haster |
1:24750b9ad5ef | 983 | 0, |
Christopher Haster |
1:24750b9ad5ef | 984 | 8, |
Christopher Haster |
1:24750b9ad5ef | 985 | &des_info |
Christopher Haster |
1:24750b9ad5ef | 986 | }; |
Christopher Haster |
1:24750b9ad5ef | 987 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 988 | |
Christopher Haster |
1:24750b9ad5ef | 989 | static const mbedtls_cipher_base_t des_ede_info = { |
Christopher Haster |
1:24750b9ad5ef | 990 | MBEDTLS_CIPHER_ID_DES, |
Christopher Haster |
1:24750b9ad5ef | 991 | des3_crypt_ecb_wrap, |
Christopher Haster |
1:24750b9ad5ef | 992 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 993 | des3_crypt_cbc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 994 | #endif |
Christopher Haster |
1:24750b9ad5ef | 995 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 996 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 997 | #endif |
Christopher Haster |
1:24750b9ad5ef | 998 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 999 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1000 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1001 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 1002 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1003 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1004 | des3_set2key_enc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1005 | des3_set2key_dec_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1006 | des3_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 1007 | des3_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 1008 | }; |
Christopher Haster |
1:24750b9ad5ef | 1009 | |
Christopher Haster |
1:24750b9ad5ef | 1010 | static const mbedtls_cipher_info_t des_ede_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 1011 | MBEDTLS_CIPHER_DES_EDE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 1012 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 1013 | MBEDTLS_KEY_LENGTH_DES_EDE, |
Christopher Haster |
1:24750b9ad5ef | 1014 | "DES-EDE-ECB", |
Christopher Haster |
1:24750b9ad5ef | 1015 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1016 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1017 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1018 | &des_ede_info |
Christopher Haster |
1:24750b9ad5ef | 1019 | }; |
Christopher Haster |
1:24750b9ad5ef | 1020 | |
Christopher Haster |
1:24750b9ad5ef | 1021 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1022 | static const mbedtls_cipher_info_t des_ede_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 1023 | MBEDTLS_CIPHER_DES_EDE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 1024 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 1025 | MBEDTLS_KEY_LENGTH_DES_EDE, |
Christopher Haster |
1:24750b9ad5ef | 1026 | "DES-EDE-CBC", |
Christopher Haster |
1:24750b9ad5ef | 1027 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1028 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1029 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1030 | &des_ede_info |
Christopher Haster |
1:24750b9ad5ef | 1031 | }; |
Christopher Haster |
1:24750b9ad5ef | 1032 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 1033 | |
Christopher Haster |
1:24750b9ad5ef | 1034 | static const mbedtls_cipher_base_t des_ede3_info = { |
Christopher Haster |
1:24750b9ad5ef | 1035 | MBEDTLS_CIPHER_ID_3DES, |
Christopher Haster |
1:24750b9ad5ef | 1036 | des3_crypt_ecb_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1037 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1038 | des3_crypt_cbc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1039 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1040 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1041 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1042 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1043 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1044 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1045 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1046 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 1047 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1048 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1049 | des3_set3key_enc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1050 | des3_set3key_dec_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1051 | des3_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 1052 | des3_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 1053 | }; |
Christopher Haster |
1:24750b9ad5ef | 1054 | |
Christopher Haster |
1:24750b9ad5ef | 1055 | static const mbedtls_cipher_info_t des_ede3_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 1056 | MBEDTLS_CIPHER_DES_EDE3_ECB, |
Christopher Haster |
1:24750b9ad5ef | 1057 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 1058 | MBEDTLS_KEY_LENGTH_DES_EDE3, |
Christopher Haster |
1:24750b9ad5ef | 1059 | "DES-EDE3-ECB", |
Christopher Haster |
1:24750b9ad5ef | 1060 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1061 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1062 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1063 | &des_ede3_info |
Christopher Haster |
1:24750b9ad5ef | 1064 | }; |
Christopher Haster |
1:24750b9ad5ef | 1065 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1066 | static const mbedtls_cipher_info_t des_ede3_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 1067 | MBEDTLS_CIPHER_DES_EDE3_CBC, |
Christopher Haster |
1:24750b9ad5ef | 1068 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 1069 | MBEDTLS_KEY_LENGTH_DES_EDE3, |
Christopher Haster |
1:24750b9ad5ef | 1070 | "DES-EDE3-CBC", |
Christopher Haster |
1:24750b9ad5ef | 1071 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1072 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1073 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1074 | &des_ede3_info |
Christopher Haster |
1:24750b9ad5ef | 1075 | }; |
Christopher Haster |
1:24750b9ad5ef | 1076 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 1077 | #endif /* MBEDTLS_DES_C */ |
Christopher Haster |
1:24750b9ad5ef | 1078 | |
Christopher Haster |
1:24750b9ad5ef | 1079 | #if defined(MBEDTLS_BLOWFISH_C) |
Christopher Haster |
1:24750b9ad5ef | 1080 | |
Christopher Haster |
1:24750b9ad5ef | 1081 | static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 1082 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 1083 | { |
Christopher Haster |
1:24750b9ad5ef | 1084 | return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input, |
Christopher Haster |
1:24750b9ad5ef | 1085 | output ); |
Christopher Haster |
1:24750b9ad5ef | 1086 | } |
Christopher Haster |
1:24750b9ad5ef | 1087 | |
Christopher Haster |
1:24750b9ad5ef | 1088 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1089 | static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 1090 | size_t length, unsigned char *iv, const unsigned char *input, |
Christopher Haster |
1:24750b9ad5ef | 1091 | unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 1092 | { |
Christopher Haster |
1:24750b9ad5ef | 1093 | return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv, |
Christopher Haster |
1:24750b9ad5ef | 1094 | input, output ); |
Christopher Haster |
1:24750b9ad5ef | 1095 | } |
Christopher Haster |
1:24750b9ad5ef | 1096 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 1097 | |
Christopher Haster |
1:24750b9ad5ef | 1098 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1099 | static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation, |
Christopher Haster |
1:24750b9ad5ef | 1100 | size_t length, size_t *iv_off, unsigned char *iv, |
Christopher Haster |
1:24750b9ad5ef | 1101 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 1102 | { |
Christopher Haster |
1:24750b9ad5ef | 1103 | return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length, |
Christopher Haster |
1:24750b9ad5ef | 1104 | iv_off, iv, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 1105 | } |
Christopher Haster |
1:24750b9ad5ef | 1106 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Christopher Haster |
1:24750b9ad5ef | 1107 | |
Christopher Haster |
1:24750b9ad5ef | 1108 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1109 | static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
Christopher Haster |
1:24750b9ad5ef | 1110 | unsigned char *nonce_counter, unsigned char *stream_block, |
Christopher Haster |
1:24750b9ad5ef | 1111 | const unsigned char *input, unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 1112 | { |
Christopher Haster |
1:24750b9ad5ef | 1113 | return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off, |
Christopher Haster |
1:24750b9ad5ef | 1114 | nonce_counter, stream_block, input, output ); |
Christopher Haster |
1:24750b9ad5ef | 1115 | } |
Christopher Haster |
1:24750b9ad5ef | 1116 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Christopher Haster |
1:24750b9ad5ef | 1117 | |
Christopher Haster |
1:24750b9ad5ef | 1118 | static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 1119 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 1120 | { |
Christopher Haster |
1:24750b9ad5ef | 1121 | return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen ); |
Christopher Haster |
1:24750b9ad5ef | 1122 | } |
Christopher Haster |
1:24750b9ad5ef | 1123 | |
Christopher Haster |
1:24750b9ad5ef | 1124 | static void * blowfish_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 1125 | { |
Christopher Haster |
1:24750b9ad5ef | 1126 | mbedtls_blowfish_context *ctx; |
Christopher Haster |
1:24750b9ad5ef | 1127 | ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 1128 | |
Christopher Haster |
1:24750b9ad5ef | 1129 | if( ctx == NULL ) |
Christopher Haster |
1:24750b9ad5ef | 1130 | return( NULL ); |
Christopher Haster |
1:24750b9ad5ef | 1131 | |
Christopher Haster |
1:24750b9ad5ef | 1132 | mbedtls_blowfish_init( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1133 | |
Christopher Haster |
1:24750b9ad5ef | 1134 | return( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1135 | } |
Christopher Haster |
1:24750b9ad5ef | 1136 | |
Christopher Haster |
1:24750b9ad5ef | 1137 | static void blowfish_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 1138 | { |
Christopher Haster |
1:24750b9ad5ef | 1139 | mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1140 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1141 | } |
Christopher Haster |
1:24750b9ad5ef | 1142 | |
Christopher Haster |
1:24750b9ad5ef | 1143 | static const mbedtls_cipher_base_t blowfish_info = { |
Christopher Haster |
1:24750b9ad5ef | 1144 | MBEDTLS_CIPHER_ID_BLOWFISH, |
Christopher Haster |
1:24750b9ad5ef | 1145 | blowfish_crypt_ecb_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1146 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1147 | blowfish_crypt_cbc_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1148 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1149 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1150 | blowfish_crypt_cfb64_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1151 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1152 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1153 | blowfish_crypt_ctr_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1154 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1155 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 1156 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1157 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1158 | blowfish_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1159 | blowfish_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1160 | blowfish_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 1161 | blowfish_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 1162 | }; |
Christopher Haster |
1:24750b9ad5ef | 1163 | |
Christopher Haster |
1:24750b9ad5ef | 1164 | static const mbedtls_cipher_info_t blowfish_ecb_info = { |
Christopher Haster |
1:24750b9ad5ef | 1165 | MBEDTLS_CIPHER_BLOWFISH_ECB, |
Christopher Haster |
1:24750b9ad5ef | 1166 | MBEDTLS_MODE_ECB, |
Christopher Haster |
1:24750b9ad5ef | 1167 | 128, |
Christopher Haster |
1:24750b9ad5ef | 1168 | "BLOWFISH-ECB", |
Christopher Haster |
1:24750b9ad5ef | 1169 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1170 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Christopher Haster |
1:24750b9ad5ef | 1171 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1172 | &blowfish_info |
Christopher Haster |
1:24750b9ad5ef | 1173 | }; |
Christopher Haster |
1:24750b9ad5ef | 1174 | |
Christopher Haster |
1:24750b9ad5ef | 1175 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1176 | static const mbedtls_cipher_info_t blowfish_cbc_info = { |
Christopher Haster |
1:24750b9ad5ef | 1177 | MBEDTLS_CIPHER_BLOWFISH_CBC, |
Christopher Haster |
1:24750b9ad5ef | 1178 | MBEDTLS_MODE_CBC, |
Christopher Haster |
1:24750b9ad5ef | 1179 | 128, |
Christopher Haster |
1:24750b9ad5ef | 1180 | "BLOWFISH-CBC", |
Christopher Haster |
1:24750b9ad5ef | 1181 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1182 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Christopher Haster |
1:24750b9ad5ef | 1183 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1184 | &blowfish_info |
Christopher Haster |
1:24750b9ad5ef | 1185 | }; |
Christopher Haster |
1:24750b9ad5ef | 1186 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Christopher Haster |
1:24750b9ad5ef | 1187 | |
Christopher Haster |
1:24750b9ad5ef | 1188 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1189 | static const mbedtls_cipher_info_t blowfish_cfb64_info = { |
Christopher Haster |
1:24750b9ad5ef | 1190 | MBEDTLS_CIPHER_BLOWFISH_CFB64, |
Christopher Haster |
1:24750b9ad5ef | 1191 | MBEDTLS_MODE_CFB, |
Christopher Haster |
1:24750b9ad5ef | 1192 | 128, |
Christopher Haster |
1:24750b9ad5ef | 1193 | "BLOWFISH-CFB64", |
Christopher Haster |
1:24750b9ad5ef | 1194 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1195 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Christopher Haster |
1:24750b9ad5ef | 1196 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1197 | &blowfish_info |
Christopher Haster |
1:24750b9ad5ef | 1198 | }; |
Christopher Haster |
1:24750b9ad5ef | 1199 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Christopher Haster |
1:24750b9ad5ef | 1200 | |
Christopher Haster |
1:24750b9ad5ef | 1201 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1202 | static const mbedtls_cipher_info_t blowfish_ctr_info = { |
Christopher Haster |
1:24750b9ad5ef | 1203 | MBEDTLS_CIPHER_BLOWFISH_CTR, |
Christopher Haster |
1:24750b9ad5ef | 1204 | MBEDTLS_MODE_CTR, |
Christopher Haster |
1:24750b9ad5ef | 1205 | 128, |
Christopher Haster |
1:24750b9ad5ef | 1206 | "BLOWFISH-CTR", |
Christopher Haster |
1:24750b9ad5ef | 1207 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1208 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Christopher Haster |
1:24750b9ad5ef | 1209 | 8, |
Christopher Haster |
1:24750b9ad5ef | 1210 | &blowfish_info |
Christopher Haster |
1:24750b9ad5ef | 1211 | }; |
Christopher Haster |
1:24750b9ad5ef | 1212 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Christopher Haster |
1:24750b9ad5ef | 1213 | #endif /* MBEDTLS_BLOWFISH_C */ |
Christopher Haster |
1:24750b9ad5ef | 1214 | |
Christopher Haster |
1:24750b9ad5ef | 1215 | #if defined(MBEDTLS_ARC4_C) |
Christopher Haster |
1:24750b9ad5ef | 1216 | static int arc4_crypt_stream_wrap( void *ctx, size_t length, |
Christopher Haster |
1:24750b9ad5ef | 1217 | const unsigned char *input, |
Christopher Haster |
1:24750b9ad5ef | 1218 | unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 1219 | { |
Christopher Haster |
1:24750b9ad5ef | 1220 | return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) ); |
Christopher Haster |
1:24750b9ad5ef | 1221 | } |
Christopher Haster |
1:24750b9ad5ef | 1222 | |
Christopher Haster |
1:24750b9ad5ef | 1223 | static int arc4_setkey_wrap( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 1224 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 1225 | { |
Christopher Haster |
1:24750b9ad5ef | 1226 | /* we get key_bitlen in bits, arc4 expects it in bytes */ |
Christopher Haster |
1:24750b9ad5ef | 1227 | if( key_bitlen % 8 != 0 ) |
Christopher Haster |
1:24750b9ad5ef | 1228 | return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); |
Christopher Haster |
1:24750b9ad5ef | 1229 | |
Christopher Haster |
1:24750b9ad5ef | 1230 | mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 ); |
Christopher Haster |
1:24750b9ad5ef | 1231 | return( 0 ); |
Christopher Haster |
1:24750b9ad5ef | 1232 | } |
Christopher Haster |
1:24750b9ad5ef | 1233 | |
Christopher Haster |
1:24750b9ad5ef | 1234 | static void * arc4_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 1235 | { |
Christopher Haster |
1:24750b9ad5ef | 1236 | mbedtls_arc4_context *ctx; |
Christopher Haster |
1:24750b9ad5ef | 1237 | ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) ); |
Christopher Haster |
1:24750b9ad5ef | 1238 | |
Christopher Haster |
1:24750b9ad5ef | 1239 | if( ctx == NULL ) |
Christopher Haster |
1:24750b9ad5ef | 1240 | return( NULL ); |
Christopher Haster |
1:24750b9ad5ef | 1241 | |
Christopher Haster |
1:24750b9ad5ef | 1242 | mbedtls_arc4_init( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1243 | |
Christopher Haster |
1:24750b9ad5ef | 1244 | return( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1245 | } |
Christopher Haster |
1:24750b9ad5ef | 1246 | |
Christopher Haster |
1:24750b9ad5ef | 1247 | static void arc4_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 1248 | { |
Christopher Haster |
1:24750b9ad5ef | 1249 | mbedtls_arc4_free( (mbedtls_arc4_context *) ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1250 | mbedtls_free( ctx ); |
Christopher Haster |
1:24750b9ad5ef | 1251 | } |
Christopher Haster |
1:24750b9ad5ef | 1252 | |
Christopher Haster |
1:24750b9ad5ef | 1253 | static const mbedtls_cipher_base_t arc4_base_info = { |
Christopher Haster |
1:24750b9ad5ef | 1254 | MBEDTLS_CIPHER_ID_ARC4, |
Christopher Haster |
1:24750b9ad5ef | 1255 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1256 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1257 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1258 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1259 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1260 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1261 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1262 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1263 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1264 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1265 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 1266 | arc4_crypt_stream_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1267 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1268 | arc4_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1269 | arc4_setkey_wrap, |
Christopher Haster |
1:24750b9ad5ef | 1270 | arc4_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 1271 | arc4_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 1272 | }; |
Christopher Haster |
1:24750b9ad5ef | 1273 | |
Christopher Haster |
1:24750b9ad5ef | 1274 | static const mbedtls_cipher_info_t arc4_128_info = { |
Christopher Haster |
1:24750b9ad5ef | 1275 | MBEDTLS_CIPHER_ARC4_128, |
Christopher Haster |
1:24750b9ad5ef | 1276 | MBEDTLS_MODE_STREAM, |
Christopher Haster |
1:24750b9ad5ef | 1277 | 128, |
Christopher Haster |
1:24750b9ad5ef | 1278 | "ARC4-128", |
Christopher Haster |
1:24750b9ad5ef | 1279 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1280 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1281 | 1, |
Christopher Haster |
1:24750b9ad5ef | 1282 | &arc4_base_info |
Christopher Haster |
1:24750b9ad5ef | 1283 | }; |
Christopher Haster |
1:24750b9ad5ef | 1284 | #endif /* MBEDTLS_ARC4_C */ |
Christopher Haster |
1:24750b9ad5ef | 1285 | |
Christopher Haster |
1:24750b9ad5ef | 1286 | #if defined(MBEDTLS_CIPHER_NULL_CIPHER) |
Christopher Haster |
1:24750b9ad5ef | 1287 | static int null_crypt_stream( void *ctx, size_t length, |
Christopher Haster |
1:24750b9ad5ef | 1288 | const unsigned char *input, |
Christopher Haster |
1:24750b9ad5ef | 1289 | unsigned char *output ) |
Christopher Haster |
1:24750b9ad5ef | 1290 | { |
Christopher Haster |
1:24750b9ad5ef | 1291 | ((void) ctx); |
Christopher Haster |
1:24750b9ad5ef | 1292 | memmove( output, input, length ); |
Christopher Haster |
1:24750b9ad5ef | 1293 | return( 0 ); |
Christopher Haster |
1:24750b9ad5ef | 1294 | } |
Christopher Haster |
1:24750b9ad5ef | 1295 | |
Christopher Haster |
1:24750b9ad5ef | 1296 | static int null_setkey( void *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 1297 | unsigned int key_bitlen ) |
Christopher Haster |
1:24750b9ad5ef | 1298 | { |
Christopher Haster |
1:24750b9ad5ef | 1299 | ((void) ctx); |
Christopher Haster |
1:24750b9ad5ef | 1300 | ((void) key); |
Christopher Haster |
1:24750b9ad5ef | 1301 | ((void) key_bitlen); |
Christopher Haster |
1:24750b9ad5ef | 1302 | |
Christopher Haster |
1:24750b9ad5ef | 1303 | return( 0 ); |
Christopher Haster |
1:24750b9ad5ef | 1304 | } |
Christopher Haster |
1:24750b9ad5ef | 1305 | |
Christopher Haster |
1:24750b9ad5ef | 1306 | static void * null_ctx_alloc( void ) |
Christopher Haster |
1:24750b9ad5ef | 1307 | { |
Christopher Haster |
1:24750b9ad5ef | 1308 | return( (void *) 1 ); |
Christopher Haster |
1:24750b9ad5ef | 1309 | } |
Christopher Haster |
1:24750b9ad5ef | 1310 | |
Christopher Haster |
1:24750b9ad5ef | 1311 | static void null_ctx_free( void *ctx ) |
Christopher Haster |
1:24750b9ad5ef | 1312 | { |
Christopher Haster |
1:24750b9ad5ef | 1313 | ((void) ctx); |
Christopher Haster |
1:24750b9ad5ef | 1314 | } |
Christopher Haster |
1:24750b9ad5ef | 1315 | |
Christopher Haster |
1:24750b9ad5ef | 1316 | static const mbedtls_cipher_base_t null_base_info = { |
Christopher Haster |
1:24750b9ad5ef | 1317 | MBEDTLS_CIPHER_ID_NULL, |
Christopher Haster |
1:24750b9ad5ef | 1318 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1319 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1320 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1321 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1322 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1323 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1324 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1325 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1326 | NULL, |
Christopher Haster |
1:24750b9ad5ef | 1327 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1328 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Christopher Haster |
1:24750b9ad5ef | 1329 | null_crypt_stream, |
Christopher Haster |
1:24750b9ad5ef | 1330 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1331 | null_setkey, |
Christopher Haster |
1:24750b9ad5ef | 1332 | null_setkey, |
Christopher Haster |
1:24750b9ad5ef | 1333 | null_ctx_alloc, |
Christopher Haster |
1:24750b9ad5ef | 1334 | null_ctx_free |
Christopher Haster |
1:24750b9ad5ef | 1335 | }; |
Christopher Haster |
1:24750b9ad5ef | 1336 | |
Christopher Haster |
1:24750b9ad5ef | 1337 | static const mbedtls_cipher_info_t null_cipher_info = { |
Christopher Haster |
1:24750b9ad5ef | 1338 | MBEDTLS_CIPHER_NULL, |
Christopher Haster |
1:24750b9ad5ef | 1339 | MBEDTLS_MODE_STREAM, |
Christopher Haster |
1:24750b9ad5ef | 1340 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1341 | "NULL", |
Christopher Haster |
1:24750b9ad5ef | 1342 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1343 | 0, |
Christopher Haster |
1:24750b9ad5ef | 1344 | 1, |
Christopher Haster |
1:24750b9ad5ef | 1345 | &null_base_info |
Christopher Haster |
1:24750b9ad5ef | 1346 | }; |
Christopher Haster |
1:24750b9ad5ef | 1347 | #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */ |
Christopher Haster |
1:24750b9ad5ef | 1348 | |
Christopher Haster |
1:24750b9ad5ef | 1349 | const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] = |
Christopher Haster |
1:24750b9ad5ef | 1350 | { |
Christopher Haster |
1:24750b9ad5ef | 1351 | #if defined(MBEDTLS_AES_C) |
Christopher Haster |
1:24750b9ad5ef | 1352 | { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1353 | { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1354 | { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1355 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1356 | { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1357 | { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1358 | { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1359 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1360 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1361 | { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info }, |
Christopher Haster |
1:24750b9ad5ef | 1362 | { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info }, |
Christopher Haster |
1:24750b9ad5ef | 1363 | { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info }, |
Christopher Haster |
1:24750b9ad5ef | 1364 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1365 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1366 | { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info }, |
Christopher Haster |
1:24750b9ad5ef | 1367 | { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info }, |
Christopher Haster |
1:24750b9ad5ef | 1368 | { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info }, |
Christopher Haster |
1:24750b9ad5ef | 1369 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1370 | #if defined(MBEDTLS_GCM_C) |
Christopher Haster |
1:24750b9ad5ef | 1371 | { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1372 | { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1373 | { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1374 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1375 | #if defined(MBEDTLS_CCM_C) |
Christopher Haster |
1:24750b9ad5ef | 1376 | { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1377 | { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1378 | { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1379 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1380 | #endif /* MBEDTLS_AES_C */ |
Christopher Haster |
1:24750b9ad5ef | 1381 | |
Christopher Haster |
1:24750b9ad5ef | 1382 | #if defined(MBEDTLS_ARC4_C) |
Christopher Haster |
1:24750b9ad5ef | 1383 | { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info }, |
Christopher Haster |
1:24750b9ad5ef | 1384 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1385 | |
Christopher Haster |
1:24750b9ad5ef | 1386 | #if defined(MBEDTLS_BLOWFISH_C) |
Christopher Haster |
1:24750b9ad5ef | 1387 | { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1388 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1389 | { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1390 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1391 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1392 | { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info }, |
Christopher Haster |
1:24750b9ad5ef | 1393 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1394 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1395 | { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info }, |
Christopher Haster |
1:24750b9ad5ef | 1396 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1397 | #endif /* MBEDTLS_BLOWFISH_C */ |
Christopher Haster |
1:24750b9ad5ef | 1398 | |
Christopher Haster |
1:24750b9ad5ef | 1399 | #if defined(MBEDTLS_CAMELLIA_C) |
Christopher Haster |
1:24750b9ad5ef | 1400 | { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1401 | { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1402 | { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1403 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1404 | { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1405 | { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1406 | { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1407 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1408 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Christopher Haster |
1:24750b9ad5ef | 1409 | { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info }, |
Christopher Haster |
1:24750b9ad5ef | 1410 | { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info }, |
Christopher Haster |
1:24750b9ad5ef | 1411 | { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info }, |
Christopher Haster |
1:24750b9ad5ef | 1412 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1413 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Christopher Haster |
1:24750b9ad5ef | 1414 | { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info }, |
Christopher Haster |
1:24750b9ad5ef | 1415 | { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info }, |
Christopher Haster |
1:24750b9ad5ef | 1416 | { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info }, |
Christopher Haster |
1:24750b9ad5ef | 1417 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1418 | #if defined(MBEDTLS_GCM_C) |
Christopher Haster |
1:24750b9ad5ef | 1419 | { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1420 | { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1421 | { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1422 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1423 | #if defined(MBEDTLS_CCM_C) |
Christopher Haster |
1:24750b9ad5ef | 1424 | { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1425 | { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1426 | { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info }, |
Christopher Haster |
1:24750b9ad5ef | 1427 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1428 | #endif /* MBEDTLS_CAMELLIA_C */ |
Christopher Haster |
1:24750b9ad5ef | 1429 | |
Christopher Haster |
1:24750b9ad5ef | 1430 | #if defined(MBEDTLS_DES_C) |
Christopher Haster |
1:24750b9ad5ef | 1431 | { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1432 | { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1433 | { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info }, |
Christopher Haster |
1:24750b9ad5ef | 1434 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Christopher Haster |
1:24750b9ad5ef | 1435 | { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1436 | { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1437 | { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info }, |
Christopher Haster |
1:24750b9ad5ef | 1438 | #endif |
Christopher Haster |
1:24750b9ad5ef | 1439 | #endif /* MBEDTLS_DES_C */ |
Christopher Haster |
1:24750b9ad5ef | 1440 | |
Christopher Haster |
1:24750b9ad5ef | 1441 | #if defined(MBEDTLS_CIPHER_NULL_CIPHER) |
Christopher Haster |
1:24750b9ad5ef | 1442 | { MBEDTLS_CIPHER_NULL, &null_cipher_info }, |
Christopher Haster |
1:24750b9ad5ef | 1443 | #endif /* MBEDTLS_CIPHER_NULL_CIPHER */ |
Christopher Haster |
1:24750b9ad5ef | 1444 | |
Christopher Haster |
1:24750b9ad5ef | 1445 | { MBEDTLS_CIPHER_NONE, NULL } |
Christopher Haster |
1:24750b9ad5ef | 1446 | }; |
Christopher Haster |
1:24750b9ad5ef | 1447 | |
Christopher Haster |
1:24750b9ad5ef | 1448 | #define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0] |
Christopher Haster |
1:24750b9ad5ef | 1449 | int mbedtls_cipher_supported[NUM_CIPHERS]; |
Christopher Haster |
1:24750b9ad5ef | 1450 | |
Christopher Haster |
1:24750b9ad5ef | 1451 | #endif /* MBEDTLS_CIPHER_C */ |