blob: 1f813aa6bb6d23e6c2216500f949978c0e27777e [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
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
6 * \warning ARC4 is considered a weak cipher and its use constitutes a
7 * security risk. We recommend considering stronger ciphers instead.
Darryl Greena40a1012018-01-05 15:33:17 +00008 */
9/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020010 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000011 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakkerb96f1542010-07-18 20:36:00 +000012 *
Paul Bakker5121ce52009-01-03 21:22:43 +000013 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020014#ifndef MBEDTLS_ARC4_H
15#define MBEDTLS_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000016
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020017#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010018#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020019#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020020#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020021#endif
Paul Bakker90995b52013-06-24 19:20:35 +020022
Rich Evans00ab4702015-02-06 13:43:58 +000023#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000024
Ron Eldor9924bdc2018-10-04 10:59:13 +030025/* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020026/** ARC4 hardware accelerator failed. */
27#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010028
Paul Bakker407a0da2013-06-27 14:29:21 +020029#ifdef __cplusplus
30extern "C" {
31#endif
32
Ron Eldorb2aacec2017-05-18 16:53:08 +030033#if !defined(MBEDTLS_ARC4_ALT)
34// Regular implementation
35//
36
Paul Bakker5121ce52009-01-03 21:22:43 +000037/**
Hanno Beckerbbca8c52017-09-25 14:53:51 +010038 * \brief ARC4 context structure
39 *
40 * \warning ARC4 is considered a weak cipher and its use constitutes a
41 * security risk. We recommend considering stronger ciphers instead.
42 *
Paul Bakker5121ce52009-01-03 21:22:43 +000043 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010044typedef struct mbedtls_arc4_context {
Paul Bakker5121ce52009-01-03 21:22:43 +000045 int x; /*!< permutation index */
46 int y; /*!< permutation index */
47 unsigned char m[256]; /*!< permutation table */
48}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000050
Ron Eldorb2aacec2017-05-18 16:53:08 +030051#else /* MBEDTLS_ARC4_ALT */
52#include "arc4_alt.h"
53#endif /* MBEDTLS_ARC4_ALT */
54
Paul Bakker5121ce52009-01-03 21:22:43 +000055/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020056 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000057 *
58 * \param ctx ARC4 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010059 *
60 * \warning ARC4 is considered a weak cipher and its use constitutes a
61 * security risk. We recommend considering stronger ciphers
62 * instead.
63 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020064 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010065void mbedtls_arc4_init(mbedtls_arc4_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020066
67/**
68 * \brief Clear ARC4 context
69 *
70 * \param ctx ARC4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010071 *
72 * \warning ARC4 is considered a weak cipher and its use constitutes a
73 * security risk. We recommend considering stronger ciphers
74 * instead.
75 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020076 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010077void mbedtls_arc4_free(mbedtls_arc4_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020078
79/**
80 * \brief ARC4 key schedule
81 *
82 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000083 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020084 * \param keylen length of the key, in bytes
Hanno Beckerbbca8c52017-09-25 14:53:51 +010085 *
86 * \warning ARC4 is considered a weak cipher and its use constitutes a
87 * security risk. We recommend considering stronger ciphers
88 * instead.
89 *
Paul Bakker5121ce52009-01-03 21:22:43 +000090 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010091void mbedtls_arc4_setup(mbedtls_arc4_context *ctx, const unsigned char *key,
92 unsigned int keylen);
Paul Bakker5121ce52009-01-03 21:22:43 +000093
94/**
95 * \brief ARC4 cipher function
96 *
97 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +000098 * \param length length of the input data
99 * \param input buffer holding the input data
100 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000101 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000102 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100103 *
104 * \warning ARC4 is considered a weak cipher and its use constitutes a
105 * security risk. We recommend considering stronger ciphers
106 * instead.
107 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000108 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100109int mbedtls_arc4_crypt(mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
110 unsigned char *output);
Paul Bakker5121ce52009-01-03 21:22:43 +0000111
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500112#if defined(MBEDTLS_SELF_TEST)
113
Paul Bakker9a736322012-11-14 12:39:52 +0000114/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000115 * \brief Checkup routine
116 *
117 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100118 *
119 * \warning ARC4 is considered a weak cipher and its use constitutes a
120 * security risk. We recommend considering stronger ciphers
121 * instead.
122 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100124int mbedtls_arc4_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500126#endif /* MBEDTLS_SELF_TEST */
127
Paul Bakker5121ce52009-01-03 21:22:43 +0000128#ifdef __cplusplus
129}
130#endif
131
132#endif /* arc4.h */