xref: /optee_os/lib/libmbedtls/mbedtls/library/padlock.h (revision 32b3180828fa15a49ccc86ecb4be9d274c140c89)
1*32b31808SJens Wiklander /**
2*32b31808SJens Wiklander  * \file padlock.h
3*32b31808SJens Wiklander  *
4*32b31808SJens Wiklander  * \brief VIA PadLock ACE for HW encryption/decryption supported by some
5*32b31808SJens Wiklander  *        processors
6*32b31808SJens Wiklander  *
7*32b31808SJens Wiklander  * \warning These functions are only for internal use by other library
8*32b31808SJens Wiklander  *          functions; you must not call them directly.
9*32b31808SJens Wiklander  */
10*32b31808SJens Wiklander /*
11*32b31808SJens Wiklander  *  Copyright The Mbed TLS Contributors
12*32b31808SJens Wiklander  *  SPDX-License-Identifier: Apache-2.0
13*32b31808SJens Wiklander  *
14*32b31808SJens Wiklander  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
15*32b31808SJens Wiklander  *  not use this file except in compliance with the License.
16*32b31808SJens Wiklander  *  You may obtain a copy of the License at
17*32b31808SJens Wiklander  *
18*32b31808SJens Wiklander  *  http://www.apache.org/licenses/LICENSE-2.0
19*32b31808SJens Wiklander  *
20*32b31808SJens Wiklander  *  Unless required by applicable law or agreed to in writing, software
21*32b31808SJens Wiklander  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22*32b31808SJens Wiklander  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23*32b31808SJens Wiklander  *  See the License for the specific language governing permissions and
24*32b31808SJens Wiklander  *  limitations under the License.
25*32b31808SJens Wiklander  */
26*32b31808SJens Wiklander #ifndef MBEDTLS_PADLOCK_H
27*32b31808SJens Wiklander #define MBEDTLS_PADLOCK_H
28*32b31808SJens Wiklander 
29*32b31808SJens Wiklander #include "mbedtls/build_info.h"
30*32b31808SJens Wiklander 
31*32b31808SJens Wiklander #include "mbedtls/aes.h"
32*32b31808SJens Wiklander 
33*32b31808SJens Wiklander #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED               -0x0030  /**< Input data should be aligned. */
34*32b31808SJens Wiklander 
35*32b31808SJens Wiklander #if defined(__has_feature)
36*32b31808SJens Wiklander #if __has_feature(address_sanitizer)
37*32b31808SJens Wiklander #define MBEDTLS_HAVE_ASAN
38*32b31808SJens Wiklander #endif
39*32b31808SJens Wiklander #endif
40*32b31808SJens Wiklander 
41*32b31808SJens Wiklander /* Some versions of ASan result in errors about not enough registers */
42*32b31808SJens Wiklander #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
43*32b31808SJens Wiklander     !defined(MBEDTLS_HAVE_ASAN)
44*32b31808SJens Wiklander 
45*32b31808SJens Wiklander #ifndef MBEDTLS_HAVE_X86
46*32b31808SJens Wiklander #define MBEDTLS_HAVE_X86
47*32b31808SJens Wiklander #endif
48*32b31808SJens Wiklander 
49*32b31808SJens Wiklander #include <stdint.h>
50*32b31808SJens Wiklander 
51*32b31808SJens Wiklander #define MBEDTLS_PADLOCK_RNG 0x000C
52*32b31808SJens Wiklander #define MBEDTLS_PADLOCK_ACE 0x00C0
53*32b31808SJens Wiklander #define MBEDTLS_PADLOCK_PHE 0x0C00
54*32b31808SJens Wiklander #define MBEDTLS_PADLOCK_PMM 0x3000
55*32b31808SJens Wiklander 
56*32b31808SJens Wiklander #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
57*32b31808SJens Wiklander 
58*32b31808SJens Wiklander #ifdef __cplusplus
59*32b31808SJens Wiklander extern "C" {
60*32b31808SJens Wiklander #endif
61*32b31808SJens Wiklander 
62*32b31808SJens Wiklander /**
63*32b31808SJens Wiklander  * \brief          Internal PadLock detection routine
64*32b31808SJens Wiklander  *
65*32b31808SJens Wiklander  * \note           This function is only for internal use by other library
66*32b31808SJens Wiklander  *                 functions; you must not call it directly.
67*32b31808SJens Wiklander  *
68*32b31808SJens Wiklander  * \param feature  The feature to detect
69*32b31808SJens Wiklander  *
70*32b31808SJens Wiklander  * \return         non-zero if CPU has support for the feature, 0 otherwise
71*32b31808SJens Wiklander  */
72*32b31808SJens Wiklander int mbedtls_padlock_has_support(int feature);
73*32b31808SJens Wiklander 
74*32b31808SJens Wiklander /**
75*32b31808SJens Wiklander  * \brief          Internal PadLock AES-ECB block en(de)cryption
76*32b31808SJens Wiklander  *
77*32b31808SJens Wiklander  * \note           This function is only for internal use by other library
78*32b31808SJens Wiklander  *                 functions; you must not call it directly.
79*32b31808SJens Wiklander  *
80*32b31808SJens Wiklander  * \param ctx      AES context
81*32b31808SJens Wiklander  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
82*32b31808SJens Wiklander  * \param input    16-byte input block
83*32b31808SJens Wiklander  * \param output   16-byte output block
84*32b31808SJens Wiklander  *
85*32b31808SJens Wiklander  * \return         0 if success, 1 if operation failed
86*32b31808SJens Wiklander  */
87*32b31808SJens Wiklander int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
88*32b31808SJens Wiklander                               int mode,
89*32b31808SJens Wiklander                               const unsigned char input[16],
90*32b31808SJens Wiklander                               unsigned char output[16]);
91*32b31808SJens Wiklander 
92*32b31808SJens Wiklander /**
93*32b31808SJens Wiklander  * \brief          Internal PadLock AES-CBC buffer en(de)cryption
94*32b31808SJens Wiklander  *
95*32b31808SJens Wiklander  * \note           This function is only for internal use by other library
96*32b31808SJens Wiklander  *                 functions; you must not call it directly.
97*32b31808SJens Wiklander  *
98*32b31808SJens Wiklander  * \param ctx      AES context
99*32b31808SJens Wiklander  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
100*32b31808SJens Wiklander  * \param length   length of the input data
101*32b31808SJens Wiklander  * \param iv       initialization vector (updated after use)
102*32b31808SJens Wiklander  * \param input    buffer holding the input data
103*32b31808SJens Wiklander  * \param output   buffer holding the output data
104*32b31808SJens Wiklander  *
105*32b31808SJens Wiklander  * \return         0 if success, 1 if operation failed
106*32b31808SJens Wiklander  */
107*32b31808SJens Wiklander int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx,
108*32b31808SJens Wiklander                               int mode,
109*32b31808SJens Wiklander                               size_t length,
110*32b31808SJens Wiklander                               unsigned char iv[16],
111*32b31808SJens Wiklander                               const unsigned char *input,
112*32b31808SJens Wiklander                               unsigned char *output);
113*32b31808SJens Wiklander 
114*32b31808SJens Wiklander #ifdef __cplusplus
115*32b31808SJens Wiklander }
116*32b31808SJens Wiklander #endif
117*32b31808SJens Wiklander 
118*32b31808SJens Wiklander #endif /* HAVE_X86  */
119*32b31808SJens Wiklander 
120*32b31808SJens Wiklander #endif /* padlock.h */
121