mbed TLS Build

Dependents:   Slave-prot-prod

Committer:
williequesada
Date:
Tue Jun 04 16:03:38 2019 +0000
Revision:
1:1a219dea6cb5
Parent:
0:cdf462088d13
compartir a Pablo

Who changed what in which revision?

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