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