diff --git a/_cmptest/sha256demo/sha256.go b/_cmptest/sha256demo/sha256.go index 41e2eab7..1ef0652d 100644 --- a/_cmptest/sha256demo/sha256.go +++ b/_cmptest/sha256demo/sha256.go @@ -3,9 +3,12 @@ package main import ( "crypto/sha256" "fmt" + "io" ) func main() { - sum := sha256.Sum256([]byte("hello world\n")) - fmt.Printf("%x", sum) + h := sha256.New() + io.WriteString(h, "The fog is getting thicker!") + io.WriteString(h, "And Leon's getting laaarger!") + fmt.Printf("%x", h.Sum(nil)) } diff --git a/_cmptest/sha512demo/sha512.go b/_cmptest/sha512demo/sha512.go index eeff921f..f2bf3791 100644 --- a/_cmptest/sha512demo/sha512.go +++ b/_cmptest/sha512demo/sha512.go @@ -3,9 +3,12 @@ package main import ( "crypto/sha512" "fmt" + "io" ) func main() { - sum := sha512.Sum512([]byte("hello world\n")) - fmt.Printf("%x", sum) + h := sha512.New() + io.WriteString(h, "The fog is getting thicker!") + io.WriteString(h, "And Leon's getting laaarger!") + fmt.Printf("%x", h.Sum(nil)) } diff --git a/internal/lib/crypto/sha256/sha256.go b/internal/lib/crypto/sha256/sha256.go index b96dfd55..d55b3d97 100644 --- a/internal/lib/crypto/sha256/sha256.go +++ b/internal/lib/crypto/sha256/sha256.go @@ -1,7 +1,6 @@ package sha256 // llgo:skipall - import ( "hash" "unsafe" @@ -67,3 +66,8 @@ func Sum256(data []byte) (ret [Size]byte) { openssl.SHA256Bytes(data, &ret[0]) return } + +func Sum(data []byte) (ret [Size]byte) { + openssl.SHA256Bytes(data, &ret[0]) + return +} diff --git a/internal/lib/crypto/sha512/sha512.go b/internal/lib/crypto/sha512/sha512.go index c566a64a..53ff4700 100644 --- a/internal/lib/crypto/sha512/sha512.go +++ b/internal/lib/crypto/sha512/sha512.go @@ -1,7 +1,6 @@ package sha512 // llgo:skipall - import ( "hash" "unsafe" @@ -73,6 +72,11 @@ func Sum512(data []byte) (ret [Size]byte) { return } +func Sum(data []byte) (ret [Size]byte) { + openssl.SHA512Bytes(data, &ret[0]) + return +} + func New512_224() hash.Hash { panic("todo: New512_224") }