Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file arc4.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief The ARCFOUR stream cipher |
| 5 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 8 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 9 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Hanno Becker | ce0c9db | 2017-09-28 15:39:45 +0100 | [diff] [blame] | 23 | * |
| 24 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 25 | * security risk. We recommend considering stronger ciphers instead. |
| 26 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 27 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 28 | #ifndef POLARSSL_ARC4_H |
| 29 | #define POLARSSL_ARC4_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 30 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 31 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 32 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 33 | #else |
| 34 | #include POLARSSL_CONFIG_FILE |
| 35 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 36 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 37 | #include <stddef.h> |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 38 | |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 39 | #if !defined(POLARSSL_ARC4_ALT) |
| 40 | // Regular implementation |
| 41 | // |
| 42 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 43 | #ifdef __cplusplus |
| 44 | extern "C" { |
| 45 | #endif |
| 46 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 47 | /** |
| 48 | * \brief ARC4 context structure |
Hanno Becker | ce0c9db | 2017-09-28 15:39:45 +0100 | [diff] [blame] | 49 | * |
| 50 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 51 | * security risk. We recommend considering stronger ciphers |
| 52 | * instead. |
| 53 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | */ |
| 55 | typedef struct |
| 56 | { |
| 57 | int x; /*!< permutation index */ |
| 58 | int y; /*!< permutation index */ |
| 59 | unsigned char m[256]; /*!< permutation table */ |
| 60 | } |
| 61 | arc4_context; |
| 62 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 63 | /** |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 64 | * \brief Initialize ARC4 context |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 65 | * |
| 66 | * \param ctx ARC4 context to be initialized |
Hanno Becker | ce0c9db | 2017-09-28 15:39:45 +0100 | [diff] [blame] | 67 | * |
| 68 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 69 | * security risk. We recommend considering stronger ciphers |
| 70 | * instead. |
| 71 | * |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 72 | */ |
| 73 | void arc4_init( arc4_context *ctx ); |
| 74 | |
| 75 | /** |
| 76 | * \brief Clear ARC4 context |
| 77 | * |
| 78 | * \param ctx ARC4 context to be cleared |
Hanno Becker | ce0c9db | 2017-09-28 15:39:45 +0100 | [diff] [blame] | 79 | * |
| 80 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 81 | * security risk. We recommend considering stronger ciphers |
| 82 | * instead. |
| 83 | * |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 84 | */ |
| 85 | void arc4_free( arc4_context *ctx ); |
| 86 | |
| 87 | /** |
| 88 | * \brief ARC4 key schedule |
| 89 | * |
| 90 | * \param ctx ARC4 context to be setup |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 91 | * \param key the secret key |
Manuel Pégourié-Gonnard | ce41125 | 2013-09-04 12:28:37 +0200 | [diff] [blame] | 92 | * \param keylen length of the key, in bytes |
Hanno Becker | ce0c9db | 2017-09-28 15:39:45 +0100 | [diff] [blame] | 93 | * |
| 94 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 95 | * security risk. We recommend considering stronger ciphers |
| 96 | * instead. |
| 97 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 98 | */ |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 99 | void arc4_setup( arc4_context *ctx, const unsigned char *key, |
| 100 | unsigned int keylen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * \brief ARC4 cipher function |
| 104 | * |
| 105 | * \param ctx ARC4 context |
Paul Bakker | baad650 | 2010-03-21 15:42:15 +0000 | [diff] [blame] | 106 | * \param length length of the input data |
| 107 | * \param input buffer holding the input data |
| 108 | * \param output buffer for the output data |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 109 | * |
Paul Bakker | 27caa8a | 2010-03-21 15:43:59 +0000 | [diff] [blame] | 110 | * \return 0 if successful |
Hanno Becker | ce0c9db | 2017-09-28 15:39:45 +0100 | [diff] [blame] | 111 | * |
| 112 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 113 | * security risk. We recommend considering stronger ciphers |
| 114 | * instead. |
| 115 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 116 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 117 | int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input, |
Paul Bakker | baad650 | 2010-03-21 15:42:15 +0000 | [diff] [blame] | 118 | unsigned char *output ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 120 | #ifdef __cplusplus |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | #else /* POLARSSL_ARC4_ALT */ |
| 125 | #include "arc4_alt.h" |
| 126 | #endif /* POLARSSL_ARC4_ALT */ |
| 127 | |
| 128 | #ifdef __cplusplus |
| 129 | extern "C" { |
| 130 | #endif |
| 131 | |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 132 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 133 | * \brief Checkup routine |
| 134 | * |
| 135 | * \return 0 if successful, or 1 if the test failed |
Hanno Becker | ce0c9db | 2017-09-28 15:39:45 +0100 | [diff] [blame] | 136 | * |
| 137 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 138 | * security risk. We recommend considering stronger ciphers |
| 139 | * instead. |
| 140 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 141 | */ |
| 142 | int arc4_self_test( int verbose ); |
| 143 | |
| 144 | #ifdef __cplusplus |
| 145 | } |
| 146 | #endif |
| 147 | |
| 148 | #endif /* arc4.h */ |