blob: 226e2dbf3c82cc585fc7449a6d98da5be627dc6e [file] [log] [blame]
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +00001/**
2 * \file aria.h
3 *
4 * \brief ARIA block cipher
5 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +01006 * The ARIA algorithm is a symmetric block cipher that can encrypt and
7 * decrypt information. It is defined by the Korean Agency for
8 * Technology and Standards (KATS) in <em>KS X 1213:2004</em> (in
9 * Korean, but see http://210.104.33.10/ARIA/index-e.html in English)
10 * and also described by the IETF in <em>RFC 5794</em>.
11 */
Bence Szépkúti86974652020-06-15 11:59:37 +020012/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020013 * Copyright The Mbed TLS Contributors
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000014 * SPDX-License-Identifier: Apache-2.0
15 *
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.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000027 */
28
29#ifndef MBEDTLS_ARIA_H
30#define MBEDTLS_ARIA_H
31
32#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010033#include "mbedtls/config.h"
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000034#else
35#include MBEDTLS_CONFIG_FILE
36#endif
37
38#include <stddef.h>
39#include <stdint.h>
40
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010041#include "mbedtls/platform_util.h"
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050042
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010043#define MBEDTLS_ARIA_ENCRYPT 1 /**< ARIA encryption. */
44#define MBEDTLS_ARIA_DECRYPT 0 /**< ARIA decryption. */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000045
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +010046#define MBEDTLS_ARIA_BLOCKSIZE 16 /**< ARIA block size in bytes. */
47#define MBEDTLS_ARIA_MAX_ROUNDS 16 /**< Maxiumum number of rounds in ARIA. */
48#define MBEDTLS_ARIA_MAX_KEYSIZE 32 /**< Maximum size of an ARIA key in bytes. */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010049
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050050#if !defined(MBEDTLS_DEPRECATED_REMOVED)
51#define MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x005C )
52#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Gilles Peskinea3974432021-07-26 18:48:10 +020053/** Bad input data. */
54#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050055
Gilles Peskinea3974432021-07-26 18:48:10 +020056/** Invalid data input length. */
57#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E
Ron Eldor9924bdc2018-10-04 10:59:13 +030058
59/* MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE is deprecated and should not be used.
60 */
Gilles Peskinea3974432021-07-26 18:48:10 +020061/** Feature not available. For example, an unsupported ARIA key size. */
62#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A
Ron Eldor9924bdc2018-10-04 10:59:13 +030063
64/* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020065/** ARIA hardware accelerator failed. */
66#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000067
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000068#ifdef __cplusplus
69extern "C" {
70#endif
71
Gilles Peskinea8d07182021-05-24 22:58:37 +020072#if !defined(MBEDTLS_ARIA_ALT)
73// Regular implementation
74//
75
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000076/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010077 * \brief The ARIA context-type definition.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000078 */
Dawid Drozd428cc522018-07-24 10:02:47 +020079typedef struct mbedtls_aria_context
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000080{
Manuel Pégourié-Gonnard906bc902018-03-01 09:39:01 +010081 unsigned char nr; /*!< The number of rounds (12, 14 or 16) */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010082 /*! The ARIA round keys. */
83 uint32_t rk[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000084}
85mbedtls_aria_context;
86
Manuel Pégourié-Gonnard0960b802018-05-22 15:22:07 +020087#else /* MBEDTLS_ARIA_ALT */
88#include "aria_alt.h"
89#endif /* MBEDTLS_ARIA_ALT */
90
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000091/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010092 * \brief This function initializes the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000093 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010094 * It must be the first API called before using
95 * the context.
96 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050097 * \param ctx The ARIA context to initialize. This must not be \c NULL.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000098 */
99void mbedtls_aria_init( mbedtls_aria_context *ctx );
100
101/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100102 * \brief This function releases and clears the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000103 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500104 * \param ctx The ARIA context to clear. This may be \c NULL, in which
105 * case this function returns immediately. If it is not \c NULL,
106 * it must point to an initialized ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000107 */
108void mbedtls_aria_free( mbedtls_aria_context *ctx );
109
110/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100111 * \brief This function sets the encryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000112 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100113 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500114 * This must be initialized.
115 * \param key The encryption key. This must be a readable buffer
116 * of size \p keybits Bits.
117 * \param keybits The size of \p key in Bits. Valid options are:
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100118 * <ul><li>128 bits</li>
119 * <li>192 bits</li>
120 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000121 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500122 * \return \c 0 on success.
123 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000124 */
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100125int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx,
126 const unsigned char *key,
127 unsigned int keybits );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000128
129/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100130 * \brief This function sets the decryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000131 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100132 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500133 * This must be initialized.
134 * \param key The decryption key. This must be a readable buffer
135 * of size \p keybits Bits.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100136 * \param keybits The size of data passed. Valid options are:
137 * <ul><li>128 bits</li>
138 * <li>192 bits</li>
139 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000140 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500141 * \return \c 0 on success.
142 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000143 */
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100144int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx,
145 const unsigned char *key,
146 unsigned int keybits );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000147
148/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100149 * \brief This function performs an ARIA single-block encryption or
150 * decryption operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000151 *
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200152 * It performs encryption or decryption (depending on whether
153 * the key was set for encryption on decryption) on the input
154 * data buffer defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000155 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200156 * mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or
157 * mbedtls_aria_setkey_dec() must be called before the first
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100158 * call to this API with the same context.
159 *
160 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500161 * This must be initialized and bound to a key.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100162 * \param input The 16-Byte buffer holding the input data.
163 * \param output The 16-Byte buffer holding the output data.
164
165 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500166 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000167 */
168int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +0100169 const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
170 unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000171
172#if defined(MBEDTLS_CIPHER_MODE_CBC)
173/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100174 * \brief This function performs an ARIA-CBC encryption or decryption operation
175 * on full blocks.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000176 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100177 * It performs the operation defined in the \p mode
178 * parameter (encrypt/decrypt), on the input data buffer defined in
179 * the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000180 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100181 * It can be called as many times as needed, until all the input
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200182 * data is processed. mbedtls_aria_init(), and either
183 * mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100184 * before the first call to this API with the same context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000185 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100186 * \note This function operates on aligned blocks, that is, the input size
187 * must be a multiple of the ARIA block size of 16 Bytes.
188 *
189 * \note Upon exit, the content of the IV is updated so that you can
190 * call the same function again on the next
191 * block(s) of data and get the same result as if it was
192 * encrypted in one call. This allows a "streaming" usage.
193 * If you need to retain the contents of the IV, you should
194 * either save it manually or use the cipher module instead.
195 *
196 *
197 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500198 * This must be initialized and bound to a key.
199 * \param mode The mode of operation. This must be either
200 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
201 * #MBEDTLS_ARIA_DECRYPT for decryption.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100202 * \param length The length of the input data in Bytes. This must be a
203 * multiple of the block size (16 Bytes).
204 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500205 * This must be a readable buffer of size 16 Bytes.
206 * \param input The buffer holding the input data. This must
207 * be a readable buffer of length \p length Bytes.
208 * \param output The buffer holding the output data. This must
209 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100210 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500211 * \return \c 0 on success.
212 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000213 */
214int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100215 int mode,
216 size_t length,
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100217 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100218 const unsigned char *input,
219 unsigned char *output );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000220#endif /* MBEDTLS_CIPHER_MODE_CBC */
221
222#if defined(MBEDTLS_CIPHER_MODE_CFB)
223/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100224 * \brief This function performs an ARIA-CFB128 encryption or decryption
225 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000226 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100227 * It performs the operation defined in the \p mode
228 * parameter (encrypt or decrypt), on the input data buffer
229 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000230 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200231 * For CFB, you must set up the context with mbedtls_aria_setkey_enc(),
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100232 * regardless of whether you are performing an encryption or decryption
233 * operation, that is, regardless of the \p mode parameter. This is
234 * because CFB mode uses the same key schedule for encryption and
235 * decryption.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000236 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100237 * \note Upon exit, the content of the IV is updated so that you can
238 * call the same function again on the next
239 * block(s) of data and get the same result as if it was
240 * encrypted in one call. This allows a "streaming" usage.
241 * If you need to retain the contents of the
242 * IV, you must either save it manually or use the cipher
243 * module instead.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000244 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100245 *
246 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500247 * This must be initialized and bound to a key.
248 * \param mode The mode of operation. This must be either
249 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
250 * #MBEDTLS_ARIA_DECRYPT for decryption.
251 * \param length The length of the input data \p input in Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100252 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500253 * This must not be larger than 15.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100254 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500255 * This must be a readable buffer of size 16 Bytes.
256 * \param input The buffer holding the input data. This must
257 * be a readable buffer of length \p length Bytes.
258 * \param output The buffer holding the output data. This must
259 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100260 *
261 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500262 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000263 */
264int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100265 int mode,
266 size_t length,
267 size_t *iv_off,
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +0100268 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100269 const unsigned char *input,
270 unsigned char *output );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000271#endif /* MBEDTLS_CIPHER_MODE_CFB */
272
273#if defined(MBEDTLS_CIPHER_MODE_CTR)
274/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100275 * \brief This function performs an ARIA-CTR encryption or decryption
276 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000277 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100278 * This function performs the operation defined in the \p mode
279 * parameter (encrypt/decrypt), on the input data buffer
280 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000281 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100282 * Due to the nature of CTR, you must use the same key schedule
283 * for both encryption and decryption operations. Therefore, you
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200284 * must use the context initialized with mbedtls_aria_setkey_enc()
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100285 * for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000286 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100287 * \warning You must never reuse a nonce value with the same key. Doing so
288 * would void the encryption for the two messages encrypted with
289 * the same nonce and key.
290 *
291 * There are two common strategies for managing nonces with CTR:
292 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200293 * 1. You can handle everything as a single message processed over
294 * successive calls to this function. In that case, you want to
295 * set \p nonce_counter and \p nc_off to 0 for the first call, and
296 * then preserve the values of \p nonce_counter, \p nc_off and \p
297 * stream_block across calls to this function as they will be
298 * updated by this function.
299 *
300 * With this strategy, you must not encrypt more than 2**128
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200301 * blocks of data with the same key.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100302 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200303 * 2. You can encrypt separate messages by dividing the \p
304 * nonce_counter buffer in two areas: the first one used for a
305 * per-message nonce, handled by yourself, and the second one
306 * updated by this function internally.
307 *
308 * For example, you might reserve the first 12 bytes for the
309 * per-message nonce, and the last 4 bytes for internal use. In that
310 * case, before calling this function on a new message you need to
311 * set the first 12 bytes of \p nonce_counter to your chosen nonce
312 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
313 * stream_block to be ignored). That way, you can encrypt at most
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200314 * 2**96 messages of up to 2**32 blocks each with the same key.
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200315 *
316 * The per-message nonce (or information sufficient to reconstruct
317 * it) needs to be communicated with the ciphertext and must be unique.
318 * The recommended way to ensure uniqueness is to use a message
319 * counter. An alternative is to generate random nonces, but this
320 * limits the number of messages that can be securely encrypted:
321 * for example, with 96-bit random nonces, you should not encrypt
322 * more than 2**32 messages with the same key.
323 *
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200324 * Note that for both stategies, sizes are measured in blocks and
325 * that an ARIA block is 16 bytes.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000326 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200327 * \warning Upon return, \p stream_block contains sensitive data. Its
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200328 * content must not be written to insecure storage and should be
329 * securely discarded as soon as it's no longer needed.
330 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100331 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500332 * This must be initialized and bound to a key.
333 * \param length The length of the input data \p input in Bytes.
334 * \param nc_off The offset in Bytes in the current \p stream_block,
335 * for resuming within the current cipher stream. The
336 * offset pointer should be \c 0 at the start of a
337 * stream. This must not be larger than \c 15 Bytes.
338 * \param nonce_counter The 128-bit nonce and counter. This must point to
339 * a read/write buffer of length \c 16 bytes.
340 * \param stream_block The saved stream block for resuming. This must
341 * point to a read/write buffer of length \c 16 bytes.
342 * This is overwritten by the function.
343 * \param input The buffer holding the input data. This must
344 * be a readable buffer of length \p length Bytes.
345 * \param output The buffer holding the output data. This must
346 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100347 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500348 * \return \c 0 on success.
349 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000350 */
351int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100352 size_t length,
353 size_t *nc_off,
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +0100354 unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
355 unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100356 const unsigned char *input,
357 unsigned char *output );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000358#endif /* MBEDTLS_CIPHER_MODE_CTR */
359
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200360#if defined(MBEDTLS_SELF_TEST)
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000361/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100362 * \brief Checkup routine.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000363 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100364 * \return \c 0 on success, or \c 1 on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000365 */
366int mbedtls_aria_self_test( int verbose );
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200367#endif /* MBEDTLS_SELF_TEST */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000368
369#ifdef __cplusplus
370}
371#endif
372
373#endif /* aria.h */