blob: 01069ea7dd43b3fa8d777a8ad47781cf302448a8 [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úti1e148272020-08-07 13:07:28 +020011 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License"); you may
15 * not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
Paul Bakker5121ce52009-01-03 21:22:43 +000025 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#ifndef MBEDTLS_PADLOCK_H
27#define MBEDTLS_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000028
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020029#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010030#include "mbedtls/config.h"
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020031#else
32#include MBEDTLS_CONFIG_FILE
33#endif
34
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010035#include "mbedtls/aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000036
Gilles Peskinea3974432021-07-26 18:48:10 +020037/** Input data should be aligned. */
38#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030
Paul Bakker70338f52011-05-23 10:19:31 +000039
Manuel Pégourié-Gonnardf659f0c2015-08-04 22:19:05 +020040#if defined(__has_feature)
41#if __has_feature(address_sanitizer)
42#define MBEDTLS_HAVE_ASAN
43#endif
44#endif
45
46/* Some versions of ASan result in errors about not enough registers */
47#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
Manuel Pégourié-Gonnarde14dec62015-08-04 22:49:07 +020048 !defined(MBEDTLS_HAVE_ASAN)
Paul Bakker5121ce52009-01-03 21:22:43 +000049
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#ifndef MBEDTLS_HAVE_X86
51#define MBEDTLS_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000052#endif
53
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020054#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#define MBEDTLS_PADLOCK_RNG 0x000C
57#define MBEDTLS_PADLOCK_ACE 0x00C0
58#define MBEDTLS_PADLOCK_PHE 0x0C00
59#define MBEDTLS_PADLOCK_PMM 0x3000
Paul Bakker5121ce52009-01-03 21:22:43 +000060
Hanno Becker1eeca412018-10-15 12:01:35 +010061#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000062
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +010068 * \brief Internal PadLock detection routine
69 *
70 * \note This function is only for internal use by other library
71 * functions; you must not call it directly.
Paul Bakker5121ce52009-01-03 21:22:43 +000072 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010073 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000074 *
Dave Rodgman6efa7222021-05-18 18:59:37 +010075 * \return non-zero if CPU has support for the feature, 0 otherwise
Paul Bakker5121ce52009-01-03 21:22:43 +000076 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010077int mbedtls_padlock_has_support(int feature);
Paul Bakker5121ce52009-01-03 21:22:43 +000078
79/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +010080 * \brief Internal PadLock AES-ECB block en(de)cryption
81 *
82 * \note This function is only for internal use by other library
83 * functions; you must not call it directly.
Paul Bakker5121ce52009-01-03 21:22:43 +000084 *
85 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +000087 * \param input 16-byte input block
88 * \param output 16-byte output block
89 *
90 * \return 0 if success, 1 if operation failed
91 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010092int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
93 int mode,
94 const unsigned char input[16],
95 unsigned char output[16]);
Paul Bakker5121ce52009-01-03 21:22:43 +000096
97/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +010098 * \brief Internal PadLock AES-CBC buffer en(de)cryption
99 *
100 * \note This function is only for internal use by other library
101 * functions; you must not call it directly.
Paul Bakker5121ce52009-01-03 21:22:43 +0000102 *
103 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +0000105 * \param length length of the input data
106 * \param iv initialization vector (updated after use)
107 * \param input buffer holding the input data
108 * \param output buffer holding the output data
109 *
110 * \return 0 if success, 1 if operation failed
111 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100112int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx,
113 int mode,
114 size_t length,
115 unsigned char iv[16],
116 const unsigned char *input,
117 unsigned char *output);
Paul Bakker5121ce52009-01-03 21:22:43 +0000118
119#ifdef __cplusplus
120}
121#endif
122
123#endif /* HAVE_X86 */
124
125#endif /* padlock.h */