blob: 8fb4e5cbf14777355afe78c4c087ff3df907659f [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file padlock.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker83ded912010-03-21 17:46:26 +00004 * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00005 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00006 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 * 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 Bakker5121ce52009-01-03 21:22:43 +000020 */
Paul Bakker40e46942009-01-03 21:51:57 +000021#ifndef POLARSSL_PADLOCK_H
22#define POLARSSL_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000023
Paul Bakker8e831ed2009-01-03 21:24:11 +000024#include "polarssl/aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Paul Bakker34a90562009-04-19 21:17:09 +000026#if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Paul Bakker40e46942009-01-03 21:51:57 +000028#ifndef POLARSSL_HAVE_X86
29#define POLARSSL_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000030#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 Bakkerf3ccc682010-03-18 21:21:02 +000039#define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x08E0
40
Paul Bakker5121ce52009-01-03 21:22:43 +000041#ifdef __cplusplus
42extern "C" {
43#endif
44
45/**
46 * \brief PadLock detection routine
47 *
Paul Bakker13e2dfe2009-07-28 07:18:38 +000048 * \param The feature to detect
49 *
Paul Bakker5121ce52009-01-03 21:22:43 +000050 * \return 1 if CPU has support for the feature, 0 otherwise
51 */
52int 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 */
64int padlock_xcryptecb( aes_context *ctx,
65 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000066 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +000067 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 */
81int padlock_xcryptcbc( aes_context *ctx,
82 int mode,
83 int length,
84 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +000085 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +000086 unsigned char *output );
87
88#ifdef __cplusplus
89}
90#endif
91
92#endif /* HAVE_X86 */
93
94#endif /* padlock.h */