blob: 91ad2a6ca6f7818d155e2d2714153b5e6f52f4b5 [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
Darryl Greena40a1012018-01-05 15:33:17 +00006 */
7/*
Bence Szépkúti44bfbe32020-08-19 16:54:51 +02008 * Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02009 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
10 *
11 * This file is provided under the Apache License 2.0, or the
12 * GNU General Public License v2.0 or later.
13 *
14 * **********
15 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020016 *
17 * Licensed under the Apache License, Version 2.0 (the "License"); you may
18 * not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 *
21 * http://www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000028 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020029 * **********
30 *
31 * **********
32 * GNU General Public License v2.0 or later:
33 *
34 * This program is free software; you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License as published by
36 * the Free Software Foundation; either version 2 of the License, or
37 * (at your option) any later version.
38 *
39 * This program is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 * GNU General Public License for more details.
43 *
44 * You should have received a copy of the GNU General Public License along
45 * with this program; if not, write to the Free Software Foundation, Inc.,
46 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
47 *
48 * **********
Paul Bakker5121ce52009-01-03 21:22:43 +000049 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#ifndef MBEDTLS_PADLOCK_H
51#define MBEDTLS_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000052
Ron Eldor0559c662018-02-14 16:02:41 +020053#if !defined(MBEDTLS_CONFIG_FILE)
54#include "config.h"
55#else
56#include MBEDTLS_CONFIG_FILE
57#endif
58
Paul Bakker314052f2011-08-15 09:07:52 +000059#include "aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000060
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
Paul Bakker70338f52011-05-23 10:19:31 +000062
Manuel Pégourié-Gonnardf659f0c2015-08-04 22:19:05 +020063#if defined(__has_feature)
64#if __has_feature(address_sanitizer)
65#define MBEDTLS_HAVE_ASAN
66#endif
67#endif
68
69/* Some versions of ASan result in errors about not enough registers */
70#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
Manuel Pégourié-Gonnarde14dec62015-08-04 22:49:07 +020071 !defined(MBEDTLS_HAVE_ASAN)
Paul Bakker5121ce52009-01-03 21:22:43 +000072
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#ifndef MBEDTLS_HAVE_X86
74#define MBEDTLS_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000075#endif
76
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020077#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079#define MBEDTLS_PADLOCK_RNG 0x000C
80#define MBEDTLS_PADLOCK_ACE 0x00C0
81#define MBEDTLS_PADLOCK_PHE 0x0C00
82#define MBEDTLS_PADLOCK_PMM 0x3000
Paul Bakker5121ce52009-01-03 21:22:43 +000083
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000085
86#ifdef __cplusplus
87extern "C" {
88#endif
89
90/**
91 * \brief PadLock detection routine
92 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010093 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000094 *
Paul Bakker5121ce52009-01-03 21:22:43 +000095 * \return 1 if CPU has support for the feature, 0 otherwise
96 */
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +010097int mbedtls_padlock_has_support( int feature );
Paul Bakker5121ce52009-01-03 21:22:43 +000098
99/**
100 * \brief PadLock AES-ECB block en(de)cryption
101 *
102 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000104 * \param input 16-byte input block
105 * \param output 16-byte output block
106 *
107 * \return 0 if success, 1 if operation failed
108 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000111 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000112 unsigned char output[16] );
113
114/**
115 * \brief PadLock AES-CBC buffer en(de)cryption
116 *
117 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000119 * \param length length of the input data
120 * \param iv initialization vector (updated after use)
121 * \param input buffer holding the input data
122 * \param output buffer holding the output data
123 *
124 * \return 0 if success, 1 if operation failed
125 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000128 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000130 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 unsigned char *output );
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* HAVE_X86 */
138
139#endif /* padlock.h */