blob: be8a42b326b54b1e8e83f4188c50893df28207b9 [file] [log] [blame]
Paul Bakker38119b12009-01-10 23:31:23 +00001/**
2 * \file camellia.h
3 *
Paul Bakker77b385e2009-07-28 17:23:11 +00004 * Copyright (C) 2006-2009, Paul Bakker <polarssl_maintainer at polarssl.org>
5 * All rights reserved.
Paul Bakker38119b12009-01-10 23:31:23 +00006 *
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 Bakker477fd322009-10-04 13:22:13 +000023
24#ifdef _MSC_VER
25#include <basetsd.h>
26typedef UINT32 uint32_t;
Paul Bakker80ab9f52009-05-24 14:42:46 +000027#else
Paul Bakker477fd322009-10-04 13:22:13 +000028#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000029#endif
Paul Bakkerc81f6c32009-05-03 13:09:15 +000030
Paul Bakker38119b12009-01-10 23:31:23 +000031#define CAMELLIA_ENCRYPT 1
32#define CAMELLIA_DECRYPT 0
33
Paul Bakker3391b122009-07-28 20:11:54 +000034#define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0a00
Paul Bakker2b222c82009-07-27 21:03:45 +000035
Paul Bakker38119b12009-01-10 23:31:23 +000036/**
37 * \brief CAMELLIA context structure
38 */
39typedef struct
40{
41 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000042 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000043}
44camellia_context;
45
46#ifdef __cplusplus
47extern "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 Bakker2b222c82009-07-27 21:03:45 +000056 *
57 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000058 */
Paul Bakker2b222c82009-07-27 21:03:45 +000059int camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000060
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 Bakker2b222c82009-07-27 21:03:45 +000067 *
68 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000069 */
Paul Bakker2b222c82009-07-27 21:03:45 +000070int camellia_setkey_dec( camellia_context *ctx, unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000071
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 */
80void 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 Bakker4c067eb2009-05-17 10:25:19 +000087 * Length should be a multiple of the block
88 * size (16 bytes)
Paul Bakker38119b12009-01-10 23:31:23 +000089 *
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 */
97void 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 */
115void 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 */
128int camellia_self_test( int verbose );
129
130#ifdef __cplusplus
131}
132#endif
133
134#endif /* camellia.h */