Modified mbed TLS headers for AES functionality only to reduce build size

Dependents:   BLE_Gateway_Linker_fix BLE_Gateway

Fork of mbedtls by sandbox

Committer:
electronichamsters
Date:
Mon Jul 10 04:00:25 2017 +0000
Revision:
5:f09f5ed830ca
Parent:
1:24750b9ad5ef
working gateway

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 1:24750b9ad5ef 1 /**
Christopher Haster 1:24750b9ad5ef 2 * \file aesni.h
Christopher Haster 1:24750b9ad5ef 3 *
Christopher Haster 1:24750b9ad5ef 4 * \brief AES-NI for hardware AES acceleration on some Intel processors
Christopher Haster 1:24750b9ad5ef 5 *
Christopher Haster 1:24750b9ad5ef 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Christopher Haster 1:24750b9ad5ef 7 * SPDX-License-Identifier: Apache-2.0
Christopher Haster 1:24750b9ad5ef 8 *
Christopher Haster 1:24750b9ad5ef 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Christopher Haster 1:24750b9ad5ef 10 * not use this file except in compliance with the License.
Christopher Haster 1:24750b9ad5ef 11 * You may obtain a copy of the License at
Christopher Haster 1:24750b9ad5ef 12 *
Christopher Haster 1:24750b9ad5ef 13 * http://www.apache.org/licenses/LICENSE-2.0
Christopher Haster 1:24750b9ad5ef 14 *
Christopher Haster 1:24750b9ad5ef 15 * Unless required by applicable law or agreed to in writing, software
Christopher Haster 1:24750b9ad5ef 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Christopher Haster 1:24750b9ad5ef 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Christopher Haster 1:24750b9ad5ef 18 * See the License for the specific language governing permissions and
Christopher Haster 1:24750b9ad5ef 19 * limitations under the License.
Christopher Haster 1:24750b9ad5ef 20 *
Christopher Haster 1:24750b9ad5ef 21 * This file is part of mbed TLS (https://tls.mbed.org)
Christopher Haster 1:24750b9ad5ef 22 */
Christopher Haster 1:24750b9ad5ef 23 #ifndef MBEDTLS_AESNI_H
Christopher Haster 1:24750b9ad5ef 24 #define MBEDTLS_AESNI_H
Christopher Haster 1:24750b9ad5ef 25
Christopher Haster 1:24750b9ad5ef 26 #include "aes.h"
Christopher Haster 1:24750b9ad5ef 27
Christopher Haster 1:24750b9ad5ef 28 #define MBEDTLS_AESNI_AES 0x02000000u
Christopher Haster 1:24750b9ad5ef 29 #define MBEDTLS_AESNI_CLMUL 0x00000002u
Christopher Haster 1:24750b9ad5ef 30
Christopher Haster 1:24750b9ad5ef 31 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
Christopher Haster 1:24750b9ad5ef 32 ( defined(__amd64__) || defined(__x86_64__) ) && \
Christopher Haster 1:24750b9ad5ef 33 ! defined(MBEDTLS_HAVE_X86_64)
Christopher Haster 1:24750b9ad5ef 34 #define MBEDTLS_HAVE_X86_64
Christopher Haster 1:24750b9ad5ef 35 #endif
Christopher Haster 1:24750b9ad5ef 36
Christopher Haster 1:24750b9ad5ef 37 #if defined(MBEDTLS_HAVE_X86_64)
Christopher Haster 1:24750b9ad5ef 38
Christopher Haster 1:24750b9ad5ef 39 #ifdef __cplusplus
Christopher Haster 1:24750b9ad5ef 40 extern "C" {
Christopher Haster 1:24750b9ad5ef 41 #endif
Christopher Haster 1:24750b9ad5ef 42
Christopher Haster 1:24750b9ad5ef 43 /**
Christopher Haster 1:24750b9ad5ef 44 * \brief AES-NI features detection routine
Christopher Haster 1:24750b9ad5ef 45 *
Christopher Haster 1:24750b9ad5ef 46 * \param what The feature to detect
Christopher Haster 1:24750b9ad5ef 47 * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
Christopher Haster 1:24750b9ad5ef 48 *
Christopher Haster 1:24750b9ad5ef 49 * \return 1 if CPU has support for the feature, 0 otherwise
Christopher Haster 1:24750b9ad5ef 50 */
Christopher Haster 1:24750b9ad5ef 51 int mbedtls_aesni_has_support( unsigned int what );
Christopher Haster 1:24750b9ad5ef 52
Christopher Haster 1:24750b9ad5ef 53 /**
Christopher Haster 1:24750b9ad5ef 54 * \brief AES-NI AES-ECB block en(de)cryption
Christopher Haster 1:24750b9ad5ef 55 *
Christopher Haster 1:24750b9ad5ef 56 * \param ctx AES context
Christopher Haster 1:24750b9ad5ef 57 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
Christopher Haster 1:24750b9ad5ef 58 * \param input 16-byte input block
Christopher Haster 1:24750b9ad5ef 59 * \param output 16-byte output block
Christopher Haster 1:24750b9ad5ef 60 *
Christopher Haster 1:24750b9ad5ef 61 * \return 0 on success (cannot fail)
Christopher Haster 1:24750b9ad5ef 62 */
Christopher Haster 1:24750b9ad5ef 63 int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
Christopher Haster 1:24750b9ad5ef 64 int mode,
Christopher Haster 1:24750b9ad5ef 65 const unsigned char input[16],
Christopher Haster 1:24750b9ad5ef 66 unsigned char output[16] );
Christopher Haster 1:24750b9ad5ef 67
Christopher Haster 1:24750b9ad5ef 68 /**
Christopher Haster 1:24750b9ad5ef 69 * \brief GCM multiplication: c = a * b in GF(2^128)
Christopher Haster 1:24750b9ad5ef 70 *
Christopher Haster 1:24750b9ad5ef 71 * \param c Result
Christopher Haster 1:24750b9ad5ef 72 * \param a First operand
Christopher Haster 1:24750b9ad5ef 73 * \param b Second operand
Christopher Haster 1:24750b9ad5ef 74 *
Christopher Haster 1:24750b9ad5ef 75 * \note Both operands and result are bit strings interpreted as
Christopher Haster 1:24750b9ad5ef 76 * elements of GF(2^128) as per the GCM spec.
Christopher Haster 1:24750b9ad5ef 77 */
Christopher Haster 1:24750b9ad5ef 78 void mbedtls_aesni_gcm_mult( unsigned char c[16],
Christopher Haster 1:24750b9ad5ef 79 const unsigned char a[16],
Christopher Haster 1:24750b9ad5ef 80 const unsigned char b[16] );
Christopher Haster 1:24750b9ad5ef 81
Christopher Haster 1:24750b9ad5ef 82 /**
Christopher Haster 1:24750b9ad5ef 83 * \brief Compute decryption round keys from encryption round keys
Christopher Haster 1:24750b9ad5ef 84 *
Christopher Haster 1:24750b9ad5ef 85 * \param invkey Round keys for the equivalent inverse cipher
Christopher Haster 1:24750b9ad5ef 86 * \param fwdkey Original round keys (for encryption)
Christopher Haster 1:24750b9ad5ef 87 * \param nr Number of rounds (that is, number of round keys minus one)
Christopher Haster 1:24750b9ad5ef 88 */
Christopher Haster 1:24750b9ad5ef 89 void mbedtls_aesni_inverse_key( unsigned char *invkey,
Christopher Haster 1:24750b9ad5ef 90 const unsigned char *fwdkey, int nr );
Christopher Haster 1:24750b9ad5ef 91
Christopher Haster 1:24750b9ad5ef 92 /**
Christopher Haster 1:24750b9ad5ef 93 * \brief Perform key expansion (for encryption)
Christopher Haster 1:24750b9ad5ef 94 *
Christopher Haster 1:24750b9ad5ef 95 * \param rk Destination buffer where the round keys are written
Christopher Haster 1:24750b9ad5ef 96 * \param key Encryption key
Christopher Haster 1:24750b9ad5ef 97 * \param bits Key size in bits (must be 128, 192 or 256)
Christopher Haster 1:24750b9ad5ef 98 *
Christopher Haster 1:24750b9ad5ef 99 * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
Christopher Haster 1:24750b9ad5ef 100 */
Christopher Haster 1:24750b9ad5ef 101 int mbedtls_aesni_setkey_enc( unsigned char *rk,
Christopher Haster 1:24750b9ad5ef 102 const unsigned char *key,
Christopher Haster 1:24750b9ad5ef 103 size_t bits );
Christopher Haster 1:24750b9ad5ef 104
Christopher Haster 1:24750b9ad5ef 105 #ifdef __cplusplus
Christopher Haster 1:24750b9ad5ef 106 }
Christopher Haster 1:24750b9ad5ef 107 #endif
Christopher Haster 1:24750b9ad5ef 108
Christopher Haster 1:24750b9ad5ef 109 #endif /* MBEDTLS_HAVE_X86_64 */
Christopher Haster 1:24750b9ad5ef 110
Christopher Haster 1:24750b9ad5ef 111 #endif /* MBEDTLS_AESNI_H */