
mbed client on ethernet with LWIP
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbedtls/mbedtls/camellia.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /** |
mbedAustin | 11:cada08fc8a70 | 2 | * \file camellia.h |
mbedAustin | 11:cada08fc8a70 | 3 | * |
mbedAustin | 11:cada08fc8a70 | 4 | * \brief Camellia block cipher |
mbedAustin | 11:cada08fc8a70 | 5 | * |
mbedAustin | 11:cada08fc8a70 | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
mbedAustin | 11:cada08fc8a70 | 7 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 8 | * |
mbedAustin | 11:cada08fc8a70 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
mbedAustin | 11:cada08fc8a70 | 10 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 11 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 12 | * |
mbedAustin | 11:cada08fc8a70 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 14 | * |
mbedAustin | 11:cada08fc8a70 | 15 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 18 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 19 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 20 | * |
mbedAustin | 11:cada08fc8a70 | 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
mbedAustin | 11:cada08fc8a70 | 22 | */ |
mbedAustin | 11:cada08fc8a70 | 23 | #ifndef MBEDTLS_CAMELLIA_H |
mbedAustin | 11:cada08fc8a70 | 24 | #define MBEDTLS_CAMELLIA_H |
mbedAustin | 11:cada08fc8a70 | 25 | |
mbedAustin | 11:cada08fc8a70 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) |
mbedAustin | 11:cada08fc8a70 | 27 | #include "config.h" |
mbedAustin | 11:cada08fc8a70 | 28 | #else |
mbedAustin | 11:cada08fc8a70 | 29 | #include MBEDTLS_CONFIG_FILE |
mbedAustin | 11:cada08fc8a70 | 30 | #endif |
mbedAustin | 11:cada08fc8a70 | 31 | |
mbedAustin | 11:cada08fc8a70 | 32 | #include <stddef.h> |
mbedAustin | 11:cada08fc8a70 | 33 | #include <stdint.h> |
mbedAustin | 11:cada08fc8a70 | 34 | |
mbedAustin | 11:cada08fc8a70 | 35 | #define MBEDTLS_CAMELLIA_ENCRYPT 1 |
mbedAustin | 11:cada08fc8a70 | 36 | #define MBEDTLS_CAMELLIA_DECRYPT 0 |
mbedAustin | 11:cada08fc8a70 | 37 | |
mbedAustin | 11:cada08fc8a70 | 38 | #define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */ |
mbedAustin | 11:cada08fc8a70 | 39 | #define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */ |
mbedAustin | 11:cada08fc8a70 | 40 | |
mbedAustin | 11:cada08fc8a70 | 41 | #if !defined(MBEDTLS_CAMELLIA_ALT) |
mbedAustin | 11:cada08fc8a70 | 42 | // Regular implementation |
mbedAustin | 11:cada08fc8a70 | 43 | // |
mbedAustin | 11:cada08fc8a70 | 44 | |
mbedAustin | 11:cada08fc8a70 | 45 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 46 | extern "C" { |
mbedAustin | 11:cada08fc8a70 | 47 | #endif |
mbedAustin | 11:cada08fc8a70 | 48 | |
mbedAustin | 11:cada08fc8a70 | 49 | /** |
mbedAustin | 11:cada08fc8a70 | 50 | * \brief CAMELLIA context structure |
mbedAustin | 11:cada08fc8a70 | 51 | */ |
mbedAustin | 11:cada08fc8a70 | 52 | typedef struct |
mbedAustin | 11:cada08fc8a70 | 53 | { |
mbedAustin | 11:cada08fc8a70 | 54 | int nr; /*!< number of rounds */ |
mbedAustin | 11:cada08fc8a70 | 55 | uint32_t rk[68]; /*!< CAMELLIA round keys */ |
mbedAustin | 11:cada08fc8a70 | 56 | } |
mbedAustin | 11:cada08fc8a70 | 57 | mbedtls_camellia_context; |
mbedAustin | 11:cada08fc8a70 | 58 | |
mbedAustin | 11:cada08fc8a70 | 59 | /** |
mbedAustin | 11:cada08fc8a70 | 60 | * \brief Initialize CAMELLIA context |
mbedAustin | 11:cada08fc8a70 | 61 | * |
mbedAustin | 11:cada08fc8a70 | 62 | * \param ctx CAMELLIA context to be initialized |
mbedAustin | 11:cada08fc8a70 | 63 | */ |
mbedAustin | 11:cada08fc8a70 | 64 | void mbedtls_camellia_init( mbedtls_camellia_context *ctx ); |
mbedAustin | 11:cada08fc8a70 | 65 | |
mbedAustin | 11:cada08fc8a70 | 66 | /** |
mbedAustin | 11:cada08fc8a70 | 67 | * \brief Clear CAMELLIA context |
mbedAustin | 11:cada08fc8a70 | 68 | * |
mbedAustin | 11:cada08fc8a70 | 69 | * \param ctx CAMELLIA context to be cleared |
mbedAustin | 11:cada08fc8a70 | 70 | */ |
mbedAustin | 11:cada08fc8a70 | 71 | void mbedtls_camellia_free( mbedtls_camellia_context *ctx ); |
mbedAustin | 11:cada08fc8a70 | 72 | |
mbedAustin | 11:cada08fc8a70 | 73 | /** |
mbedAustin | 11:cada08fc8a70 | 74 | * \brief CAMELLIA key schedule (encryption) |
mbedAustin | 11:cada08fc8a70 | 75 | * |
mbedAustin | 11:cada08fc8a70 | 76 | * \param ctx CAMELLIA context to be initialized |
mbedAustin | 11:cada08fc8a70 | 77 | * \param key encryption key |
mbedAustin | 11:cada08fc8a70 | 78 | * \param keybits must be 128, 192 or 256 |
mbedAustin | 11:cada08fc8a70 | 79 | * |
mbedAustin | 11:cada08fc8a70 | 80 | * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH |
mbedAustin | 11:cada08fc8a70 | 81 | */ |
mbedAustin | 11:cada08fc8a70 | 82 | int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, const unsigned char *key, |
mbedAustin | 11:cada08fc8a70 | 83 | unsigned int keybits ); |
mbedAustin | 11:cada08fc8a70 | 84 | |
mbedAustin | 11:cada08fc8a70 | 85 | /** |
mbedAustin | 11:cada08fc8a70 | 86 | * \brief CAMELLIA key schedule (decryption) |
mbedAustin | 11:cada08fc8a70 | 87 | * |
mbedAustin | 11:cada08fc8a70 | 88 | * \param ctx CAMELLIA context to be initialized |
mbedAustin | 11:cada08fc8a70 | 89 | * \param key decryption key |
mbedAustin | 11:cada08fc8a70 | 90 | * \param keybits must be 128, 192 or 256 |
mbedAustin | 11:cada08fc8a70 | 91 | * |
mbedAustin | 11:cada08fc8a70 | 92 | * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH |
mbedAustin | 11:cada08fc8a70 | 93 | */ |
mbedAustin | 11:cada08fc8a70 | 94 | int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, const unsigned char *key, |
mbedAustin | 11:cada08fc8a70 | 95 | unsigned int keybits ); |
mbedAustin | 11:cada08fc8a70 | 96 | |
mbedAustin | 11:cada08fc8a70 | 97 | /** |
mbedAustin | 11:cada08fc8a70 | 98 | * \brief CAMELLIA-ECB block encryption/decryption |
mbedAustin | 11:cada08fc8a70 | 99 | * |
mbedAustin | 11:cada08fc8a70 | 100 | * \param ctx CAMELLIA context |
mbedAustin | 11:cada08fc8a70 | 101 | * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT |
mbedAustin | 11:cada08fc8a70 | 102 | * \param input 16-byte input block |
mbedAustin | 11:cada08fc8a70 | 103 | * \param output 16-byte output block |
mbedAustin | 11:cada08fc8a70 | 104 | * |
mbedAustin | 11:cada08fc8a70 | 105 | * \return 0 if successful |
mbedAustin | 11:cada08fc8a70 | 106 | */ |
mbedAustin | 11:cada08fc8a70 | 107 | int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, |
mbedAustin | 11:cada08fc8a70 | 108 | int mode, |
mbedAustin | 11:cada08fc8a70 | 109 | const unsigned char input[16], |
mbedAustin | 11:cada08fc8a70 | 110 | unsigned char output[16] ); |
mbedAustin | 11:cada08fc8a70 | 111 | |
mbedAustin | 11:cada08fc8a70 | 112 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
mbedAustin | 11:cada08fc8a70 | 113 | /** |
mbedAustin | 11:cada08fc8a70 | 114 | * \brief CAMELLIA-CBC buffer encryption/decryption |
mbedAustin | 11:cada08fc8a70 | 115 | * Length should be a multiple of the block |
mbedAustin | 11:cada08fc8a70 | 116 | * size (16 bytes) |
mbedAustin | 11:cada08fc8a70 | 117 | * |
mbedAustin | 11:cada08fc8a70 | 118 | * \note Upon exit, the content of the IV is updated so that you can |
mbedAustin | 11:cada08fc8a70 | 119 | * call the function same function again on the following |
mbedAustin | 11:cada08fc8a70 | 120 | * block(s) of data and get the same result as if it was |
mbedAustin | 11:cada08fc8a70 | 121 | * encrypted in one call. This allows a "streaming" usage. |
mbedAustin | 11:cada08fc8a70 | 122 | * If on the other hand you need to retain the contents of the |
mbedAustin | 11:cada08fc8a70 | 123 | * IV, you should either save it manually or use the cipher |
mbedAustin | 11:cada08fc8a70 | 124 | * module instead. |
mbedAustin | 11:cada08fc8a70 | 125 | * |
mbedAustin | 11:cada08fc8a70 | 126 | * \param ctx CAMELLIA context |
mbedAustin | 11:cada08fc8a70 | 127 | * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT |
mbedAustin | 11:cada08fc8a70 | 128 | * \param length length of the input data |
mbedAustin | 11:cada08fc8a70 | 129 | * \param iv initialization vector (updated after use) |
mbedAustin | 11:cada08fc8a70 | 130 | * \param input buffer holding the input data |
mbedAustin | 11:cada08fc8a70 | 131 | * \param output buffer holding the output data |
mbedAustin | 11:cada08fc8a70 | 132 | * |
mbedAustin | 11:cada08fc8a70 | 133 | * \return 0 if successful, or |
mbedAustin | 11:cada08fc8a70 | 134 | * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH |
mbedAustin | 11:cada08fc8a70 | 135 | */ |
mbedAustin | 11:cada08fc8a70 | 136 | int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, |
mbedAustin | 11:cada08fc8a70 | 137 | int mode, |
mbedAustin | 11:cada08fc8a70 | 138 | size_t length, |
mbedAustin | 11:cada08fc8a70 | 139 | unsigned char iv[16], |
mbedAustin | 11:cada08fc8a70 | 140 | const unsigned char *input, |
mbedAustin | 11:cada08fc8a70 | 141 | unsigned char *output ); |
mbedAustin | 11:cada08fc8a70 | 142 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
mbedAustin | 11:cada08fc8a70 | 143 | |
mbedAustin | 11:cada08fc8a70 | 144 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
mbedAustin | 11:cada08fc8a70 | 145 | /** |
mbedAustin | 11:cada08fc8a70 | 146 | * \brief CAMELLIA-CFB128 buffer encryption/decryption |
mbedAustin | 11:cada08fc8a70 | 147 | * |
mbedAustin | 11:cada08fc8a70 | 148 | * Note: Due to the nature of CFB you should use the same key schedule for |
mbedAustin | 11:cada08fc8a70 | 149 | * both encryption and decryption. So a context initialized with |
mbedAustin | 11:cada08fc8a70 | 150 | * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT. |
mbedAustin | 11:cada08fc8a70 | 151 | * |
mbedAustin | 11:cada08fc8a70 | 152 | * \note Upon exit, the content of the IV is updated so that you can |
mbedAustin | 11:cada08fc8a70 | 153 | * call the function same function again on the following |
mbedAustin | 11:cada08fc8a70 | 154 | * block(s) of data and get the same result as if it was |
mbedAustin | 11:cada08fc8a70 | 155 | * encrypted in one call. This allows a "streaming" usage. |
mbedAustin | 11:cada08fc8a70 | 156 | * If on the other hand you need to retain the contents of the |
mbedAustin | 11:cada08fc8a70 | 157 | * IV, you should either save it manually or use the cipher |
mbedAustin | 11:cada08fc8a70 | 158 | * module instead. |
mbedAustin | 11:cada08fc8a70 | 159 | * |
mbedAustin | 11:cada08fc8a70 | 160 | * \param ctx CAMELLIA context |
mbedAustin | 11:cada08fc8a70 | 161 | * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT |
mbedAustin | 11:cada08fc8a70 | 162 | * \param length length of the input data |
mbedAustin | 11:cada08fc8a70 | 163 | * \param iv_off offset in IV (updated after use) |
mbedAustin | 11:cada08fc8a70 | 164 | * \param iv initialization vector (updated after use) |
mbedAustin | 11:cada08fc8a70 | 165 | * \param input buffer holding the input data |
mbedAustin | 11:cada08fc8a70 | 166 | * \param output buffer holding the output data |
mbedAustin | 11:cada08fc8a70 | 167 | * |
mbedAustin | 11:cada08fc8a70 | 168 | * \return 0 if successful, or |
mbedAustin | 11:cada08fc8a70 | 169 | * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH |
mbedAustin | 11:cada08fc8a70 | 170 | */ |
mbedAustin | 11:cada08fc8a70 | 171 | int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, |
mbedAustin | 11:cada08fc8a70 | 172 | int mode, |
mbedAustin | 11:cada08fc8a70 | 173 | size_t length, |
mbedAustin | 11:cada08fc8a70 | 174 | size_t *iv_off, |
mbedAustin | 11:cada08fc8a70 | 175 | unsigned char iv[16], |
mbedAustin | 11:cada08fc8a70 | 176 | const unsigned char *input, |
mbedAustin | 11:cada08fc8a70 | 177 | unsigned char *output ); |
mbedAustin | 11:cada08fc8a70 | 178 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
mbedAustin | 11:cada08fc8a70 | 179 | |
mbedAustin | 11:cada08fc8a70 | 180 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
mbedAustin | 11:cada08fc8a70 | 181 | /** |
mbedAustin | 11:cada08fc8a70 | 182 | * \brief CAMELLIA-CTR buffer encryption/decryption |
mbedAustin | 11:cada08fc8a70 | 183 | * |
mbedAustin | 11:cada08fc8a70 | 184 | * Warning: You have to keep the maximum use of your counter in mind! |
mbedAustin | 11:cada08fc8a70 | 185 | * |
mbedAustin | 11:cada08fc8a70 | 186 | * Note: Due to the nature of CTR you should use the same key schedule for |
mbedAustin | 11:cada08fc8a70 | 187 | * both encryption and decryption. So a context initialized with |
mbedAustin | 11:cada08fc8a70 | 188 | * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and MBEDTLS_CAMELLIA_DECRYPT. |
mbedAustin | 11:cada08fc8a70 | 189 | * |
mbedAustin | 11:cada08fc8a70 | 190 | * \param ctx CAMELLIA context |
mbedAustin | 11:cada08fc8a70 | 191 | * \param length The length of the data |
mbedAustin | 11:cada08fc8a70 | 192 | * \param nc_off The offset in the current stream_block (for resuming |
mbedAustin | 11:cada08fc8a70 | 193 | * within current cipher stream). The offset pointer to |
mbedAustin | 11:cada08fc8a70 | 194 | * should be 0 at the start of a stream. |
mbedAustin | 11:cada08fc8a70 | 195 | * \param nonce_counter The 128-bit nonce and counter. |
mbedAustin | 11:cada08fc8a70 | 196 | * \param stream_block The saved stream-block for resuming. Is overwritten |
mbedAustin | 11:cada08fc8a70 | 197 | * by the function. |
mbedAustin | 11:cada08fc8a70 | 198 | * \param input The input data stream |
mbedAustin | 11:cada08fc8a70 | 199 | * \param output The output data stream |
mbedAustin | 11:cada08fc8a70 | 200 | * |
mbedAustin | 11:cada08fc8a70 | 201 | * \return 0 if successful |
mbedAustin | 11:cada08fc8a70 | 202 | */ |
mbedAustin | 11:cada08fc8a70 | 203 | int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, |
mbedAustin | 11:cada08fc8a70 | 204 | size_t length, |
mbedAustin | 11:cada08fc8a70 | 205 | size_t *nc_off, |
mbedAustin | 11:cada08fc8a70 | 206 | unsigned char nonce_counter[16], |
mbedAustin | 11:cada08fc8a70 | 207 | unsigned char stream_block[16], |
mbedAustin | 11:cada08fc8a70 | 208 | const unsigned char *input, |
mbedAustin | 11:cada08fc8a70 | 209 | unsigned char *output ); |
mbedAustin | 11:cada08fc8a70 | 210 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
mbedAustin | 11:cada08fc8a70 | 211 | |
mbedAustin | 11:cada08fc8a70 | 212 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 213 | } |
mbedAustin | 11:cada08fc8a70 | 214 | #endif |
mbedAustin | 11:cada08fc8a70 | 215 | |
mbedAustin | 11:cada08fc8a70 | 216 | #else /* MBEDTLS_CAMELLIA_ALT */ |
mbedAustin | 11:cada08fc8a70 | 217 | #include "camellia_alt.h" |
mbedAustin | 11:cada08fc8a70 | 218 | #endif /* MBEDTLS_CAMELLIA_ALT */ |
mbedAustin | 11:cada08fc8a70 | 219 | |
mbedAustin | 11:cada08fc8a70 | 220 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 221 | extern "C" { |
mbedAustin | 11:cada08fc8a70 | 222 | #endif |
mbedAustin | 11:cada08fc8a70 | 223 | |
mbedAustin | 11:cada08fc8a70 | 224 | /** |
mbedAustin | 11:cada08fc8a70 | 225 | * \brief Checkup routine |
mbedAustin | 11:cada08fc8a70 | 226 | * |
mbedAustin | 11:cada08fc8a70 | 227 | * \return 0 if successful, or 1 if the test failed |
mbedAustin | 11:cada08fc8a70 | 228 | */ |
mbedAustin | 11:cada08fc8a70 | 229 | int mbedtls_camellia_self_test( int verbose ); |
mbedAustin | 11:cada08fc8a70 | 230 | |
mbedAustin | 11:cada08fc8a70 | 231 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 232 | } |
mbedAustin | 11:cada08fc8a70 | 233 | #endif |
mbedAustin | 11:cada08fc8a70 | 234 | |
mbedAustin | 11:cada08fc8a70 | 235 | #endif /* camellia.h */ |