summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/modes
diff options
context:
space:
mode:
authormiod <>2016-11-04 17:30:30 +0000
committermiod <>2016-11-04 17:30:30 +0000
commit723502d9588ba0e1cc08af1b12654917da74d440 (patch)
tree77b413175d422148cfb0ef7b2062340230aa5413 /src/lib/libcrypto/modes
parent391f8ce21bb7929810460a73e2fde2c80540848d (diff)
downloadopenbsd-723502d9588ba0e1cc08af1b12654917da74d440.tar.gz
openbsd-723502d9588ba0e1cc08af1b12654917da74d440.tar.bz2
openbsd-723502d9588ba0e1cc08af1b12654917da74d440.zip
Replace all uses of magic numbers when operating on OPENSSL_ia32_P[] by
meaningful constants in a private header file, so that reviewers can actually get a chance to figure out what the code is attempting to do without knowing all cpuid bits. While there, turn it from an array of two 32-bit ints into a properly aligned 64-bit int. Use of OPENSSL_ia32_P is now restricted to the assembler parts. C code will now always use OPENSSL_cpu_caps() and check for the proper bits in the whole 64-bit word it returns. i386 tests and ok jsing@
Diffstat (limited to 'src/lib/libcrypto/modes')
-rw-r--r--src/lib/libcrypto/modes/gcm128.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/lib/libcrypto/modes/gcm128.c b/src/lib/libcrypto/modes/gcm128.c
index 6f8a8dd7f4..95ee755f83 100644
--- a/src/lib/libcrypto/modes/gcm128.c
+++ b/src/lib/libcrypto/modes/gcm128.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gcm128.c,v 1.14 2016/11/04 13:56:05 miod Exp $ */ 1/* $OpenBSD: gcm128.c,v 1.15 2016/11/04 17:30:30 miod Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -637,13 +637,19 @@ static void gcm_gmult_1bit(u64 Xi[2],const u64 H[2])
637 637
638#endif 638#endif
639 639
640#if defined(GHASH_ASM) && \
641 (defined(__i386) || defined(__i386__) || \
642 defined(__x86_64) || defined(__x86_64__) || \
643 defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
644#include "x86_arch.h"
645#endif
646
640#if TABLE_BITS==4 && defined(GHASH_ASM) 647#if TABLE_BITS==4 && defined(GHASH_ASM)
641# if (defined(__i386) || defined(__i386__) || \ 648# if (defined(__i386) || defined(__i386__) || \
642 defined(__x86_64) || defined(__x86_64__) || \ 649 defined(__x86_64) || defined(__x86_64__) || \
643 defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) 650 defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
644# define GHASH_ASM_X86_OR_64 651# define GHASH_ASM_X86_OR_64
645# define GCM_FUNCREF_4BIT 652# define GCM_FUNCREF_4BIT
646extern unsigned int OPENSSL_ia32cap_P[2];
647 653
648void gcm_init_clmul(u128 Htable[16],const u64 Xi[2]); 654void gcm_init_clmul(u128 Htable[16],const u64 Xi[2]);
649void gcm_gmult_clmul(u64 Xi[2],const u128 Htable[16]); 655void gcm_gmult_clmul(u64 Xi[2],const u128 Htable[16]);
@@ -705,8 +711,9 @@ void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block)
705#elif TABLE_BITS==4 711#elif TABLE_BITS==4
706# if defined(GHASH_ASM_X86_OR_64) 712# if defined(GHASH_ASM_X86_OR_64)
707# if !defined(GHASH_ASM_X86) || defined(OPENSSL_IA32_SSE2) 713# if !defined(GHASH_ASM_X86) || defined(OPENSSL_IA32_SSE2)
708 if (OPENSSL_ia32cap_P[0]&(1<<24) && /* check FXSR bit */ 714 /* check FXSR and PCLMULQDQ bits */
709 OPENSSL_ia32cap_P[1]&(1<<1) ) { /* check PCLMULQDQ bit */ 715 if ((OPENSSL_cpu_caps() & (CPUCAP_MASK_FXSR | CPUCAP_MASK_PCLMUL)) ==
716 (CPUCAP_MASK_FXSR | CPUCAP_MASK_PCLMUL)) {
710 gcm_init_clmul(ctx->Htable,ctx->H.u); 717 gcm_init_clmul(ctx->Htable,ctx->H.u);
711 ctx->gmult = gcm_gmult_clmul; 718 ctx->gmult = gcm_gmult_clmul;
712 ctx->ghash = gcm_ghash_clmul; 719 ctx->ghash = gcm_ghash_clmul;
@@ -716,9 +723,9 @@ void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block)
716 gcm_init_4bit(ctx->Htable,ctx->H.u); 723 gcm_init_4bit(ctx->Htable,ctx->H.u);
717# if defined(GHASH_ASM_X86) /* x86 only */ 724# if defined(GHASH_ASM_X86) /* x86 only */
718# if defined(OPENSSL_IA32_SSE2) 725# if defined(OPENSSL_IA32_SSE2)
719 if (OPENSSL_ia32cap_P[0]&(1<<25)) { /* check SSE bit */ 726 if (OPENSSL_cpu_caps() & CPUCAP_MASK_SSE) { /* check SSE bit */
720# else 727# else
721 if (OPENSSL_ia32cap_P[0]&(1<<23)) { /* check MMX bit */ 728 if (OPENSSL_cpu_caps() & CPUCAP_MASK_MMX) { /* check MMX bit */
722# endif 729# endif
723 ctx->gmult = gcm_gmult_4bit_mmx; 730 ctx->gmult = gcm_gmult_4bit_mmx;
724 ctx->ghash = gcm_ghash_4bit_mmx; 731 ctx->ghash = gcm_ghash_4bit_mmx;