blob: f33d593427a0903bfbcf776e959c9396e4240e87 [file] [log] [blame]
Jerry Yu49231312023-01-10 16:57:21 +08001/*
2 * Arm64 crypto engine support functions
3 *
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#include <string.h>
21#include "common.h"
22
23#if defined(MBEDTLS_AESCE_C)
24
25#include "aesce.h"
26
27#if defined(MBEDTLS_HAVE_ARM64)
28
29#if defined(__clang__)
30# if __clang_major__ < 4
31# error "A more recent Clang is required for MBEDTLS_AES_C"
32# endif
33#elif defined(__GNUC__)
34# if __GNUC__ < 6
35# error "A more recent GCC is required for MBEDTLS_AES_C"
36# endif
37#else
38# error "Only GCC and Clang supported for MBEDTLS_AES_C"
39#endif
40
41#if !defined(__ARM_FEATURE_CRYPTO)
42# error "`crypto` feature moddifier MUST be enabled for MBEDTLS_AESCE_C."
43# error "Typical option for GCC and Clang is `-march=armv8-a+crypto`."
44#endif /* !__ARM_FEATURE_CRYPTO */
45
46#include <arm_neon.h>
47
Jerry Yub95c7762023-01-10 16:59:51 +080048#if defined(__linux__)
49#include <asm/hwcap.h>
50#include <sys/auxv.h>
51#endif
52
53/*
54 * AES instruction support detection routine
55 */
56int mbedtls_aesce_has_support(void)
57{
58#if defined(__linux__)
59 unsigned long auxval = getauxval(AT_HWCAP);
60 return (auxval & (HWCAP_ASIMD | HWCAP_AES)) ==
61 (HWCAP_ASIMD | HWCAP_AES);
62#else
63 /* Suppose aes instructions are supported. */
64 return 1;
65#endif
66}
67
Jerry Yu49231312023-01-10 16:57:21 +080068#endif /* MBEDTLS_HAVE_ARM64 */
69
70#endif /* MBEDTLS_AESCE_C */