Browse Source

core/crypto/_aes/hw_intel: Use a constant for the PSHUFB indicies

Yawning Angel 1 year ago
parent
commit
dfc4df9807
2 changed files with 3 additions and 7 deletions
  1. 1 1
      core/crypto/_aes/hw_intel/api.odin
  2. 2 6
      core/crypto/_aes/hw_intel/ghash.odin

+ 1 - 1
core/crypto/_aes/hw_intel/api.odin

@@ -3,7 +3,7 @@ package aes_hw_intel
 
 
 import "core:sys/info"
 import "core:sys/info"
 
 
-// is_supporte returns true iff hardware accelerated AES
+// is_supported returns true iff hardware accelerated AES
 // is supported.
 // is supported.
 is_supported :: proc "contextless" () -> bool {
 is_supported :: proc "contextless" () -> bool {
 	features, ok := info.cpu_features.?
 	features, ok := info.cpu_features.?

+ 2 - 6
core/crypto/_aes/hw_intel/ghash.odin

@@ -25,7 +25,6 @@ package aes_hw_intel
 
 
 import "base:intrinsics"
 import "base:intrinsics"
 import "core:crypto/_aes"
 import "core:crypto/_aes"
-import "core:simd"
 import "core:simd/x86"
 import "core:simd/x86"
 
 
 @(private = "file")
 @(private = "file")
@@ -58,14 +57,11 @@ GHASH_STRIDE_BYTES_HW :: GHASH_STRIDE_HW * _aes.GHASH_BLOCK_SIZE
 // chunks. We number chunks from 0 to 3 in left to right order.
 // chunks. We number chunks from 0 to 3 in left to right order.
 
 
 @(private = "file")
 @(private = "file")
-byteswap_index := transmute(x86.__m128i)simd.i8x16{
-	// Note: simd.i8x16 is reverse order from x86._mm_set_epi8.
-	15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
-}
+_BYTESWAP_INDEX: x86.__m128i : { 0x08090a0b0c0d0e0f, 0x0001020304050607 }
 
 
 @(private = "file", require_results, enable_target_feature = "sse2,ssse3")
 @(private = "file", require_results, enable_target_feature = "sse2,ssse3")
 byteswap :: #force_inline proc "contextless" (x: x86.__m128i) -> x86.__m128i {
 byteswap :: #force_inline proc "contextless" (x: x86.__m128i) -> x86.__m128i {
-	return x86._mm_shuffle_epi8(x, byteswap_index)
+	return x86._mm_shuffle_epi8(x, _BYTESWAP_INDEX)
 }
 }
 
 
 // From a 128-bit value kw, compute kx as the XOR of the two 64-bit
 // From a 128-bit value kw, compute kx as the XOR of the two 64-bit