blob: 12fa7d3c95a79ac912277734080e887913897e0d [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file padlock.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000011 * 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 Bakker5121ce52009-01-03 21:22:43 +000024 */
Paul Bakker40e46942009-01-03 21:51:57 +000025#ifndef POLARSSL_PADLOCK_H
26#define POLARSSL_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Paul Bakker8e831ed2009-01-03 21:24:11 +000028#include "polarssl/aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker34a90562009-04-19 21:17:09 +000030#if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
Paul Bakker5121ce52009-01-03 21:22:43 +000031
Paul Bakker40e46942009-01-03 21:51:57 +000032#ifndef POLARSSL_HAVE_X86
33#define POLARSSL_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000034#endif
35
36#define PADLOCK_RNG 0x000C
37#define PADLOCK_ACE 0x00C0
38#define PADLOCK_PHE 0x0C00
39#define PADLOCK_PMM 0x3000
40
41#define PADLOCK_ALIGN16(x) (unsigned long *) (16 + ((long) x & ~15))
42
Paul Bakkerf3ccc682010-03-18 21:21:02 +000043#define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x08E0
44
Paul Bakker5121ce52009-01-03 21:22:43 +000045#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * \brief PadLock detection routine
51 *
Paul Bakker13e2dfe2009-07-28 07:18:38 +000052 * \param The feature to detect
53 *
Paul Bakker5121ce52009-01-03 21:22:43 +000054 * \return 1 if CPU has support for the feature, 0 otherwise
55 */
56int padlock_supports( int feature );
57
58/**
59 * \brief PadLock AES-ECB block en(de)cryption
60 *
61 * \param ctx AES context
62 * \param mode AES_ENCRYPT or AES_DECRYPT
63 * \param input 16-byte input block
64 * \param output 16-byte output block
65 *
66 * \return 0 if success, 1 if operation failed
67 */
68int padlock_xcryptecb( aes_context *ctx,
69 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000070 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +000071 unsigned char output[16] );
72
73/**
74 * \brief PadLock AES-CBC buffer en(de)cryption
75 *
76 * \param ctx AES context
77 * \param mode AES_ENCRYPT or AES_DECRYPT
78 * \param length length of the input data
79 * \param iv initialization vector (updated after use)
80 * \param input buffer holding the input data
81 * \param output buffer holding the output data
82 *
83 * \return 0 if success, 1 if operation failed
84 */
85int padlock_xcryptcbc( aes_context *ctx,
86 int mode,
87 int length,
88 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +000089 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +000090 unsigned char *output );
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif /* HAVE_X86 */
97
98#endif /* padlock.h */