mbed TLS library

Dependents:   HTTPClient-SSL WS_SERVER

Committer:
ansond
Date:
Thu Jun 11 03:27:03 2015 +0000
Revision:
0:137634ff4186
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:137634ff4186 1 /**
ansond 0:137634ff4186 2 * \file aesni.h
ansond 0:137634ff4186 3 *
ansond 0:137634ff4186 4 * \brief AES-NI for hardware AES acceleration on some Intel processors
ansond 0:137634ff4186 5 *
ansond 0:137634ff4186 6 * Copyright (C) 2013, ARM Limited, All Rights Reserved
ansond 0:137634ff4186 7 *
ansond 0:137634ff4186 8 * This file is part of mbed TLS (https://tls.mbed.org)
ansond 0:137634ff4186 9 *
ansond 0:137634ff4186 10 * This program is free software; you can redistribute it and/or modify
ansond 0:137634ff4186 11 * it under the terms of the GNU General Public License as published by
ansond 0:137634ff4186 12 * the Free Software Foundation; either version 2 of the License, or
ansond 0:137634ff4186 13 * (at your option) any later version.
ansond 0:137634ff4186 14 *
ansond 0:137634ff4186 15 * This program is distributed in the hope that it will be useful,
ansond 0:137634ff4186 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ansond 0:137634ff4186 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ansond 0:137634ff4186 18 * GNU General Public License for more details.
ansond 0:137634ff4186 19 *
ansond 0:137634ff4186 20 * You should have received a copy of the GNU General Public License along
ansond 0:137634ff4186 21 * with this program; if not, write to the Free Software Foundation, Inc.,
ansond 0:137634ff4186 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ansond 0:137634ff4186 23 */
ansond 0:137634ff4186 24 #ifndef POLARSSL_AESNI_H
ansond 0:137634ff4186 25 #define POLARSSL_AESNI_H
ansond 0:137634ff4186 26
ansond 0:137634ff4186 27 #include "aes.h"
ansond 0:137634ff4186 28
ansond 0:137634ff4186 29 #define POLARSSL_AESNI_AES 0x02000000u
ansond 0:137634ff4186 30 #define POLARSSL_AESNI_CLMUL 0x00000002u
ansond 0:137634ff4186 31
ansond 0:137634ff4186 32 #if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && \
ansond 0:137634ff4186 33 ( defined(__amd64__) || defined(__x86_64__) ) && \
ansond 0:137634ff4186 34 ! defined(POLARSSL_HAVE_X86_64)
ansond 0:137634ff4186 35 #define POLARSSL_HAVE_X86_64
ansond 0:137634ff4186 36 #endif
ansond 0:137634ff4186 37
ansond 0:137634ff4186 38 #if defined(POLARSSL_HAVE_X86_64)
ansond 0:137634ff4186 39
ansond 0:137634ff4186 40 #ifdef __cplusplus
ansond 0:137634ff4186 41 extern "C" {
ansond 0:137634ff4186 42 #endif
ansond 0:137634ff4186 43
ansond 0:137634ff4186 44 /**
ansond 0:137634ff4186 45 * \brief AES-NI features detection routine
ansond 0:137634ff4186 46 *
ansond 0:137634ff4186 47 * \param what The feature to detect
ansond 0:137634ff4186 48 * (POLARSSL_AESNI_AES or POLARSSL_AESNI_CLMUL)
ansond 0:137634ff4186 49 *
ansond 0:137634ff4186 50 * \return 1 if CPU has support for the feature, 0 otherwise
ansond 0:137634ff4186 51 */
ansond 0:137634ff4186 52 int aesni_supports( unsigned int what );
ansond 0:137634ff4186 53
ansond 0:137634ff4186 54 /**
ansond 0:137634ff4186 55 * \brief AES-NI AES-ECB block en(de)cryption
ansond 0:137634ff4186 56 *
ansond 0:137634ff4186 57 * \param ctx AES context
ansond 0:137634ff4186 58 * \param mode AES_ENCRYPT or AES_DECRYPT
ansond 0:137634ff4186 59 * \param input 16-byte input block
ansond 0:137634ff4186 60 * \param output 16-byte output block
ansond 0:137634ff4186 61 *
ansond 0:137634ff4186 62 * \return 0 on success (cannot fail)
ansond 0:137634ff4186 63 */
ansond 0:137634ff4186 64 int aesni_crypt_ecb( aes_context *ctx,
ansond 0:137634ff4186 65 int mode,
ansond 0:137634ff4186 66 const unsigned char input[16],
ansond 0:137634ff4186 67 unsigned char output[16] );
ansond 0:137634ff4186 68
ansond 0:137634ff4186 69 /**
ansond 0:137634ff4186 70 * \brief GCM multiplication: c = a * b in GF(2^128)
ansond 0:137634ff4186 71 *
ansond 0:137634ff4186 72 * \param c Result
ansond 0:137634ff4186 73 * \param a First operand
ansond 0:137634ff4186 74 * \param b Second operand
ansond 0:137634ff4186 75 *
ansond 0:137634ff4186 76 * \note Both operands and result are bit strings interpreted as
ansond 0:137634ff4186 77 * elements of GF(2^128) as per the GCM spec.
ansond 0:137634ff4186 78 */
ansond 0:137634ff4186 79 void aesni_gcm_mult( unsigned char c[16],
ansond 0:137634ff4186 80 const unsigned char a[16],
ansond 0:137634ff4186 81 const unsigned char b[16] );
ansond 0:137634ff4186 82
ansond 0:137634ff4186 83 /**
ansond 0:137634ff4186 84 * \brief Compute decryption round keys from encryption round keys
ansond 0:137634ff4186 85 *
ansond 0:137634ff4186 86 * \param invkey Round keys for the equivalent inverse cipher
ansond 0:137634ff4186 87 * \param fwdkey Original round keys (for encryption)
ansond 0:137634ff4186 88 * \param nr Number of rounds (that is, number of round keys minus one)
ansond 0:137634ff4186 89 */
ansond 0:137634ff4186 90 void aesni_inverse_key( unsigned char *invkey,
ansond 0:137634ff4186 91 const unsigned char *fwdkey, int nr );
ansond 0:137634ff4186 92
ansond 0:137634ff4186 93 /**
ansond 0:137634ff4186 94 * \brief Perform key expansion (for encryption)
ansond 0:137634ff4186 95 *
ansond 0:137634ff4186 96 * \param rk Destination buffer where the round keys are written
ansond 0:137634ff4186 97 * \param key Encryption key
ansond 0:137634ff4186 98 * \param bits Key size in bits (must be 128, 192 or 256)
ansond 0:137634ff4186 99 *
ansond 0:137634ff4186 100 * \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
ansond 0:137634ff4186 101 */
ansond 0:137634ff4186 102 int aesni_setkey_enc( unsigned char *rk,
ansond 0:137634ff4186 103 const unsigned char *key,
ansond 0:137634ff4186 104 size_t bits );
ansond 0:137634ff4186 105
ansond 0:137634ff4186 106 #ifdef __cplusplus
ansond 0:137634ff4186 107 }
ansond 0:137634ff4186 108 #endif
ansond 0:137634ff4186 109
ansond 0:137634ff4186 110 #endif /* POLARSSL_HAVE_X86_64 */
ansond 0:137634ff4186 111
ansond 0:137634ff4186 112 #endif /* POLARSSL_AESNI_H */
ansond 0:137634ff4186 113