Jaeden Amero | e54e693 | 2018-08-06 16:19:58 +0100 | [diff] [blame] | 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 (C) 2006-2015, ARM Limited, All Rights Reserved |
| 11 | * SPDX-License-Identifier: Apache-2.0 |
| 12 | * |
| 13 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 14 | * not use this file except in compliance with the License. |
| 15 | * You may obtain a copy of the License at |
| 16 | * |
| 17 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | * |
| 19 | * Unless required by applicable law or agreed to in writing, software |
| 20 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | * See the License for the specific language governing permissions and |
| 23 | * limitations under the License. |
| 24 | * |
| 25 | * This file is part of Mbed Crypto (https://tls.mbed.org) |
| 26 | * |
| 27 | */ |
| 28 | #ifndef MBEDCRYPTO_ARC4_H |
| 29 | #define MBEDCRYPTO_ARC4_H |
| 30 | |
| 31 | #if !defined(MBEDCRYPTO_CONFIG_FILE) |
| 32 | #include "config.h" |
| 33 | #else |
| 34 | #include MBEDCRYPTO_CONFIG_FILE |
| 35 | #endif |
| 36 | |
| 37 | #include <stddef.h> |
| 38 | |
| 39 | #define MBEDCRYPTO_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */ |
| 40 | |
| 41 | #ifdef __cplusplus |
| 42 | extern "C" { |
| 43 | #endif |
| 44 | |
| 45 | #if !defined(MBEDCRYPTO_ARC4_ALT) |
| 46 | // Regular implementation |
| 47 | // |
| 48 | |
| 49 | /** |
| 50 | * \brief ARC4 context structure |
| 51 | * |
| 52 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 53 | * security risk. We recommend considering stronger ciphers instead. |
| 54 | * |
| 55 | */ |
| 56 | typedef struct |
| 57 | { |
| 58 | int x; /*!< permutation index */ |
| 59 | int y; /*!< permutation index */ |
| 60 | unsigned char m[256]; /*!< permutation table */ |
| 61 | } |
| 62 | mbedcrypto_arc4_context; |
| 63 | |
| 64 | #else /* MBEDCRYPTO_ARC4_ALT */ |
| 65 | #include "arc4_alt.h" |
| 66 | #endif /* MBEDCRYPTO_ARC4_ALT */ |
| 67 | |
| 68 | /** |
| 69 | * \brief Initialize ARC4 context |
| 70 | * |
| 71 | * \param ctx ARC4 context to be initialized |
| 72 | * |
| 73 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 74 | * security risk. We recommend considering stronger ciphers |
| 75 | * instead. |
| 76 | * |
| 77 | */ |
| 78 | void mbedcrypto_arc4_init( mbedcrypto_arc4_context *ctx ); |
| 79 | |
| 80 | /** |
| 81 | * \brief Clear ARC4 context |
| 82 | * |
| 83 | * \param ctx ARC4 context to be cleared |
| 84 | * |
| 85 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 86 | * security risk. We recommend considering stronger ciphers |
| 87 | * instead. |
| 88 | * |
| 89 | */ |
| 90 | void mbedcrypto_arc4_free( mbedcrypto_arc4_context *ctx ); |
| 91 | |
| 92 | /** |
| 93 | * \brief ARC4 key schedule |
| 94 | * |
| 95 | * \param ctx ARC4 context to be setup |
| 96 | * \param key the secret key |
| 97 | * \param keylen length of the key, in bytes |
| 98 | * |
| 99 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 100 | * security risk. We recommend considering stronger ciphers |
| 101 | * instead. |
| 102 | * |
| 103 | */ |
| 104 | void mbedcrypto_arc4_setup( mbedcrypto_arc4_context *ctx, const unsigned char *key, |
| 105 | unsigned int keylen ); |
| 106 | |
| 107 | /** |
| 108 | * \brief ARC4 cipher function |
| 109 | * |
| 110 | * \param ctx ARC4 context |
| 111 | * \param length length of the input data |
| 112 | * \param input buffer holding the input data |
| 113 | * \param output buffer for the output data |
| 114 | * |
| 115 | * \return 0 if successful |
| 116 | * |
| 117 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 118 | * security risk. We recommend considering stronger ciphers |
| 119 | * instead. |
| 120 | * |
| 121 | */ |
| 122 | int mbedcrypto_arc4_crypt( mbedcrypto_arc4_context *ctx, size_t length, const unsigned char *input, |
| 123 | unsigned char *output ); |
| 124 | |
| 125 | /** |
| 126 | * \brief Checkup routine |
| 127 | * |
| 128 | * \return 0 if successful, or 1 if the test failed |
| 129 | * |
| 130 | * \warning ARC4 is considered a weak cipher and its use constitutes a |
| 131 | * security risk. We recommend considering stronger ciphers |
| 132 | * instead. |
| 133 | * |
| 134 | */ |
| 135 | int mbedcrypto_arc4_self_test( int verbose ); |
| 136 | |
| 137 | #ifdef __cplusplus |
| 138 | } |
| 139 | #endif |
| 140 | |
| 141 | #endif /* arc4.h */ |