blob: 38871288e4bd4a25d047ecd401d950eb3d817dce [file] [log] [blame]
Paul Bakker38119b12009-01-10 23:31:23 +00001/**
2 * \file camellia.h
3 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief Camellia block cipher
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Bence Szépkútia2947ac2020-08-19 16:37:36 +02007 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +02008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020015 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000027 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020028 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
Paul Bakker38119b12009-01-10 23:31:23 +000048 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#ifndef MBEDTLS_CAMELLIA_H
50#define MBEDTLS_CAMELLIA_H
Paul Bakker477fd322009-10-04 13:22:13 +000051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020053#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020054#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#endif
Paul Bakker90995b52013-06-24 19:20:35 +020057
Rich Evans00ab4702015-02-06 13:43:58 +000058#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020059#include <stdint.h>
Paul Bakkerc81f6c32009-05-03 13:09:15 +000060
Hanno Becker4c029d02018-12-17 13:20:05 +000061#include "platform_util.h"
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#define MBEDTLS_CAMELLIA_ENCRYPT 1
64#define MBEDTLS_CAMELLIA_DECRYPT 0
Paul Bakker38119b12009-01-10 23:31:23 +000065
Hanno Becker4c029d02018-12-17 13:20:05 +000066#if !defined(MBEDTLS_DEPRECATED_REMOVED)
67#define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0024 )
Hanno Becker4c029d02018-12-17 13:20:05 +000068#endif /* !MBEDTLS_DEPRECATED_REMOVED */
69#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024 /**< Bad input data. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030070
Hanno Becker938f9e92018-12-18 09:40:25 +000071#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
72
Ron Eldor9924bdc2018-10-04 10:59:13 +030073/* MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED is deprecated and should not be used.
74 */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010075#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */
Paul Bakker2b222c82009-07-27 21:03:45 +000076
Paul Bakker407a0da2013-06-27 14:29:21 +020077#ifdef __cplusplus
78extern "C" {
79#endif
80
Ron Eldorb2aacec2017-05-18 16:53:08 +030081#if !defined(MBEDTLS_CAMELLIA_ALT)
82// Regular implementation
83//
84
Paul Bakker38119b12009-01-10 23:31:23 +000085/**
86 * \brief CAMELLIA context structure
87 */
Dawid Drozd428cc522018-07-24 10:02:47 +020088typedef struct mbedtls_camellia_context
Paul Bakker38119b12009-01-10 23:31:23 +000089{
90 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000091 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000092}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093mbedtls_camellia_context;
Paul Bakker38119b12009-01-10 23:31:23 +000094
Ron Eldorb2aacec2017-05-18 16:53:08 +030095#else /* MBEDTLS_CAMELLIA_ALT */
96#include "camellia_alt.h"
97#endif /* MBEDTLS_CAMELLIA_ALT */
98
Paul Bakker38119b12009-01-10 23:31:23 +000099/**
Hanno Becker7a16aad2018-12-12 14:54:16 +0000100 * \brief Initialize a CAMELLIA context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200101 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000102 * \param ctx The CAMELLIA context to be initialized.
103 * This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200104 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200106
107/**
Hanno Becker7a16aad2018-12-12 14:54:16 +0000108 * \brief Clear a CAMELLIA context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200109 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000110 * \param ctx The CAMELLIA context to be cleared. This may be \c NULL,
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000111 * in which case this function returns immediately. If it is not
Hanno Becker7a16aad2018-12-12 14:54:16 +0000112 * \c NULL, it must be initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200113 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200115
116/**
Hanno Becker70ded362018-12-19 13:42:05 +0000117 * \brief Perform a CAMELLIA key schedule operation for encryption.
Paul Bakker38119b12009-01-10 23:31:23 +0000118 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000119 * \param ctx The CAMELLIA context to use. This must be initialized.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000120 * \param key The encryption key to use. This must be a readable buffer
Hanno Beckere939de72018-12-13 15:39:24 +0000121 * of size \p keybits Bits.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000122 * \param keybits The length of \p key in Bits. This must be either \c 128,
Hanno Becker7a16aad2018-12-12 14:54:16 +0000123 * \c 192 or \c 256.
Paul Bakker9af723c2014-05-01 13:03:14 +0200124 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000125 * \return \c 0 if successful.
126 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000127 */
Hanno Becker7a16aad2018-12-12 14:54:16 +0000128int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
129 const unsigned char *key,
130 unsigned int keybits );
Paul Bakker38119b12009-01-10 23:31:23 +0000131
132/**
Hanno Becker70ded362018-12-19 13:42:05 +0000133 * \brief Perform a CAMELLIA key schedule operation for decryption.
Paul Bakker38119b12009-01-10 23:31:23 +0000134 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000135 * \param ctx The CAMELLIA context to use. This must be initialized.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000136 * \param key The decryption key. This must be a readable buffer
Hanno Beckere939de72018-12-13 15:39:24 +0000137 * of size \p keybits Bits.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000138 * \param keybits The length of \p key in Bits. This must be either \c 128,
Hanno Becker7a16aad2018-12-12 14:54:16 +0000139 * \c 192 or \c 256.
Paul Bakker9af723c2014-05-01 13:03:14 +0200140 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000141 * \return \c 0 if successful.
142 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000143 */
Hanno Becker7a16aad2018-12-12 14:54:16 +0000144int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx,
145 const unsigned char *key,
146 unsigned int keybits );
Paul Bakker38119b12009-01-10 23:31:23 +0000147
148/**
Hanno Becker70ded362018-12-19 13:42:05 +0000149 * \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000150 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000151 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000152 * and bound to a key.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000153 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000154 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000155 * \param input The input block. This must be a readable buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000156 * of size \c 16 Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000157 * \param output The output block. This must be a writable buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000158 * of size \c 16 Bytes.
Paul Bakker9af723c2014-05-01 13:03:14 +0200159 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000160 * \return \c 0 if successful.
161 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000162 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000164 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000165 const unsigned char input[16],
Paul Bakker38119b12009-01-10 23:31:23 +0000166 unsigned char output[16] );
167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker38119b12009-01-10 23:31:23 +0000169/**
Hanno Becker70ded362018-12-19 13:42:05 +0000170 * \brief Perform a CAMELLIA-CBC buffer encryption/decryption operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000171 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000172 * \note Upon exit, the content of the IV is updated so that you can
173 * call the function same function again on the following
174 * block(s) of data and get the same result as if it was
175 * encrypted in one call. This allows a "streaming" usage.
176 * If on the other hand you need to retain the contents of the
177 * IV, you should either save it manually or use the cipher
178 * module instead.
179 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000180 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000181 * and bound to a key.
Hanno Beckere939de72018-12-13 15:39:24 +0000182 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000183 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000184 * \param length The length in Bytes of the input data \p input.
Hanno Becker70ded362018-12-19 13:42:05 +0000185 * This must be a multiple of \c 16 Bytes.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000186 * \param iv The initialization vector. This must be a read/write buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000187 * of length \c 16 Bytes. It is updated to allow streaming
188 * use as explained above.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000189 * \param input The buffer holding the input data. This must point to a
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000190 * readable buffer of length \p length Bytes.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000191 * \param output The buffer holding the output data. This must point to a
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000192 * writable buffer of length \p length Bytes.
Paul Bakker9af723c2014-05-01 13:03:14 +0200193 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000194 * \return \c 0 if successful.
195 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000196 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000198 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000199 size_t length,
Paul Bakker38119b12009-01-10 23:31:23 +0000200 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000201 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000202 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker38119b12009-01-10 23:31:23 +0000204
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker38119b12009-01-10 23:31:23 +0000206/**
Hanno Becker70ded362018-12-19 13:42:05 +0000207 * \brief Perform a CAMELLIA-CFB128 buffer encryption/decryption
208 * operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000209 *
Hanno Becker70ded362018-12-19 13:42:05 +0000210 * \note Due to the nature of CFB mode, you should use the same
211 * key for both encryption and decryption. In particular, calls
212 * to this function should be preceded by a key-schedule via
213 * mbedtls_camellia_setkey_enc() regardless of whether \p mode
214 * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000215 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000216 * \note Upon exit, the content of the IV is updated so that you can
217 * call the function same function again on the following
218 * block(s) of data and get the same result as if it was
219 * encrypted in one call. This allows a "streaming" usage.
220 * If on the other hand you need to retain the contents of the
221 * IV, you should either save it manually or use the cipher
222 * module instead.
223 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000224 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000225 * and bound to a key.
Hanno Beckere939de72018-12-13 15:39:24 +0000226 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000227 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000228 * \param length The length of the input data \p input. Any value is allowed.
Hanno Becker7a16aad2018-12-12 14:54:16 +0000229 * \param iv_off The current offset in the IV. This must be smaller
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000230 * than \c 16 Bytes. It is updated after this call to allow
Hanno Becker7a16aad2018-12-12 14:54:16 +0000231 * the aforementioned streaming usage.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000232 * \param iv The initialization vector. This must be a read/write buffer
233 * of length \c 16 Bytes. It is updated after this call to
Hanno Becker7a16aad2018-12-12 14:54:16 +0000234 * allow the aforementioned streaming usage.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000235 * \param input The buffer holding the input data. This must be a readable
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000236 * buffer of size \p length Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000237 * \param output The buffer to hold the output data. This must be a writable
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000238 * buffer of length \p length Bytes.
Paul Bakkerdcbfdcc2013-09-10 16:16:50 +0200239 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000240 * \return \c 0 if successful.
241 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000242 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000244 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000245 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000246 size_t *iv_off,
Paul Bakker38119b12009-01-10 23:31:23 +0000247 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000248 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000249 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200250#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker38119b12009-01-10 23:31:23 +0000251
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker9a736322012-11-14 12:39:52 +0000253/**
Hanno Becker70ded362018-12-19 13:42:05 +0000254 * \brief Perform a CAMELLIA-CTR buffer encryption/decryption operation.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000255 *
Hanno Becker70ded362018-12-19 13:42:05 +0000256 * *note Due to the nature of CTR mode, you should use the same
257 * key for both encryption and decryption. In particular, calls
258 * to this function should be preceded by a key-schedule via
259 * mbedtls_camellia_setkey_enc() regardless of whether \p mode
260 * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000261 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100262 * \warning You must never reuse a nonce value with the same key. Doing so
263 * would void the encryption for the two messages encrypted with
264 * the same nonce and key.
265 *
266 * There are two common strategies for managing nonces with CTR:
267 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200268 * 1. You can handle everything as a single message processed over
269 * successive calls to this function. In that case, you want to
270 * set \p nonce_counter and \p nc_off to 0 for the first call, and
271 * then preserve the values of \p nonce_counter, \p nc_off and \p
272 * stream_block across calls to this function as they will be
273 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100274 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200275 * With this strategy, you must not encrypt more than 2**128
276 * blocks of data with the same key.
277 *
278 * 2. You can encrypt separate messages by dividing the \p
279 * nonce_counter buffer in two areas: the first one used for a
280 * per-message nonce, handled by yourself, and the second one
281 * updated by this function internally.
282 *
Hanno Becker70ded362018-12-19 13:42:05 +0000283 * For example, you might reserve the first \c 12 Bytes for the
284 * per-message nonce, and the last \c 4 Bytes for internal use.
285 * In that case, before calling this function on a new message you
286 * need to set the first \c 12 Bytes of \p nonce_counter to your
287 * chosen nonce value, the last four to \c 0, and \p nc_off to \c 0
288 * (which will cause \p stream_block to be ignored). That way, you
289 * can encrypt at most \c 2**96 messages of up to \c 2**32 blocks
290 * each with the same key.
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200291 *
292 * The per-message nonce (or information sufficient to reconstruct
Hanno Beckerdf4b5962018-12-19 15:50:02 +0000293 * it) needs to be communicated with the ciphertext and must be
Hanno Becker70ded362018-12-19 13:42:05 +0000294 * unique. The recommended way to ensure uniqueness is to use a
295 * message counter. An alternative is to generate random nonces,
296 * but this limits the number of messages that can be securely
297 * encrypted: for example, with 96-bit random nonces, you should
298 * not encrypt more than 2**32 messages with the same key.
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200299 *
300 * Note that for both stategies, sizes are measured in blocks and
Hanno Beckerdf4b5962018-12-19 15:50:02 +0000301 * that a CAMELLIA block is \c 16 Bytes.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100302 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200303 * \warning Upon return, \p stream_block contains sensitive data. Its
304 * content must not be written to insecure storage and should be
305 * securely discarded as soon as it's no longer needed.
306 *
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000307 * \param ctx The CAMELLIA context to use. This must be initialized
308 * and bound to a key.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000309 * \param length The length of the input data \p input in Bytes.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000310 * Any value is allowed.
Hanno Becker7a16aad2018-12-12 14:54:16 +0000311 * \param nc_off The offset in the current \p stream_block (for resuming
Paul Bakker1ef71df2011-06-09 14:14:58 +0000312 * within current cipher stream). The offset pointer to
Hanno Becker7a16aad2018-12-12 14:54:16 +0000313 * should be \c 0 at the start of a stream. It is updated
314 * at the end of this call.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000315 * \param nonce_counter The 128-bit nonce and counter. This must be a read/write
316 * buffer of length \c 16 Bytes.
317 * \param stream_block The saved stream-block for resuming. This must be a
318 * read/write buffer of length \c 16 Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000319 * \param input The input data stream. This must be a readable buffer of
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000320 * size \p length Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000321 * \param output The output data stream. This must be a writable buffer
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000322 * of size \p length Bytes.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000323 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000324 * \return \c 0 if successful.
325 * \return A negative error code on failure.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000326 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200327int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000328 size_t length,
329 size_t *nc_off,
330 unsigned char nonce_counter[16],
331 unsigned char stream_block[16],
332 const unsigned char *input,
333 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker1ef71df2011-06-09 14:14:58 +0000335
Ron Eldorfa8f6352017-06-20 15:48:46 +0300336#if defined(MBEDTLS_SELF_TEST)
337
Paul Bakker38119b12009-01-10 23:31:23 +0000338/**
339 * \brief Checkup routine
340 *
341 * \return 0 if successful, or 1 if the test failed
342 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200343int mbedtls_camellia_self_test( int verbose );
Paul Bakker38119b12009-01-10 23:31:23 +0000344
Ron Eldorfa8f6352017-06-20 15:48:46 +0300345#endif /* MBEDTLS_SELF_TEST */
346
Paul Bakker38119b12009-01-10 23:31:23 +0000347#ifdef __cplusplus
348}
349#endif
350
351#endif /* camellia.h */