diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-08-28 23:50:35 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-09-03 23:52:11 -0600 |
commit | 07dac52be6336be4a77a399fd7928802711fb77f (patch) | |
tree | ce42d6b1924ad4a67145d6f43ab3b5fcfba2031f /src/crypto/zinc/curve25519/curve25519-x86_64-glue.h | |
parent | 6a4e34f63be70ea96851e593172e0d3773086219 (diff) |
crypto: import zinc
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc/curve25519/curve25519-x86_64-glue.h')
-rw-r--r-- | src/crypto/zinc/curve25519/curve25519-x86_64-glue.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/crypto/zinc/curve25519/curve25519-x86_64-glue.h b/src/crypto/zinc/curve25519/curve25519-x86_64-glue.h new file mode 100644 index 0000000..4499cd9 --- /dev/null +++ b/src/crypto/zinc/curve25519/curve25519-x86_64-glue.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + */ + +#include <zinc/curve25519.h> +#include <crypto/algapi.h> +#include <asm/cpufeature.h> +#include <asm/processor.h> + +#include "curve25519-x86_64.h" + +static bool curve25519_use_bmi2 __ro_after_init; +static bool curve25519_use_adx __ro_after_init; + +void __init curve25519_fpu_init(void) +{ + curve25519_use_bmi2 = boot_cpu_has(X86_FEATURE_BMI2); + curve25519_use_adx = boot_cpu_has(X86_FEATURE_BMI2) && + boot_cpu_has(X86_FEATURE_ADX); +} + +static inline bool curve25519_arch(u8 mypublic[CURVE25519_POINT_SIZE], + const u8 secret[CURVE25519_POINT_SIZE], + const u8 basepoint[CURVE25519_POINT_SIZE]) +{ + if (curve25519_use_adx) { + curve25519_adx(mypublic, secret, basepoint); + return true; + } else if (curve25519_use_bmi2) { + curve25519_bmi2(mypublic, secret, basepoint); + return true; + } + return false; +} + +static inline bool curve25519_base_arch(u8 pub[CURVE25519_POINT_SIZE], + const u8 secret[CURVE25519_POINT_SIZE]) +{ + if (curve25519_use_adx) { + curve25519_adx_base(pub, secret); + return true; + } else if (curve25519_use_bmi2) { + curve25519_bmi2_base(pub, secret); + return true; + } + return false; +} + +#define HAVE_CURVE25519_ARCH_IMPLEMENTATION |