| 1 |
/* |
| 2 |
* Copyright (c) The mlkem-native project authors |
| 3 |
* Copyright (c) The mldsa-native project authors |
| 4 |
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
/* References |
| 8 |
* ========== |
| 9 |
* |
| 10 |
* - [HYBRID] |
| 11 |
* Hybrid scalar/vector implementations of Keccak and SPHINCS+ on AArch64 |
| 12 |
* Becker, Kannwischer |
| 13 |
* https://eprint.iacr.org/2022/1243 |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef MLD_FIPS202_NATIVE_AARCH64_AUTO_H |
| 17 |
#define MLD_FIPS202_NATIVE_AARCH64_AUTO_H |
| 18 |
/* Default FIPS202 assembly profile for AArch64 systems */ |
| 19 |
|
| 20 |
/* |
| 21 |
* Default logic to decide which implementation to use. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
/* |
| 26 |
* Keccak-f1600 |
| 27 |
* |
| 28 |
* - On Arm-based Apple CPUs, we pick a pure Neon implementation. |
| 29 |
* - Otherwise, unless MLD_SYS_AARCH64_SLOW_BARREL_SHIFTER is set, |
| 30 |
* we use lazy-rotation scalar assembly from @[HYBRID]. |
| 31 |
* - Otherwise, if MLD_SYS_AARCH64_SLOW_BARREL_SHIFTER is set, we |
| 32 |
* fall back to the standard C implementation. |
| 33 |
*/ |
| 34 |
#if defined(__ARM_FEATURE_SHA3) && defined(__APPLE__) |
| 35 |
#include "x1_v84a.h" |
| 36 |
#elif !defined(MLD_SYS_AARCH64_SLOW_BARREL_SHIFTER) |
| 37 |
#include "x1_scalar.h" |
| 38 |
#endif |
| 39 |
|
| 40 |
/* |
| 41 |
* Keccak-f1600x2/x4 |
| 42 |
* |
| 43 |
* The optimal implementation is highly CPU-specific; see @[HYBRID]. |
| 44 |
* |
| 45 |
* For now, if v8.4-A is not implemented, we fall back to Keccak-f1600. |
| 46 |
* If v8.4-A is implemented and we are on an Apple CPU, we use a plain |
| 47 |
* Neon-based implementation. |
| 48 |
* If v8.4-A is implemented and we are not on an Apple CPU, we use a |
| 49 |
* scalar/Neon/Neon hybrid. |
| 50 |
* The reason for this distinction is that Apple CPUs appear to implement |
| 51 |
* the SHA3 instructions on all SIMD units, while Arm CPUs prior to Cortex-X4 |
| 52 |
* don't, and ordinary Neon instructions are still needed. |
| 53 |
*/ |
| 54 |
#if defined(__ARM_FEATURE_SHA3) |
| 55 |
/* |
| 56 |
* For Apple-M cores, we use a plain implementation leveraging SHA3 |
| 57 |
* instructions only. |
| 58 |
*/ |
| 59 |
#if defined(__APPLE__) |
| 60 |
#include "x2_v84a.h" |
| 61 |
#else |
| 62 |
#include "x4_v8a_v84a_scalar.h" |
| 63 |
#endif |
| 64 |
|
| 65 |
#else /* __ARM_FEATURE_SHA3 */ |
| 66 |
|
| 67 |
#include "x4_v8a_scalar.h" |
| 68 |
|
| 69 |
#endif /* !__ARM_FEATURE_SHA3 */ |
| 70 |
|
| 71 |
#endif /* !MLD_FIPS202_NATIVE_AARCH64_AUTO_H */ |