blob: 918e6195ad405407b3491ce7339f7d5fde851dba [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
Darryl Greena40a1012018-01-05 15:33:17 +00006 */
7/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000022 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000023 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000024 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#ifndef MBEDTLS_PADLOCK_H
26#define MBEDTLS_PADLOCK_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020028#if !defined(MBEDTLS_CONFIG_FILE)
29#include "config.h"
30#else
31#include MBEDTLS_CONFIG_FILE
32#endif
33
Paul Bakker314052f2011-08-15 09:07:52 +000034#include "aes.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
Paul Bakker70338f52011-05-23 10:19:31 +000037
Manuel Pégourié-Gonnardf659f0c2015-08-04 22:19:05 +020038#if defined(__has_feature)
39#if __has_feature(address_sanitizer)
40#define MBEDTLS_HAVE_ASAN
41#endif
42#endif
43
44/* Some versions of ASan result in errors about not enough registers */
45#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
Manuel Pégourié-Gonnarde14dec62015-08-04 22:49:07 +020046 !defined(MBEDTLS_HAVE_ASAN)
Paul Bakker5121ce52009-01-03 21:22:43 +000047
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#ifndef MBEDTLS_HAVE_X86
49#define MBEDTLS_HAVE_X86
Paul Bakker5121ce52009-01-03 21:22:43 +000050#endif
51
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020052#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000053
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#define MBEDTLS_PADLOCK_RNG 0x000C
55#define MBEDTLS_PADLOCK_ACE 0x00C0
56#define MBEDTLS_PADLOCK_PHE 0x0C00
57#define MBEDTLS_PADLOCK_PMM 0x3000
Paul Bakker5121ce52009-01-03 21:22:43 +000058
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
Paul Bakker5121ce52009-01-03 21:22:43 +000060
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65/**
66 * \brief PadLock detection routine
67 *
Paul Bakkera36d23e2013-12-30 17:57:27 +010068 * \param feature The feature to detect
Paul Bakker13e2dfe2009-07-28 07:18:38 +000069 *
Paul Bakker5121ce52009-01-03 21:22:43 +000070 * \return 1 if CPU has support for the feature, 0 otherwise
71 */
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +010072int mbedtls_padlock_has_support( int feature );
Paul Bakker5121ce52009-01-03 21:22:43 +000073
74/**
75 * \brief PadLock AES-ECB block en(de)cryption
76 *
77 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +000079 * \param input 16-byte input block
80 * \param output 16-byte output block
81 *
82 * \return 0 if success, 1 if operation failed
83 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +000085 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000086 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +000087 unsigned char output[16] );
88
89/**
90 * \brief PadLock AES-CBC buffer en(de)cryption
91 *
92 * \param ctx AES context
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Paul Bakker5121ce52009-01-03 21:22:43 +000094 * \param length length of the input data
95 * \param iv initialization vector (updated after use)
96 * \param input buffer holding the input data
97 * \param output buffer holding the output data
98 *
99 * \return 0 if success, 1 if operation failed
100 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000102 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000103 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000104 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000105 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000106 unsigned char *output );
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif /* HAVE_X86 */
113
114#endif /* padlock.h */