1 /**
2  * \file padlock.h
3  *
4  * \brief VIA PadLock ACE for HW encryption/decryption supported by some
5  *        processors
6  *
7  * \warning These functions are only for internal use by other library
8  *          functions; you must not call them directly.
9  */
10 /*
11  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
12  *  SPDX-License-Identifier: GPL-2.0
13  *
14  *  This program is free software; you can redistribute it and/or modify
15  *  it under the terms of the GNU General Public License as published by
16  *  the Free Software Foundation; either version 2 of the License, or
17  *  (at your option) any later version.
18  *
19  *  This program is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *  GNU General Public License for more details.
23  *
24  *  You should have received a copy of the GNU General Public License along
25  *  with this program; if not, write to the Free Software Foundation, Inc.,
26  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  *
28  *  This file is part of mbed TLS (https://tls.mbed.org)
29  */
30 #ifndef MBEDTLS_PADLOCK_H
31 #define MBEDTLS_PADLOCK_H
32 
33 #include "aes.h"
34 
35 #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED               -0x0030  /**< Input data should be aligned. */
36 
37 #if defined(__has_feature)
38 #if __has_feature(address_sanitizer)
39 #define MBEDTLS_HAVE_ASAN
40 #endif
41 #endif
42 
43 /* Some versions of ASan result in errors about not enough registers */
44 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
45     !defined(MBEDTLS_HAVE_ASAN)
46 
47 #ifndef MBEDTLS_HAVE_X86
48 #define MBEDTLS_HAVE_X86
49 #endif
50 
51 #include <stdint.h>
52 
53 #define MBEDTLS_PADLOCK_RNG 0x000C
54 #define MBEDTLS_PADLOCK_ACE 0x00C0
55 #define MBEDTLS_PADLOCK_PHE 0x0C00
56 #define MBEDTLS_PADLOCK_PMM 0x3000
57 
58 #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /**
65  * \brief          Internal PadLock detection routine
66  *
67  * \note           This function is only for internal use by other library
68  *                 functions; you must not call it directly.
69  *
70  * \param feature  The feature to detect
71  *
72  * \return         1 if CPU has support for the feature, 0 otherwise
73  */
74 int mbedtls_padlock_has_support( int feature );
75 
76 /**
77  * \brief          Internal PadLock AES-ECB block en(de)cryption
78  *
79  * \note           This function is only for internal use by other library
80  *                 functions; you must not call it directly.
81  *
82  * \param ctx      AES context
83  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
84  * \param input    16-byte input block
85  * \param output   16-byte output block
86  *
87  * \return         0 if success, 1 if operation failed
88  */
89 int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
90                                int mode,
91                                const unsigned char input[16],
92                                unsigned char output[16] );
93 
94 /**
95  * \brief          Internal PadLock AES-CBC buffer en(de)cryption
96  *
97  * \note           This function is only for internal use by other library
98  *                 functions; you must not call it directly.
99  *
100  * \param ctx      AES context
101  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
102  * \param length   length of the input data
103  * \param iv       initialization vector (updated after use)
104  * \param input    buffer holding the input data
105  * \param output   buffer holding the output data
106  *
107  * \return         0 if success, 1 if operation failed
108  */
109 int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
110                                int mode,
111                                size_t length,
112                                unsigned char iv[16],
113                                const unsigned char *input,
114                                unsigned char *output );
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif /* HAVE_X86  */
121 
122 #endif /* padlock.h */
123