blob: 323d03ea5856db3363e9604a44925a5a583b016f [file] [log] [blame]
Paul Bakker38119b12009-01-10 23:31:23 +00001/**
2 * \file camellia.h
3 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakker38119b12009-01-10 23:31:23 +000010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25#ifndef POLARSSL_CAMELLIA_H
26#define POLARSSL_CAMELLIA_H
Paul Bakker477fd322009-10-04 13:22:13 +000027
28#ifdef _MSC_VER
29#include <basetsd.h>
30typedef UINT32 uint32_t;
Paul Bakker80ab9f52009-05-24 14:42:46 +000031#else
Paul Bakker477fd322009-10-04 13:22:13 +000032#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000033#endif
Paul Bakkerc81f6c32009-05-03 13:09:15 +000034
Paul Bakker38119b12009-01-10 23:31:23 +000035#define CAMELLIA_ENCRYPT 1
36#define CAMELLIA_DECRYPT 0
37
Paul Bakker3391b122009-07-28 20:11:54 +000038#define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0a00
Paul Bakkerf3ccc682010-03-18 21:21:02 +000039#define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0a10
Paul Bakker2b222c82009-07-27 21:03:45 +000040
Paul Bakker38119b12009-01-10 23:31:23 +000041/**
42 * \brief CAMELLIA context structure
43 */
44typedef struct
45{
46 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000047 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000048}
49camellia_context;
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/**
56 * \brief CAMELLIA key schedule (encryption)
57 *
58 * \param ctx CAMELLIA context to be initialized
59 * \param key encryption key
60 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000061 *
62 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000063 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000064int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000065
66/**
67 * \brief CAMELLIA key schedule (decryption)
68 *
69 * \param ctx CAMELLIA context to be initialized
70 * \param key decryption key
71 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000072 *
73 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000074 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000075int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000076
77/**
78 * \brief CAMELLIA-ECB block encryption/decryption
79 *
80 * \param ctx CAMELLIA context
81 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
82 * \param input 16-byte input block
83 * \param output 16-byte output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +000084 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000085 * \return 0 if successful
Paul Bakker38119b12009-01-10 23:31:23 +000086 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +000087int camellia_crypt_ecb( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +000088 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000089 const unsigned char input[16],
Paul Bakker38119b12009-01-10 23:31:23 +000090 unsigned char output[16] );
91
92/**
93 * \brief CAMELLIA-CBC buffer encryption/decryption
Paul Bakker4c067eb2009-05-17 10:25:19 +000094 * Length should be a multiple of the block
95 * size (16 bytes)
Paul Bakker38119b12009-01-10 23:31:23 +000096 *
97 * \param ctx CAMELLIA context
98 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
99 * \param length length of the input data
100 * \param iv initialization vector (updated after use)
101 * \param input buffer holding the input data
102 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000103 *
104 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +0000105 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000106int camellia_crypt_cbc( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000107 int mode,
108 int length,
109 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000110 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000111 unsigned char *output );
112
113/**
114 * \brief CAMELLIA-CFB128 buffer encryption/decryption
115 *
116 * \param ctx CAMELLIA context
117 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
118 * \param length length of the input data
119 * \param iv_off offset in IV (updated after use)
120 * \param iv initialization vector (updated after use)
121 * \param input buffer holding the input data
122 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000123 *
124 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +0000125 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000126int camellia_crypt_cfb128( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000127 int mode,
128 int length,
129 int *iv_off,
130 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000131 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000132 unsigned char *output );
133
134/**
135 * \brief Checkup routine
136 *
137 * \return 0 if successful, or 1 if the test failed
138 */
139int camellia_self_test( int verbose );
140
141#ifdef __cplusplus
142}
143#endif
144
145#endif /* camellia.h */