• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 The Mbed TLS Contributors
12  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13  */
14 #ifndef MBEDTLS_PADLOCK_H
15 #define MBEDTLS_PADLOCK_H
16 
17 #if !defined(MBEDTLS_CONFIG_FILE)
18 #include "mbedtls/config.h"
19 #else
20 #include MBEDTLS_CONFIG_FILE
21 #endif
22 
23 #include "mbedtls/aes.h"
24 
25 /** Input data should be aligned. */
26 #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED               -0x0030
27 
28 #if defined(__has_feature)
29 #if __has_feature(address_sanitizer)
30 #define MBEDTLS_HAVE_ASAN
31 #endif
32 #endif
33 
34 /* Some versions of ASan result in errors about not enough registers */
35 #if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_ASM) && \
36     defined(__GNUC__) && defined(__i386__) && \
37     !defined(MBEDTLS_HAVE_ASAN)
38 
39 #define MBEDTLS_VIA_PADLOCK_HAVE_CODE
40 
41 #ifndef MBEDTLS_HAVE_X86
42 #define MBEDTLS_HAVE_X86
43 #endif
44 
45 #include <stdint.h>
46 
47 #define MBEDTLS_PADLOCK_RNG 0x000C
48 #define MBEDTLS_PADLOCK_ACE 0x00C0
49 #define MBEDTLS_PADLOCK_PHE 0x0C00
50 #define MBEDTLS_PADLOCK_PMM 0x3000
51 
52 #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /**
59  * \brief          Internal PadLock detection routine
60  *
61  * \note           This function is only for internal use by other library
62  *                 functions; you must not call it directly.
63  *
64  * \param feature  The feature to detect
65  *
66  * \return         non-zero if CPU has support for the feature, 0 otherwise
67  */
68 int mbedtls_padlock_has_support(int feature);
69 
70 /**
71  * \brief          Internal PadLock AES-ECB block en(de)cryption
72  *
73  * \note           This function is only for internal use by other library
74  *                 functions; you must not call it directly.
75  *
76  * \param ctx      AES context
77  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
78  * \param input    16-byte input block
79  * \param output   16-byte output block
80  *
81  * \return         0 if success, 1 if operation failed
82  */
83 int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
84                               int mode,
85                               const unsigned char input[16],
86                               unsigned char output[16]);
87 
88 /**
89  * \brief          Internal PadLock AES-CBC buffer en(de)cryption
90  *
91  * \note           This function is only for internal use by other library
92  *                 functions; you must not call it directly.
93  *
94  * \param ctx      AES context
95  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
96  * \param length   length of the input data
97  * \param iv       initialization vector (updated after use)
98  * \param input    buffer holding the input data
99  * \param output   buffer holding the output data
100  *
101  * \return         0 if success, 1 if operation failed
102  */
103 int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx,
104                               int mode,
105                               size_t length,
106                               unsigned char iv[16],
107                               const unsigned char *input,
108                               unsigned char *output);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif /* MBEDTLS_PADLOCK_C && MBEDTLS_HAVE_ASM &&
115           __GNUC__ && __i386__ && !MBEDTLS_HAVE_ASAN */
116 
117 #endif /* padlock.h */
118