blob: 92d72af516e7c1b851eb8f5d075ff0a808c5d15d [file] [log] [blame]
Jens Wiklander817466c2018-05-22 13:49:31 +02001/**
2 * \file padlock.h
3 *
4 * \brief VIA PadLock ACE for HW encryption/decryption supported by some
5 * processors
6 *
Jens Wiklander3d3b0592019-03-20 15:30:29 +01007 * \warning These functions are only for internal use by other library
8 * functions; you must not call them directly.
9 */
10/*
Jerome Forissier79013242021-07-28 10:24:04 +020011 * Copyright The Mbed TLS Contributors
Tom Van Eyckc1633172024-04-09 18:44:13 +020012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Jens Wiklander817466c2018-05-22 13:49:31 +020013 */
14#ifndef MBEDTLS_PADLOCK_H
15#define MBEDTLS_PADLOCK_H
16
Jens Wiklander32b31802023-10-06 16:59:46 +020017#include "mbedtls/build_info.h"
Jerome Forissier5b25c762020-04-07 11:18:49 +020018
Jerome Forissier11fa71b2020-04-20 17:17:56 +020019#include "mbedtls/aes.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020020
Jens Wiklander32b31802023-10-06 16:59:46 +020021#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
Jens Wiklander817466c2018-05-22 13:49:31 +020022
23#if defined(__has_feature)
24#if __has_feature(address_sanitizer)
25#define MBEDTLS_HAVE_ASAN
26#endif
27#endif
28
Tom Van Eyckc1633172024-04-09 18:44:13 +020029/*
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) && \
Jens Wiklander817466c2018-05-22 13:49:31 +020036 !defined(MBEDTLS_HAVE_ASAN)
37
Tom Van Eyckc1633172024-04-09 18:44:13 +020038#define MBEDTLS_VIA_PADLOCK_HAVE_CODE
Jens Wiklander817466c2018-05-22 13:49:31 +020039
40#include <stdint.h>
41
42#define MBEDTLS_PADLOCK_RNG 0x000C
43#define MBEDTLS_PADLOCK_ACE 0x00C0
44#define MBEDTLS_PADLOCK_PHE 0x0C00
45#define MBEDTLS_PADLOCK_PMM 0x3000
46
Jerome Forissier5b25c762020-04-07 11:18:49 +020047#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
Jens Wiklander817466c2018-05-22 13:49:31 +020048
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010054 * \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.
Jens Wiklander817466c2018-05-22 13:49:31 +020058 *
59 * \param feature The feature to detect
60 *
Jerome Forissier79013242021-07-28 10:24:04 +020061 * \return non-zero if CPU has support for the feature, 0 otherwise
Jens Wiklander817466c2018-05-22 13:49:31 +020062 */
Jens Wiklander32b31802023-10-06 16:59:46 +020063int mbedtls_padlock_has_support(int feature);
Jens Wiklander817466c2018-05-22 13:49:31 +020064
65/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010066 * \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.
Jens Wiklander817466c2018-05-22 13:49:31 +020070 *
71 * \param ctx AES context
72 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
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 */
Jens Wiklander32b31802023-10-06 16:59:46 +020078int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
79 int mode,
80 const unsigned char input[16],
81 unsigned char output[16]);
Jens Wiklander817466c2018-05-22 13:49:31 +020082
83/**
Jens Wiklander3d3b0592019-03-20 15:30:29 +010084 * \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.
Jens Wiklander817466c2018-05-22 13:49:31 +020088 *
89 * \param ctx AES context
90 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
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 */
Jens Wiklander32b31802023-10-06 16:59:46 +020098int 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);
Jens Wiklander817466c2018-05-22 13:49:31 +0200104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* HAVE_X86 */
110
111#endif /* padlock.h */