diff --git a/examples/sig/sig.go b/examples/sig/sig.go index f7a9622..da1c580 100644 --- a/examples/sig/sig.go +++ b/examples/sig/sig.go @@ -32,7 +32,10 @@ func main() { fmt.Printf("\nSigner public key:\n% X ... % X\n", pubKey[0:8], pubKey[len(pubKey)-8:]) - signature, _ := signer.Sign(msg) + signature, err := signer.Sign(msg) + if err != nil { + log.Fatal(err) + } fmt.Printf("\nSignature:\n% X ... % X\n", signature[0:8], signature[len(signature)-8:]) diff --git a/oqstests/kem_test.go b/oqstests/kem_test.go index 069c0e8..dc839bd 100644 --- a/oqstests/kem_test.go +++ b/oqstests/kem_test.go @@ -16,7 +16,7 @@ import ( var disabledKEMPatterns []string // noThreadKEMPatterns lists KEMs that have issues running in a separate thread -var noThreadKEMPatterns = []string{"LEDAcryptKEM-LT52", "HQC-256"} +var noThreadKEMPatterns = []string{} // wgKEMCorrectness groups goroutines and blocks the caller until all goroutines finish. var wgKEMCorrectness sync.WaitGroup @@ -71,7 +71,7 @@ func testKEMWrongCiphertext(kemName string, threading bool, t *testing.T) { func TestKeyEncapsulationCorrectness(t *testing.T) { // Disable some KEMs in macOS/OSX if runtime.GOOS == "darwin" { - disabledKEMPatterns = []string{"Classic-McEliece", "HQC-256"} + disabledKEMPatterns = []string{} } // Disable some KEMs in OpenIndiana if runtime.GOOS == "illumos" { @@ -79,7 +79,7 @@ func TestKeyEncapsulationCorrectness(t *testing.T) { } // Disable some KEMs in Windows if runtime.GOOS == "windows" { - disabledKEMPatterns = []string{"Classic-McEliece"} + disabledKEMPatterns = []string{} } // First test KEMs that belong to noThreadKEMPatterns[] in the main // goroutine, due to issues with stack size being too small in macOS or @@ -113,7 +113,7 @@ func TestKeyEncapsulationCorrectness(t *testing.T) { func TestKeyEncapsulationWrongCiphertext(t *testing.T) { // disable some KEMs in macOS/OSX if runtime.GOOS == "darwin" { - disabledKEMPatterns = []string{"Classic-McEliece", "HQC-256"} + disabledKEMPatterns = []string{} } // Disable some KEMs in OpenIndiana if runtime.GOOS == "illumos" { @@ -121,7 +121,7 @@ func TestKeyEncapsulationWrongCiphertext(t *testing.T) { } // Disable some KEMs in Windows if runtime.GOOS == "windows" { - disabledKEMPatterns = []string{"Classic-McEliece"} + disabledKEMPatterns = []string{} } // First test KEMs that belong to noThreadKEMPatterns[] in the main // goroutine, due to issues with stack size being too small in macOS or diff --git a/oqstests/sig_test.go b/oqstests/sig_test.go index 3a9249b..59b36ad 100644 --- a/oqstests/sig_test.go +++ b/oqstests/sig_test.go @@ -46,17 +46,23 @@ func testSigCorrectness(sigName string, msg []byte, threading bool, t *testing.T } } -// testSigCorrectness tests a specific signature with context string. +// testSigCorrectnessWithCtxStr tests a specific signature with context string. func testSigCorrectnessWithCtxStr(sigName string, msg []byte, threading bool, t *testing.T) { - log.Println("Correctness - ", sigName) // thread-safe if threading == true { defer wgSigCorrectness.Done() } var signer, verifier oqs.Signature defer signer.Clean() defer verifier.Clean() + // Ignore potential errors everywhere _ = signer.Init(sigName, nil) + if !signer.Details().SigWithCtxSupport { + return + } + + log.Println("Correctness with context string - ", sigName) // thread-safe + // Ignore potential errors everywhere _ = verifier.Init(sigName, nil) pubKey, _ := signer.GenerateKeyPair() signature, _ := signer.Sign(msg) @@ -115,11 +121,11 @@ func testSigWrongPublicKey(sigName string, msg []byte, threading bool, t *testin func TestSignatureCorrectness(t *testing.T) { // Disable some sigs in macOS/OSX if runtime.GOOS == "darwin" { - disabledSigPatterns = []string{"Rainbow-III", "Rainbow-V"} + disabledSigPatterns = []string{} } // Disable some sigs in Windows if runtime.GOOS == "windows" { - disabledSigPatterns = []string{"Rainbow-V"} + disabledSigPatterns = []string{} } msg := []byte("This is our favourite message to sign") // First test sigs that belong to noThreadSigPatterns[] in the main @@ -150,16 +156,55 @@ func TestSignatureCorrectness(t *testing.T) { wgSigCorrectness.Wait() } +// TestSignatureCorrectnessWithCtxStr tests all enabled signatures that support context strings. +func TestSignatureCorrectnessWithCtxStr(t *testing.T) { + // Disable some sigs in macOS/OSX + if runtime.GOOS == "darwin" { + disabledSigPatterns = []string{} + } + // Disable some sigs in Windows + if runtime.GOOS == "windows" { + disabledSigPatterns = []string{} + } + msg := []byte("This is our favourite message to sign") + // First test sigs that belong to noThreadSigPatterns[] in the main + // goroutine, due to issues with stack size being too small in macOS or + // Windows + cnt := 0 + for _, sigName := range oqs.EnabledSigs() { + if stringMatchSlice(sigName, disabledSigPatterns) { + cnt++ + continue + } + // Issues with stack size being too small + if stringMatchSlice(sigName, noThreadSigPatterns) { + cnt++ + testSigCorrectnessWithCtxStr(sigName, msg, false, t) + } + } + // Test the remaining sigs in separate goroutines + wgSigCorrectness.Add(len(oqs.EnabledSigs()) - cnt) + for _, sigName := range oqs.EnabledSigs() { + if stringMatchSlice(sigName, disabledSigPatterns) { + continue + } + if !stringMatchSlice(sigName, noThreadSigPatterns) { + go testSigCorrectnessWithCtxStr(sigName, msg, true, t) + } + } + wgSigCorrectness.Wait() +} + // TestSignatureWrongSignature tests the wrong signature regime of all enabled // signatures. func TestSignatureWrongSignature(t *testing.T) { // Disable some sigs in macOS/OSX if runtime.GOOS == "darwin" { - disabledSigPatterns = []string{"Rainbow-III", "Rainbow-V"} + disabledSigPatterns = []string{} } // Disable some sigs in Windows if runtime.GOOS == "windows" { - disabledSigPatterns = []string{"Rainbow-V"} + disabledSigPatterns = []string{} } msg := []byte("This is our favourite message to sign") // First test sigs that belong to noThreadSigPatterns[] in the main @@ -196,11 +241,11 @@ func TestSignatureWrongSignature(t *testing.T) { func TestSignatureWrongPublicKey(t *testing.T) { // Disable some sigs in macOS/OSX if runtime.GOOS == "darwin" { - disabledSigPatterns = []string{"Rainbow-III", "Rainbow-V"} + disabledSigPatterns = []string{} } // Disable some sigs in Windows if runtime.GOOS == "windows" { - disabledSigPatterns = []string{"Rainbow-V"} + disabledSigPatterns = []string{} } msg := []byte("This is our favourite message to sign") // First test sigs that belong to noThreadSigPatterns[] in the main