blob: e360aa64c1e4e89f431165a5742a05d3f4030f67 [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
Dave Rodgman7ff79652023-11-03 12:04:52 +000014 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000015 */
16
17#ifndef MBEDTLS_ARIA_H
18#define MBEDTLS_ARIA_H
19
20#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010021#include "mbedtls/config.h"
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000022#else
23#include MBEDTLS_CONFIG_FILE
24#endif
25
26#include <stddef.h>
27#include <stdint.h>
28
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010029#include "mbedtls/platform_util.h"
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050030
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010031#define MBEDTLS_ARIA_ENCRYPT 1 /**< ARIA encryption. */
32#define MBEDTLS_ARIA_DECRYPT 0 /**< ARIA decryption. */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000033
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +010034#define MBEDTLS_ARIA_BLOCKSIZE 16 /**< ARIA block size in bytes. */
Shaun Case0e7791f2021-12-20 21:14:10 -080035#define MBEDTLS_ARIA_MAX_ROUNDS 16 /**< Maximum number of rounds in ARIA. */
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +010036#define MBEDTLS_ARIA_MAX_KEYSIZE 32 /**< Maximum size of an ARIA key in bytes. */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010037
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050038#if !defined(MBEDTLS_DEPRECATED_REMOVED)
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010039#define MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(-0x005C)
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050040#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Gilles Peskinea3974432021-07-26 18:48:10 +020041/** Bad input data. */
42#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050043
Gilles Peskinea3974432021-07-26 18:48:10 +020044/** Invalid data input length. */
45#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E
Ron Eldor9924bdc2018-10-04 10:59:13 +030046
47/* MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE is deprecated and should not be used.
48 */
Gilles Peskinea3974432021-07-26 18:48:10 +020049/** Feature not available. For example, an unsupported ARIA key size. */
50#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A
Ron Eldor9924bdc2018-10-04 10:59:13 +030051
52/* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020053/** ARIA hardware accelerator failed. */
54#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000055
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000056#ifdef __cplusplus
57extern "C" {
58#endif
59
Gilles Peskinea8d07182021-05-24 22:58:37 +020060#if !defined(MBEDTLS_ARIA_ALT)
61// Regular implementation
62//
63
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000064/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010065 * \brief The ARIA context-type definition.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000066 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010067typedef struct mbedtls_aria_context {
Manuel Pégourié-Gonnard906bc902018-03-01 09:39:01 +010068 unsigned char nr; /*!< The number of rounds (12, 14 or 16) */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010069 /*! The ARIA round keys. */
70 uint32_t rk[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000071}
72mbedtls_aria_context;
73
Manuel Pégourié-Gonnard0960b802018-05-22 15:22:07 +020074#else /* MBEDTLS_ARIA_ALT */
75#include "aria_alt.h"
76#endif /* MBEDTLS_ARIA_ALT */
77
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000078/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010079 * \brief This function initializes the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000080 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010081 * It must be the first API called before using
82 * the context.
83 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050084 * \param ctx The ARIA context to initialize. This must not be \c NULL.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000085 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010086void mbedtls_aria_init(mbedtls_aria_context *ctx);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000087
88/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010089 * \brief This function releases and clears the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000090 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050091 * \param ctx The ARIA context to clear. This may be \c NULL, in which
92 * case this function returns immediately. If it is not \c NULL,
93 * it must point to an initialized ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000094 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010095void mbedtls_aria_free(mbedtls_aria_context *ctx);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000096
97/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010098 * \brief This function sets the encryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000099 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100100 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500101 * This must be initialized.
102 * \param key The encryption key. This must be a readable buffer
103 * of size \p keybits Bits.
104 * \param keybits The size of \p key in Bits. Valid options are:
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100105 * <ul><li>128 bits</li>
106 * <li>192 bits</li>
107 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000108 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500109 * \return \c 0 on success.
110 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000111 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100112int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
113 const unsigned char *key,
114 unsigned int keybits);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000115
116/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100117 * \brief This function sets the decryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000118 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100119 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500120 * This must be initialized.
121 * \param key The decryption key. This must be a readable buffer
122 * of size \p keybits Bits.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100123 * \param keybits The size of data passed. Valid options are:
124 * <ul><li>128 bits</li>
125 * <li>192 bits</li>
126 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000127 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500128 * \return \c 0 on success.
129 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000130 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100131int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
132 const unsigned char *key,
133 unsigned int keybits);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000134
135/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100136 * \brief This function performs an ARIA single-block encryption or
137 * decryption operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000138 *
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200139 * It performs encryption or decryption (depending on whether
140 * the key was set for encryption on decryption) on the input
141 * data buffer defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000142 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200143 * mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or
144 * mbedtls_aria_setkey_dec() must be called before the first
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100145 * call to this API with the same context.
146 *
147 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500148 * This must be initialized and bound to a key.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100149 * \param input The 16-Byte buffer holding the input data.
150 * \param output The 16-Byte buffer holding the output data.
151
152 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500153 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000154 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100155int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx,
156 const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
157 unsigned char output[MBEDTLS_ARIA_BLOCKSIZE]);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000158
159#if defined(MBEDTLS_CIPHER_MODE_CBC)
160/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100161 * \brief This function performs an ARIA-CBC encryption or decryption operation
162 * on full blocks.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000163 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100164 * It performs the operation defined in the \p mode
165 * parameter (encrypt/decrypt), on the input data buffer defined in
166 * the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000167 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100168 * It can be called as many times as needed, until all the input
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200169 * data is processed. mbedtls_aria_init(), and either
170 * mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100171 * before the first call to this API with the same context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000172 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100173 * \note This function operates on aligned blocks, that is, the input size
174 * must be a multiple of the ARIA block size of 16 Bytes.
175 *
176 * \note Upon exit, the content of the IV is updated so that you can
177 * call the same function again on the next
178 * block(s) of data and get the same result as if it was
179 * encrypted in one call. This allows a "streaming" usage.
180 * If you need to retain the contents of the IV, you should
181 * either save it manually or use the cipher module instead.
182 *
183 *
184 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500185 * This must be initialized and bound to a key.
186 * \param mode The mode of operation. This must be either
187 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
188 * #MBEDTLS_ARIA_DECRYPT for decryption.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100189 * \param length The length of the input data in Bytes. This must be a
190 * multiple of the block size (16 Bytes).
191 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500192 * This must be a readable buffer of size 16 Bytes.
193 * \param input The buffer holding the input data. This must
194 * be a readable buffer of length \p length Bytes.
195 * \param output The buffer holding the output data. This must
196 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100197 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500198 * \return \c 0 on success.
199 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000200 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100201int mbedtls_aria_crypt_cbc(mbedtls_aria_context *ctx,
202 int mode,
203 size_t length,
204 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
205 const unsigned char *input,
206 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000207#endif /* MBEDTLS_CIPHER_MODE_CBC */
208
209#if defined(MBEDTLS_CIPHER_MODE_CFB)
210/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100211 * \brief This function performs an ARIA-CFB128 encryption or decryption
212 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000213 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100214 * It performs the operation defined in the \p mode
215 * parameter (encrypt or decrypt), on the input data buffer
216 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000217 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200218 * For CFB, you must set up the context with mbedtls_aria_setkey_enc(),
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100219 * regardless of whether you are performing an encryption or decryption
220 * operation, that is, regardless of the \p mode parameter. This is
221 * because CFB mode uses the same key schedule for encryption and
222 * decryption.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000223 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100224 * \note Upon exit, the content of the IV is updated so that you can
225 * call the same function again on the next
226 * block(s) of data and get the same result as if it was
227 * encrypted in one call. This allows a "streaming" usage.
228 * If you need to retain the contents of the
229 * IV, you must either save it manually or use the cipher
230 * module instead.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000231 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100232 *
233 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500234 * This must be initialized and bound to a key.
235 * \param mode The mode of operation. This must be either
236 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
237 * #MBEDTLS_ARIA_DECRYPT for decryption.
238 * \param length The length of the input data \p input in Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100239 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500240 * This must not be larger than 15.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100241 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500242 * This must be a readable buffer of size 16 Bytes.
243 * \param input The buffer holding the input data. This must
244 * be a readable buffer of length \p length Bytes.
245 * \param output The buffer holding the output data. This must
246 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100247 *
248 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500249 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000250 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100251int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx,
252 int mode,
253 size_t length,
254 size_t *iv_off,
255 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
256 const unsigned char *input,
257 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000258#endif /* MBEDTLS_CIPHER_MODE_CFB */
259
260#if defined(MBEDTLS_CIPHER_MODE_CTR)
261/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100262 * \brief This function performs an ARIA-CTR encryption or decryption
263 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000264 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100265 * Due to the nature of CTR, you must use the same key schedule
266 * for both encryption and decryption operations. Therefore, you
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200267 * must use the context initialized with mbedtls_aria_setkey_enc()
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100268 * for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000269 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100270 * \warning You must never reuse a nonce value with the same key. Doing so
271 * would void the encryption for the two messages encrypted with
272 * the same nonce and key.
273 *
274 * There are two common strategies for managing nonces with CTR:
275 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200276 * 1. You can handle everything as a single message processed over
277 * successive calls to this function. In that case, you want to
278 * set \p nonce_counter and \p nc_off to 0 for the first call, and
279 * then preserve the values of \p nonce_counter, \p nc_off and \p
280 * stream_block across calls to this function as they will be
281 * updated by this function.
282 *
283 * With this strategy, you must not encrypt more than 2**128
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200284 * blocks of data with the same key.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100285 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200286 * 2. You can encrypt separate messages by dividing the \p
287 * nonce_counter buffer in two areas: the first one used for a
288 * per-message nonce, handled by yourself, and the second one
289 * updated by this function internally.
290 *
291 * For example, you might reserve the first 12 bytes for the
292 * per-message nonce, and the last 4 bytes for internal use. In that
293 * case, before calling this function on a new message you need to
294 * set the first 12 bytes of \p nonce_counter to your chosen nonce
295 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
296 * stream_block to be ignored). That way, you can encrypt at most
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200297 * 2**96 messages of up to 2**32 blocks each with the same key.
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200298 *
299 * The per-message nonce (or information sufficient to reconstruct
300 * it) needs to be communicated with the ciphertext and must be unique.
301 * The recommended way to ensure uniqueness is to use a message
302 * counter. An alternative is to generate random nonces, but this
303 * limits the number of messages that can be securely encrypted:
304 * for example, with 96-bit random nonces, you should not encrypt
305 * more than 2**32 messages with the same key.
306 *
Tom Cosgrove2b150752022-05-26 11:55:43 +0100307 * Note that for both strategies, sizes are measured in blocks and
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200308 * that an ARIA block is 16 bytes.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000309 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200310 * \warning Upon return, \p stream_block contains sensitive data. Its
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200311 * content must not be written to insecure storage and should be
312 * securely discarded as soon as it's no longer needed.
313 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100314 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500315 * This must be initialized and bound to a key.
316 * \param length The length of the input data \p input in Bytes.
317 * \param nc_off The offset in Bytes in the current \p stream_block,
318 * for resuming within the current cipher stream. The
319 * offset pointer should be \c 0 at the start of a
320 * stream. This must not be larger than \c 15 Bytes.
321 * \param nonce_counter The 128-bit nonce and counter. This must point to
322 * a read/write buffer of length \c 16 bytes.
323 * \param stream_block The saved stream block for resuming. This must
324 * point to a read/write buffer of length \c 16 bytes.
325 * This is overwritten by the function.
326 * \param input The buffer holding the input data. This must
327 * be a readable buffer of length \p length Bytes.
328 * \param output The buffer holding the output data. This must
329 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100330 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500331 * \return \c 0 on success.
332 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000333 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100334int mbedtls_aria_crypt_ctr(mbedtls_aria_context *ctx,
335 size_t length,
336 size_t *nc_off,
337 unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
338 unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
339 const unsigned char *input,
340 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000341#endif /* MBEDTLS_CIPHER_MODE_CTR */
342
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200343#if defined(MBEDTLS_SELF_TEST)
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000344/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100345 * \brief Checkup routine.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000346 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100347 * \return \c 0 on success, or \c 1 on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000348 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100349int mbedtls_aria_self_test(int verbose);
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200350#endif /* MBEDTLS_SELF_TEST */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000351
352#ifdef __cplusplus
353}
354#endif
355
356#endif /* aria.h */