var useSHANI = useAVX2 && cpu.X86.HasSHA
func init() {
- impl.Register("crypto/sha256", "AVX2", &useAVX2)
- impl.Register("crypto/sha256", "SHA-NI", &useSHANI)
+ impl.Register("sha256", "AVX2", &useAVX2)
+ impl.Register("sha256", "SHA-NI", &useSHANI)
}
//go:noescape
var useSHA2 = cpu.ARM64.HasSHA2
func init() {
- impl.Register("crypto/sha256", "Armv8.0", &useSHA2)
+ impl.Register("sha256", "Armv8.0", &useSHA2)
}
//go:noescape
var ppc64sha2 = godebug.New("#ppc64sha2").Value() != "off"
func init() {
- impl.Register("crypto/sha256", "POWER8", &ppc64sha2)
+ impl.Register("sha256", "POWER8", &ppc64sha2)
}
//go:noescape
func init() {
// CP Assist for Cryptographic Functions (CPACF)
// https://www.ibm.com/docs/en/zos/3.1.0?topic=icsf-cp-assist-cryptographic-functions-cpacf
- impl.Register("crypto/sha256", "CPACF", &useSHA256)
+ impl.Register("sha256", "CPACF", &useSHA256)
}
//go:noescape
func init() {
// CP Assist for Cryptographic Functions (CPACF)
- impl.Register("crypto/sha3", "CPACF", &useSHA3)
+ impl.Register("sha3", "CPACF", &useSHA3)
}
func keccakF1600(a *[200]byte) {
// TestKeccak does a basic test of the non-standardized Keccak hash functions.
func TestKeccak(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testKeccak)
+ cryptotest.TestAllImplementations(t, "sha3", testKeccak)
}
func testKeccak(t *testing.T) {
// TestShakeSum tests that the output of Sum matches the output of Read.
func TestShakeSum(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testShakeSum)
+ cryptotest.TestAllImplementations(t, "sha3", testShakeSum)
}
func testShakeSum(t *testing.T) {
// TestUnalignedWrite tests that writing data in an arbitrary pattern with
// small input buffers.
func TestUnalignedWrite(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testUnalignedWrite)
+ cryptotest.TestAllImplementations(t, "sha3", testUnalignedWrite)
}
func testUnalignedWrite(t *testing.T) {
// TestAppend checks that appending works when reallocation is necessary.
func TestAppend(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testAppend)
+ cryptotest.TestAllImplementations(t, "sha3", testAppend)
}
func testAppend(t *testing.T) {
// TestAppendNoRealloc tests that appending works when no reallocation is necessary.
func TestAppendNoRealloc(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testAppendNoRealloc)
+ cryptotest.TestAllImplementations(t, "sha3", testAppendNoRealloc)
}
func testAppendNoRealloc(t *testing.T) {
// TestSqueezing checks that squeezing the full output a single time produces
// the same output as repeatedly squeezing the instance.
func TestSqueezing(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testSqueezing)
+ cryptotest.TestAllImplementations(t, "sha3", testSqueezing)
}
func testSqueezing(t *testing.T) {
}
func TestReset(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testReset)
+ cryptotest.TestAllImplementations(t, "sha3", testReset)
}
func testReset(t *testing.T) {
}
func TestClone(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testClone)
+ cryptotest.TestAllImplementations(t, "sha3", testClone)
}
func testClone(t *testing.T) {
// }
// console.log(bytesToHex(acc.xof(32)));
//
- cryptotest.TestAllImplementations(t, "crypto/sha3", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha3", func(t *testing.T) {
t.Run("cSHAKE128", func(t *testing.T) {
testCSHAKEAccumulated(t, NewCShake128, (1600-256)/8,
"bb14f8657c6ec5403d0b0e2ef3d3393497e9d3b1a9a9e8e6c81dbaa5fd809252")
}
func TestCSHAKELargeS(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", testCSHAKELargeS)
+ cryptotest.TestAllImplementations(t, "sha3", testCSHAKELargeS)
}
func testCSHAKELargeS(t *testing.T) {
}
func TestMarshalUnmarshal(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha3", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha3", func(t *testing.T) {
t.Run("SHA3-224", func(t *testing.T) { testMarshalUnmarshal(t, New224()) })
t.Run("SHA3-256", func(t *testing.T) { testMarshalUnmarshal(t, New256()) })
t.Run("SHA3-384", func(t *testing.T) { testMarshalUnmarshal(t, New384()) })
var useAVX2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI1 && cpu.X86.HasBMI2
func init() {
- impl.Register("crypto/sha512", "AVX2", &useAVX2)
+ impl.Register("sha512", "AVX2", &useAVX2)
}
//go:noescape
var useSHA512 = cpu.ARM64.HasSHA512
func init() {
- impl.Register("crypto/sha512", "Armv8.2", &useSHA512)
+ impl.Register("sha512", "Armv8.2", &useSHA512)
}
//go:noescape
var ppc64sha512 = godebug.New("#ppc64sha512").Value() != "off"
func init() {
- impl.Register("crypto/sha512", "POWER8", &ppc64sha512)
+ impl.Register("sha512", "POWER8", &ppc64sha512)
}
//go:noescape
func init() {
// CP Assist for Cryptographic Functions (CPACF)
// https://www.ibm.com/docs/en/zos/3.1.0?topic=icsf-cp-assist-cryptographic-functions-cpacf
- impl.Register("crypto/sha512", "CPACF", &useSHA512)
+ impl.Register("sha512", "CPACF", &useSHA512)
}
//go:noescape
// primitives, to allow selecting them for testing.
package impl
+import "strings"
+
type implementation struct {
Package string
Name string
// remaining one must be used (i.e. disabling one implementation must not
// implicitly disable any other). Each package has an implicit base
// implementation that is selected when all alternatives are unavailable or
-// disabled.
+// disabled. pkg must be the package name, not path (e.g. "aes" not "crypto/aes").
func Register(pkg, name string, available *bool) {
+ if strings.Contains(pkg, "/") {
+ panic("impl: package name must not contain slashes")
+ }
allImplementations = append(allImplementations, implementation{
Package: pkg,
Name: name,
}
func TestGolden(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha256", testGolden)
+ cryptotest.TestAllImplementations(t, "sha256", testGolden)
}
func testGolden(t *testing.T) {
}
func TestGoldenMarshal(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha256", testGoldenMarshal)
+ cryptotest.TestAllImplementations(t, "sha256", testGoldenMarshal)
}
func testGoldenMarshal(t *testing.T) {
func TestHash(t *testing.T) {
t.Run("SHA-224", func(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha256", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha256", func(t *testing.T) {
cryptotest.TestHash(t, New224)
})
})
t.Run("SHA-256", func(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha256", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha256", func(t *testing.T) {
cryptotest.TestHash(t, New)
})
})
}
func TestGolden(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha512", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha512", func(t *testing.T) {
testGolden(t)
})
}
}
func TestGoldenMarshal(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha512", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha512", func(t *testing.T) {
testGoldenMarshal(t)
})
}
func TestHash(t *testing.T) {
t.Run("SHA-384", func(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha512", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha512", func(t *testing.T) {
cryptotest.TestHash(t, New384)
})
})
t.Run("SHA-512/224", func(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha512", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha512", func(t *testing.T) {
cryptotest.TestHash(t, New512_224)
})
})
t.Run("SHA-512/256", func(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha512", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha512", func(t *testing.T) {
cryptotest.TestHash(t, New512_256)
})
})
t.Run("SHA-512", func(t *testing.T) {
- cryptotest.TestAllImplementations(t, "crypto/sha512", func(t *testing.T) {
+ cryptotest.TestAllImplementations(t, "sha512", func(t *testing.T) {
cryptotest.TestHash(t, New)
})
})
NET, log
< net/mail;
- NONE < crypto/internal/impl;
+ STR < crypto/internal/impl;
# FIPS is the FIPS 140 module.
# It must not depend on external crypto packages.