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