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 * Copyright (C) 2006-2014, Brainspark B.V. 00007 * 00008 * This file is part of PolarSSL (http://www.polarssl.org) 00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> 00010 * 00011 * All rights reserved. 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2 of the License, or 00016 * (at your option) any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License along 00024 * with this program; if not, write to the Free Software Foundation, Inc., 00025 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00026 */ 00027 #ifndef POLARSSL_CAMELLIA_H 00028 #define POLARSSL_CAMELLIA_H 00029 00030 #if !defined(POLARSSL_CONFIG_FILE) 00031 #include "config.h" 00032 #else 00033 #include POLARSSL_CONFIG_FILE 00034 #endif 00035 00036 #include <string.h> 00037 00038 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) 00039 #include <basetsd.h> 00040 typedef UINT32 uint32_t; 00041 #else 00042 #include <inttypes.h> 00043 #endif 00044 00045 #define CAMELLIA_ENCRYPT 1 00046 #define CAMELLIA_DECRYPT 0 00047 00048 #define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */ 00049 #define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */ 00050 00051 #if !defined(POLARSSL_CAMELLIA_ALT) 00052 // Regular implementation 00053 // 00054 00055 #ifdef __cplusplus 00056 extern "C" { 00057 #endif 00058 00059 /** 00060 * \brief CAMELLIA context structure 00061 */ 00062 typedef struct 00063 { 00064 int nr ; /*!< number of rounds */ 00065 uint32_t rk[68]; /*!< CAMELLIA round keys */ 00066 } 00067 camellia_context; 00068 00069 /** 00070 * \brief CAMELLIA key schedule (encryption) 00071 * 00072 * \param ctx CAMELLIA context to be initialized 00073 * \param key encryption key 00074 * \param keysize must be 128, 192 or 256 00075 * 00076 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH 00077 */ 00078 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, 00079 unsigned int keysize ); 00080 00081 /** 00082 * \brief CAMELLIA key schedule (decryption) 00083 * 00084 * \param ctx CAMELLIA context to be initialized 00085 * \param key decryption key 00086 * \param keysize must be 128, 192 or 256 00087 * 00088 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH 00089 */ 00090 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, 00091 unsigned int keysize ); 00092 00093 /** 00094 * \brief CAMELLIA-ECB block encryption/decryption 00095 * 00096 * \param ctx CAMELLIA context 00097 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT 00098 * \param input 16-byte input block 00099 * \param output 16-byte output block 00100 * 00101 * \return 0 if successful 00102 */ 00103 int camellia_crypt_ecb( camellia_context *ctx, 00104 int mode, 00105 const unsigned char input[16], 00106 unsigned char output[16] ); 00107 00108 #if defined(POLARSSL_CIPHER_MODE_CBC) 00109 /** 00110 * \brief CAMELLIA-CBC buffer encryption/decryption 00111 * Length should be a multiple of the block 00112 * size (16 bytes) 00113 * 00114 * \param ctx CAMELLIA context 00115 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT 00116 * \param length length of the input data 00117 * \param iv initialization vector (updated after use) 00118 * \param input buffer holding the input data 00119 * \param output buffer holding the output data 00120 * 00121 * \return 0 if successful, or 00122 * POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH 00123 */ 00124 int camellia_crypt_cbc( camellia_context *ctx, 00125 int mode, 00126 size_t length, 00127 unsigned char iv[16], 00128 const unsigned char *input, 00129 unsigned char *output ); 00130 #endif /* POLARSSL_CIPHER_MODE_CBC */ 00131 00132 #if defined(POLARSSL_CIPHER_MODE_CFB) 00133 /** 00134 * \brief CAMELLIA-CFB128 buffer encryption/decryption 00135 * 00136 * Note: Due to the nature of CFB you should use the same key schedule for 00137 * both encryption and decryption. So a context initialized with 00138 * camellia_setkey_enc() for both CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT. 00139 * 00140 * \param ctx CAMELLIA context 00141 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT 00142 * \param length length of the input data 00143 * \param iv_off offset in IV (updated after use) 00144 * \param iv initialization vector (updated after use) 00145 * \param input buffer holding the input data 00146 * \param output buffer holding the output data 00147 * 00148 * \return 0 if successful, or 00149 * POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH 00150 */ 00151 int camellia_crypt_cfb128( camellia_context *ctx, 00152 int mode, 00153 size_t length, 00154 size_t *iv_off, 00155 unsigned char iv[16], 00156 const unsigned char *input, 00157 unsigned char *output ); 00158 #endif /* POLARSSL_CIPHER_MODE_CFB */ 00159 00160 #if defined(POLARSSL_CIPHER_MODE_CTR) 00161 /** 00162 * \brief CAMELLIA-CTR buffer encryption/decryption 00163 * 00164 * Warning: You have to keep the maximum use of your counter in mind! 00165 * 00166 * Note: Due to the nature of CTR you should use the same key schedule for 00167 * both encryption and decryption. So a context initialized with 00168 * camellia_setkey_enc() for both CAMELLIA_ENCRYPT and CAMELLIA_DECRYPT. 00169 * 00170 * \param ctx CAMELLIA context 00171 * \param length The length of the data 00172 * \param nc_off The offset in the current stream_block (for resuming 00173 * within current cipher stream). The offset pointer to 00174 * should be 0 at the start of a stream. 00175 * \param nonce_counter The 128-bit nonce and counter. 00176 * \param stream_block The saved stream-block for resuming. Is overwritten 00177 * by the function. 00178 * \param input The input data stream 00179 * \param output The output data stream 00180 * 00181 * \return 0 if successful 00182 */ 00183 int camellia_crypt_ctr( camellia_context *ctx, 00184 size_t length, 00185 size_t *nc_off, 00186 unsigned char nonce_counter[16], 00187 unsigned char stream_block[16], 00188 const unsigned char *input, 00189 unsigned char *output ); 00190 #endif /* POLARSSL_CIPHER_MODE_CTR */ 00191 00192 #ifdef __cplusplus 00193 } 00194 #endif 00195 00196 #else /* POLARSSL_CAMELLIA_ALT */ 00197 #include "camellia_alt.h" 00198 #endif /* POLARSSL_CAMELLIA_ALT */ 00199 00200 #ifdef __cplusplus 00201 extern "C" { 00202 #endif 00203 00204 /** 00205 * \brief Checkup routine 00206 * 00207 * \return 0 if successful, or 1 if the test failed 00208 */ 00209 int camellia_self_test( int verbose ); 00210 00211 #ifdef __cplusplus 00212 } 00213 #endif 00214 00215 #endif /* camellia.h */ 00216 00217
Generated on Tue Jul 12 2022 19:40:15 by
1.7.2