BA / Mbed OS BaBoRo1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arc4.h Source File

arc4.h

00001 /**
00002  * \file arc4.h
00003  *
00004  * \brief The ARCFOUR stream cipher
00005  *
00006  * \warning   ARC4 is considered a weak cipher and its use constitutes a
00007  *            security risk. We recommend considering stronger ciphers instead.
00008  */
00009 /*
00010  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00011  *  SPDX-License-Identifier: Apache-2.0
00012  *
00013  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00014  *  not use this file except in compliance with the License.
00015  *  You may obtain a copy of the License at
00016  *
00017  *  http://www.apache.org/licenses/LICENSE-2.0
00018  *
00019  *  Unless required by applicable law or agreed to in writing, software
00020  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00021  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022  *  See the License for the specific language governing permissions and
00023  *  limitations under the License.
00024  *
00025  *  This file is part of mbed TLS (https://tls.mbed.org)
00026  *
00027  */
00028 #ifndef MBEDTLS_ARC4_H
00029 #define MBEDTLS_ARC4_H
00030 
00031 #if !defined(MBEDTLS_CONFIG_FILE)
00032 #include "config.h"
00033 #else
00034 #include MBEDTLS_CONFIG_FILE
00035 #endif
00036 
00037 #include <stddef.h>
00038 
00039 #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED                  -0x0019  /**< ARC4 hardware accelerator failed. */
00040 
00041 #if !defined(MBEDTLS_ARC4_ALT)
00042 // Regular implementation
00043 //
00044 
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048 
00049 /**
00050  * \brief     ARC4 context structure
00051  *
00052  * \warning   ARC4 is considered a weak cipher and its use constitutes a
00053  *            security risk. We recommend considering stronger ciphers instead.
00054  *
00055  */
00056 typedef struct
00057 {
00058     int x ;                      /*!< permutation index */
00059     int y ;                      /*!< permutation index */
00060     unsigned char m[256];       /*!< permutation table */
00061 }
00062 mbedtls_arc4_context;
00063 
00064 /**
00065  * \brief          Initialize ARC4 context
00066  *
00067  * \param ctx      ARC4 context to be initialized
00068  *
00069  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00070  *                 security risk. We recommend considering stronger ciphers
00071  *                 instead.
00072  *
00073  */
00074 void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
00075 
00076 /**
00077  * \brief          Clear ARC4 context
00078  *
00079  * \param ctx      ARC4 context to be cleared
00080  *
00081  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00082  *                 security risk. We recommend considering stronger ciphers
00083  *                 instead.
00084  *
00085  */
00086 void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
00087 
00088 /**
00089  * \brief          ARC4 key schedule
00090  *
00091  * \param ctx      ARC4 context to be setup
00092  * \param key      the secret key
00093  * \param keylen   length of the key, in bytes
00094  *
00095  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00096  *                 security risk. We recommend considering stronger ciphers
00097  *                 instead.
00098  *
00099  */
00100 void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
00101                  unsigned int keylen );
00102 
00103 /**
00104  * \brief          ARC4 cipher function
00105  *
00106  * \param ctx      ARC4 context
00107  * \param length   length of the input data
00108  * \param input    buffer holding the input data
00109  * \param output   buffer for the output data
00110  *
00111  * \return         0 if successful
00112  *
00113  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00114  *                 security risk. We recommend considering stronger ciphers
00115  *                 instead.
00116  *
00117  */
00118 int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
00119                 unsigned char *output );
00120 
00121 #ifdef __cplusplus
00122 }
00123 #endif
00124 
00125 #else  /* MBEDTLS_ARC4_ALT */
00126 #include "arc4_alt.h"
00127 #endif /* MBEDTLS_ARC4_ALT */
00128 
00129 #ifdef __cplusplus
00130 extern "C" {
00131 #endif
00132 
00133 /**
00134  * \brief          Checkup routine
00135  *
00136  * \return         0 if successful, or 1 if the test failed
00137  *
00138  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00139  *                 security risk. We recommend considering stronger ciphers
00140  *                 instead.
00141  *
00142  */
00143 int mbedtls_arc4_self_test( int verbose );
00144 
00145 #ifdef __cplusplus
00146 }
00147 #endif
00148 
00149 #endif /* arc4.h */