blob: 875c574317e62633ea1a498460ce00bbdfced432 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file arc4.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief The ARCFOUR stream cipher
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_ARC4_H
25#define MBEDTLS_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker90995b52013-06-24 19:20:35 +020032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000034
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010035#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */
36
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#if !defined(MBEDTLS_ARC4_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020038// Regular implementation
39//
40
Paul Bakker407a0da2013-06-27 14:29:21 +020041#ifdef __cplusplus
42extern "C" {
43#endif
44
Paul Bakker5121ce52009-01-03 21:22:43 +000045/**
46 * \brief ARC4 context structure
47 */
48typedef struct
49{
50 int x; /*!< permutation index */
51 int y; /*!< permutation index */
52 unsigned char m[256]; /*!< permutation table */
53}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000055
Paul Bakker5121ce52009-01-03 21:22:43 +000056/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020057 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000058 *
59 * \param ctx ARC4 context to be initialized
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020060 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020062
63/**
64 * \brief Clear ARC4 context
65 *
66 * \param ctx ARC4 context to be cleared
67 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020069
70/**
71 * \brief ARC4 key schedule
72 *
73 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000074 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020075 * \param keylen length of the key, in bytes
Paul Bakker5121ce52009-01-03 21:22:43 +000076 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020078 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000079
80/**
81 * \brief ARC4 cipher function
82 *
83 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +000084 * \param length length of the input data
85 * \param input buffer holding the input data
86 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +000087 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000088 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000089 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +000091 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +000092
Paul Bakker90995b52013-06-24 19:20:35 +020093#ifdef __cplusplus
94}
95#endif
96
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#else /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +020098#include "arc4_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#endif /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
Paul Bakker9a736322012-11-14 12:39:52 +0000105/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000106 * \brief Checkup routine
107 *
108 * \return 0 if successful, or 1 if the test failed
109 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110int mbedtls_arc4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000111
112#ifdef __cplusplus
113}
114#endif
115
116#endif /* arc4.h */