blob: 85868d9fe1d263e7b3cc134e13622012580ac615 [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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 * **********
49 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000050 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000051 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#ifndef MBEDTLS_PADLOCK_H
53#define MBEDTLS_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000054
Ron Eldor0559c662018-02-14 16:02:41 +020055#if !defined(MBEDTLS_CONFIG_FILE)
56#include "config.h"
57#else
58#include MBEDTLS_CONFIG_FILE
59#endif
60
Paul Bakker314052f2011-08-15 09:07:52 +000061#include "aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000062
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
Paul Bakker70338f52011-05-23 10:19:31 +000064
Manuel Pégourié-Gonnardf659f0c2015-08-04 22:19:05 +020065#if defined(__has_feature)
66#if __has_feature(address_sanitizer)
67#define MBEDTLS_HAVE_ASAN
68#endif
69#endif
70
71/* Some versions of ASan result in errors about not enough registers */
72#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
Manuel Pégourié-Gonnarde14dec62015-08-04 22:49:07 +020073 !defined(MBEDTLS_HAVE_ASAN)
Paul Bakker5121ce52009-01-03 21:22:43 +000074
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#ifndef MBEDTLS_HAVE_X86
76#define MBEDTLS_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000077#endif
78
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020079#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000080
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081#define MBEDTLS_PADLOCK_RNG 0x000C
82#define MBEDTLS_PADLOCK_ACE 0x00C0
83#define MBEDTLS_PADLOCK_PHE 0x0C00
84#define MBEDTLS_PADLOCK_PMM 0x3000
Paul Bakker5121ce52009-01-03 21:22:43 +000085
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000087
88#ifdef __cplusplus
89extern "C" {
90#endif
91
92/**
93 * \brief PadLock detection routine
94 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010095 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000096 *
Paul Bakker5121ce52009-01-03 21:22:43 +000097 * \return 1 if CPU has support for the feature, 0 otherwise
98 */
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +010099int mbedtls_padlock_has_support( int feature );
Paul Bakker5121ce52009-01-03 21:22:43 +0000100
101/**
102 * \brief PadLock AES-ECB block en(de)cryption
103 *
104 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000106 * \param input 16-byte input block
107 * \param output 16-byte output block
108 *
109 * \return 0 if success, 1 if operation failed
110 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000112 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000113 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 unsigned char output[16] );
115
116/**
117 * \brief PadLock AES-CBC buffer en(de)cryption
118 *
119 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000121 * \param length length of the input data
122 * \param iv initialization vector (updated after use)
123 * \param input buffer holding the input data
124 * \param output buffer holding the output data
125 *
126 * \return 0 if success, 1 if operation failed
127 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000130 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000132 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 unsigned char *output );
134
135#ifdef __cplusplus
136}
137#endif
138
139#endif /* HAVE_X86 */
140
141#endif /* padlock.h */