blob: 62c4aa43e8289bd85ec4501b0c14c0ad59ed6e83 [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
Mateusz Starzyk846f0212021-05-19 19:44:07 +020031#include "mbedtls/private_access.h"
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000032
Bence Szépkútic662b362021-05-27 11:25:03 +020033#include "mbedtls/build_info.h"
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000034
35#include <stddef.h>
36#include <stdint.h>
37
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010038#include "mbedtls/platform_util.h"
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050039
Mateusz Starzyk16fec332021-07-22 16:43:35 +020040/** ARIA encryption. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020041#define MBEDTLS_ARIA_ENCRYPT 1
Mateusz Starzyk16fec332021-07-22 16:43:35 +020042/** ARIA decryption. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020043#define MBEDTLS_ARIA_DECRYPT 0
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000044
Mateusz Starzyk16fec332021-07-22 16:43:35 +020045/** ARIA block size in bytes. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020046#define MBEDTLS_ARIA_BLOCKSIZE 16
Mateusz Starzyk16fec332021-07-22 16:43:35 +020047/** Maxiumum number of rounds in ARIA. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020048#define MBEDTLS_ARIA_MAX_ROUNDS 16
Mateusz Starzyk16fec332021-07-22 16:43:35 +020049/** Maximum size of an ARIA key in bytes. */
50#define MBEDTLS_ARIA_MAX_KEYSIZE 32
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010051
Gilles Peskined2971572021-07-26 18:48:10 +020052/** Bad input data. */
53#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050054
Gilles Peskined2971572021-07-26 18:48:10 +020055/** Invalid data input length. */
56#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E
Ron Eldor9924bdc2018-10-04 10:59:13 +030057
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000058#ifdef __cplusplus
59extern "C" {
60#endif
61
Gilles Peskine59392b02021-05-24 22:58:37 +020062#if !defined(MBEDTLS_ARIA_ALT)
63// Regular implementation
64//
65
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000066/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010067 * \brief The ARIA context-type definition.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000068 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020069typedef struct mbedtls_aria_context {
70 unsigned char MBEDTLS_PRIVATE(nr); /*!< The number of rounds (12, 14 or 16)
71 */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010072 /*! The ARIA round keys. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020073 uint32_t MBEDTLS_PRIVATE(rk)[MBEDTLS_ARIA_MAX_ROUNDS + 1]
74 [MBEDTLS_ARIA_BLOCKSIZE / 4];
75} mbedtls_aria_context;
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000076
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020077#else /* MBEDTLS_ARIA_ALT */
78# include "aria_alt.h"
Manuel Pégourié-Gonnard0960b802018-05-22 15:22:07 +020079#endif /* MBEDTLS_ARIA_ALT */
80
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000081/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010082 * \brief This function initializes the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000083 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010084 * It must be the first API called before using
85 * the context.
86 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050087 * \param ctx The ARIA context to initialize. This must not be \c NULL.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000088 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020089void mbedtls_aria_init(mbedtls_aria_context *ctx);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000090
91/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010092 * \brief This function releases and clears the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000093 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050094 * \param ctx The ARIA context to clear. This may be \c NULL, in which
95 * case this function returns immediately. If it is not \c NULL,
96 * it must point to an initialized ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000097 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020098void mbedtls_aria_free(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 sets the encryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000102 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100103 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500104 * This must be initialized.
105 * \param key The encryption key. This must be a readable buffer
106 * of size \p keybits Bits.
107 * \param keybits The size of \p key in Bits. Valid options are:
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100108 * <ul><li>128 bits</li>
109 * <li>192 bits</li>
110 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000111 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500112 * \return \c 0 on success.
113 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000114 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200115int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
116 const unsigned char *key,
117 unsigned int keybits);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000118
119/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100120 * \brief This function sets the decryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000121 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100122 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500123 * This must be initialized.
124 * \param key The decryption key. This must be a readable buffer
125 * of size \p keybits Bits.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100126 * \param keybits The size of data passed. Valid options are:
127 * <ul><li>128 bits</li>
128 * <li>192 bits</li>
129 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000130 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500131 * \return \c 0 on success.
132 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000133 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200134int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
135 const unsigned char *key,
136 unsigned int keybits);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000137
138/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100139 * \brief This function performs an ARIA single-block encryption or
140 * decryption operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000141 *
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200142 * It performs encryption or decryption (depending on whether
143 * the key was set for encryption on decryption) on the input
144 * data buffer defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000145 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200146 * mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or
147 * mbedtls_aria_setkey_dec() must be called before the first
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100148 * call to this API with the same context.
149 *
150 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500151 * This must be initialized and bound to a key.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100152 * \param input The 16-Byte buffer holding the input data.
153 * \param output The 16-Byte buffer holding the output data.
154
155 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500156 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000157 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200158int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx,
159 const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
160 unsigned char output[MBEDTLS_ARIA_BLOCKSIZE]);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000161
162#if defined(MBEDTLS_CIPHER_MODE_CBC)
163/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100164 * \brief This function performs an ARIA-CBC encryption or decryption operation
165 * on full blocks.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000166 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100167 * It performs the operation defined in the \p mode
168 * parameter (encrypt/decrypt), on the input data buffer defined in
169 * the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000170 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100171 * It can be called as many times as needed, until all the input
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200172 * data is processed. mbedtls_aria_init(), and either
173 * mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100174 * before the first call to this API with the same context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000175 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100176 * \note This function operates on aligned blocks, that is, the input size
177 * must be a multiple of the ARIA block size of 16 Bytes.
178 *
179 * \note Upon exit, the content of the IV is updated so that you can
180 * call the same function again on the next
181 * block(s) of data and get the same result as if it was
182 * encrypted in one call. This allows a "streaming" usage.
183 * If you need to retain the contents of the IV, you should
184 * either save it manually or use the cipher module instead.
185 *
186 *
187 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500188 * This must be initialized and bound to a key.
189 * \param mode The mode of operation. This must be either
190 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
191 * #MBEDTLS_ARIA_DECRYPT for decryption.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100192 * \param length The length of the input data in Bytes. This must be a
193 * multiple of the block size (16 Bytes).
194 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500195 * This must be a readable buffer of size 16 Bytes.
196 * \param input The buffer holding the input data. This must
197 * be a readable buffer of length \p length Bytes.
198 * \param output The buffer holding the output data. This must
199 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100200 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500201 * \return \c 0 on success.
202 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000203 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200204int mbedtls_aria_crypt_cbc(mbedtls_aria_context *ctx,
205 int mode,
206 size_t length,
207 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
208 const unsigned char *input,
209 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000210#endif /* MBEDTLS_CIPHER_MODE_CBC */
211
212#if defined(MBEDTLS_CIPHER_MODE_CFB)
213/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100214 * \brief This function performs an ARIA-CFB128 encryption or decryption
215 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000216 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100217 * It performs the operation defined in the \p mode
218 * parameter (encrypt or decrypt), on the input data buffer
219 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000220 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200221 * For CFB, you must set up the context with mbedtls_aria_setkey_enc(),
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100222 * regardless of whether you are performing an encryption or decryption
223 * operation, that is, regardless of the \p mode parameter. This is
224 * because CFB mode uses the same key schedule for encryption and
225 * decryption.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000226 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100227 * \note Upon exit, the content of the IV is updated so that you can
228 * call the same function again on the next
229 * block(s) of data and get the same result as if it was
230 * encrypted in one call. This allows a "streaming" usage.
231 * If you need to retain the contents of the
232 * IV, you must either save it manually or use the cipher
233 * module instead.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000234 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100235 *
236 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500237 * This must be initialized and bound to a key.
238 * \param mode The mode of operation. This must be either
239 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
240 * #MBEDTLS_ARIA_DECRYPT for decryption.
241 * \param length The length of the input data \p input in Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100242 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500243 * This must not be larger than 15.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100244 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500245 * This must be a readable buffer of size 16 Bytes.
246 * \param input The buffer holding the input data. This must
247 * be a readable buffer of length \p length Bytes.
248 * \param output The buffer holding the output data. This must
249 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100250 *
251 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500252 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000253 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200254int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx,
255 int mode,
256 size_t length,
257 size_t *iv_off,
258 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
259 const unsigned char *input,
260 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000261#endif /* MBEDTLS_CIPHER_MODE_CFB */
262
263#if defined(MBEDTLS_CIPHER_MODE_CTR)
264/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100265 * \brief This function performs an ARIA-CTR encryption or decryption
266 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000267 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100268 * This function performs the operation defined in the \p mode
269 * parameter (encrypt/decrypt), on the input data buffer
270 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000271 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100272 * Due to the nature of CTR, you must use the same key schedule
273 * for both encryption and decryption operations. Therefore, you
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200274 * must use the context initialized with mbedtls_aria_setkey_enc()
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100275 * for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000276 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100277 * \warning You must never reuse a nonce value with the same key. Doing so
278 * would void the encryption for the two messages encrypted with
279 * the same nonce and key.
280 *
281 * There are two common strategies for managing nonces with CTR:
282 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200283 * 1. You can handle everything as a single message processed over
284 * successive calls to this function. In that case, you want to
285 * set \p nonce_counter and \p nc_off to 0 for the first call, and
286 * then preserve the values of \p nonce_counter, \p nc_off and \p
287 * stream_block across calls to this function as they will be
288 * updated by this function.
289 *
290 * With this strategy, you must not encrypt more than 2**128
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200291 * blocks of data with the same key.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100292 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200293 * 2. You can encrypt separate messages by dividing the \p
294 * nonce_counter buffer in two areas: the first one used for a
295 * per-message nonce, handled by yourself, and the second one
296 * updated by this function internally.
297 *
298 * For example, you might reserve the first 12 bytes for the
299 * per-message nonce, and the last 4 bytes for internal use. In that
300 * case, before calling this function on a new message you need to
301 * set the first 12 bytes of \p nonce_counter to your chosen nonce
302 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
303 * stream_block to be ignored). That way, you can encrypt at most
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200304 * 2**96 messages of up to 2**32 blocks each with the same key.
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200305 *
306 * The per-message nonce (or information sufficient to reconstruct
307 * it) needs to be communicated with the ciphertext and must be unique.
308 * The recommended way to ensure uniqueness is to use a message
309 * counter. An alternative is to generate random nonces, but this
310 * limits the number of messages that can be securely encrypted:
311 * for example, with 96-bit random nonces, you should not encrypt
312 * more than 2**32 messages with the same key.
313 *
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200314 * Note that for both stategies, sizes are measured in blocks and
315 * that an ARIA block is 16 bytes.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000316 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200317 * \warning Upon return, \p stream_block contains sensitive data. Its
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200318 * content must not be written to insecure storage and should be
319 * securely discarded as soon as it's no longer needed.
320 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100321 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500322 * This must be initialized and bound to a key.
323 * \param length The length of the input data \p input in Bytes.
324 * \param nc_off The offset in Bytes in the current \p stream_block,
325 * for resuming within the current cipher stream. The
326 * offset pointer should be \c 0 at the start of a
327 * stream. This must not be larger than \c 15 Bytes.
328 * \param nonce_counter The 128-bit nonce and counter. This must point to
329 * a read/write buffer of length \c 16 bytes.
330 * \param stream_block The saved stream block for resuming. This must
331 * point to a read/write buffer of length \c 16 bytes.
332 * This is overwritten by the function.
333 * \param input The buffer holding the input data. This must
334 * be a readable buffer of length \p length Bytes.
335 * \param output The buffer holding the output data. This must
336 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100337 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500338 * \return \c 0 on success.
339 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000340 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200341int mbedtls_aria_crypt_ctr(mbedtls_aria_context *ctx,
342 size_t length,
343 size_t *nc_off,
344 unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
345 unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
346 const unsigned char *input,
347 unsigned char *output);
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000348#endif /* MBEDTLS_CIPHER_MODE_CTR */
349
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200350#if defined(MBEDTLS_SELF_TEST)
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000351/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100352 * \brief Checkup routine.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000353 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100354 * \return \c 0 on success, or \c 1 on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000355 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200356int mbedtls_aria_self_test(int verbose);
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200357#endif /* MBEDTLS_SELF_TEST */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000358
359#ifdef __cplusplus
360}
361#endif
362
363#endif /* aria.h */