blob: f99e76fb6cc2fc05e8066debebeeee695c645ae7 [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/*
13 * Copyright (C) 2006-2018, ARM Limited, All Rights Reserved
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.
27 *
28 * This file is part of mbed TLS (https://tls.mbed.org)
29 */
30
31#ifndef MBEDTLS_ARIA_H
32#define MBEDTLS_ARIA_H
33
34#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010035#include "mbedtls/config.h"
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000036#else
37#include MBEDTLS_CONFIG_FILE
38#endif
39
40#include <stddef.h>
41#include <stdint.h>
42
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010043#include "mbedtls/platform_util.h"
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050044
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010045#define MBEDTLS_ARIA_ENCRYPT 1 /**< ARIA encryption. */
46#define MBEDTLS_ARIA_DECRYPT 0 /**< ARIA decryption. */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000047
Manuel Pégourié-Gonnard8abc3492018-03-01 10:02:47 +010048#define MBEDTLS_ARIA_BLOCKSIZE 16 /**< ARIA block size in bytes. */
49#define MBEDTLS_ARIA_MAX_ROUNDS 16 /**< Maxiumum number of rounds in ARIA. */
50#define MBEDTLS_ARIA_MAX_KEYSIZE 32 /**< Maximum size of an ARIA key in bytes. */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010051
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050052#if !defined(MBEDTLS_DEPRECATED_REMOVED)
53#define MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x005C )
54#endif /* !MBEDTLS_DEPRECATED_REMOVED */
55#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C /**< Bad input data. */
56
57#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E /**< Invalid data input length. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030058
59/* MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE is deprecated and should not be used.
60 */
Manuel Pégourié-Gonnard3c800092018-03-01 09:02:16 +010061#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A /**< Feature not available. For example, an unsupported ARIA key size. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030062
63/* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */
Manuel Pégourié-Gonnard3c800092018-03-01 09:02:16 +010064#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058 /**< ARIA hardware accelerator failed. */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000065
66#if !defined(MBEDTLS_ARIA_ALT)
67// Regular implementation
68//
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010075 * \brief The ARIA context-type definition.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000076 */
Dawid Drozd428cc522018-07-24 10:02:47 +020077typedef struct mbedtls_aria_context
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000078{
Manuel Pégourié-Gonnard906bc902018-03-01 09:39:01 +010079 unsigned char nr; /*!< The number of rounds (12, 14 or 16) */
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +010080 /*! The ARIA round keys. */
81 uint32_t rk[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000082}
83mbedtls_aria_context;
84
Manuel Pégourié-Gonnard0960b802018-05-22 15:22:07 +020085#else /* MBEDTLS_ARIA_ALT */
86#include "aria_alt.h"
87#endif /* MBEDTLS_ARIA_ALT */
88
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000089/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010090 * \brief This function initializes the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000091 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +010092 * It must be the first API called before using
93 * the context.
94 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050095 * \param ctx The ARIA context to initialize. This must not be \c NULL.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +000096 */
97void mbedtls_aria_init( mbedtls_aria_context *ctx );
98
99/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100100 * \brief This function releases and clears the specified ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000101 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500102 * \param ctx The ARIA context to clear. This may be \c NULL, in which
103 * case this function returns immediately. If it is not \c NULL,
104 * it must point to an initialized ARIA context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000105 */
106void mbedtls_aria_free( mbedtls_aria_context *ctx );
107
108/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100109 * \brief This function sets the encryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000110 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100111 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500112 * This must be initialized.
113 * \param key The encryption key. This must be a readable buffer
114 * of size \p keybits Bits.
115 * \param keybits The size of \p key in Bits. Valid options are:
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100116 * <ul><li>128 bits</li>
117 * <li>192 bits</li>
118 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000119 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500120 * \return \c 0 on success.
121 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000122 */
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100123int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx,
124 const unsigned char *key,
125 unsigned int keybits );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000126
127/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100128 * \brief This function sets the decryption key.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000129 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100130 * \param ctx The ARIA context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500131 * This must be initialized.
132 * \param key The decryption key. This must be a readable buffer
133 * of size \p keybits Bits.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100134 * \param keybits The size of data passed. Valid options are:
135 * <ul><li>128 bits</li>
136 * <li>192 bits</li>
137 * <li>256 bits</li></ul>
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000138 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500139 * \return \c 0 on success.
140 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000141 */
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100142int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx,
143 const unsigned char *key,
144 unsigned int keybits );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000145
146/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100147 * \brief This function performs an ARIA single-block encryption or
148 * decryption operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000149 *
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200150 * It performs encryption or decryption (depending on whether
151 * the key was set for encryption on decryption) on the input
152 * data buffer defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000153 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200154 * mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or
155 * mbedtls_aria_setkey_dec() must be called before the first
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100156 * call to this API with the same context.
157 *
158 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500159 * This must be initialized and bound to a key.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100160 * \param input The 16-Byte buffer holding the input data.
161 * \param output The 16-Byte buffer holding the output data.
162
163 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500164 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000165 */
166int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +0100167 const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
168 unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000169
170#if defined(MBEDTLS_CIPHER_MODE_CBC)
171/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100172 * \brief This function performs an ARIA-CBC encryption or decryption operation
173 * on full blocks.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000174 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100175 * It performs the operation defined in the \p mode
176 * parameter (encrypt/decrypt), on the input data buffer defined in
177 * the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000178 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100179 * It can be called as many times as needed, until all the input
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200180 * data is processed. mbedtls_aria_init(), and either
181 * mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100182 * before the first call to this API with the same context.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000183 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100184 * \note This function operates on aligned blocks, that is, the input size
185 * must be a multiple of the ARIA block size of 16 Bytes.
186 *
187 * \note Upon exit, the content of the IV is updated so that you can
188 * call the same function again on the next
189 * block(s) of data and get the same result as if it was
190 * encrypted in one call. This allows a "streaming" usage.
191 * If you need to retain the contents of the IV, you should
192 * either save it manually or use the cipher module instead.
193 *
194 *
195 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500196 * This must be initialized and bound to a key.
197 * \param mode The mode of operation. This must be either
198 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
199 * #MBEDTLS_ARIA_DECRYPT for decryption.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100200 * \param length The length of the input data in Bytes. This must be a
201 * multiple of the block size (16 Bytes).
202 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500203 * This must be a readable buffer of size 16 Bytes.
204 * \param input The buffer holding the input data. This must
205 * be a readable buffer of length \p length Bytes.
206 * \param output The buffer holding the output data. This must
207 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100208 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500209 * \return \c 0 on success.
210 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000211 */
212int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100213 int mode,
214 size_t length,
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100215 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100216 const unsigned char *input,
217 unsigned char *output );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000218#endif /* MBEDTLS_CIPHER_MODE_CBC */
219
220#if defined(MBEDTLS_CIPHER_MODE_CFB)
221/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100222 * \brief This function performs an ARIA-CFB128 encryption or decryption
223 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000224 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100225 * It performs the operation defined in the \p mode
226 * parameter (encrypt or decrypt), on the input data buffer
227 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000228 *
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200229 * For CFB, you must set up the context with mbedtls_aria_setkey_enc(),
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100230 * regardless of whether you are performing an encryption or decryption
231 * operation, that is, regardless of the \p mode parameter. This is
232 * because CFB mode uses the same key schedule for encryption and
233 * decryption.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000234 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100235 * \note Upon exit, the content of the IV is updated so that you can
236 * call the same function again on the next
237 * block(s) of data and get the same result as if it was
238 * encrypted in one call. This allows a "streaming" usage.
239 * If you need to retain the contents of the
240 * IV, you must either save it manually or use the cipher
241 * module instead.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000242 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100243 *
244 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500245 * This must be initialized and bound to a key.
246 * \param mode The mode of operation. This must be either
247 * #MBEDTLS_ARIA_ENCRYPT for encryption, or
248 * #MBEDTLS_ARIA_DECRYPT for decryption.
249 * \param length The length of the input data \p input in Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100250 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500251 * This must not be larger than 15.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100252 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500253 * This must be a readable buffer of size 16 Bytes.
254 * \param input The buffer holding the input data. This must
255 * be a readable buffer of length \p length Bytes.
256 * \param output The buffer holding the output data. This must
257 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100258 *
259 * \return \c 0 on success.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500260 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000261 */
262int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100263 int mode,
264 size_t length,
265 size_t *iv_off,
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +0100266 unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100267 const unsigned char *input,
268 unsigned char *output );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000269#endif /* MBEDTLS_CIPHER_MODE_CFB */
270
271#if defined(MBEDTLS_CIPHER_MODE_CTR)
272/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100273 * \brief This function performs an ARIA-CTR encryption or decryption
274 * operation.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000275 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100276 * This function performs the operation defined in the \p mode
277 * parameter (encrypt/decrypt), on the input data buffer
278 * defined in the \p input parameter.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000279 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100280 * Due to the nature of CTR, you must use the same key schedule
281 * for both encryption and decryption operations. Therefore, you
Manuel Pégourié-Gonnard9d410732018-05-22 12:49:22 +0200282 * must use the context initialized with mbedtls_aria_setkey_enc()
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100283 * for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000284 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100285 * \warning You must never reuse a nonce value with the same key. Doing so
286 * would void the encryption for the two messages encrypted with
287 * the same nonce and key.
288 *
289 * There are two common strategies for managing nonces with CTR:
290 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200291 * 1. You can handle everything as a single message processed over
292 * successive calls to this function. In that case, you want to
293 * set \p nonce_counter and \p nc_off to 0 for the first call, and
294 * then preserve the values of \p nonce_counter, \p nc_off and \p
295 * stream_block across calls to this function as they will be
296 * updated by this function.
297 *
298 * With this strategy, you must not encrypt more than 2**128
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200299 * blocks of data with the same key.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100300 *
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200301 * 2. You can encrypt separate messages by dividing the \p
302 * nonce_counter buffer in two areas: the first one used for a
303 * per-message nonce, handled by yourself, and the second one
304 * updated by this function internally.
305 *
306 * For example, you might reserve the first 12 bytes for the
307 * per-message nonce, and the last 4 bytes for internal use. In that
308 * case, before calling this function on a new message you need to
309 * set the first 12 bytes of \p nonce_counter to your chosen nonce
310 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
311 * stream_block to be ignored). That way, you can encrypt at most
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200312 * 2**96 messages of up to 2**32 blocks each with the same key.
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200313 *
314 * The per-message nonce (or information sufficient to reconstruct
315 * it) needs to be communicated with the ciphertext and must be unique.
316 * The recommended way to ensure uniqueness is to use a message
317 * counter. An alternative is to generate random nonces, but this
318 * limits the number of messages that can be securely encrypted:
319 * for example, with 96-bit random nonces, you should not encrypt
320 * more than 2**32 messages with the same key.
321 *
Manuel Pégourié-Gonnardf5842862018-05-24 11:51:58 +0200322 * Note that for both stategies, sizes are measured in blocks and
323 * that an ARIA block is 16 bytes.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000324 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200325 * \warning Upon return, \p stream_block contains sensitive data. Its
Manuel Pégourié-Gonnard8a1b2c82018-05-23 13:26:22 +0200326 * content must not be written to insecure storage and should be
327 * securely discarded as soon as it's no longer needed.
328 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100329 * \param ctx The ARIA context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500330 * This must be initialized and bound to a key.
331 * \param length The length of the input data \p input in Bytes.
332 * \param nc_off The offset in Bytes in the current \p stream_block,
333 * for resuming within the current cipher stream. The
334 * offset pointer should be \c 0 at the start of a
335 * stream. This must not be larger than \c 15 Bytes.
336 * \param nonce_counter The 128-bit nonce and counter. This must point to
337 * a read/write buffer of length \c 16 bytes.
338 * \param stream_block The saved stream block for resuming. This must
339 * point to a read/write buffer of length \c 16 bytes.
340 * This is overwritten by the function.
341 * \param input The buffer holding the input data. This must
342 * be a readable buffer of length \p length Bytes.
343 * \param output The buffer holding the output data. This must
344 * be a writable buffer of length \p length Bytes.
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100345 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500346 * \return \c 0 on success.
347 * \return A negative error code on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000348 */
349int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx,
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100350 size_t length,
351 size_t *nc_off,
Manuel Pégourié-Gonnard5ad88b62018-03-01 09:20:47 +0100352 unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
353 unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
Manuel Pégourié-Gonnard4231e7f2018-02-28 10:54:31 +0100354 const unsigned char *input,
355 unsigned char *output );
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000356#endif /* MBEDTLS_CIPHER_MODE_CTR */
357
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200358#if defined(MBEDTLS_SELF_TEST)
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000359/**
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100360 * \brief Checkup routine.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000361 *
Manuel Pégourié-Gonnard5aa4e3b2018-02-28 11:55:49 +0100362 * \return \c 0 on success, or \c 1 on failure.
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000363 */
364int mbedtls_aria_self_test( int verbose );
Manuel Pégourié-Gonnardc0893122018-05-22 15:17:20 +0200365#endif /* MBEDTLS_SELF_TEST */
Markku-Juhani O. Saarinen41efbaa2017-11-30 11:37:55 +0000366
367#ifdef __cplusplus
368}
369#endif
370
371#endif /* aria.h */