Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file camellia.h |
| 3 | * |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame^] | 4 | * Copyright (C) 2006-2010, Brainspark B.V. |
| 5 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 6 | * All rights reserved. |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | #ifndef POLARSSL_CAMELLIA_H |
| 23 | #define POLARSSL_CAMELLIA_H |
Paul Bakker | 477fd32 | 2009-10-04 13:22:13 +0000 | [diff] [blame] | 24 | |
| 25 | #ifdef _MSC_VER |
| 26 | #include <basetsd.h> |
| 27 | typedef UINT32 uint32_t; |
Paul Bakker | 80ab9f5 | 2009-05-24 14:42:46 +0000 | [diff] [blame] | 28 | #else |
Paul Bakker | 477fd32 | 2009-10-04 13:22:13 +0000 | [diff] [blame] | 29 | #include <inttypes.h> |
Paul Bakker | 80ab9f5 | 2009-05-24 14:42:46 +0000 | [diff] [blame] | 30 | #endif |
Paul Bakker | c81f6c3 | 2009-05-03 13:09:15 +0000 | [diff] [blame] | 31 | |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 32 | #define CAMELLIA_ENCRYPT 1 |
| 33 | #define CAMELLIA_DECRYPT 0 |
| 34 | |
Paul Bakker | 3391b12 | 2009-07-28 20:11:54 +0000 | [diff] [blame] | 35 | #define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0a00 |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 36 | #define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0a10 |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 37 | |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 38 | /** |
| 39 | * \brief CAMELLIA context structure |
| 40 | */ |
| 41 | typedef struct |
| 42 | { |
| 43 | int nr; /*!< number of rounds */ |
Paul Bakker | c81f6c3 | 2009-05-03 13:09:15 +0000 | [diff] [blame] | 44 | uint32_t rk[68]; /*!< CAMELLIA round keys */ |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 45 | } |
| 46 | camellia_context; |
| 47 | |
| 48 | #ifdef __cplusplus |
| 49 | extern "C" { |
| 50 | #endif |
| 51 | |
| 52 | /** |
| 53 | * \brief CAMELLIA key schedule (encryption) |
| 54 | * |
| 55 | * \param ctx CAMELLIA context to be initialized |
| 56 | * \param key encryption key |
| 57 | * \param keysize must be 128, 192 or 256 |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 58 | * |
| 59 | * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 60 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 61 | int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * \brief CAMELLIA key schedule (decryption) |
| 65 | * |
| 66 | * \param ctx CAMELLIA context to be initialized |
| 67 | * \param key decryption key |
| 68 | * \param keysize must be 128, 192 or 256 |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 69 | * |
| 70 | * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 71 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 72 | int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize ); |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * \brief CAMELLIA-ECB block encryption/decryption |
| 76 | * |
| 77 | * \param ctx CAMELLIA context |
| 78 | * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT |
| 79 | * \param input 16-byte input block |
| 80 | * \param output 16-byte output block |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 81 | * |
Paul Bakker | 27caa8a | 2010-03-21 15:43:59 +0000 | [diff] [blame] | 82 | * \return 0 if successful |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 83 | */ |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 84 | int camellia_crypt_ecb( camellia_context *ctx, |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 85 | int mode, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 86 | const unsigned char input[16], |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 87 | unsigned char output[16] ); |
| 88 | |
| 89 | /** |
| 90 | * \brief CAMELLIA-CBC buffer encryption/decryption |
Paul Bakker | 4c067eb | 2009-05-17 10:25:19 +0000 | [diff] [blame] | 91 | * Length should be a multiple of the block |
| 92 | * size (16 bytes) |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 93 | * |
| 94 | * \param ctx CAMELLIA context |
| 95 | * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT |
| 96 | * \param length length of the input data |
| 97 | * \param iv initialization vector (updated after use) |
| 98 | * \param input buffer holding the input data |
| 99 | * \param output buffer holding the output data |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 100 | * |
| 101 | * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 102 | */ |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 103 | int camellia_crypt_cbc( camellia_context *ctx, |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 104 | int mode, |
| 105 | int length, |
| 106 | unsigned char iv[16], |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 107 | const unsigned char *input, |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 108 | unsigned char *output ); |
| 109 | |
| 110 | /** |
| 111 | * \brief CAMELLIA-CFB128 buffer encryption/decryption |
| 112 | * |
| 113 | * \param ctx CAMELLIA context |
| 114 | * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT |
| 115 | * \param length length of the input data |
| 116 | * \param iv_off offset in IV (updated after use) |
| 117 | * \param iv initialization vector (updated after use) |
| 118 | * \param input buffer holding the input data |
| 119 | * \param output buffer holding the output data |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 120 | * |
| 121 | * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 122 | */ |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 123 | int camellia_crypt_cfb128( camellia_context *ctx, |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 124 | int mode, |
| 125 | int length, |
| 126 | int *iv_off, |
| 127 | unsigned char iv[16], |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 128 | const unsigned char *input, |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 129 | unsigned char *output ); |
| 130 | |
| 131 | /** |
| 132 | * \brief Checkup routine |
| 133 | * |
| 134 | * \return 0 if successful, or 1 if the test failed |
| 135 | */ |
| 136 | int camellia_self_test( int verbose ); |
| 137 | |
| 138 | #ifdef __cplusplus |
| 139 | } |
| 140 | #endif |
| 141 | |
| 142 | #endif /* camellia.h */ |