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