| 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 | 
| Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 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. | 
| Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 25 | * | 
| Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 26 | *  This file is part of mbed TLS (https://tls.mbed.org) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 27 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 28 | #ifndef MBEDTLS_PADLOCK_H | 
|  | 29 | #define MBEDTLS_PADLOCK_H | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 30 |  | 
| Ron Eldor | 8b0cf2e | 2018-02-14 16:02:41 +0200 | [diff] [blame] | 31 | #if !defined(MBEDTLS_CONFIG_FILE) | 
|  | 32 | #include "config.h" | 
|  | 33 | #else | 
|  | 34 | #include MBEDTLS_CONFIG_FILE | 
|  | 35 | #endif | 
|  | 36 |  | 
| Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 37 | #include "aes.h" | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 38 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 39 | #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED               -0x0030  /**< Input data should be aligned. */ | 
| Paul Bakker | 70338f5 | 2011-05-23 10:19:31 +0000 | [diff] [blame] | 40 |  | 
| Manuel Pégourié-Gonnard | f659f0c | 2015-08-04 22:19:05 +0200 | [diff] [blame] | 41 | #if defined(__has_feature) | 
|  | 42 | #if __has_feature(address_sanitizer) | 
|  | 43 | #define MBEDTLS_HAVE_ASAN | 
|  | 44 | #endif | 
|  | 45 | #endif | 
|  | 46 |  | 
|  | 47 | /* Some versions of ASan result in errors about not enough registers */ | 
|  | 48 | #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \ | 
| Manuel Pégourié-Gonnard | e14dec6 | 2015-08-04 22:49:07 +0200 | [diff] [blame] | 49 | !defined(MBEDTLS_HAVE_ASAN) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 50 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 51 | #ifndef MBEDTLS_HAVE_X86 | 
|  | 52 | #define MBEDTLS_HAVE_X86 | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 53 | #endif | 
|  | 54 |  | 
| Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 55 | #include <stdint.h> | 
| Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 56 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 57 | #define MBEDTLS_PADLOCK_RNG 0x000C | 
|  | 58 | #define MBEDTLS_PADLOCK_ACE 0x00C0 | 
|  | 59 | #define MBEDTLS_PADLOCK_PHE 0x0C00 | 
|  | 60 | #define MBEDTLS_PADLOCK_PMM 0x3000 | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 61 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15)) | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 63 |  | 
|  | 64 | #ifdef __cplusplus | 
|  | 65 | extern "C" { | 
|  | 66 | #endif | 
|  | 67 |  | 
|  | 68 | /** | 
| Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 69 | * \brief          Internal PadLock detection routine | 
|  | 70 | * | 
|  | 71 | * \note           This function is only for internal use by other library | 
|  | 72 | *                 functions; you must not call it directly. | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 73 | * | 
| Paul Bakker | a36d23e | 2013-12-30 17:57:27 +0100 | [diff] [blame] | 74 | * \param feature  The feature to detect | 
| Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 75 | * | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 76 | * \return         1 if CPU has support for the feature, 0 otherwise | 
|  | 77 | */ | 
| Manuel Pégourié-Gonnard | c730ed3 | 2015-06-02 10:38:50 +0100 | [diff] [blame] | 78 | int mbedtls_padlock_has_support( int feature ); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 79 |  | 
|  | 80 | /** | 
| Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 81 | * \brief          Internal PadLock AES-ECB block en(de)cryption | 
|  | 82 | * | 
|  | 83 | * \note           This function is only for internal use by other library | 
|  | 84 | *                 functions; you must not call it directly. | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 85 | * | 
|  | 86 | * \param ctx      AES context | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 87 | * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 88 | * \param input    16-byte input block | 
|  | 89 | * \param output   16-byte output block | 
|  | 90 | * | 
|  | 91 | * \return         0 if success, 1 if operation failed | 
|  | 92 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, | 
| Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 94 | int mode, | 
|  | 95 | const unsigned char input[16], | 
|  | 96 | unsigned char output[16] ); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 97 |  | 
|  | 98 | /** | 
| Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 99 | * \brief          Internal PadLock AES-CBC buffer en(de)cryption | 
|  | 100 | * | 
|  | 101 | * \note           This function is only for internal use by other library | 
|  | 102 | *                 functions; you must not call it directly. | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 103 | * | 
|  | 104 | * \param ctx      AES context | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 105 | * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 106 | * \param length   length of the input data | 
|  | 107 | * \param iv       initialization vector (updated after use) | 
|  | 108 | * \param input    buffer holding the input data | 
|  | 109 | * \param output   buffer holding the output data | 
|  | 110 | * | 
|  | 111 | * \return         0 if success, 1 if operation failed | 
|  | 112 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 113 | int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, | 
| Manuel Pégourié-Gonnard | ad54c49 | 2018-12-13 11:15:26 +0100 | [diff] [blame] | 114 | int mode, | 
|  | 115 | size_t length, | 
|  | 116 | unsigned char iv[16], | 
|  | 117 | const unsigned char *input, | 
|  | 118 | unsigned char *output ); | 
| Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 |  | 
|  | 120 | #ifdef __cplusplus | 
|  | 121 | } | 
|  | 122 | #endif | 
|  | 123 |  | 
|  | 124 | #endif /* HAVE_X86  */ | 
|  | 125 |  | 
|  | 126 | #endif /* padlock.h */ |