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 padlock.h
HannesTschofenig 0:796d0f61a05b 3 *
HannesTschofenig 0:796d0f61a05b 4 * \brief VIA PadLock ACE for HW encryption/decryption supported by some
HannesTschofenig 0:796d0f61a05b 5 * processors
HannesTschofenig 0:796d0f61a05b 6 *
HannesTschofenig 0:796d0f61a05b 7 * Copyright (C) 2006-2014, Brainspark B.V.
HannesTschofenig 0:796d0f61a05b 8 *
HannesTschofenig 0:796d0f61a05b 9 * This file is part of PolarSSL (http://www.polarssl.org)
HannesTschofenig 0:796d0f61a05b 10 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
HannesTschofenig 0:796d0f61a05b 11 *
HannesTschofenig 0:796d0f61a05b 12 * All rights reserved.
HannesTschofenig 0:796d0f61a05b 13 *
HannesTschofenig 0:796d0f61a05b 14 * This program is free software; you can redistribute it and/or modify
HannesTschofenig 0:796d0f61a05b 15 * it under the terms of the GNU General Public License as published by
HannesTschofenig 0:796d0f61a05b 16 * the Free Software Foundation; either version 2 of the License, or
HannesTschofenig 0:796d0f61a05b 17 * (at your option) any later version.
HannesTschofenig 0:796d0f61a05b 18 *
HannesTschofenig 0:796d0f61a05b 19 * This program is distributed in the hope that it will be useful,
HannesTschofenig 0:796d0f61a05b 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
HannesTschofenig 0:796d0f61a05b 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
HannesTschofenig 0:796d0f61a05b 22 * GNU General Public License for more details.
HannesTschofenig 0:796d0f61a05b 23 *
HannesTschofenig 0:796d0f61a05b 24 * You should have received a copy of the GNU General Public License along
HannesTschofenig 0:796d0f61a05b 25 * with this program; if not, write to the Free Software Foundation, Inc.,
HannesTschofenig 0:796d0f61a05b 26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
HannesTschofenig 0:796d0f61a05b 27 */
HannesTschofenig 0:796d0f61a05b 28 #ifndef POLARSSL_PADLOCK_H
HannesTschofenig 0:796d0f61a05b 29 #define POLARSSL_PADLOCK_H
HannesTschofenig 0:796d0f61a05b 30
HannesTschofenig 0:796d0f61a05b 31 #include "aes.h"
HannesTschofenig 0:796d0f61a05b 32
HannesTschofenig 0:796d0f61a05b 33 #define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
HannesTschofenig 0:796d0f61a05b 34
HannesTschofenig 0:796d0f61a05b 35 #if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
HannesTschofenig 0:796d0f61a05b 36
HannesTschofenig 0:796d0f61a05b 37 #ifndef POLARSSL_HAVE_X86
HannesTschofenig 0:796d0f61a05b 38 #define POLARSSL_HAVE_X86
HannesTschofenig 0:796d0f61a05b 39 #endif
HannesTschofenig 0:796d0f61a05b 40
HannesTschofenig 0:796d0f61a05b 41 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
HannesTschofenig 0:796d0f61a05b 42 #include <basetsd.h>
HannesTschofenig 0:796d0f61a05b 43 typedef INT32 int32_t;
HannesTschofenig 0:796d0f61a05b 44 #else
HannesTschofenig 0:796d0f61a05b 45 #include <inttypes.h>
HannesTschofenig 0:796d0f61a05b 46 #endif
HannesTschofenig 0:796d0f61a05b 47
HannesTschofenig 0:796d0f61a05b 48
HannesTschofenig 0:796d0f61a05b 49 #define PADLOCK_RNG 0x000C
HannesTschofenig 0:796d0f61a05b 50 #define PADLOCK_ACE 0x00C0
HannesTschofenig 0:796d0f61a05b 51 #define PADLOCK_PHE 0x0C00
HannesTschofenig 0:796d0f61a05b 52 #define PADLOCK_PMM 0x3000
HannesTschofenig 0:796d0f61a05b 53
HannesTschofenig 0:796d0f61a05b 54 #define PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
HannesTschofenig 0:796d0f61a05b 55
HannesTschofenig 0:796d0f61a05b 56 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 57 extern "C" {
HannesTschofenig 0:796d0f61a05b 58 #endif
HannesTschofenig 0:796d0f61a05b 59
HannesTschofenig 0:796d0f61a05b 60 /**
HannesTschofenig 0:796d0f61a05b 61 * \brief PadLock detection routine
HannesTschofenig 0:796d0f61a05b 62 *
HannesTschofenig 0:796d0f61a05b 63 * \param feature The feature to detect
HannesTschofenig 0:796d0f61a05b 64 *
HannesTschofenig 0:796d0f61a05b 65 * \return 1 if CPU has support for the feature, 0 otherwise
HannesTschofenig 0:796d0f61a05b 66 */
HannesTschofenig 0:796d0f61a05b 67 int padlock_supports( int feature );
HannesTschofenig 0:796d0f61a05b 68
HannesTschofenig 0:796d0f61a05b 69 /**
HannesTschofenig 0:796d0f61a05b 70 * \brief PadLock AES-ECB block en(de)cryption
HannesTschofenig 0:796d0f61a05b 71 *
HannesTschofenig 0:796d0f61a05b 72 * \param ctx AES context
HannesTschofenig 0:796d0f61a05b 73 * \param mode AES_ENCRYPT or AES_DECRYPT
HannesTschofenig 0:796d0f61a05b 74 * \param input 16-byte input block
HannesTschofenig 0:796d0f61a05b 75 * \param output 16-byte output block
HannesTschofenig 0:796d0f61a05b 76 *
HannesTschofenig 0:796d0f61a05b 77 * \return 0 if success, 1 if operation failed
HannesTschofenig 0:796d0f61a05b 78 */
HannesTschofenig 0:796d0f61a05b 79 int padlock_xcryptecb( aes_context *ctx,
HannesTschofenig 0:796d0f61a05b 80 int mode,
HannesTschofenig 0:796d0f61a05b 81 const unsigned char input[16],
HannesTschofenig 0:796d0f61a05b 82 unsigned char output[16] );
HannesTschofenig 0:796d0f61a05b 83
HannesTschofenig 0:796d0f61a05b 84 /**
HannesTschofenig 0:796d0f61a05b 85 * \brief PadLock AES-CBC buffer en(de)cryption
HannesTschofenig 0:796d0f61a05b 86 *
HannesTschofenig 0:796d0f61a05b 87 * \param ctx AES context
HannesTschofenig 0:796d0f61a05b 88 * \param mode AES_ENCRYPT or AES_DECRYPT
HannesTschofenig 0:796d0f61a05b 89 * \param length length of the input data
HannesTschofenig 0:796d0f61a05b 90 * \param iv initialization vector (updated after use)
HannesTschofenig 0:796d0f61a05b 91 * \param input buffer holding the input data
HannesTschofenig 0:796d0f61a05b 92 * \param output buffer holding the output data
HannesTschofenig 0:796d0f61a05b 93 *
HannesTschofenig 0:796d0f61a05b 94 * \return 0 if success, 1 if operation failed
HannesTschofenig 0:796d0f61a05b 95 */
HannesTschofenig 0:796d0f61a05b 96 int padlock_xcryptcbc( aes_context *ctx,
HannesTschofenig 0:796d0f61a05b 97 int mode,
HannesTschofenig 0:796d0f61a05b 98 size_t length,
HannesTschofenig 0:796d0f61a05b 99 unsigned char iv[16],
HannesTschofenig 0:796d0f61a05b 100 const unsigned char *input,
HannesTschofenig 0:796d0f61a05b 101 unsigned char *output );
HannesTschofenig 0:796d0f61a05b 102
HannesTschofenig 0:796d0f61a05b 103 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 104 }
HannesTschofenig 0:796d0f61a05b 105 #endif
HannesTschofenig 0:796d0f61a05b 106
HannesTschofenig 0:796d0f61a05b 107 #endif /* HAVE_X86 */
HannesTschofenig 0:796d0f61a05b 108
HannesTschofenig 0:796d0f61a05b 109 #endif /* padlock.h */
HannesTschofenig 0:796d0f61a05b 110
HannesTschofenig 0:796d0f61a05b 111