blob: 3c5f7258b4f6e2d2e2aebd1501e64ba5d3353b0f [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file padlock.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02004 * \brief VIA PadLock ACE for HW encryption/decryption supported by some
5 * processors
Paul Bakker37ca75d2011-01-06 12:28:03 +00006 *
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02007 * Copyright (C) 2006-2014, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
9 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +000010 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000011 *
Paul Bakker77b385e2009-07-28 17:23:11 +000012 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000014 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000027 */
Paul Bakker40e46942009-01-03 21:51:57 +000028#ifndef POLARSSL_PADLOCK_H
29#define POLARSSL_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Paul Bakker314052f2011-08-15 09:07:52 +000031#include "aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000032
Paul Bakker70338f52011-05-23 10:19:31 +000033#define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
34
Paul Bakker34a90562009-04-19 21:17:09 +000035#if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
Paul Bakker5121ce52009-01-03 21:22:43 +000036
Paul Bakker40e46942009-01-03 21:51:57 +000037#ifndef POLARSSL_HAVE_X86
38#define POLARSSL_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000039#endif
40
Paul Bakkerfa6a6202013-10-28 18:48:30 +010041#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker5c2364c2012-10-01 14:41:15 +000042#include <basetsd.h>
43typedef INT32 int32_t;
44#else
45#include <inttypes.h>
46#endif
47
48
Paul Bakker5121ce52009-01-03 21:22:43 +000049#define PADLOCK_RNG 0x000C
50#define PADLOCK_ACE 0x00C0
51#define PADLOCK_PHE 0x0C00
52#define PADLOCK_PMM 0x3000
53
Paul Bakker5c2364c2012-10-01 14:41:15 +000054#define PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000055
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60/**
61 * \brief PadLock detection routine
62 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010063 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000064 *
Paul Bakker5121ce52009-01-03 21:22:43 +000065 * \return 1 if CPU has support for the feature, 0 otherwise
66 */
67int padlock_supports( int feature );
68
69/**
70 * \brief PadLock AES-ECB block en(de)cryption
71 *
72 * \param ctx AES context
73 * \param mode AES_ENCRYPT or AES_DECRYPT
74 * \param input 16-byte input block
75 * \param output 16-byte output block
76 *
77 * \return 0 if success, 1 if operation failed
78 */
79int padlock_xcryptecb( aes_context *ctx,
80 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000081 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +000082 unsigned char output[16] );
83
84/**
85 * \brief PadLock AES-CBC buffer en(de)cryption
86 *
87 * \param ctx AES context
88 * \param mode AES_ENCRYPT or AES_DECRYPT
89 * \param length length of the input data
90 * \param iv initialization vector (updated after use)
91 * \param input buffer holding the input data
92 * \param output buffer holding the output data
93 *
94 * \return 0 if success, 1 if operation failed
95 */
96int padlock_xcryptcbc( aes_context *ctx,
97 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +000098 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +000099 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000100 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000101 unsigned char *output );
102
103#ifdef __cplusplus
104}
105#endif
106
107#endif /* HAVE_X86 */
108
109#endif /* padlock.h */