Skip to content

Commit

Permalink
deduplicate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Jan 8, 2025
1 parent 7266341 commit 0fc0aaf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
11 changes: 2 additions & 9 deletions cng/sha3.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,9 @@ func SumSHAKE256(data []byte, length int) []byte {
return out
}

// SupportsSHAKE returns true if the SHAKE extendable output function with the
// given securityBits is supported.
// SupportsSHAKE returns true if the SHAKE and CSHAKE extendable output functions
// with the given securityBits are supported.
func SupportsSHAKE(securityBits int) bool {
// CNG implements SHAKE using CSHAKE with empty N and S.
return SupportsCSHAKE(securityBits)
}

// SupportsCSHAKE returns true if the CSHAKE extendable output function with the
// given securityBits is supported.
func SupportsCSHAKE(securityBits int) bool {
var id string
switch securityBits {
case 128:
Expand Down
8 changes: 2 additions & 6 deletions cng/sha3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ var testShakes = map[string]struct {
func skipCSHAKEIfNotSupported(t *testing.T, algo string) {
var supported bool
switch algo {
case "SHAKE128":
case "SHAKE128", "CSHAKE128":
supported = cng.SupportsSHAKE(128)
case "SHAKE256":
case "SHAKE256", "CSHAKE256":
supported = cng.SupportsSHAKE(256)
case "CSHAKE128":
supported = cng.SupportsCSHAKE(128)
case "CSHAKE256":
supported = cng.SupportsCSHAKE(256)
}
if !supported {
t.Skip("skipping: not supported")
Expand Down

0 comments on commit 0fc0aaf

Please sign in to comment.