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