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