Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
camellia.h
00001 /** 00002 * \file camellia.h 00003 * 00004 * \brief Camellia block cipher 00005 */ 00006 /* 00007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00008 * SPDX-License-Identifier: Apache-2.0 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00011 * not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00018 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 * 00022 * This file is part of mbed TLS (https://tls.mbed.org) 00023 */ 00024 #ifndef MBEDTLS_CAMELLIA_H 00025 #define MBEDTLS_CAMELLIA_H 00026 00027 #if !defined(MBEDTLS_CONFIG_FILE) 00028 #include "config.h" 00029 #else 00030 #include MBEDTLS_CONFIG_FILE 00031 #endif 00032 00033 #include <stddef.h> 00034 #include <stdint.h> 00035 00036 #define MBEDTLS_CAMELLIA_ENCRYPT 1 00037 #define MBEDTLS_CAMELLIA_DECRYPT 0 00038 00039 #define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */ 00040 #define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */ 00041 #define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */ 00042 00043 #if !defined(MBEDTLS_CAMELLIA_ALT) 00044 // Regular implementation 00045 // 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 /** 00052 * \brief CAMELLIA context structure 00053 */ 00054 typedef struct 00055 { 00056 int nr ; /*!< number of rounds */ 00057 uint32_t rk[68]; /*!< CAMELLIA round keys */ 00058 } 00059 mbedtls_camellia_context; 00060 00061 /** 00062 * \brief Initialize CAMELLIA context 00063 * 00064 * \param ctx CAMELLIA context to be initialized 00065 */ 00066 void mbedtls_camellia_init( mbedtls_camellia_context *ctx ); 00067 00068 /** 00069 * \brief Clear CAMELLIA context 00070 * 00071 * \param ctx CAMELLIA context to be cleared 00072 */ 00073 void mbedtls_camellia_free( mbedtls_camellia_context *ctx ); 00074 00075 /** 00076 * \brief CAMELLIA key schedule (encryption) 00077 * 00078 * \param ctx CAMELLIA context to be initialized 00079 * \param key encryption key 00080 * \param keybits must be 128, 192 or 256 00081 * 00082 * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH 00083 */ 00084 int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, const unsigned char *key, 00085 unsigned int keybits ); 00086 00087 /** 00088 * \brief CAMELLIA key schedule (decryption) 00089 * 00090 * \param ctx CAMELLIA context to be initialized 00091 * \param key decryption key 00092 * \param keybits must be 128, 192 or 256 00093 * 00094 * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH 00095 */ 00096 int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, const unsigned char *key, 00097 unsigned int keybits ); 00098 00099 /** 00100 * \brief CAMELLIA-ECB block encryption/decryption 00101 * 00102 * \param ctx CAMELLIA context 00103 * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT 00104 * \param input 16-byte input block 00105 * \param output 16-byte output block 00106 * 00107 * \return 0 if successful 00108 */ 00109 int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, 00110 int mode, 00111 const unsigned char input[16], 00112 unsigned char output[16] ); 00113 00114 #if defined(MBEDTLS_CIPHER_MODE_CBC) 00115 /** 00116 * \brief CAMELLIA-CBC buffer encryption/decryption 00117 * Length should be a multiple of the block 00118 * size (16 bytes) 00119 * 00120 * \note Upon exit, the content of the IV is updated so that you can 00121 * call the function same function again on the following 00122 * block(s) of data and get the same result as if it was 00123 * encrypted in one call. This allows a "streaming" usage. 00124 * If on the other hand you need to retain the contents of the 00125 * IV, you should either save it manually or use the cipher 00126 * module instead. 00127 * 00128 * \param ctx CAMELLIA context 00129 * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT 00130 * \param length length of the input data 00131 * \param iv initialization vector (updated after use) 00132 * \param input buffer holding the input data 00133 * \param output buffer holding the output data 00134 * 00135 * \return 0 if successful, or 00136 * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH 00137 */ 00138 int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, 00139 int mode, 00140 size_t length, 00141 unsigned char iv[16], 00142 const unsigned char *input, 00143 unsigned char *output ); 00144 #endif /* MBEDTLS_CIPHER_MODE_CBC */ 00145 00146 #if defined(MBEDTLS_CIPHER_MODE_CFB) 00147 /** 00148 * \brief CAMELLIA-CFB128 buffer encryption/decryption 00149 * 00150 * Note: Due to the nature of CFB you should use the same key schedule for 00151 * both encryption and decryption. So a context initialized with 00152 * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT. 00153 * 00154 * \note Upon exit, the content of the IV is updated so that you can 00155 * call the function same function again on the following 00156 * block(s) of data and get the same result as if it was 00157 * encrypted in one call. This allows a "streaming" usage. 00158 * If on the other hand you need to retain the contents of the 00159 * IV, you should either save it manually or use the cipher 00160 * module instead. 00161 * 00162 * \param ctx CAMELLIA context 00163 * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT 00164 * \param length length of the input data 00165 * \param iv_off offset in IV (updated after use) 00166 * \param iv initialization vector (updated after use) 00167 * \param input buffer holding the input data 00168 * \param output buffer holding the output data 00169 * 00170 * \return 0 if successful, or 00171 * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH 00172 */ 00173 int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, 00174 int mode, 00175 size_t length, 00176 size_t *iv_off, 00177 unsigned char iv[16], 00178 const unsigned char *input, 00179 unsigned char *output ); 00180 #endif /* MBEDTLS_CIPHER_MODE_CFB */ 00181 00182 #if defined(MBEDTLS_CIPHER_MODE_CTR) 00183 /** 00184 * \brief CAMELLIA-CTR buffer encryption/decryption 00185 * 00186 * Warning: You have to keep the maximum use of your counter in mind! 00187 * 00188 * Note: Due to the nature of CTR you should use the same key schedule for 00189 * both encryption and decryption. So a context initialized with 00190 * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and MBEDTLS_CAMELLIA_DECRYPT. 00191 * 00192 * \param ctx CAMELLIA context 00193 * \param length The length of the data 00194 * \param nc_off The offset in the current stream_block (for resuming 00195 * within current cipher stream). The offset pointer to 00196 * should be 0 at the start of a stream. 00197 * \param nonce_counter The 128-bit nonce and counter. 00198 * \param stream_block The saved stream-block for resuming. Is overwritten 00199 * by the function. 00200 * \param input The input data stream 00201 * \param output The output data stream 00202 * 00203 * \return 0 if successful 00204 */ 00205 int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, 00206 size_t length, 00207 size_t *nc_off, 00208 unsigned char nonce_counter[16], 00209 unsigned char stream_block[16], 00210 const unsigned char *input, 00211 unsigned char *output ); 00212 #endif /* MBEDTLS_CIPHER_MODE_CTR */ 00213 00214 #ifdef __cplusplus 00215 } 00216 #endif 00217 00218 #else /* MBEDTLS_CAMELLIA_ALT */ 00219 #include "camellia_alt.h" 00220 #endif /* MBEDTLS_CAMELLIA_ALT */ 00221 00222 #ifdef __cplusplus 00223 extern "C" { 00224 #endif 00225 00226 /** 00227 * \brief Checkup routine 00228 * 00229 * \return 0 if successful, or 1 if the test failed 00230 */ 00231 int mbedtls_camellia_self_test( int verbose ); 00232 00233 #ifdef __cplusplus 00234 } 00235 #endif 00236 00237 #endif /* camellia.h */
Generated on Tue Jul 12 2022 18:18:29 by
