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