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