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 |
| 22 | |
Paul Bakker | c81f6c3 | 2009-05-03 13:09:15 +0000 | [diff] [blame] | 23 | #include <inttypes.h> |
| 24 | |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 25 | #define CAMELLIA_ENCRYPT 1 |
| 26 | #define CAMELLIA_DECRYPT 0 |
| 27 | |
| 28 | /** |
| 29 | * \brief CAMELLIA context structure |
| 30 | */ |
| 31 | typedef struct |
| 32 | { |
| 33 | int nr; /*!< number of rounds */ |
Paul Bakker | c81f6c3 | 2009-05-03 13:09:15 +0000 | [diff] [blame] | 34 | uint32_t rk[68]; /*!< CAMELLIA round keys */ |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 35 | } |
| 36 | camellia_context; |
| 37 | |
| 38 | #ifdef __cplusplus |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | |
| 42 | /** |
| 43 | * \brief CAMELLIA key schedule (encryption) |
| 44 | * |
| 45 | * \param ctx CAMELLIA context to be initialized |
| 46 | * \param key encryption key |
| 47 | * \param keysize must be 128, 192 or 256 |
| 48 | */ |
| 49 | void camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize ); |
| 50 | |
| 51 | /** |
| 52 | * \brief CAMELLIA key schedule (decryption) |
| 53 | * |
| 54 | * \param ctx CAMELLIA context to be initialized |
| 55 | * \param key decryption key |
| 56 | * \param keysize must be 128, 192 or 256 |
| 57 | */ |
| 58 | void camellia_setkey_dec( camellia_context *ctx, unsigned char *key, int keysize ); |
| 59 | |
| 60 | /** |
| 61 | * \brief CAMELLIA-ECB block encryption/decryption |
| 62 | * |
| 63 | * \param ctx CAMELLIA context |
| 64 | * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT |
| 65 | * \param input 16-byte input block |
| 66 | * \param output 16-byte output block |
| 67 | */ |
| 68 | void camellia_crypt_ecb( camellia_context *ctx, |
| 69 | int mode, |
| 70 | unsigned char input[16], |
| 71 | unsigned char output[16] ); |
| 72 | |
| 73 | /** |
| 74 | * \brief CAMELLIA-CBC buffer encryption/decryption |
Paul Bakker | c0983aa | 2009-05-17 10:30:00 +0000 | [diff] [blame] | 75 | * Length should be a multiple of the block |
| 76 | * size (16 bytes) |
Paul Bakker | 38119b1 | 2009-01-10 23:31:23 +0000 | [diff] [blame] | 77 | * |
| 78 | * \param ctx CAMELLIA context |
| 79 | * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT |
| 80 | * \param length length of the input data |
| 81 | * \param iv initialization vector (updated after use) |
| 82 | * \param input buffer holding the input data |
| 83 | * \param output buffer holding the output data |
| 84 | */ |
| 85 | void camellia_crypt_cbc( camellia_context *ctx, |
| 86 | int mode, |
| 87 | int length, |
| 88 | unsigned char iv[16], |
| 89 | unsigned char *input, |
| 90 | unsigned char *output ); |
| 91 | |
| 92 | /** |
| 93 | * \brief CAMELLIA-CFB128 buffer encryption/decryption |
| 94 | * |
| 95 | * \param ctx CAMELLIA context |
| 96 | * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT |
| 97 | * \param length length of the input data |
| 98 | * \param iv_off offset in IV (updated after use) |
| 99 | * \param iv initialization vector (updated after use) |
| 100 | * \param input buffer holding the input data |
| 101 | * \param output buffer holding the output data |
| 102 | */ |
| 103 | void camellia_crypt_cfb128( camellia_context *ctx, |
| 104 | int mode, |
| 105 | int length, |
| 106 | int *iv_off, |
| 107 | unsigned char iv[16], |
| 108 | unsigned char *input, |
| 109 | unsigned char *output ); |
| 110 | |
| 111 | /** |
| 112 | * \brief Checkup routine |
| 113 | * |
| 114 | * \return 0 if successful, or 1 if the test failed |
| 115 | */ |
| 116 | int camellia_self_test( int verbose ); |
| 117 | |
| 118 | #ifdef __cplusplus |
| 119 | } |
| 120 | #endif |
| 121 | |
| 122 | #endif /* camellia.h */ |