blob: d8246e2cd015b7de3b4b7f14b33ba3df807591ca [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
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +01006 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +01007 * \warning These functions are only for internal use by other library
8 * functions; you must not call them directly.
Darryl Greena40a1012018-01-05 15:33:17 +00009 */
10/*
Bence Szépkútia2947ac2020-08-19 16:37:36 +020011 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +020012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13 *
14 * This file is provided under the Apache License 2.0, or the
15 * GNU General Public License v2.0 or later.
16 *
17 * **********
18 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020019 *
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may
21 * not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000031 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020032 * **********
33 *
34 * **********
35 * GNU General Public License v2.0 or later:
36 *
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License along
48 * with this program; if not, write to the Free Software Foundation, Inc.,
49 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50 *
51 * **********
Paul Bakker5121ce52009-01-03 21:22:43 +000052 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#ifndef MBEDTLS_PADLOCK_H
54#define MBEDTLS_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000055
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020056#if !defined(MBEDTLS_CONFIG_FILE)
57#include "config.h"
58#else
59#include MBEDTLS_CONFIG_FILE
60#endif
61
Paul Bakker314052f2011-08-15 09:07:52 +000062#include "aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000063
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
Paul Bakker70338f52011-05-23 10:19:31 +000065
Manuel Pégourié-Gonnardf659f0c2015-08-04 22:19:05 +020066#if defined(__has_feature)
67#if __has_feature(address_sanitizer)
68#define MBEDTLS_HAVE_ASAN
69#endif
70#endif
71
72/* Some versions of ASan result in errors about not enough registers */
73#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
Manuel Pégourié-Gonnarde14dec62015-08-04 22:49:07 +020074 !defined(MBEDTLS_HAVE_ASAN)
Paul Bakker5121ce52009-01-03 21:22:43 +000075
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#ifndef MBEDTLS_HAVE_X86
77#define MBEDTLS_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000078#endif
79
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020080#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000081
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082#define MBEDTLS_PADLOCK_RNG 0x000C
83#define MBEDTLS_PADLOCK_ACE 0x00C0
84#define MBEDTLS_PADLOCK_PHE 0x0C00
85#define MBEDTLS_PADLOCK_PMM 0x3000
Paul Bakker5121ce52009-01-03 21:22:43 +000086
Hanno Beckerd6028a12018-10-15 12:01:35 +010087#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000088
89#ifdef __cplusplus
90extern "C" {
91#endif
92
93/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +010094 * \brief Internal PadLock detection routine
95 *
96 * \note This function is only for internal use by other library
97 * functions; you must not call it directly.
Paul Bakker5121ce52009-01-03 21:22:43 +000098 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010099 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +0000100 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000101 * \return 1 if CPU has support for the feature, 0 otherwise
102 */
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100103int mbedtls_padlock_has_support( int feature );
Paul Bakker5121ce52009-01-03 21:22:43 +0000104
105/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +0100106 * \brief Internal PadLock AES-ECB block en(de)cryption
107 *
108 * \note This function is only for internal use by other library
109 * functions; you must not call it directly.
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 *
111 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000113 * \param input 16-byte input block
114 * \param output 16-byte output block
115 *
116 * \return 0 if success, 1 if operation failed
117 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +0100119 int mode,
120 const unsigned char input[16],
121 unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000122
123/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +0100124 * \brief Internal PadLock AES-CBC buffer en(de)cryption
125 *
126 * \note This function is only for internal use by other library
127 * functions; you must not call it directly.
Paul Bakker5121ce52009-01-03 21:22:43 +0000128 *
129 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 * \param length length of the input data
132 * \param iv initialization vector (updated after use)
133 * \param input buffer holding the input data
134 * \param output buffer holding the output data
135 *
136 * \return 0 if success, 1 if operation failed
137 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +0100139 int mode,
140 size_t length,
141 unsigned char iv[16],
142 const unsigned char *input,
143 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +0000144
145#ifdef __cplusplus
146}
147#endif
148
149#endif /* HAVE_X86 */
150
151#endif /* padlock.h */