blob: da66ceb184bee2cf7a8dc6a392ebf4cff0872920 [file] [log] [blame]
Paul Bakker38119b12009-01-10 23:31:23 +00001/**
2 * \file camellia.h
3 *
Paul Bakker785a9ee2009-01-25 14:15:10 +00004 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
Paul Bakker38119b12009-01-10 23:31:23 +00005 *
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 Bakker80ab9f52009-05-24 14:42:46 +000022
23#ifdef _MSC_VER
24#include <basetsd.h>
25typedef UINT32 uint32_t;
26#else
27#include <inttypes.h>
28#endif
Paul Bakkerc81f6c32009-05-03 13:09:15 +000029
Paul Bakker38119b12009-01-10 23:31:23 +000030#define CAMELLIA_ENCRYPT 1
31#define CAMELLIA_DECRYPT 0
32
Paul Bakker2b222c82009-07-27 21:03:45 +000033#define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH 0x0a00
34
Paul Bakker38119b12009-01-10 23:31:23 +000035/**
36 * \brief CAMELLIA context structure
37 */
38typedef struct
39{
40 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000041 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000042}
43camellia_context;
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * \brief CAMELLIA key schedule (encryption)
51 *
52 * \param ctx CAMELLIA context to be initialized
53 * \param key encryption key
54 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000055 *
56 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000057 */
Paul Bakker2b222c82009-07-27 21:03:45 +000058int camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000059
60/**
61 * \brief CAMELLIA key schedule (decryption)
62 *
63 * \param ctx CAMELLIA context to be initialized
64 * \param key decryption key
65 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000066 *
67 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000068 */
Paul Bakker2b222c82009-07-27 21:03:45 +000069int camellia_setkey_dec( camellia_context *ctx, unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000070
71/**
72 * \brief CAMELLIA-ECB block encryption/decryption
73 *
74 * \param ctx CAMELLIA context
75 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
76 * \param input 16-byte input block
77 * \param output 16-byte output block
78 */
79void camellia_crypt_ecb( camellia_context *ctx,
80 int mode,
81 unsigned char input[16],
82 unsigned char output[16] );
83
84/**
85 * \brief CAMELLIA-CBC buffer encryption/decryption
Paul Bakker4c067eb2009-05-17 10:25:19 +000086 * Length should be a multiple of the block
87 * size (16 bytes)
Paul Bakker38119b12009-01-10 23:31:23 +000088 *
89 * \param ctx CAMELLIA context
90 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
91 * \param length length of the input data
92 * \param iv initialization vector (updated after use)
93 * \param input buffer holding the input data
94 * \param output buffer holding the output data
95 */
96void camellia_crypt_cbc( camellia_context *ctx,
97 int mode,
98 int length,
99 unsigned char iv[16],
100 unsigned char *input,
101 unsigned char *output );
102
103/**
104 * \brief CAMELLIA-CFB128 buffer encryption/decryption
105 *
106 * \param ctx CAMELLIA context
107 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
108 * \param length length of the input data
109 * \param iv_off offset in IV (updated after use)
110 * \param iv initialization vector (updated after use)
111 * \param input buffer holding the input data
112 * \param output buffer holding the output data
113 */
114void camellia_crypt_cfb128( camellia_context *ctx,
115 int mode,
116 int length,
117 int *iv_off,
118 unsigned char iv[16],
119 unsigned char *input,
120 unsigned char *output );
121
122/**
123 * \brief Checkup routine
124 *
125 * \return 0 if successful, or 1 if the test failed
126 */
127int camellia_self_test( int verbose );
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* camellia.h */