Manuel Pégourié-Gonnard | 92ac76f | 2013-12-16 17:12:53 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * AES-NI support functions |
| 3 | * |
| 4 | * Copyright (C) 2013, Brainspark B.V. |
| 5 | * |
| 6 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * [AES-WP] http://software.intel.com/en-us/articles/intel-advanced-encryption-standard-aes-instructions-set |
| 28 | */ |
| 29 | |
| 30 | #include "polarssl/config.h" |
| 31 | |
| 32 | #if defined(POLARSSL_AESNI_C) |
| 33 | |
| 34 | #include "polarssl/aesni.h" |
| 35 | |
| 36 | #if defined(POLARSSL_HAVE_X86_64) |
| 37 | |
| 38 | /* |
| 39 | * AES-NI support detection routine, [AES-WP] figure 23 |
| 40 | */ |
| 41 | int aesni_supported( void ) |
| 42 | { |
| 43 | static int supported = -1; |
| 44 | unsigned int c; |
| 45 | |
| 46 | if( supported == -1 ) |
| 47 | { |
| 48 | asm( "movl $1, %%eax \n" |
| 49 | "cpuid \n" |
| 50 | : "=c" (c) |
| 51 | : |
| 52 | : "eax", "ebx", "edx" ); |
| 53 | supported = ( ( c & 0x02000000 ) != 0 ); |
| 54 | } |
| 55 | |
| 56 | return( supported ); |
| 57 | } |
| 58 | |
| 59 | #endif /* POLARSSL_HAVE_X86_64 */ |
| 60 | |
| 61 | #endif /* POLARSSL_AESNI_C */ |