blob: b5f0d7d7a3d40962534b85073fc90157ae1f8cef [file] [log] [blame]
Jens Wiklander817466c2018-05-22 13:49:31 +02001/**
2 * \file padlock.h
3 *
4 * \brief VIA PadLock ACE for HW encryption/decryption supported by some
5 * processors
6 *
Jens Wiklander3d3b0592019-03-20 15:30:29 +01007 * \warning These functions are only for internal use by other library
8 * functions; you must not call them directly.
9 */
10/*
Jerome Forissier79013242021-07-28 10:24:04 +020011 * Copyright The Mbed TLS Contributors
12 * SPDX-License-Identifier: Apache-2.0
Jens Wiklander817466c2018-05-22 13:49:31 +020013 *
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.
Jens Wiklander817466c2018-05-22 13:49:31 +020025 */
26#ifndef MBEDTLS_PADLOCK_H
27#define MBEDTLS_PADLOCK_H
28
Jens Wiklander32b31802023-10-06 16:59:46 +020029#include "mbedtls/build_info.h"
Jerome Forissier5b25c762020-04-07 11:18:49 +020030
Jerome Forissier11fa71b2020-04-20 17:17:56 +020031#include "mbedtls/aes.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020032
Jens Wiklander32b31802023-10-06 16:59:46 +020033#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
Jens Wiklander817466c2018-05-22 13:49:31 +020034
35#if defined(__has_feature)
36#if __has_feature(address_sanitizer)
37#define MBEDTLS_HAVE_ASAN
38#endif
39#endif
40
41/* Some versions of ASan result in errors about not enough registers */
42#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
43 !defined(MBEDTLS_HAVE_ASAN)
44
45#ifndef MBEDTLS_HAVE_X86
46#define MBEDTLS_HAVE_X86
47#endif
48
49#include <stdint.h>
50
51#define MBEDTLS_PADLOCK_RNG 0x000C
52#define MBEDTLS_PADLOCK_ACE 0x00C0
53#define MBEDTLS_PADLOCK_PHE 0x0C00
54#define MBEDTLS_PADLOCK_PMM 0x3000
55
Jerome Forissier5b25c762020-04-07 11:18:49 +020056#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
Jens Wiklander817466c2018-05-22 13:49:31 +020057
58#ifdef __cplusplus
59extern "C" {
60#endif
61
62/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010063 * \brief Internal PadLock detection routine
64 *
65 * \note This function is only for internal use by other library
66 * functions; you must not call it directly.
Jens Wiklander817466c2018-05-22 13:49:31 +020067 *
68 * \param feature The feature to detect
69 *
Jerome Forissier79013242021-07-28 10:24:04 +020070 * \return non-zero if CPU has support for the feature, 0 otherwise
Jens Wiklander817466c2018-05-22 13:49:31 +020071 */
Jens Wiklander32b31802023-10-06 16:59:46 +020072int mbedtls_padlock_has_support(int feature);
Jens Wiklander817466c2018-05-22 13:49:31 +020073
74/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010075 * \brief Internal PadLock AES-ECB block en(de)cryption
76 *
77 * \note This function is only for internal use by other library
78 * functions; you must not call it directly.
Jens Wiklander817466c2018-05-22 13:49:31 +020079 *
80 * \param ctx AES context
81 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
82 * \param input 16-byte input block
83 * \param output 16-byte output block
84 *
85 * \return 0 if success, 1 if operation failed
86 */
Jens Wiklander32b31802023-10-06 16:59:46 +020087int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
88 int mode,
89 const unsigned char input[16],
90 unsigned char output[16]);
Jens Wiklander817466c2018-05-22 13:49:31 +020091
92/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010093 * \brief Internal PadLock AES-CBC buffer en(de)cryption
94 *
95 * \note This function is only for internal use by other library
96 * functions; you must not call it directly.
Jens Wiklander817466c2018-05-22 13:49:31 +020097 *
98 * \param ctx AES context
99 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
100 * \param length length of the input data
101 * \param iv initialization vector (updated after use)
102 * \param input buffer holding the input data
103 * \param output buffer holding the output data
104 *
105 * \return 0 if success, 1 if operation failed
106 */
Jens Wiklander32b31802023-10-06 16:59:46 +0200107int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx,
108 int mode,
109 size_t length,
110 unsigned char iv[16],
111 const unsigned char *input,
112 unsigned char *output);
Jens Wiklander817466c2018-05-22 13:49:31 +0200113
114#ifdef __cplusplus
115}
116#endif
117
118#endif /* HAVE_X86 */
119
120#endif /* padlock.h */