blob: 3f2e6a754f68e6a3fa7e0b4377e7cb54f6e01a87 [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
33/**
34 * \brief CAMELLIA context structure
35 */
36typedef struct
37{
38 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000039 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000040}
41camellia_context;
42
43#ifdef __cplusplus
44extern "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 */
54void 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 */
63void 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 */
73void 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 Bakker4c067eb2009-05-17 10:25:19 +000080 * Length should be a multiple of the block
81 * size (16 bytes)
Paul Bakker38119b12009-01-10 23:31:23 +000082 *
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 */
90void 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 */
108void 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 */
121int camellia_self_test( int verbose );
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif /* camellia.h */