blob: c4ac54cb973dc57e8fa079a644fcf16027ad7cb2 [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 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00007 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00009 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +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 Bakker314052f2011-08-15 09:07:52 +000028#include "aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker70338f52011-05-23 10:19:31 +000030#define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
31
Manuel Pégourié-Gonnard027ead92015-08-10 17:44:53 +020032#if defined(__has_feature)
33#if __has_feature(address_sanitizer)
34#define POLARSSL_HAVE_ASAN
35#endif
36#endif
37
38/* Some versions of ASan result in errors about not enough registers */
39#if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
40 !defined(POLARSSL_HAVE_ASAN)
Paul Bakker5121ce52009-01-03 21:22:43 +000041
Paul Bakker40e46942009-01-03 21:51:57 +000042#ifndef POLARSSL_HAVE_X86
43#define POLARSSL_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000044#endif
45
Paul Bakkerfa6a6202013-10-28 18:48:30 +010046#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker5c2364c2012-10-01 14:41:15 +000047#include <basetsd.h>
48typedef INT32 int32_t;
49#else
50#include <inttypes.h>
51#endif
52
Paul Bakker5121ce52009-01-03 21:22:43 +000053#define PADLOCK_RNG 0x000C
54#define PADLOCK_ACE 0x00C0
55#define PADLOCK_PHE 0x0C00
56#define PADLOCK_PMM 0x3000
57
Paul Bakker5c2364c2012-10-01 14:41:15 +000058#define PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000059
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64/**
65 * \brief PadLock detection routine
66 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010067 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000068 *
Paul Bakker5121ce52009-01-03 21:22:43 +000069 * \return 1 if CPU has support for the feature, 0 otherwise
70 */
71int padlock_supports( int feature );
72
73/**
74 * \brief PadLock AES-ECB block en(de)cryption
75 *
76 * \param ctx AES context
77 * \param mode AES_ENCRYPT or AES_DECRYPT
78 * \param input 16-byte input block
79 * \param output 16-byte output block
80 *
81 * \return 0 if success, 1 if operation failed
82 */
83int padlock_xcryptecb( aes_context *ctx,
84 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000085 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +000086 unsigned char output[16] );
87
88/**
89 * \brief PadLock AES-CBC buffer en(de)cryption
90 *
91 * \param ctx AES context
92 * \param mode AES_ENCRYPT or AES_DECRYPT
93 * \param length length of the input data
94 * \param iv initialization vector (updated after use)
95 * \param input buffer holding the input data
96 * \param output buffer holding the output data
97 *
98 * \return 0 if success, 1 if operation failed
99 */
100int padlock_xcryptcbc( aes_context *ctx,
101 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000102 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000103 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000104 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000105 unsigned char *output );
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif /* HAVE_X86 */
112
113#endif /* padlock.h */