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