From 841d8e1b09250eacd42d5388cfb8f3c4200b7d94 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 16 Feb 2022 21:58:01 +0100 Subject: [PATCH] missed a file. MIT license --- tools/mfd_aes_brute/detectaes.h | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tools/mfd_aes_brute/detectaes.h diff --git a/tools/mfd_aes_brute/detectaes.h b/tools/mfd_aes_brute/detectaes.h new file mode 100644 index 000000000..cf028ed06 --- /dev/null +++ b/tools/mfd_aes_brute/detectaes.h @@ -0,0 +1,72 @@ +// Checks if CPU has support of AES instructions +// +// @author kryukov@frtk.ru +// +// Source code from: +// +// https://github.com/pavelkryukov/putty-aes-ni/blob/master/aescpuid.c +// +// MIT License +// Copyright (c) 2012-2021 Pavel Kryukov, Maxim Kuznetsov, and Svyatoslav Kuzmich +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#include +#include + +#if defined(__x86_64__) || defined(__i386) + +#if defined(__clang__) || defined(__GNUC__) + +#include +static bool platform_aes_hw_available(void) { + unsigned int CPUInfo[4]; + __cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); + return (CPUInfo[2] & (1 << 25)) != 0 && (CPUInfo[2] & (1 << 19)) != 0; /* Check AES and SSE4.1 */ +} + +#else /* defined(__clang__) || defined(__GNUC__) */ + +static bool platform_aes_hw_available(void) { + unsigned int CPUInfo[4]; + __cpuid(CPUInfo, 1); + return (CPUInfo[2] & (1 << 25)) != 0 && (CPUInfo[2] & (1 << 19)) != 0; /* Check AES and SSE4.1 */ +} + +#endif /* defined(__clang__) || defined(__GNUC__) */ + +#else /* defined(__x86_64__) || defined(__i386) */ + + +#include +#include + +static bool platform_aes_hw_available(void) { +#if defined HWCAP_AES + return (getauxval(AT_HWCAP) & HWCAP_AES) != 0; +#elif defined HWCAP2_AES + return (getauxval(AT_HWCAP2) & HWCAP2_AES) != 0; + +#else + return false; +#endif +} + +#endif /* defined(__x86_64__) || defined(__i386) */