diff options
Diffstat (limited to 'providers')
-rw-r--r-- | providers/implementations/digests/sha3_prov.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/providers/implementations/digests/sha3_prov.c b/providers/implementations/digests/sha3_prov.c index 825d3249fa..1348d0e06a 100644 --- a/providers/implementations/digests/sha3_prov.c +++ b/providers/implementations/digests/sha3_prov.c @@ -249,6 +249,65 @@ static PROV_SHA3_METHOD kmac_s390x_md = } else { \ ctx->meth = sha3_generic_md; \ } +#elif defined(__aarch64__) +# include "arm_arch.h" + +static sha3_absorb_fn armsha3_sha3_absorb; + +size_t SHA3_absorb_cext(uint64_t A[5][5], const unsigned char *inp, size_t len, + size_t r); +/*- + * Hardware-assisted ARMv8.2 SHA3 extension version of the absorb() + */ +static size_t armsha3_sha3_absorb(void *vctx, const void *inp, size_t len) +{ + KECCAK1600_CTX *ctx = vctx; + + return SHA3_absorb_cext(ctx->A, inp, len, ctx->block_size); +} + +static PROV_SHA3_METHOD sha3_ARMSHA3_md = +{ + armsha3_sha3_absorb, + generic_sha3_final +}; +/* Detection on Apple operating systems */ +# if defined(__APPLE__) +# define ARM_SHA3_CAPABLE (OPENSSL_armcap_P & ARMV8_SHA3) +# define SHA3_SET_MD(uname, typ) \ + if (ARM_SHA3_CAPABLE) { \ + ctx->meth = sha3_ARMSHA3_md; \ + } else { \ + ctx->meth = sha3_generic_md; \ + } +# define KMAC_SET_MD(bitlen) \ + if (ARM_SHA3_CAPABLE) { \ + ctx->meth = sha3_ARMSHA3_md; \ + } else { \ + ctx->meth = sha3_generic_md; \ + } +/* Detection on other operating systems */ +# else +# define ARM_HAS_FASTER_SHA3 \ + (MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_FIRESTORM) ||\ + MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_FIRESTORM_PRO) ||\ + MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_FIRESTORM_MAX) ||\ + MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE) ||\ + MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_PRO) ||\ + MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_MAX)) +# define SHA3_SET_MD(uname, typ) \ + if (ARM_HAS_FASTER_SHA3) { \ + ctx->meth = sha3_ARMSHA3_md; \ + } else { \ + ctx->meth = sha3_generic_md; \ + } +# define KMAC_SET_MD(bitlen) \ + if (ARM_HAS_FASTER_SHA3) { \ + ctx->meth = sha3_ARMSHA3_md; \ + } else { \ + ctx->meth = sha3_generic_md; \ + } +# endif /* APPLE */ #else # define SHA3_SET_MD(uname, typ) ctx->meth = sha3_generic_md; # define KMAC_SET_MD(bitlen) ctx->meth = sha3_generic_md; |