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 | /* |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 11 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 12 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 13 | * |
| 14 | * This file is provided under the Apache License 2.0, or the |
| 15 | * GNU General Public License v2.0 or later. |
| 16 | * |
| 17 | * ********** |
| 18 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | * not use this file except in compliance with the License. |
| 22 | * You may obtain a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | * See the License for the specific language governing permissions and |
| 30 | * limitations under the License. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 31 | * |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 32 | * ********** |
| 33 | * |
| 34 | * ********** |
| 35 | * GNU General Public License v2.0 or later: |
| 36 | * |
| 37 | * This program is free software; you can redistribute it and/or modify |
| 38 | * it under the terms of the GNU General Public License as published by |
| 39 | * the Free Software Foundation; either version 2 of the License, or |
| 40 | * (at your option) any later version. |
| 41 | * |
| 42 | * This program is distributed in the hope that it will be useful, |
| 43 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 44 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 45 | * GNU General Public License for more details. |
| 46 | * |
| 47 | * You should have received a copy of the GNU General Public License along |
| 48 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 49 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 50 | * |
| 51 | * ********** |
| 52 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 53 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | #ifndef MBEDTLS_PADLOCK_H |
| 56 | #define MBEDTLS_PADLOCK_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 57 | |
Ron Eldor | 8b0cf2e | 2018-02-14 16:02:41 +0200 | [diff] [blame] | 58 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 59 | #include "config.h" |
| 60 | #else |
| 61 | #include MBEDTLS_CONFIG_FILE |
| 62 | #endif |
| 63 | |
Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 64 | #include "aes.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 65 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ |
Paul Bakker | 70338f5 | 2011-05-23 10:19:31 +0000 | [diff] [blame] | 67 | |
Manuel Pégourié-Gonnard | f659f0c | 2015-08-04 22:19:05 +0200 | [diff] [blame] | 68 | #if defined(__has_feature) |
| 69 | #if __has_feature(address_sanitizer) |
| 70 | #define MBEDTLS_HAVE_ASAN |
| 71 | #endif |
| 72 | #endif |
| 73 | |
| 74 | /* Some versions of ASan result in errors about not enough registers */ |
| 75 | #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \ |
Manuel Pégourié-Gonnard | e14dec6 | 2015-08-04 22:49:07 +0200 | [diff] [blame] | 76 | !defined(MBEDTLS_HAVE_ASAN) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 77 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 78 | #ifndef MBEDTLS_HAVE_X86 |
| 79 | #define MBEDTLS_HAVE_X86 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 82 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 83 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 84 | #define MBEDTLS_PADLOCK_RNG 0x000C |
| 85 | #define MBEDTLS_PADLOCK_ACE 0x00C0 |
| 86 | #define MBEDTLS_PADLOCK_PHE 0x0C00 |
| 87 | #define MBEDTLS_PADLOCK_PMM 0x3000 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 88 | |
Hanno Becker | d6028a1 | 2018-10-15 12:01:35 +0100 | [diff] [blame] | 89 | #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15)) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 90 | |
| 91 | #ifdef __cplusplus |
| 92 | extern "C" { |
| 93 | #endif |
| 94 | |
| 95 | /** |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 96 | * \brief Internal PadLock detection routine |
| 97 | * |
| 98 | * \note This function is only for internal use by other library |
| 99 | * functions; you must not call it directly. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 100 | * |
Paul Bakker | a36d23e | 2013-12-30 17:57:27 +0100 | [diff] [blame] | 101 | * \param feature The feature to detect |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 102 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 103 | * \return 1 if CPU has support for the feature, 0 otherwise |
| 104 | */ |
Manuel Pégourié-Gonnard | c730ed3 | 2015-06-02 10:38:50 +0100 | [diff] [blame] | 105 | int mbedtls_padlock_has_support( int feature ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 106 | |
| 107 | /** |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 108 | * \brief Internal PadLock AES-ECB block en(de)cryption |
| 109 | * |
| 110 | * \note This function is only for internal use by other library |
| 111 | * functions; you must not call it directly. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 112 | * |
| 113 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 114 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 115 | * \param input 16-byte input block |
| 116 | * \param output 16-byte output block |
| 117 | * |
| 118 | * \return 0 if success, 1 if operation failed |
| 119 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 120 | int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 121 | int mode, |
| 122 | const unsigned char input[16], |
| 123 | unsigned char output[16] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 124 | |
| 125 | /** |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 126 | * \brief Internal PadLock AES-CBC buffer en(de)cryption |
| 127 | * |
| 128 | * \note This function is only for internal use by other library |
| 129 | * functions; you must not call it directly. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 130 | * |
| 131 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 132 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 133 | * \param length length of the input data |
| 134 | * \param iv initialization vector (updated after use) |
| 135 | * \param input buffer holding the input data |
| 136 | * \param output buffer holding the output data |
| 137 | * |
| 138 | * \return 0 if success, 1 if operation failed |
| 139 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 140 | int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, |
Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 141 | int mode, |
| 142 | size_t length, |
| 143 | unsigned char iv[16], |
| 144 | const unsigned char *input, |
| 145 | unsigned char *output ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 146 | |
| 147 | #ifdef __cplusplus |
| 148 | } |
| 149 | #endif |
| 150 | |
| 151 | #endif /* HAVE_X86 */ |
| 152 | |
| 153 | #endif /* padlock.h */ |