blob: 0821105f1a6b39045b82c43a36d39da64f9ddcd9 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file padlock.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02004 * \brief VIA PadLock ACE for HW encryption/decryption supported by some
5 * processors
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +01006 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +01007 * \warning These functions are only for internal use by other library
8 * functions; you must not call them directly.
Darryl Greena40a1012018-01-05 15:33:17 +00009 */
10/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020011 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker5121ce52009-01-03 21:22:43 +000013 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020014#ifndef MBEDTLS_PADLOCK_H
15#define MBEDTLS_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000016
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020017#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010018#include "mbedtls/config.h"
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020019#else
20#include MBEDTLS_CONFIG_FILE
21#endif
22
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010023#include "mbedtls/aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000024
Gilles Peskinea3974432021-07-26 18:48:10 +020025/** Input data should be aligned. */
26#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030
Paul Bakker70338f52011-05-23 10:19:31 +000027
Manuel Pégourié-Gonnardf659f0c2015-08-04 22:19:05 +020028#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 */
Pengyu Lv7fb6fc62023-09-14 14:02:02 +080035#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_ASM) && \
36 defined(__GNUC__) && defined(__i386__) && \
Manuel Pégourié-Gonnarde14dec62015-08-04 22:49:07 +020037 !defined(MBEDTLS_HAVE_ASAN)
Paul Bakker5121ce52009-01-03 21:22:43 +000038
Pengyu Lv7fb6fc62023-09-14 14:02:02 +080039#define MBEDTLS_VIA_PADLOCK_HAVE_CODE
40
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#ifndef MBEDTLS_HAVE_X86
42#define MBEDTLS_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000043#endif
44
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020045#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000046
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#define MBEDTLS_PADLOCK_RNG 0x000C
48#define MBEDTLS_PADLOCK_ACE 0x00C0
49#define MBEDTLS_PADLOCK_PHE 0x0C00
50#define MBEDTLS_PADLOCK_PMM 0x3000
Paul Bakker5121ce52009-01-03 21:22:43 +000051
Hanno Becker1eeca412018-10-15 12:01:35 +010052#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000053
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +010059 * \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.
Paul Bakker5121ce52009-01-03 21:22:43 +000063 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010064 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000065 *
Dave Rodgman6efa7222021-05-18 18:59:37 +010066 * \return non-zero if CPU has support for the feature, 0 otherwise
Paul Bakker5121ce52009-01-03 21:22:43 +000067 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010068int mbedtls_padlock_has_support(int feature);
Paul Bakker5121ce52009-01-03 21:22:43 +000069
70/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +010071 * \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.
Paul Bakker5121ce52009-01-03 21:22:43 +000075 *
76 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +000078 * \param input 16-byte input block
79 * \param output 16-byte output block
80 *
81 * \return 0 if success, 1 if operation failed
82 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010083int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
84 int mode,
85 const unsigned char input[16],
86 unsigned char output[16]);
Paul Bakker5121ce52009-01-03 21:22:43 +000087
88/**
Manuel Pégourié-Gonnardad54c492018-12-13 11:15:26 +010089 * \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.
Paul Bakker5121ce52009-01-03 21:22:43 +000093 *
94 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +000096 * \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 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100103int 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);
Paul Bakker5121ce52009-01-03 21:22:43 +0000109
110#ifdef __cplusplus
111}
112#endif
113
Pengyu Lv8068b082023-09-26 09:27:04 +0800114#endif /* MBEDTLS_PADLOCK_C && MBEDTLS_HAVE_ASM &&
115 __GNUC__ && __i386__ && !MBEDTLS_HAVE_ASAN */
Paul Bakker5121ce52009-01-03 21:22:43 +0000116
117#endif /* padlock.h */