blob: fe5ac3721f16035d372cf75e98fc56bef9b16a15 [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 */
Gilles Peskine1990fab2021-07-26 18:48:10 +020069/** Bad input data. */
70#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024
Ron Eldor9924bdc2018-10-04 10:59:13 +030071
Gilles Peskine1990fab2021-07-26 18:48:10 +020072/** Invalid data input length. */
73#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026
Hanno Becker938f9e92018-12-18 09:40:25 +000074
Ron Eldor9924bdc2018-10-04 10:59:13 +030075/* MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED is deprecated and should not be used.
76 */
Gilles Peskine1990fab2021-07-26 18:48:10 +020077/** Camellia hardware accelerator failed. */
78#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027
Paul Bakker2b222c82009-07-27 21:03:45 +000079
Paul Bakker407a0da2013-06-27 14:29:21 +020080#ifdef __cplusplus
81extern "C" {
82#endif
83
Ron Eldorb2aacec2017-05-18 16:53:08 +030084#if !defined(MBEDTLS_CAMELLIA_ALT)
85// Regular implementation
86//
87
Paul Bakker38119b12009-01-10 23:31:23 +000088/**
89 * \brief CAMELLIA context structure
90 */
Dawid Drozd428cc522018-07-24 10:02:47 +020091typedef struct mbedtls_camellia_context
Paul Bakker38119b12009-01-10 23:31:23 +000092{
93 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000094 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000095}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096mbedtls_camellia_context;
Paul Bakker38119b12009-01-10 23:31:23 +000097
Ron Eldorb2aacec2017-05-18 16:53:08 +030098#else /* MBEDTLS_CAMELLIA_ALT */
99#include "camellia_alt.h"
100#endif /* MBEDTLS_CAMELLIA_ALT */
101
Paul Bakker38119b12009-01-10 23:31:23 +0000102/**
Hanno Becker7a16aad2018-12-12 14:54:16 +0000103 * \brief Initialize a CAMELLIA context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200104 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000105 * \param ctx The CAMELLIA context to be initialized.
106 * This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200107 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200109
110/**
Hanno Becker7a16aad2018-12-12 14:54:16 +0000111 * \brief Clear a CAMELLIA context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200112 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000113 * \param ctx The CAMELLIA context to be cleared. This may be \c NULL,
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000114 * in which case this function returns immediately. If it is not
Hanno Becker7a16aad2018-12-12 14:54:16 +0000115 * \c NULL, it must be initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200116 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200118
119/**
Hanno Becker70ded362018-12-19 13:42:05 +0000120 * \brief Perform a CAMELLIA key schedule operation for encryption.
Paul Bakker38119b12009-01-10 23:31:23 +0000121 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000122 * \param ctx The CAMELLIA context to use. This must be initialized.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000123 * \param key The encryption key to use. This must be a readable buffer
Hanno Beckere939de72018-12-13 15:39:24 +0000124 * of size \p keybits Bits.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000125 * \param keybits The length of \p key in Bits. This must be either \c 128,
Hanno Becker7a16aad2018-12-12 14:54:16 +0000126 * \c 192 or \c 256.
Paul Bakker9af723c2014-05-01 13:03:14 +0200127 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000128 * \return \c 0 if successful.
129 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000130 */
Hanno Becker7a16aad2018-12-12 14:54:16 +0000131int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
132 const unsigned char *key,
133 unsigned int keybits );
Paul Bakker38119b12009-01-10 23:31:23 +0000134
135/**
Hanno Becker70ded362018-12-19 13:42:05 +0000136 * \brief Perform a CAMELLIA key schedule operation for decryption.
Paul Bakker38119b12009-01-10 23:31:23 +0000137 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000138 * \param ctx The CAMELLIA context to use. This must be initialized.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000139 * \param key The decryption key. This must be a readable buffer
Hanno Beckere939de72018-12-13 15:39:24 +0000140 * of size \p keybits Bits.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000141 * \param keybits The length of \p key in Bits. This must be either \c 128,
Hanno Becker7a16aad2018-12-12 14:54:16 +0000142 * \c 192 or \c 256.
Paul Bakker9af723c2014-05-01 13:03:14 +0200143 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000144 * \return \c 0 if successful.
145 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000146 */
Hanno Becker7a16aad2018-12-12 14:54:16 +0000147int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx,
148 const unsigned char *key,
149 unsigned int keybits );
Paul Bakker38119b12009-01-10 23:31:23 +0000150
151/**
Hanno Becker70ded362018-12-19 13:42:05 +0000152 * \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000153 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000154 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000155 * and bound to a key.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000156 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000157 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000158 * \param input The input block. This must be a readable buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000159 * of size \c 16 Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000160 * \param output The output block. This must be a writable buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000161 * of size \c 16 Bytes.
Paul Bakker9af723c2014-05-01 13:03:14 +0200162 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000163 * \return \c 0 if successful.
164 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000165 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000167 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000168 const unsigned char input[16],
Paul Bakker38119b12009-01-10 23:31:23 +0000169 unsigned char output[16] );
170
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker38119b12009-01-10 23:31:23 +0000172/**
Hanno Becker70ded362018-12-19 13:42:05 +0000173 * \brief Perform a CAMELLIA-CBC buffer encryption/decryption operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000174 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000175 * \note Upon exit, the content of the IV is updated so that you can
176 * call the function same function again on the following
177 * block(s) of data and get the same result as if it was
178 * encrypted in one call. This allows a "streaming" usage.
179 * If on the other hand you need to retain the contents of the
180 * IV, you should either save it manually or use the cipher
181 * module instead.
182 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000183 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000184 * and bound to a key.
Hanno Beckere939de72018-12-13 15:39:24 +0000185 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000186 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000187 * \param length The length in Bytes of the input data \p input.
Hanno Becker70ded362018-12-19 13:42:05 +0000188 * This must be a multiple of \c 16 Bytes.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000189 * \param iv The initialization vector. This must be a read/write buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000190 * of length \c 16 Bytes. It is updated to allow streaming
191 * use as explained above.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000192 * \param input The buffer holding the input data. This must point to a
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000193 * readable buffer of length \p length Bytes.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000194 * \param output The buffer holding the output data. This must point to a
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000195 * writable buffer of length \p length Bytes.
Paul Bakker9af723c2014-05-01 13:03:14 +0200196 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000197 * \return \c 0 if successful.
198 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000199 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000201 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000202 size_t length,
Paul Bakker38119b12009-01-10 23:31:23 +0000203 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000204 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000205 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker38119b12009-01-10 23:31:23 +0000207
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker38119b12009-01-10 23:31:23 +0000209/**
Hanno Becker70ded362018-12-19 13:42:05 +0000210 * \brief Perform a CAMELLIA-CFB128 buffer encryption/decryption
211 * operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000212 *
Hanno Becker70ded362018-12-19 13:42:05 +0000213 * \note Due to the nature of CFB mode, you should use the same
214 * key for both encryption and decryption. In particular, calls
215 * to this function should be preceded by a key-schedule via
216 * mbedtls_camellia_setkey_enc() regardless of whether \p mode
217 * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000218 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000219 * \note Upon exit, the content of the IV is updated so that you can
220 * call the function same function again on the following
221 * block(s) of data and get the same result as if it was
222 * encrypted in one call. This allows a "streaming" usage.
223 * If on the other hand you need to retain the contents of the
224 * IV, you should either save it manually or use the cipher
225 * module instead.
226 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000227 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000228 * and bound to a key.
Hanno Beckere939de72018-12-13 15:39:24 +0000229 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000230 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000231 * \param length The length of the input data \p input. Any value is allowed.
Hanno Becker7a16aad2018-12-12 14:54:16 +0000232 * \param iv_off The current offset in the IV. This must be smaller
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000233 * than \c 16 Bytes. It is updated after this call to allow
Hanno Becker7a16aad2018-12-12 14:54:16 +0000234 * the aforementioned streaming usage.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000235 * \param iv The initialization vector. This must be a read/write buffer
236 * of length \c 16 Bytes. It is updated after this call to
Hanno Becker7a16aad2018-12-12 14:54:16 +0000237 * allow the aforementioned streaming usage.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000238 * \param input The buffer holding the input data. This must be a readable
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000239 * buffer of size \p length Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000240 * \param output The buffer to hold the output data. This must be a writable
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000241 * buffer of length \p length Bytes.
Paul Bakkerdcbfdcc2013-09-10 16:16:50 +0200242 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000243 * \return \c 0 if successful.
244 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000245 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000247 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000248 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000249 size_t *iv_off,
Paul Bakker38119b12009-01-10 23:31:23 +0000250 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000251 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000252 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker38119b12009-01-10 23:31:23 +0000254
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker9a736322012-11-14 12:39:52 +0000256/**
Hanno Becker70ded362018-12-19 13:42:05 +0000257 * \brief Perform a CAMELLIA-CTR buffer encryption/decryption operation.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000258 *
Hanno Becker70ded362018-12-19 13:42:05 +0000259 * *note Due to the nature of CTR mode, you should use the same
260 * key for both encryption and decryption. In particular, calls
261 * to this function should be preceded by a key-schedule via
262 * mbedtls_camellia_setkey_enc() regardless of whether \p mode
263 * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000264 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100265 * \warning You must never reuse a nonce value with the same key. Doing so
266 * would void the encryption for the two messages encrypted with
267 * the same nonce and key.
268 *
269 * There are two common strategies for managing nonces with CTR:
270 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200271 * 1. You can handle everything as a single message processed over
272 * successive calls to this function. In that case, you want to
273 * set \p nonce_counter and \p nc_off to 0 for the first call, and
274 * then preserve the values of \p nonce_counter, \p nc_off and \p
275 * stream_block across calls to this function as they will be
276 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100277 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200278 * With this strategy, you must not encrypt more than 2**128
279 * blocks of data with the same key.
280 *
281 * 2. You can encrypt separate messages by dividing the \p
282 * nonce_counter buffer in two areas: the first one used for a
283 * per-message nonce, handled by yourself, and the second one
284 * updated by this function internally.
285 *
Hanno Becker70ded362018-12-19 13:42:05 +0000286 * For example, you might reserve the first \c 12 Bytes for the
287 * per-message nonce, and the last \c 4 Bytes for internal use.
288 * In that case, before calling this function on a new message you
289 * need to set the first \c 12 Bytes of \p nonce_counter to your
290 * chosen nonce value, the last four to \c 0, and \p nc_off to \c 0
291 * (which will cause \p stream_block to be ignored). That way, you
292 * can encrypt at most \c 2**96 messages of up to \c 2**32 blocks
293 * each with the same key.
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200294 *
295 * The per-message nonce (or information sufficient to reconstruct
Hanno Beckerdf4b5962018-12-19 15:50:02 +0000296 * it) needs to be communicated with the ciphertext and must be
Hanno Becker70ded362018-12-19 13:42:05 +0000297 * unique. The recommended way to ensure uniqueness is to use a
298 * message counter. An alternative is to generate random nonces,
299 * but this limits the number of messages that can be securely
300 * encrypted: for example, with 96-bit random nonces, you should
301 * not encrypt more than 2**32 messages with the same key.
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200302 *
303 * Note that for both stategies, sizes are measured in blocks and
Hanno Beckerdf4b5962018-12-19 15:50:02 +0000304 * that a CAMELLIA block is \c 16 Bytes.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100305 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200306 * \warning Upon return, \p stream_block contains sensitive data. Its
307 * content must not be written to insecure storage and should be
308 * securely discarded as soon as it's no longer needed.
309 *
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000310 * \param ctx The CAMELLIA context to use. This must be initialized
311 * and bound to a key.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000312 * \param length The length of the input data \p input in Bytes.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000313 * Any value is allowed.
Hanno Becker7a16aad2018-12-12 14:54:16 +0000314 * \param nc_off The offset in the current \p stream_block (for resuming
Paul Bakker1ef71df2011-06-09 14:14:58 +0000315 * within current cipher stream). The offset pointer to
Hanno Becker7a16aad2018-12-12 14:54:16 +0000316 * should be \c 0 at the start of a stream. It is updated
317 * at the end of this call.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000318 * \param nonce_counter The 128-bit nonce and counter. This must be a read/write
319 * buffer of length \c 16 Bytes.
320 * \param stream_block The saved stream-block for resuming. This must be a
321 * read/write buffer of length \c 16 Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000322 * \param input The input data stream. This must be a readable buffer of
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000323 * size \p length Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000324 * \param output The output data stream. This must be a writable buffer
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000325 * of size \p length Bytes.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000326 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000327 * \return \c 0 if successful.
328 * \return A negative error code on failure.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000329 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200330int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000331 size_t length,
332 size_t *nc_off,
333 unsigned char nonce_counter[16],
334 unsigned char stream_block[16],
335 const unsigned char *input,
336 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200337#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker1ef71df2011-06-09 14:14:58 +0000338
Ron Eldorfa8f6352017-06-20 15:48:46 +0300339#if defined(MBEDTLS_SELF_TEST)
340
Paul Bakker38119b12009-01-10 23:31:23 +0000341/**
342 * \brief Checkup routine
343 *
344 * \return 0 if successful, or 1 if the test failed
345 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200346int mbedtls_camellia_self_test( int verbose );
Paul Bakker38119b12009-01-10 23:31:23 +0000347
Ron Eldorfa8f6352017-06-20 15:48:46 +0300348#endif /* MBEDTLS_SELF_TEST */
349
Paul Bakker38119b12009-01-10 23:31:23 +0000350#ifdef __cplusplus
351}
352#endif
353
354#endif /* camellia.h */