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