Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

Committer:
HannesTschofenig
Date:
Thu Sep 27 06:34:22 2018 +0000
Revision:
0:796d0f61a05b
Example AES-GCM test program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
HannesTschofenig 0:796d0f61a05b 1 /**
HannesTschofenig 0:796d0f61a05b 2 * \file arc4.h
HannesTschofenig 0:796d0f61a05b 3 *
HannesTschofenig 0:796d0f61a05b 4 * \brief The ARCFOUR stream cipher
HannesTschofenig 0:796d0f61a05b 5 *
HannesTschofenig 0:796d0f61a05b 6 * Copyright (C) 2006-2014, Brainspark B.V.
HannesTschofenig 0:796d0f61a05b 7 *
HannesTschofenig 0:796d0f61a05b 8 * This file is part of PolarSSL (http://www.polarssl.org)
HannesTschofenig 0:796d0f61a05b 9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
HannesTschofenig 0:796d0f61a05b 10 *
HannesTschofenig 0:796d0f61a05b 11 * All rights reserved.
HannesTschofenig 0:796d0f61a05b 12 *
HannesTschofenig 0:796d0f61a05b 13 * This program is free software; you can redistribute it and/or modify
HannesTschofenig 0:796d0f61a05b 14 * it under the terms of the GNU General Public License as published by
HannesTschofenig 0:796d0f61a05b 15 * the Free Software Foundation; either version 2 of the License, or
HannesTschofenig 0:796d0f61a05b 16 * (at your option) any later version.
HannesTschofenig 0:796d0f61a05b 17 *
HannesTschofenig 0:796d0f61a05b 18 * This program is distributed in the hope that it will be useful,
HannesTschofenig 0:796d0f61a05b 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
HannesTschofenig 0:796d0f61a05b 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
HannesTschofenig 0:796d0f61a05b 21 * GNU General Public License for more details.
HannesTschofenig 0:796d0f61a05b 22 *
HannesTschofenig 0:796d0f61a05b 23 * You should have received a copy of the GNU General Public License along
HannesTschofenig 0:796d0f61a05b 24 * with this program; if not, write to the Free Software Foundation, Inc.,
HannesTschofenig 0:796d0f61a05b 25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
HannesTschofenig 0:796d0f61a05b 26 */
HannesTschofenig 0:796d0f61a05b 27 #ifndef POLARSSL_ARC4_H
HannesTschofenig 0:796d0f61a05b 28 #define POLARSSL_ARC4_H
HannesTschofenig 0:796d0f61a05b 29
HannesTschofenig 0:796d0f61a05b 30 #if !defined(POLARSSL_CONFIG_FILE)
HannesTschofenig 0:796d0f61a05b 31 #include "config.h"
HannesTschofenig 0:796d0f61a05b 32 #else
HannesTschofenig 0:796d0f61a05b 33 #include POLARSSL_CONFIG_FILE
HannesTschofenig 0:796d0f61a05b 34 #endif
HannesTschofenig 0:796d0f61a05b 35
HannesTschofenig 0:796d0f61a05b 36 #include <string.h>
HannesTschofenig 0:796d0f61a05b 37
HannesTschofenig 0:796d0f61a05b 38 #if !defined(POLARSSL_ARC4_ALT)
HannesTschofenig 0:796d0f61a05b 39 // Regular implementation
HannesTschofenig 0:796d0f61a05b 40 //
HannesTschofenig 0:796d0f61a05b 41
HannesTschofenig 0:796d0f61a05b 42 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 43 extern "C" {
HannesTschofenig 0:796d0f61a05b 44 #endif
HannesTschofenig 0:796d0f61a05b 45
HannesTschofenig 0:796d0f61a05b 46 /**
HannesTschofenig 0:796d0f61a05b 47 * \brief ARC4 context structure
HannesTschofenig 0:796d0f61a05b 48 */
HannesTschofenig 0:796d0f61a05b 49 typedef struct
HannesTschofenig 0:796d0f61a05b 50 {
HannesTschofenig 0:796d0f61a05b 51 int x; /*!< permutation index */
HannesTschofenig 0:796d0f61a05b 52 int y; /*!< permutation index */
HannesTschofenig 0:796d0f61a05b 53 unsigned char m[256]; /*!< permutation table */
HannesTschofenig 0:796d0f61a05b 54 }
HannesTschofenig 0:796d0f61a05b 55 arc4_context;
HannesTschofenig 0:796d0f61a05b 56
HannesTschofenig 0:796d0f61a05b 57 /**
HannesTschofenig 0:796d0f61a05b 58 * \brief ARC4 key schedule
HannesTschofenig 0:796d0f61a05b 59 *
HannesTschofenig 0:796d0f61a05b 60 * \param ctx ARC4 context to be initialized
HannesTschofenig 0:796d0f61a05b 61 * \param key the secret key
HannesTschofenig 0:796d0f61a05b 62 * \param keylen length of the key, in bytes
HannesTschofenig 0:796d0f61a05b 63 */
HannesTschofenig 0:796d0f61a05b 64 void arc4_setup( arc4_context *ctx, const unsigned char *key,
HannesTschofenig 0:796d0f61a05b 65 unsigned int keylen );
HannesTschofenig 0:796d0f61a05b 66
HannesTschofenig 0:796d0f61a05b 67 /**
HannesTschofenig 0:796d0f61a05b 68 * \brief ARC4 cipher function
HannesTschofenig 0:796d0f61a05b 69 *
HannesTschofenig 0:796d0f61a05b 70 * \param ctx ARC4 context
HannesTschofenig 0:796d0f61a05b 71 * \param length length of the input data
HannesTschofenig 0:796d0f61a05b 72 * \param input buffer holding the input data
HannesTschofenig 0:796d0f61a05b 73 * \param output buffer for the output data
HannesTschofenig 0:796d0f61a05b 74 *
HannesTschofenig 0:796d0f61a05b 75 * \return 0 if successful
HannesTschofenig 0:796d0f61a05b 76 */
HannesTschofenig 0:796d0f61a05b 77 int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input,
HannesTschofenig 0:796d0f61a05b 78 unsigned char *output );
HannesTschofenig 0:796d0f61a05b 79
HannesTschofenig 0:796d0f61a05b 80 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 81 }
HannesTschofenig 0:796d0f61a05b 82 #endif
HannesTschofenig 0:796d0f61a05b 83
HannesTschofenig 0:796d0f61a05b 84 #else /* POLARSSL_ARC4_ALT */
HannesTschofenig 0:796d0f61a05b 85 #include "arc4_alt.h"
HannesTschofenig 0:796d0f61a05b 86 #endif /* POLARSSL_ARC4_ALT */
HannesTschofenig 0:796d0f61a05b 87
HannesTschofenig 0:796d0f61a05b 88 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 89 extern "C" {
HannesTschofenig 0:796d0f61a05b 90 #endif
HannesTschofenig 0:796d0f61a05b 91
HannesTschofenig 0:796d0f61a05b 92 /**
HannesTschofenig 0:796d0f61a05b 93 * \brief Checkup routine
HannesTschofenig 0:796d0f61a05b 94 *
HannesTschofenig 0:796d0f61a05b 95 * \return 0 if successful, or 1 if the test failed
HannesTschofenig 0:796d0f61a05b 96 */
HannesTschofenig 0:796d0f61a05b 97 int arc4_self_test( int verbose );
HannesTschofenig 0:796d0f61a05b 98
HannesTschofenig 0:796d0f61a05b 99 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 100 }
HannesTschofenig 0:796d0f61a05b 101 #endif
HannesTschofenig 0:796d0f61a05b 102
HannesTschofenig 0:796d0f61a05b 103 #endif /* arc4.h */
HannesTschofenig 0:796d0f61a05b 104
HannesTschofenig 0:796d0f61a05b 105