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