blob: 41d6f955baef543860af39d19270a0d9ff1f6725 [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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 * **********
48 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000049 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker38119b12009-01-10 23:31:23 +000050 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#ifndef MBEDTLS_CAMELLIA_H
52#define MBEDTLS_CAMELLIA_H
Paul Bakker477fd322009-10-04 13:22:13 +000053
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020055#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020058#endif
Paul Bakker90995b52013-06-24 19:20:35 +020059
Rich Evans00ab4702015-02-06 13:43:58 +000060#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020061#include <stdint.h>
Paul Bakkerc81f6c32009-05-03 13:09:15 +000062
Hanno Becker4c029d02018-12-17 13:20:05 +000063#include "platform_util.h"
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#define MBEDTLS_CAMELLIA_ENCRYPT 1
66#define MBEDTLS_CAMELLIA_DECRYPT 0
Paul Bakker38119b12009-01-10 23:31:23 +000067
Hanno Becker4c029d02018-12-17 13:20:05 +000068#if !defined(MBEDTLS_DEPRECATED_REMOVED)
69#define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0024 )
Hanno Becker4c029d02018-12-17 13:20:05 +000070#endif /* !MBEDTLS_DEPRECATED_REMOVED */
71#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024 /**< Bad input data. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030072
Hanno Becker938f9e92018-12-18 09:40:25 +000073#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
74
Ron Eldor9924bdc2018-10-04 10:59:13 +030075/* MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED is deprecated and should not be used.
76 */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010077#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */
Paul Bakker2b222c82009-07-27 21:03:45 +000078
Paul Bakker407a0da2013-06-27 14:29:21 +020079#ifdef __cplusplus
80extern "C" {
81#endif
82
Ron Eldorb2aacec2017-05-18 16:53:08 +030083#if !defined(MBEDTLS_CAMELLIA_ALT)
84// Regular implementation
85//
86
Paul Bakker38119b12009-01-10 23:31:23 +000087/**
88 * \brief CAMELLIA context structure
89 */
Dawid Drozd428cc522018-07-24 10:02:47 +020090typedef struct mbedtls_camellia_context
Paul Bakker38119b12009-01-10 23:31:23 +000091{
92 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000093 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000094}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095mbedtls_camellia_context;
Paul Bakker38119b12009-01-10 23:31:23 +000096
Ron Eldorb2aacec2017-05-18 16:53:08 +030097#else /* MBEDTLS_CAMELLIA_ALT */
98#include "camellia_alt.h"
99#endif /* MBEDTLS_CAMELLIA_ALT */
100
Paul Bakker38119b12009-01-10 23:31:23 +0000101/**
Hanno Becker7a16aad2018-12-12 14:54:16 +0000102 * \brief Initialize a CAMELLIA context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200103 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000104 * \param ctx The CAMELLIA context to be initialized.
105 * This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200106 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200108
109/**
Hanno Becker7a16aad2018-12-12 14:54:16 +0000110 * \brief Clear a CAMELLIA context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200111 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000112 * \param ctx The CAMELLIA context to be cleared. This may be \c NULL,
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000113 * in which case this function returns immediately. If it is not
Hanno Becker7a16aad2018-12-12 14:54:16 +0000114 * \c NULL, it must be initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200115 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200117
118/**
Hanno Becker70ded362018-12-19 13:42:05 +0000119 * \brief Perform a CAMELLIA key schedule operation for encryption.
Paul Bakker38119b12009-01-10 23:31:23 +0000120 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000121 * \param ctx The CAMELLIA context to use. This must be initialized.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000122 * \param key The encryption key to use. This must be a readable buffer
Hanno Beckere939de72018-12-13 15:39:24 +0000123 * of size \p keybits Bits.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000124 * \param keybits The length of \p key in Bits. This must be either \c 128,
Hanno Becker7a16aad2018-12-12 14:54:16 +0000125 * \c 192 or \c 256.
Paul Bakker9af723c2014-05-01 13:03:14 +0200126 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000127 * \return \c 0 if successful.
128 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000129 */
Hanno Becker7a16aad2018-12-12 14:54:16 +0000130int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
131 const unsigned char *key,
132 unsigned int keybits );
Paul Bakker38119b12009-01-10 23:31:23 +0000133
134/**
Hanno Becker70ded362018-12-19 13:42:05 +0000135 * \brief Perform a CAMELLIA key schedule operation for decryption.
Paul Bakker38119b12009-01-10 23:31:23 +0000136 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000137 * \param ctx The CAMELLIA context to use. This must be initialized.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000138 * \param key The decryption key. This must be a readable buffer
Hanno Beckere939de72018-12-13 15:39:24 +0000139 * of size \p keybits Bits.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000140 * \param keybits The length of \p key in Bits. This must be either \c 128,
Hanno Becker7a16aad2018-12-12 14:54:16 +0000141 * \c 192 or \c 256.
Paul Bakker9af723c2014-05-01 13:03:14 +0200142 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000143 * \return \c 0 if successful.
144 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000145 */
Hanno Becker7a16aad2018-12-12 14:54:16 +0000146int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx,
147 const unsigned char *key,
148 unsigned int keybits );
Paul Bakker38119b12009-01-10 23:31:23 +0000149
150/**
Hanno Becker70ded362018-12-19 13:42:05 +0000151 * \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000152 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000153 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000154 * and bound to a key.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000155 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000156 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000157 * \param input The input block. This must be a readable buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000158 * of size \c 16 Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000159 * \param output The output block. This must be a writable buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000160 * of size \c 16 Bytes.
Paul Bakker9af723c2014-05-01 13:03:14 +0200161 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000162 * \return \c 0 if successful.
163 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000164 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000166 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000167 const unsigned char input[16],
Paul Bakker38119b12009-01-10 23:31:23 +0000168 unsigned char output[16] );
169
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200170#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker38119b12009-01-10 23:31:23 +0000171/**
Hanno Becker70ded362018-12-19 13:42:05 +0000172 * \brief Perform a CAMELLIA-CBC buffer encryption/decryption operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000173 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000174 * \note Upon exit, the content of the IV is updated so that you can
175 * call the function same function again on the following
176 * block(s) of data and get the same result as if it was
177 * encrypted in one call. This allows a "streaming" usage.
178 * If on the other hand you need to retain the contents of the
179 * IV, you should either save it manually or use the cipher
180 * module instead.
181 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000182 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000183 * and bound to a key.
Hanno Beckere939de72018-12-13 15:39:24 +0000184 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000185 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000186 * \param length The length in Bytes of the input data \p input.
Hanno Becker70ded362018-12-19 13:42:05 +0000187 * This must be a multiple of \c 16 Bytes.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000188 * \param iv The initialization vector. This must be a read/write buffer
Hanno Becker7a16aad2018-12-12 14:54:16 +0000189 * of length \c 16 Bytes. It is updated to allow streaming
190 * use as explained above.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000191 * \param input The buffer holding the input data. This must point to a
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000192 * readable buffer of length \p length Bytes.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000193 * \param output The buffer holding the output data. This must point to a
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000194 * writable buffer of length \p length Bytes.
Paul Bakker9af723c2014-05-01 13:03:14 +0200195 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000196 * \return \c 0 if successful.
197 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000198 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000200 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000201 size_t length,
Paul Bakker38119b12009-01-10 23:31:23 +0000202 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000203 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000204 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker38119b12009-01-10 23:31:23 +0000206
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker38119b12009-01-10 23:31:23 +0000208/**
Hanno Becker70ded362018-12-19 13:42:05 +0000209 * \brief Perform a CAMELLIA-CFB128 buffer encryption/decryption
210 * operation.
Paul Bakker38119b12009-01-10 23:31:23 +0000211 *
Hanno Becker70ded362018-12-19 13:42:05 +0000212 * \note Due to the nature of CFB mode, you should use the same
213 * key for both encryption and decryption. In particular, calls
214 * to this function should be preceded by a key-schedule via
215 * mbedtls_camellia_setkey_enc() regardless of whether \p mode
216 * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000217 *
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000218 * \note Upon exit, the content of the IV is updated so that you can
219 * call the function same function again on the following
220 * block(s) of data and get the same result as if it was
221 * encrypted in one call. This allows a "streaming" usage.
222 * If on the other hand you need to retain the contents of the
223 * IV, you should either save it manually or use the cipher
224 * module instead.
225 *
Hanno Beckerf10905a2018-12-13 15:15:36 +0000226 * \param ctx The CAMELLIA context to use. This must be initialized
Hanno Becker7a16aad2018-12-12 14:54:16 +0000227 * and bound to a key.
Hanno Beckere939de72018-12-13 15:39:24 +0000228 * \param mode The mode of operation. This must be either
Hanno Becker7a16aad2018-12-12 14:54:16 +0000229 * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000230 * \param length The length of the input data \p input. Any value is allowed.
Hanno Becker7a16aad2018-12-12 14:54:16 +0000231 * \param iv_off The current offset in the IV. This must be smaller
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000232 * than \c 16 Bytes. It is updated after this call to allow
Hanno Becker7a16aad2018-12-12 14:54:16 +0000233 * the aforementioned streaming usage.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000234 * \param iv The initialization vector. This must be a read/write buffer
235 * of length \c 16 Bytes. It is updated after this call to
Hanno Becker7a16aad2018-12-12 14:54:16 +0000236 * allow the aforementioned streaming usage.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000237 * \param input The buffer holding the input data. This must be a readable
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000238 * buffer of size \p length Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000239 * \param output The buffer to hold the output data. This must be a writable
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000240 * buffer of length \p length Bytes.
Paul Bakkerdcbfdcc2013-09-10 16:16:50 +0200241 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000242 * \return \c 0 if successful.
243 * \return A negative error code on failure.
Paul Bakker38119b12009-01-10 23:31:23 +0000244 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000246 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000247 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000248 size_t *iv_off,
Paul Bakker38119b12009-01-10 23:31:23 +0000249 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000250 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000251 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker38119b12009-01-10 23:31:23 +0000253
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200254#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker9a736322012-11-14 12:39:52 +0000255/**
Hanno Becker70ded362018-12-19 13:42:05 +0000256 * \brief Perform a CAMELLIA-CTR buffer encryption/decryption operation.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000257 *
Hanno Becker70ded362018-12-19 13:42:05 +0000258 * *note Due to the nature of CTR mode, you should use the same
259 * key for both encryption and decryption. In particular, calls
260 * to this function should be preceded by a key-schedule via
261 * mbedtls_camellia_setkey_enc() regardless of whether \p mode
262 * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000263 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100264 * \warning You must never reuse a nonce value with the same key. Doing so
265 * would void the encryption for the two messages encrypted with
266 * the same nonce and key.
267 *
268 * There are two common strategies for managing nonces with CTR:
269 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200270 * 1. You can handle everything as a single message processed over
271 * successive calls to this function. In that case, you want to
272 * set \p nonce_counter and \p nc_off to 0 for the first call, and
273 * then preserve the values of \p nonce_counter, \p nc_off and \p
274 * stream_block across calls to this function as they will be
275 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100276 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200277 * With this strategy, you must not encrypt more than 2**128
278 * blocks of data with the same key.
279 *
280 * 2. You can encrypt separate messages by dividing the \p
281 * nonce_counter buffer in two areas: the first one used for a
282 * per-message nonce, handled by yourself, and the second one
283 * updated by this function internally.
284 *
Hanno Becker70ded362018-12-19 13:42:05 +0000285 * For example, you might reserve the first \c 12 Bytes for the
286 * per-message nonce, and the last \c 4 Bytes for internal use.
287 * In that case, before calling this function on a new message you
288 * need to set the first \c 12 Bytes of \p nonce_counter to your
289 * chosen nonce value, the last four to \c 0, and \p nc_off to \c 0
290 * (which will cause \p stream_block to be ignored). That way, you
291 * can encrypt at most \c 2**96 messages of up to \c 2**32 blocks
292 * each with the same key.
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200293 *
294 * The per-message nonce (or information sufficient to reconstruct
Hanno Beckerdf4b5962018-12-19 15:50:02 +0000295 * it) needs to be communicated with the ciphertext and must be
Hanno Becker70ded362018-12-19 13:42:05 +0000296 * unique. The recommended way to ensure uniqueness is to use a
297 * message counter. An alternative is to generate random nonces,
298 * but this limits the number of messages that can be securely
299 * encrypted: for example, with 96-bit random nonces, you should
300 * not encrypt more than 2**32 messages with the same key.
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200301 *
302 * Note that for both stategies, sizes are measured in blocks and
Hanno Beckerdf4b5962018-12-19 15:50:02 +0000303 * that a CAMELLIA block is \c 16 Bytes.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100304 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200305 * \warning Upon return, \p stream_block contains sensitive data. Its
306 * content must not be written to insecure storage and should be
307 * securely discarded as soon as it's no longer needed.
308 *
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000309 * \param ctx The CAMELLIA context to use. This must be initialized
310 * and bound to a key.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000311 * \param length The length of the input data \p input in Bytes.
Hanno Beckeraf4b83b2018-12-17 09:30:27 +0000312 * Any value is allowed.
Hanno Becker7a16aad2018-12-12 14:54:16 +0000313 * \param nc_off The offset in the current \p stream_block (for resuming
Paul Bakker1ef71df2011-06-09 14:14:58 +0000314 * within current cipher stream). The offset pointer to
Hanno Becker7a16aad2018-12-12 14:54:16 +0000315 * should be \c 0 at the start of a stream. It is updated
316 * at the end of this call.
Hanno Beckerc7579ec2018-12-17 15:18:02 +0000317 * \param nonce_counter The 128-bit nonce and counter. This must be a read/write
318 * buffer of length \c 16 Bytes.
319 * \param stream_block The saved stream-block for resuming. This must be a
320 * read/write buffer of length \c 16 Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000321 * \param input The input data stream. This must be a readable buffer of
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000322 * size \p length Bytes.
Hanno Beckerf10905a2018-12-13 15:15:36 +0000323 * \param output The output data stream. This must be a writable buffer
Hanno Beckerbdb7cd42018-12-18 17:49:48 +0000324 * of size \p length Bytes.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000325 *
Hanno Becker7a16aad2018-12-12 14:54:16 +0000326 * \return \c 0 if successful.
327 * \return A negative error code on failure.
Paul Bakker1ef71df2011-06-09 14:14:58 +0000328 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000330 size_t length,
331 size_t *nc_off,
332 unsigned char nonce_counter[16],
333 unsigned char stream_block[16],
334 const unsigned char *input,
335 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200336#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker1ef71df2011-06-09 14:14:58 +0000337
Ron Eldorfa8f6352017-06-20 15:48:46 +0300338#if defined(MBEDTLS_SELF_TEST)
339
Paul Bakker38119b12009-01-10 23:31:23 +0000340/**
341 * \brief Checkup routine
342 *
343 * \return 0 if successful, or 1 if the test failed
344 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200345int mbedtls_camellia_self_test( int verbose );
Paul Bakker38119b12009-01-10 23:31:23 +0000346
Ron Eldorfa8f6352017-06-20 15:48:46 +0300347#endif /* MBEDTLS_SELF_TEST */
348
Paul Bakker38119b12009-01-10 23:31:23 +0000349#ifdef __cplusplus
350}
351#endif
352
353#endif /* camellia.h */