• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * \file arc4.h
3  *
4  * \brief The ARCFOUR stream cipher
5  *
6  * \warning   ARC4 is considered a weak cipher and its use constitutes a
7  *            security risk. We recommend considering stronger ciphers instead.
8  */
9 /*
10  *  Copyright The Mbed TLS Contributors
11  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
12  *
13  */
14 #ifndef MBEDTLS_ARC4_H
15 #define MBEDTLS_ARC4_H
16 
17 #if !defined(MBEDTLS_CONFIG_FILE)
18 #include "mbedtls/config.h"
19 #else
20 #include MBEDTLS_CONFIG_FILE
21 #endif
22 
23 #include <stddef.h>
24 
25 /* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
26 /** ARC4 hardware accelerator failed. */
27 #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED                  -0x0019
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #if !defined(MBEDTLS_ARC4_ALT)
34 // Regular implementation
35 //
36 
37 /**
38  * \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  *
43  */
44 typedef struct mbedtls_arc4_context {
45     int x;                      /*!< permutation index */
46     int y;                      /*!< permutation index */
47     unsigned char m[256];       /*!< permutation table */
48 }
49 mbedtls_arc4_context;
50 
51 #else  /* MBEDTLS_ARC4_ALT */
52 #include "arc4_alt.h"
53 #endif /* MBEDTLS_ARC4_ALT */
54 
55 /**
56  * \brief          Initialize ARC4 context
57  *
58  * \param ctx      ARC4 context to be initialized
59  *
60  * \warning        ARC4 is considered a weak cipher and its use constitutes a
61  *                 security risk. We recommend considering stronger ciphers
62  *                 instead.
63  *
64  */
65 void mbedtls_arc4_init(mbedtls_arc4_context *ctx);
66 
67 /**
68  * \brief          Clear ARC4 context
69  *
70  * \param ctx      ARC4 context to be cleared
71  *
72  * \warning        ARC4 is considered a weak cipher and its use constitutes a
73  *                 security risk. We recommend considering stronger ciphers
74  *                 instead.
75  *
76  */
77 void mbedtls_arc4_free(mbedtls_arc4_context *ctx);
78 
79 /**
80  * \brief          ARC4 key schedule
81  *
82  * \param ctx      ARC4 context to be setup
83  * \param key      the secret key
84  * \param keylen   length of the key, in bytes
85  *
86  * \warning        ARC4 is considered a weak cipher and its use constitutes a
87  *                 security risk. We recommend considering stronger ciphers
88  *                 instead.
89  *
90  */
91 void mbedtls_arc4_setup(mbedtls_arc4_context *ctx, const unsigned char *key,
92                         unsigned int keylen);
93 
94 /**
95  * \brief          ARC4 cipher function
96  *
97  * \param ctx      ARC4 context
98  * \param length   length of the input data
99  * \param input    buffer holding the input data
100  * \param output   buffer for the output data
101  *
102  * \return         0 if successful
103  *
104  * \warning        ARC4 is considered a weak cipher and its use constitutes a
105  *                 security risk. We recommend considering stronger ciphers
106  *                 instead.
107  *
108  */
109 int mbedtls_arc4_crypt(mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
110                        unsigned char *output);
111 
112 #if defined(MBEDTLS_SELF_TEST)
113 
114 /**
115  * \brief          Checkup routine
116  *
117  * \return         0 if successful, or 1 if the test failed
118  *
119  * \warning        ARC4 is considered a weak cipher and its use constitutes a
120  *                 security risk. We recommend considering stronger ciphers
121  *                 instead.
122  *
123  */
124 int mbedtls_arc4_self_test(int verbose);
125 
126 #endif /* MBEDTLS_SELF_TEST */
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* arc4.h */
133