blob: f3f9fc31d04bc60552cf4746b34a39310c689265 [file] [log] [blame]
Manuel Pégourié-Gonnard92ac76f2013-12-16 17:12:53 +01001/**
2 * \file aesni.h
3 *
4 * \brief AES-NI for hardware AES acceleration on some Intel processors
5 *
6 * Copyright (C) 2013, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_AESNI_H
28#define POLARSSL_AESNI_H
29
30#include "aes.h"
31
Manuel Pégourié-Gonnard8eaf20b2013-12-18 19:14:53 +010032#define POLARSSL_AESNI_AES 0x02000000u
33#define POLARSSL_AESNI_CLMUL 0x00000002u
34
Manuel Pégourié-Gonnard92ac76f2013-12-16 17:12:53 +010035#if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && \
36 ( defined(__amd64__) || defined(__x86_64__) ) && \
37 ! defined(POLARSSL_HAVE_X86_64)
38#define POLARSSL_HAVE_X86_64
39#endif
40
41#if defined(POLARSSL_HAVE_X86_64)
42
43/**
Manuel Pégourié-Gonnard8eaf20b2013-12-18 19:14:53 +010044 * \brief AES-NI features detection routine
Manuel Pégourié-Gonnard92ac76f2013-12-16 17:12:53 +010045 *
Manuel Pégourié-Gonnard8eaf20b2013-12-18 19:14:53 +010046 * \param what The feature to detect
47 * (POLARSSL_AESNI_AES or POLARSSL_AESNI_CLMUL)
48 *
49 * \return 1 if CPU has support for the feature, 0 otherwise
Manuel Pégourié-Gonnard92ac76f2013-12-16 17:12:53 +010050 */
Manuel Pégourié-Gonnard8eaf20b2013-12-18 19:14:53 +010051int aesni_supports( unsigned int what );
Manuel Pégourié-Gonnard92ac76f2013-12-16 17:12:53 +010052
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010053/**
54 * \brief AES-NI AES-ECB block en(de)cryption
55 *
56 * \param ctx AES context
57 * \param mode AES_ENCRYPT or AES_DECRYPT
58 * \param input 16-byte input block
59 * \param output 16-byte output block
60 *
Manuel Pégourié-Gonnardd333f672013-12-26 11:44:46 +010061 * \return 0 on success (cannot fail)
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010062 */
63int aesni_crypt_ecb( aes_context *ctx,
64 int mode,
65 const unsigned char input[16],
66 unsigned char output[16] );
67
Manuel Pégourié-Gonnardd333f672013-12-26 11:44:46 +010068/**
69 * \brief GCM multiplication: c = a * b in GF(2^128)
70 *
71 * \param c Result
72 * \param a First operand
73 * \param b Second operand
74 *
75 * \note Both operands and result are bit strings interpreted as
76 * elements of GF(2^128) as per the GCM spec.
77 *
78 * \return 0 on success (cannot fail)
79 */
80int aesni_gcm_mult( unsigned char c[16],
81 const unsigned char a[16],
82 const unsigned char b[16] );
83
Manuel Pégourié-Gonnard92ac76f2013-12-16 17:12:53 +010084#endif /* POLARSSL_HAVE_X86_64 */
85
86#endif /* POLARSSL_AESNI_H */