blob: 4f4e40034622b535fa348c385d60b99457e812d0 [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
Jerome Forissier5b25c762020-04-07 11:18:49 +020029#if !defined(MBEDTLS_CONFIG_FILE)
Jerome Forissier11fa71b2020-04-20 17:17:56 +020030#include "mbedtls/config.h"
Jerome Forissier5b25c762020-04-07 11:18:49 +020031#else
32#include MBEDTLS_CONFIG_FILE
33#endif
34
Jerome Forissier11fa71b2020-04-20 17:17:56 +020035#include "mbedtls/aes.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020036
37#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
38
39#if defined(__has_feature)
40#if __has_feature(address_sanitizer)
41#define MBEDTLS_HAVE_ASAN
42#endif
43#endif
44
45/* Some versions of ASan result in errors about not enough registers */
46#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
47 !defined(MBEDTLS_HAVE_ASAN)
48
49#ifndef MBEDTLS_HAVE_X86
50#define MBEDTLS_HAVE_X86
51#endif
52
53#include <stdint.h>
54
55#define MBEDTLS_PADLOCK_RNG 0x000C
56#define MBEDTLS_PADLOCK_ACE 0x00C0
57#define MBEDTLS_PADLOCK_PHE 0x0C00
58#define MBEDTLS_PADLOCK_PMM 0x3000
59
Jerome Forissier5b25c762020-04-07 11:18:49 +020060#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
Jens Wiklander817466c2018-05-22 13:49:31 +020061
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010067 * \brief Internal PadLock detection routine
68 *
69 * \note This function is only for internal use by other library
70 * functions; you must not call it directly.
Jens Wiklander817466c2018-05-22 13:49:31 +020071 *
72 * \param feature The feature to detect
73 *
Jerome Forissier79013242021-07-28 10:24:04 +020074 * \return non-zero if CPU has support for the feature, 0 otherwise
Jens Wiklander817466c2018-05-22 13:49:31 +020075 */
76int mbedtls_padlock_has_support( int feature );
77
78/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010079 * \brief Internal PadLock AES-ECB block en(de)cryption
80 *
81 * \note This function is only for internal use by other library
82 * functions; you must not call it directly.
Jens Wiklander817466c2018-05-22 13:49:31 +020083 *
84 * \param ctx AES context
85 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
86 * \param input 16-byte input block
87 * \param output 16-byte output block
88 *
89 * \return 0 if success, 1 if operation failed
90 */
91int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
Jens Wiklander3d3b0592019-03-20 15:30:29 +010092 int mode,
93 const unsigned char input[16],
94 unsigned char output[16] );
Jens Wiklander817466c2018-05-22 13:49:31 +020095
96/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010097 * \brief Internal PadLock AES-CBC buffer en(de)cryption
98 *
99 * \note This function is only for internal use by other library
100 * functions; you must not call it directly.
Jens Wiklander817466c2018-05-22 13:49:31 +0200101 *
102 * \param ctx AES context
103 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
104 * \param length length of the input data
105 * \param iv initialization vector (updated after use)
106 * \param input buffer holding the input data
107 * \param output buffer holding the output data
108 *
109 * \return 0 if success, 1 if operation failed
110 */
111int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100112 int mode,
113 size_t length,
114 unsigned char iv[16],
115 const unsigned char *input,
116 unsigned char *output );
Jens Wiklander817466c2018-05-22 13:49:31 +0200117
118#ifdef __cplusplus
119}
120#endif
121
122#endif /* HAVE_X86 */
123
124#endif /* padlock.h */