blob: c3815832b70d806c72a5a7ab5cb83ba2ada95ac9 [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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#ifndef MBEDTLS_PADLOCK_H
26#define MBEDTLS_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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
Paul Bakker70338f52011-05-23 10:19:31 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
Paul Bakker5121ce52009-01-03 21:22:43 +000033
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#ifndef MBEDTLS_HAVE_X86
35#define MBEDTLS_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000036#endif
37
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020038#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000039
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#define MBEDTLS_PADLOCK_RNG 0x000C
41#define MBEDTLS_PADLOCK_ACE 0x00C0
42#define MBEDTLS_PADLOCK_PHE 0x0C00
43#define MBEDTLS_PADLOCK_PMM 0x3000
Paul Bakker5121ce52009-01-03 21:22:43 +000044
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000046
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * \brief PadLock detection routine
53 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010054 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000055 *
Paul Bakker5121ce52009-01-03 21:22:43 +000056 * \return 1 if CPU has support for the feature, 0 otherwise
57 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058int mbedtls_padlock_supports( int feature );
Paul Bakker5121ce52009-01-03 21:22:43 +000059
60/**
61 * \brief PadLock AES-ECB block en(de)cryption
62 *
63 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +000065 * \param input 16-byte input block
66 * \param output 16-byte output block
67 *
68 * \return 0 if success, 1 if operation failed
69 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +000071 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000072 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +000073 unsigned char output[16] );
74
75/**
76 * \brief PadLock AES-CBC buffer en(de)cryption
77 *
78 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +000080 * \param length length of the input data
81 * \param iv initialization vector (updated after use)
82 * \param input buffer holding the input data
83 * \param output buffer holding the output data
84 *
85 * \return 0 if success, 1 if operation failed
86 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +000088 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +000089 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +000090 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +000091 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +000092 unsigned char *output );
93
94#ifdef __cplusplus
95}
96#endif
97
98#endif /* HAVE_X86 */
99
100#endif /* padlock.h */