Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file padlock.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 4 | * \brief VIA PadLock ACE for HW encryption/decryption supported by some |
| 5 | * processors |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 6 | * |
Manuel Pégourié-Gonnard | b66e7db | 2018-12-18 09:57:18 +0100 | [diff] [blame] | 7 | * \warning These functions are only for internal use by other library |
| 8 | * functions; you must not call them directly. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 9 | */ |
| 10 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 11 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 12 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 13 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 14 | #ifndef MBEDTLS_PADLOCK_H |
| 15 | #define MBEDTLS_PADLOCK_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 16 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 17 | #include "mbedtls/build_info.h" |
Ron Eldor | 8b0cf2e | 2018-02-14 16:02:41 +0200 | [diff] [blame] | 18 | |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 19 | #include "mbedtls/aes.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 20 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 21 | #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ |
Paul Bakker | 70338f5 | 2011-05-23 10:19:31 +0000 | [diff] [blame] | 22 | |
Manuel Pégourié-Gonnard | f659f0c | 2015-08-04 22:19:05 +0200 | [diff] [blame] | 23 | #if defined(__has_feature) |
| 24 | #if __has_feature(address_sanitizer) |
| 25 | #define MBEDTLS_HAVE_ASAN |
| 26 | #endif |
| 27 | #endif |
| 28 | |
Jerry Yu | f65f71e | 2023-08-28 10:58:24 +0800 | [diff] [blame] | 29 | /* |
| 30 | * - `padlock` is implements with GNUC assembly for x86 target. |
| 31 | * - Some versions of ASan result in errors about not enough registers. |
| 32 | */ |
| 33 | #if defined(MBEDTLS_PADLOCK_C) && \ |
| 34 | defined(__GNUC__) && defined(MBEDTLS_ARCH_IS_X86) && \ |
| 35 | defined(MBEDTLS_HAVE_ASM) && \ |
| 36 | !defined(MBEDTLS_HAVE_ASAN) |
Jerry Yu | d76ded0 | 2023-04-19 11:07:40 +0800 | [diff] [blame] | 37 | |
Jerry Yu | 9e62862 | 2023-08-17 11:20:09 +0800 | [diff] [blame] | 38 | #define MBEDTLS_VIA_PADLOCK_HAVE_CODE |
| 39 | |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 40 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 41 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 42 | #define MBEDTLS_PADLOCK_RNG 0x000C |
| 43 | #define MBEDTLS_PADLOCK_ACE 0x00C0 |
| 44 | #define MBEDTLS_PADLOCK_PHE 0x0C00 |
| 45 | #define MBEDTLS_PADLOCK_PMM 0x3000 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 46 | |
Hanno Becker | 1eeca41 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 47 | #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15)) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 48 | |
| 49 | #ifdef __cplusplus |
| 50 | extern "C" { |
| 51 | #endif |
| 52 | |
| 53 | /** |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 54 | * \brief Internal PadLock detection routine |
| 55 | * |
| 56 | * \note This function is only for internal use by other library |
| 57 | * functions; you must not call it directly. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 58 | * |
Paul Bakker | a36d23e | 2013-12-30 17:57:27 +0100 | [diff] [blame] | 59 | * \param feature The feature to detect |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 60 | * |
Dave Rodgman | c1ae30a | 2021-05-18 18:59:37 +0100 | [diff] [blame] | 61 | * \return non-zero if CPU has support for the feature, 0 otherwise |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 62 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 63 | int mbedtls_padlock_has_support(int feature); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 64 | |
| 65 | /** |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 66 | * \brief Internal PadLock AES-ECB block en(de)cryption |
| 67 | * |
| 68 | * \note This function is only for internal use by other library |
| 69 | * functions; you must not call it directly. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 70 | * |
| 71 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 72 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 73 | * \param input 16-byte input block |
| 74 | * \param output 16-byte output block |
| 75 | * |
| 76 | * \return 0 if success, 1 if operation failed |
| 77 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 78 | int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx, |
| 79 | int mode, |
| 80 | const unsigned char input[16], |
| 81 | unsigned char output[16]); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 82 | |
| 83 | /** |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 84 | * \brief Internal PadLock AES-CBC buffer en(de)cryption |
| 85 | * |
| 86 | * \note This function is only for internal use by other library |
| 87 | * functions; you must not call it directly. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 88 | * |
| 89 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 90 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 91 | * \param length length of the input data |
| 92 | * \param iv initialization vector (updated after use) |
| 93 | * \param input buffer holding the input data |
| 94 | * \param output buffer holding the output data |
| 95 | * |
| 96 | * \return 0 if success, 1 if operation failed |
| 97 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 98 | int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx, |
| 99 | int mode, |
| 100 | size_t length, |
| 101 | unsigned char iv[16], |
| 102 | const unsigned char *input, |
| 103 | unsigned char *output); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 104 | |
| 105 | #ifdef __cplusplus |
| 106 | } |
| 107 | #endif |
| 108 | |
| 109 | #endif /* HAVE_X86 */ |
| 110 | |
| 111 | #endif /* padlock.h */ |