Skip to content

Commit

Permalink
Version 0.12.0
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Gheorghiu <[email protected]>
  • Loading branch information
vsoftco committed Jan 15, 2025
1 parent b8480fc commit 63ef6fe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 14 deletions.
5 changes: 4 additions & 1 deletion examples/sig/sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:])

Expand Down
10 changes: 5 additions & 5 deletions oqstests/kem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,15 +71,15 @@ 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" {
disabledKEMPatterns = []string{"Classic-McEliece"}
}
// 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
Expand Down Expand Up @@ -113,15 +113,15 @@ 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" {
disabledKEMPatterns = []string{"Classic-McEliece"}
}
// 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
Expand Down
61 changes: 53 additions & 8 deletions oqstests/sig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 63ef6fe

Please sign in to comment.