From 9cb3ef8ef1618654212b3b6fdd65f5889ce65336 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 27 Sep 2018 00:28:47 +0200 Subject: crypto: prefer IS_ENABLED to ifdefs Suggested-by: Ard Biesheuvel --- src/crypto/zinc/poly1305/poly1305-arm-glue.h | 36 ++++++++--------- src/crypto/zinc/poly1305/poly1305-mips-glue.h | 1 + src/crypto/zinc/poly1305/poly1305-x86_64-glue.h | 51 +++++++------------------ 3 files changed, 30 insertions(+), 58 deletions(-) (limited to 'src/crypto/zinc/poly1305') diff --git a/src/crypto/zinc/poly1305/poly1305-arm-glue.h b/src/crypto/zinc/poly1305/poly1305-arm-glue.h index 9d34d21..15ad53f 100644 --- a/src/crypto/zinc/poly1305/poly1305-arm-glue.h +++ b/src/crypto/zinc/poly1305/poly1305-arm-glue.h @@ -10,11 +10,9 @@ asmlinkage void poly1305_init_arm(void *ctx, const u8 key[16]); asmlinkage void poly1305_blocks_arm(void *ctx, const u8 *inp, const size_t len, const u32 padbit); asmlinkage void poly1305_emit_arm(void *ctx, u8 mac[16], const u32 nonce[4]); -#if defined(CONFIG_KERNEL_MODE_NEON) asmlinkage void poly1305_blocks_neon(void *ctx, const u8 *inp, const size_t len, const u32 padbit); asmlinkage void poly1305_emit_neon(void *ctx, u8 mac[16], const u32 nonce[4]); -#endif static bool poly1305_use_neon __ro_after_init; @@ -52,7 +50,6 @@ struct poly1305_arch_internal { }; #endif -#if defined(CONFIG_KERNEL_MODE_NEON) static void convert_to_base2_64(void *ctx) { struct poly1305_arch_internal *state = ctx; @@ -68,10 +65,10 @@ static void convert_to_base2_64(void *ctx) state->h0 = ((u64)state->h[2] << 52) | ((u64)state->h[1] << 26) | state->h[0]; state->h1 = ((u64)state->h[4] << 40) | ((u64)state->h[3] << 14) | (state->h[2] >> 12); state->h2 = state->h[4] >> 24; -#if defined(CONFIG_ARM) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - state->h0 = rol64(state->h0, 32); - state->h1 = rol64(state->h1, 32); -#endif + if (IS_ENABLED(CONFIG_ARM) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) { + state->h0 = rol64(state->h0, 32); + state->h1 = rol64(state->h1, 32); + } #define ULT(a, b) ((a ^ ((a ^ b) | ((a - b) ^ b))) >> (sizeof(a) * 8 - 1)) cy = (state->h2 >> 2) + (state->h2 & ~3ULL); state->h2 &= 3; @@ -81,7 +78,6 @@ static void convert_to_base2_64(void *ctx) #undef ULT state->is_base2_26 = 0; } -#endif static inline bool poly1305_init_arch(void *ctx, const u8 key[POLY1305_KEY_SIZE]) @@ -94,13 +90,13 @@ static inline bool poly1305_blocks_arch(void *ctx, const u8 *inp, const size_t len, const u32 padbit, simd_context_t *simd_context) { -#if defined(CONFIG_KERNEL_MODE_NEON) - if (poly1305_use_neon && simd_use(simd_context)) { - poly1305_blocks_neon(ctx, inp, len, padbit); - return true; + if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON)) { + if (poly1305_use_neon && simd_use(simd_context)) { + poly1305_blocks_neon(ctx, inp, len, padbit); + return true; + } + convert_to_base2_64(ctx); } - convert_to_base2_64(ctx); -#endif poly1305_blocks_arm(ctx, inp, len, padbit); return true; @@ -110,13 +106,13 @@ static inline bool poly1305_emit_arch(void *ctx, u8 mac[POLY1305_MAC_SIZE], const u32 nonce[4], simd_context_t *simd_context) { -#if defined(CONFIG_KERNEL_MODE_NEON) - if (poly1305_use_neon && simd_use(simd_context)) { - poly1305_emit_neon(ctx, mac, nonce); - return true; + if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON)) { + if (poly1305_use_neon && simd_use(simd_context)) { + poly1305_emit_neon(ctx, mac, nonce); + return true; + } + convert_to_base2_64(ctx); } - convert_to_base2_64(ctx); -#endif poly1305_emit_arm(ctx, mac, nonce); return true; diff --git a/src/crypto/zinc/poly1305/poly1305-mips-glue.h b/src/crypto/zinc/poly1305/poly1305-mips-glue.h index eb38cd5..4a0badb 100644 --- a/src/crypto/zinc/poly1305/poly1305-mips-glue.h +++ b/src/crypto/zinc/poly1305/poly1305-mips-glue.h @@ -7,6 +7,7 @@ asmlinkage void poly1305_init_mips(void *ctx, const u8 key[16]); asmlinkage void poly1305_blocks_mips(void *ctx, const u8 *inp, const size_t len, const u32 padbit); asmlinkage void poly1305_emit_mips(void *ctx, u8 mac[16], const u32 nonce[4]); + static void __init poly1305_fpu_init(void) { } diff --git a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h index 4926d27..285cb31 100644 --- a/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h +++ b/src/crypto/zinc/poly1305/poly1305-x86_64-glue.h @@ -13,20 +13,14 @@ asmlinkage void poly1305_blocks_x86_64(void *ctx, const u8 *inp, const size_t len, const u32 padbit); asmlinkage void poly1305_emit_x86_64(void *ctx, u8 mac[POLY1305_MAC_SIZE], const u32 nonce[4]); -#ifdef CONFIG_AS_AVX asmlinkage void poly1305_emit_avx(void *ctx, u8 mac[POLY1305_MAC_SIZE], const u32 nonce[4]); asmlinkage void poly1305_blocks_avx(void *ctx, const u8 *inp, const size_t len, const u32 padbit); -#endif -#ifdef CONFIG_AS_AVX2 asmlinkage void poly1305_blocks_avx2(void *ctx, const u8 *inp, const size_t len, const u32 padbit); -#endif -#ifdef CONFIG_AS_AVX512 asmlinkage void poly1305_blocks_avx512(void *ctx, const u8 *inp, const size_t len, const u32 padbit); -#endif static bool poly1305_use_avx __ro_after_init; static bool poly1305_use_avx2 __ro_after_init; @@ -104,35 +98,21 @@ static inline bool poly1305_blocks_arch(void *ctx, const u8 *inp, { struct poly1305_arch_internal *state = ctx; - if (!poly1305_use_avx || + if (!IS_ENABLED(CONFIG_AS_AVX) || !poly1305_use_avx || (len < (POLY1305_BLOCK_SIZE * 18) && !state->is_base2_26) || - !simd_use(simd_context)) - goto scalar; - -#ifdef CONFIG_AS_AVX512 - if (poly1305_use_avx512) { - poly1305_blocks_avx512(ctx, inp, len, padbit); + !simd_use(simd_context)) { + convert_to_base2_64(ctx); + poly1305_blocks_x86_64(ctx, inp, len, padbit); return true; } -#endif -#ifdef CONFIG_AS_AVX2 - if (poly1305_use_avx2) { + if (IS_ENABLED(CONFIG_AS_AVX512) && poly1305_use_avx512) + poly1305_blocks_avx512(ctx, inp, len, padbit); + else if (IS_ENABLED(CONFIG_AS_AVX2) && poly1305_use_avx2) poly1305_blocks_avx2(ctx, inp, len, padbit); - return true; - } -#endif - -#ifdef CONFIG_AS_AVX - if (poly1305_use_avx) { + else poly1305_blocks_avx(ctx, inp, len, padbit); - return true; - } -#endif -scalar: - convert_to_base2_64(ctx); - poly1305_blocks_x86_64(ctx, inp, len, padbit); return true; } @@ -142,18 +122,13 @@ static inline bool poly1305_emit_arch(void *ctx, u8 mac[POLY1305_MAC_SIZE], { struct poly1305_arch_internal *state = ctx; - if (!poly1305_use_avx || !state->is_base2_26 ||!simd_use(simd_context)) - goto scalar; - -#ifdef CONFIG_AS_AVX - if (poly1305_use_avx || poly1305_use_avx2 || poly1305_use_avx512) { - poly1305_emit_avx(ctx, mac, nonce); + if (!IS_ENABLED(CONFIG_AS_AVX) || !poly1305_use_avx || + !state->is_base2_26 || !simd_use(simd_context)) { + convert_to_base2_64(ctx); + poly1305_emit_x86_64(ctx, mac, nonce); return true; } -#endif -scalar: - convert_to_base2_64(ctx); - poly1305_emit_x86_64(ctx, mac, nonce); + poly1305_emit_avx(ctx, mac, nonce); return true; } -- cgit v1.2.3-59-g8ed1b