blob: 9856a1cae7ee147af714bfc9985db8f888cdd13e [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. */
Shaun Case0e7791f2021-12-20 21:14:10 -080047#define MBEDTLS_ARIA_MAX_ROUNDS 16 /**< Maximum number of rounds in ARIA. */
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +010048#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)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010051#define MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(-0x005C)
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050052#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 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010079typedef struct mbedtls_aria_context {
Manuel Pégourié-Gonnard906bc902018-03-01 09:39:01 +010080 unsigned char nr; /*!< The number of rounds (12, 14 or 16) */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010081 /*! The ARIA round keys. */
82 uint32_t rk[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000083}
84mbedtls_aria_context;
85
Manuel Pégourié-Gonnard0960b802018-05-22 15:22:07 +020086#else /* MBEDTLS_ARIA_ALT */
87#include "aria_alt.h"
88#endif /* MBEDTLS_ARIA_ALT */
89
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000090/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010091 * \brief This function initializes the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000092 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010093 * It must be the first API called before using
94 * the context.
95 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050096 * \param ctx The ARIA context to initialize. This must not be \c NULL.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000097 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010098void mbedtls_aria_init(mbedtls_aria_context *ctx);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000099
100/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100101 * \brief This function releases and clears the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000102 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500103 * \param ctx The ARIA context to clear. This may be \c NULL, in which
104 * case this function returns immediately. If it is not \c NULL,
105 * it must point to an initialized ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000106 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100107void mbedtls_aria_free(mbedtls_aria_context *ctx);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000108
109/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100110 * \brief This function sets the encryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000111 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100112 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500113 * This must be initialized.
114 * \param key The encryption key. This must be a readable buffer
115 * of size \p keybits Bits.
116 * \param keybits The size of \p key in Bits. Valid options are:
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100117 * <ul><li>128 bits</li>
118 * <li>192 bits</li>
119 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000120 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500121 * \return \c 0 on success.
122 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000123 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100124int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
125 const unsigned char *key,
126 unsigned int keybits);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000127
128/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100129 * \brief This function sets the decryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000130 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100131 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500132 * This must be initialized.
133 * \param key The decryption key. This must be a readable buffer
134 * of size \p keybits Bits.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100135 * \param keybits The size of data passed. Valid options are:
136 * <ul><li>128 bits</li>
137 * <li>192 bits</li>
138 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000139 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500140 * \return \c 0 on success.
141 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000142 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100143int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
144 const unsigned char *key,
145 unsigned int keybits);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000146
147/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100148 * \brief This function performs an ARIA single-block encryption or
149 * decryption operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000150 *
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200151 * It performs encryption or decryption (depending on whether
152 * the key was set for encryption on decryption) on the input
153 * data buffer defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000154 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200155 * mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or
156 * mbedtls_aria_setkey_dec() must be called before the first
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100157 * call to this API with the same context.
158 *
159 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500160 * This must be initialized and bound to a key.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100161 * \param input The 16-Byte buffer holding the input data.
162 * \param output The 16-Byte buffer holding the output data.
163
164 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500165 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000166 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100167int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx,
168 const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
169 unsigned char output[MBEDTLS_ARIA_BLOCKSIZE]);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000170
171#if defined(MBEDTLS_CIPHER_MODE_CBC)
172/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100173 * \brief This function performs an ARIA-CBC encryption or decryption operation
174 * on full blocks.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000175 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100176 * It performs the operation defined in the \p mode
177 * parameter (encrypt/decrypt), on the input data buffer defined in
178 * the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000179 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100180 * It can be called as many times as needed, until all the input
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200181 * data is processed. mbedtls_aria_init(), and either
182 * mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100183 * before the first call to this API with the same context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000184 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100185 * \note This function operates on aligned blocks, that is, the input size
186 * must be a multiple of the ARIA block size of 16 Bytes.
187 *
188 * \note Upon exit, the content of the IV is updated so that you can
189 * call the same function again on the next
190 * block(s) of data and get the same result as if it was
191 * encrypted in one call. This allows a "streaming" usage.
192 * If you need to retain the contents of the IV, you should
193 * either save it manually or use the cipher module instead.
194 *
195 *
196 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500197 * This must be initialized and bound to a key.
198 * \param mode The mode of operation. This must be either
199 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
200 * #MBEDTLS_ARIA_DECRYPT for decryption.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100201 * \param length The length of the input data in Bytes. This must be a
202 * multiple of the block size (16 Bytes).
203 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500204 * This must be a readable buffer of size 16 Bytes.
205 * \param input The buffer holding the input data. This must
206 * be a readable buffer of length \p length Bytes.
207 * \param output The buffer holding the output data. This must
208 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100209 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500210 * \return \c 0 on success.
211 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000212 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100213int mbedtls_aria_crypt_cbc(mbedtls_aria_context *ctx,
214 int mode,
215 size_t length,
216 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
217 const unsigned char *input,
218 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000219#endif /* MBEDTLS_CIPHER_MODE_CBC */
220
221#if defined(MBEDTLS_CIPHER_MODE_CFB)
222/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100223 * \brief This function performs an ARIA-CFB128 encryption or decryption
224 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000225 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100226 * It performs the operation defined in the \p mode
227 * parameter (encrypt or decrypt), on the input data buffer
228 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000229 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200230 * For CFB, you must set up the context with mbedtls_aria_setkey_enc(),
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100231 * regardless of whether you are performing an encryption or decryption
232 * operation, that is, regardless of the \p mode parameter. This is
233 * because CFB mode uses the same key schedule for encryption and
234 * decryption.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000235 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100236 * \note Upon exit, the content of the IV is updated so that you can
237 * call the same function again on the next
238 * block(s) of data and get the same result as if it was
239 * encrypted in one call. This allows a "streaming" usage.
240 * If you need to retain the contents of the
241 * IV, you must either save it manually or use the cipher
242 * module instead.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000243 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100244 *
245 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500246 * This must be initialized and bound to a key.
247 * \param mode The mode of operation. This must be either
248 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
249 * #MBEDTLS_ARIA_DECRYPT for decryption.
250 * \param length The length of the input data \p input in Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100251 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500252 * This must not be larger than 15.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100253 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500254 * This must be a readable buffer of size 16 Bytes.
255 * \param input The buffer holding the input data. This must
256 * be a readable buffer of length \p length Bytes.
257 * \param output The buffer holding the output data. This must
258 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100259 *
260 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500261 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000262 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100263int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx,
264 int mode,
265 size_t length,
266 size_t *iv_off,
267 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
268 const unsigned char *input,
269 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000270#endif /* MBEDTLS_CIPHER_MODE_CFB */
271
272#if defined(MBEDTLS_CIPHER_MODE_CTR)
273/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100274 * \brief This function performs an ARIA-CTR encryption or decryption
275 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000276 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100277 * This function performs the operation defined in the \p mode
278 * parameter (encrypt/decrypt), on the input data buffer
279 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000280 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100281 * Due to the nature of CTR, you must use the same key schedule
282 * for both encryption and decryption operations. Therefore, you
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200283 * must use the context initialized with mbedtls_aria_setkey_enc()
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100284 * for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000285 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100286 * \warning You must never reuse a nonce value with the same key. Doing so
287 * would void the encryption for the two messages encrypted with
288 * the same nonce and key.
289 *
290 * There are two common strategies for managing nonces with CTR:
291 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200292 * 1. You can handle everything as a single message processed over
293 * successive calls to this function. In that case, you want to
294 * set \p nonce_counter and \p nc_off to 0 for the first call, and
295 * then preserve the values of \p nonce_counter, \p nc_off and \p
296 * stream_block across calls to this function as they will be
297 * updated by this function.
298 *
299 * With this strategy, you must not encrypt more than 2**128
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200300 * blocks of data with the same key.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100301 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200302 * 2. You can encrypt separate messages by dividing the \p
303 * nonce_counter buffer in two areas: the first one used for a
304 * per-message nonce, handled by yourself, and the second one
305 * updated by this function internally.
306 *
307 * For example, you might reserve the first 12 bytes for the
308 * per-message nonce, and the last 4 bytes for internal use. In that
309 * case, before calling this function on a new message you need to
310 * set the first 12 bytes of \p nonce_counter to your chosen nonce
311 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
312 * stream_block to be ignored). That way, you can encrypt at most
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200313 * 2**96 messages of up to 2**32 blocks each with the same key.
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200314 *
315 * The per-message nonce (or information sufficient to reconstruct
316 * it) needs to be communicated with the ciphertext and must be unique.
317 * The recommended way to ensure uniqueness is to use a message
318 * counter. An alternative is to generate random nonces, but this
319 * limits the number of messages that can be securely encrypted:
320 * for example, with 96-bit random nonces, you should not encrypt
321 * more than 2**32 messages with the same key.
322 *
Tom Cosgrove2b150752022-05-26 11:55:43 +0100323 * Note that for both strategies, sizes are measured in blocks and
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200324 * that an ARIA block is 16 bytes.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000325 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200326 * \warning Upon return, \p stream_block contains sensitive data. Its
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200327 * content must not be written to insecure storage and should be
328 * securely discarded as soon as it's no longer needed.
329 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100330 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500331 * This must be initialized and bound to a key.
332 * \param length The length of the input data \p input in Bytes.
333 * \param nc_off The offset in Bytes in the current \p stream_block,
334 * for resuming within the current cipher stream. The
335 * offset pointer should be \c 0 at the start of a
336 * stream. This must not be larger than \c 15 Bytes.
337 * \param nonce_counter The 128-bit nonce and counter. This must point to
338 * a read/write buffer of length \c 16 bytes.
339 * \param stream_block The saved stream block for resuming. This must
340 * point to a read/write buffer of length \c 16 bytes.
341 * This is overwritten by the function.
342 * \param input The buffer holding the input data. This must
343 * be a readable buffer of length \p length Bytes.
344 * \param output The buffer holding the output data. This must
345 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100346 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500347 * \return \c 0 on success.
348 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000349 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100350int mbedtls_aria_crypt_ctr(mbedtls_aria_context *ctx,
351 size_t length,
352 size_t *nc_off,
353 unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
354 unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
355 const unsigned char *input,
356 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000357#endif /* MBEDTLS_CIPHER_MODE_CTR */
358
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200359#if defined(MBEDTLS_SELF_TEST)
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000360/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100361 * \brief Checkup routine.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000362 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100363 * \return \c 0 on success, or \c 1 on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000364 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100365int mbedtls_aria_self_test(int verbose);
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200366#endif /* MBEDTLS_SELF_TEST */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000367
368#ifdef __cplusplus
369}
370#endif
371
372#endif /* aria.h */