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