diff --git a/src/crypto/subtle/dit_test.go b/src/crypto/subtle/dit_test.go index 8753ed623fd..29779683b57 100644 --- a/src/crypto/subtle/dit_test.go +++ b/src/crypto/subtle/dit_test.go @@ -15,6 +15,8 @@ func TestWithDataIndependentTiming(t *testing.T) { t.Skip("CPU does not support DIT") } + ditAlreadyEnabled := sys.DITEnabled() + WithDataIndependentTiming(func() { if !sys.DITEnabled() { t.Fatal("dit not enabled within WithDataIndependentTiming closure") @@ -31,7 +33,7 @@ func TestWithDataIndependentTiming(t *testing.T) { } }) - if sys.DITEnabled() { + if !ditAlreadyEnabled && sys.DITEnabled() { t.Fatal("dit not unset after returning from WithDataIndependentTiming closure") } } @@ -41,12 +43,14 @@ func TestDITPanic(t *testing.T) { t.Skip("CPU does not support DIT") } + ditAlreadyEnabled := sys.DITEnabled() + defer func() { e := recover() if e == nil { t.Fatal("didn't panic") } - if sys.DITEnabled() { + if !ditAlreadyEnabled && sys.DITEnabled() { t.Error("DIT still enabled after panic inside of WithDataIndependentTiming closure") } }()