Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sign: Adding SLH-DSA signature #512

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Alternatively, look at the [Cloudflare Go](https://github.com/cloudflare/go/tree
[RFC-9496]: https://doi.org/10.17487/RFC9496
[RFC-9497]: https://doi.org/10.17487/RFC9497
[FIPS 202]: https://doi.org/10.6028/NIST.FIPS.202
[FIPS 204]: https://doi.org/10.6028/NIST.FIPS.204
[FIPS 205]: https://doi.org/10.6028/NIST.FIPS.205
[FIPS 186-5]: https://doi.org/10.6028/NIST.FIPS.186-5
[BLS12-381]: https://electriccoin.co/blog/new-snark-curve/
[ia.cr/2015/267]: https://ia.cr/2015/267
Expand Down Expand Up @@ -91,7 +93,8 @@ Alternatively, look at the [Cloudflare Go](https://github.com/cloudflare/go/tree
|:---:|

- [Dilithium](./sign/dilithium): modes 2, 3, 5 ([Dilithium](https://pq-crystals.org/dilithium/)).
- [ML-DSA](./sign/mldsa): modes 44, 65, 87 ([FIPS 204](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.204.pdf)).
- [ML-DSA](./sign/mldsa): modes 44, 65, 87 ([FIPS 204]).
- [SLH-DSA](./sign/slhdsa): twelve parameter sets, pure and pre-hash signing ([FIPS 205]).

### Zero-knowledge Proofs

Expand Down
25 changes: 25 additions & 0 deletions internal/test/test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package test

import (
"bytes"
"encoding"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -58,3 +60,26 @@ func CheckPanic(f func()) error {
f()
return hasPanicked
}

func CheckMarshal(
t *testing.T,
x, y interface {
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
},
) {
t.Helper()

want, err := x.MarshalBinary()
CheckNoErr(t, err, fmt.Sprintf("cannot marshal %T = %v", x, x))

err = y.UnmarshalBinary(want)
CheckNoErr(t, err, fmt.Sprintf("cannot unmarshal %T from %x", y, want))

got, err := y.MarshalBinary()
CheckNoErr(t, err, fmt.Sprintf("cannot marshal %T = %v", y, y))

if !bytes.Equal(got, want) {
ReportError(t, got, want, x, y)
}
}
23 changes: 19 additions & 4 deletions sign/schemes/schemes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@
// Ed448
// Ed25519-Dilithium2
// Ed448-Dilithium3
// Dilithium
// ML-DSA
// SLH-DSA
package schemes

import (
"strings"

"github.com/cloudflare/circl/sign"
dilithium2 "github.com/cloudflare/circl/sign/dilithium/mode2"
dilithium3 "github.com/cloudflare/circl/sign/dilithium/mode3"
dilithium5 "github.com/cloudflare/circl/sign/dilithium/mode5"
"github.com/cloudflare/circl/sign/ed25519"
"github.com/cloudflare/circl/sign/ed448"
"github.com/cloudflare/circl/sign/eddilithium2"
"github.com/cloudflare/circl/sign/eddilithium3"

dilithium2 "github.com/cloudflare/circl/sign/dilithium/mode2"
dilithium3 "github.com/cloudflare/circl/sign/dilithium/mode3"
dilithium5 "github.com/cloudflare/circl/sign/dilithium/mode5"
"github.com/cloudflare/circl/sign/mldsa/mldsa44"
"github.com/cloudflare/circl/sign/mldsa/mldsa65"
"github.com/cloudflare/circl/sign/mldsa/mldsa87"
"github.com/cloudflare/circl/sign/slhdsa"
)

var allSchemes = [...]sign.Scheme{
Expand All @@ -36,6 +39,18 @@ var allSchemes = [...]sign.Scheme{
mldsa44.Scheme(),
mldsa65.Scheme(),
mldsa87.Scheme(),
slhdsa.SHA2_128s.Scheme(),
slhdsa.SHAKE_128s.Scheme(),
slhdsa.SHA2_128f.Scheme(),
slhdsa.SHAKE_128f.Scheme(),
slhdsa.SHA2_192s.Scheme(),
slhdsa.SHAKE_192s.Scheme(),
slhdsa.SHA2_192f.Scheme(),
slhdsa.SHAKE_192f.Scheme(),
slhdsa.SHA2_256s.Scheme(),
slhdsa.SHAKE_256s.Scheme(),
slhdsa.SHA2_256f.Scheme(),
slhdsa.SHAKE_256f.Scheme(),
}

var allSchemeNames map[string]sign.Scheme
Expand Down
12 changes: 12 additions & 0 deletions sign/schemes/schemes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ func Example() {
// ML-DSA-44
// ML-DSA-65
// ML-DSA-87
// SLH-DSA-SHA2-128s
// SLH-DSA-SHAKE-128s
// SLH-DSA-SHA2-128f
// SLH-DSA-SHAKE-128f
// SLH-DSA-SHA2-192s
// SLH-DSA-SHAKE-192s
// SLH-DSA-SHA2-192f
// SLH-DSA-SHAKE-192f
// SLH-DSA-SHA2-256s
// SLH-DSA-SHAKE-256s
// SLH-DSA-SHA2-256f
// SLH-DSA-SHAKE-256f
}

func BenchmarkGenerateKeyPair(b *testing.B) {
Expand Down
Loading