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