1 /**
2  * \file arc4.h
3  *
4  * \brief The ARCFOUR stream cipher
5  *
6  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7  *  SPDX-License-Identifier: Apache-2.0
8  *
9  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
10  *  not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  *
13  *  http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  *
21  *  This file is part of mbed TLS (https://tls.mbed.org)
22  */
23 #ifndef MBEDTLS_ARC4_H
24 #define MBEDTLS_ARC4_H
25 
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
31 
32 #include <stddef.h>
33 
34 #if !defined(MBEDTLS_ARC4_ALT)
35 // Regular implementation
36 //
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**
43  * \brief          ARC4 context structure
44  */
45 typedef struct
46 {
47     int x;                      /*!< permutation index */
48     int y;                      /*!< permutation index */
49     unsigned char m[256];       /*!< permutation table */
50 }
51 mbedtls_arc4_context;
52 
53 /**
54  * \brief          Initialize ARC4 context
55  *
56  * \param ctx      ARC4 context to be initialized
57  */
58 void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
59 
60 /**
61  * \brief          Clear ARC4 context
62  *
63  * \param ctx      ARC4 context to be cleared
64  */
65 void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
66 
67 /**
68  * \brief          ARC4 key schedule
69  *
70  * \param ctx      ARC4 context to be setup
71  * \param key      the secret key
72  * \param keylen   length of the key, in bytes
73  */
74 void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
75                  unsigned int keylen );
76 
77 /**
78  * \brief          ARC4 cipher function
79  *
80  * \param ctx      ARC4 context
81  * \param length   length of the input data
82  * \param input    buffer holding the input data
83  * \param output   buffer for the output data
84  *
85  * \return         0 if successful
86  */
87 int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
88                 unsigned char *output );
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #else  /* MBEDTLS_ARC4_ALT */
95 #include "arc4_alt.h"
96 #endif /* MBEDTLS_ARC4_ALT */
97 
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101 
102 /**
103  * \brief          Checkup routine
104  *
105  * \return         0 if successful, or 1 if the test failed
106  */
107 int mbedtls_arc4_self_test( int verbose );
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* arc4.h */
114