Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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 "mbedtls/config.h"
00033 #else
00034 #include MBEDTLS_CONFIG_FILE
00035 #endif
00036 
00037 #include <stddef.h>
00038 
00039 /* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
00040 #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED                  -0x0019  /**< ARC4 hardware accelerator failed. */
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 #if !defined(MBEDTLS_ARC4_ALT)
00047 // Regular implementation
00048 //
00049 
00050 /**
00051  * \brief     ARC4 context structure
00052  *
00053  * \warning   ARC4 is considered a weak cipher and its use constitutes a
00054  *            security risk. We recommend considering stronger ciphers instead.
00055  *
00056  */
00057 typedef struct mbedtls_arc4_context
00058 {
00059     int x ;                      /*!< permutation index */
00060     int y ;                      /*!< permutation index */
00061     unsigned char m [256];       /*!< permutation table */
00062 }
00063 mbedtls_arc4_context;
00064 
00065 #else  /* MBEDTLS_ARC4_ALT */
00066 #include "arc4_alt.h"
00067 #endif /* MBEDTLS_ARC4_ALT */
00068 
00069 /**
00070  * \brief          Initialize ARC4 context
00071  *
00072  * \param ctx      ARC4 context to be initialized
00073  *
00074  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00075  *                 security risk. We recommend considering stronger ciphers
00076  *                 instead.
00077  *
00078  */
00079 void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
00080 
00081 /**
00082  * \brief          Clear ARC4 context
00083  *
00084  * \param ctx      ARC4 context to be cleared
00085  *
00086  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00087  *                 security risk. We recommend considering stronger ciphers
00088  *                 instead.
00089  *
00090  */
00091 void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
00092 
00093 /**
00094  * \brief          ARC4 key schedule
00095  *
00096  * \param ctx      ARC4 context to be setup
00097  * \param key      the secret key
00098  * \param keylen   length of the key, in bytes
00099  *
00100  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00101  *                 security risk. We recommend considering stronger ciphers
00102  *                 instead.
00103  *
00104  */
00105 void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
00106                  unsigned int keylen );
00107 
00108 /**
00109  * \brief          ARC4 cipher function
00110  *
00111  * \param ctx      ARC4 context
00112  * \param length   length of the input data
00113  * \param input    buffer holding the input data
00114  * \param output   buffer for the output data
00115  *
00116  * \return         0 if successful
00117  *
00118  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00119  *                 security risk. We recommend considering stronger ciphers
00120  *                 instead.
00121  *
00122  */
00123 int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
00124                 unsigned char *output );
00125 
00126 #if defined(MBEDTLS_SELF_TEST)
00127 
00128 /**
00129  * \brief          Checkup routine
00130  *
00131  * \return         0 if successful, or 1 if the test failed
00132  *
00133  * \warning        ARC4 is considered a weak cipher and its use constitutes a
00134  *                 security risk. We recommend considering stronger ciphers
00135  *                 instead.
00136  *
00137  */
00138 int mbedtls_arc4_self_test( int verbose );
00139 
00140 #endif /* MBEDTLS_SELF_TEST */
00141 
00142 #ifdef __cplusplus
00143 }
00144 #endif
00145 
00146 #endif /* arc4.h */