Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers padlock.h Source File

padlock.h

Go to the documentation of this file.
00001 /**
00002  * \file padlock.h
00003  *
00004  * \brief VIA PadLock ACE for HW encryption/decryption supported by some
00005  *        processors
00006  */
00007 /*
00008  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00009  *  SPDX-License-Identifier: Apache-2.0
00010  *
00011  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00012  *  not use this file except in compliance with the License.
00013  *  You may obtain a copy of the License at
00014  *
00015  *  http://www.apache.org/licenses/LICENSE-2.0
00016  *
00017  *  Unless required by applicable law or agreed to in writing, software
00018  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00019  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020  *  See the License for the specific language governing permissions and
00021  *  limitations under the License.
00022  *
00023  *  This file is part of mbed TLS (https://tls.mbed.org)
00024  */
00025 #ifndef MBEDTLS_PADLOCK_H
00026 #define MBEDTLS_PADLOCK_H
00027 
00028 #include "aes.h"
00029 
00030 #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED               -0x0030  /**< Input data should be aligned. */
00031 
00032 #if defined(__has_feature)
00033 #if __has_feature(address_sanitizer)
00034 #define MBEDTLS_HAVE_ASAN
00035 #endif
00036 #endif
00037 
00038 /* Some versions of ASan result in errors about not enough registers */
00039 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
00040     !defined(MBEDTLS_HAVE_ASAN)
00041 
00042 #ifndef MBEDTLS_HAVE_X86
00043 #define MBEDTLS_HAVE_X86
00044 #endif
00045 
00046 #include <stdint.h>
00047 
00048 #define MBEDTLS_PADLOCK_RNG 0x000C
00049 #define MBEDTLS_PADLOCK_ACE 0x00C0
00050 #define MBEDTLS_PADLOCK_PHE 0x0C00
00051 #define MBEDTLS_PADLOCK_PMM 0x3000
00052 
00053 #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
00054 
00055 #ifdef __cplusplus
00056 extern "C" {
00057 #endif
00058 
00059 /**
00060  * \brief          PadLock detection routine
00061  *
00062  * \param feature  The feature to detect
00063  *
00064  * \return         1 if CPU has support for the feature, 0 otherwise
00065  */
00066 int mbedtls_padlock_has_support( int feature );
00067 
00068 /**
00069  * \brief          PadLock AES-ECB block en(de)cryption
00070  *
00071  * \param ctx      AES context
00072  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
00073  * \param input    16-byte input block
00074  * \param output   16-byte output block
00075  *
00076  * \return         0 if success, 1 if operation failed
00077  */
00078 int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
00079                        int mode,
00080                        const unsigned char input[16],
00081                        unsigned char output[16] );
00082 
00083 /**
00084  * \brief          PadLock AES-CBC buffer en(de)cryption
00085  *
00086  * \param ctx      AES context
00087  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
00088  * \param length   length of the input data
00089  * \param iv       initialization vector (updated after use)
00090  * \param input    buffer holding the input data
00091  * \param output   buffer holding the output data
00092  *
00093  * \return         0 if success, 1 if operation failed
00094  */
00095 int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
00096                        int mode,
00097                        size_t length,
00098                        unsigned char iv[16],
00099                        const unsigned char *input,
00100                        unsigned char *output );
00101 
00102 #ifdef __cplusplus
00103 }
00104 #endif
00105 
00106 #endif /* HAVE_X86  */
00107 
00108 #endif /* padlock.h */