library: crypto/{sha1, sha256, sha512}

This commit is contained in:
xushiwei
2024-07-31 18:55:46 +08:00
parent 16174ca874
commit 27677f86e4
7 changed files with 63 additions and 34 deletions

View File

@@ -2,6 +2,7 @@ package sha256
// llgo:skipall
import (
"crypto"
"hash"
"unsafe"
@@ -9,15 +10,17 @@ import (
"github.com/goplus/llgo/c/openssl"
)
func init() {
crypto.RegisterHash(crypto.SHA224, New224)
crypto.RegisterHash(crypto.SHA256, New)
}
// The blocksize of SHA256 and SHA224 in bytes.
const BlockSize = 64
// The size of a SHA256 checksum in bytes.
const Size = 32
// The size of a SHA224 checksum in bytes.
const Size224 = 28
type digest256 struct {
ctx openssl.SHA256_CTX
}
@@ -48,19 +51,6 @@ func New() hash.Hash {
return d
}
// New224 returns a new hash.Hash computing the SHA224 checksum.
func New224() hash.Hash {
d := new(digest224)
d.ctx.Init()
return d
}
// Sum224 returns the SHA224 checksum of the data.
func Sum224(data []byte) (ret [Size224]byte) {
openssl.SHA224Bytes(data, &ret[0])
return
}
// Sum256 returns the SHA256 checksum of the data.
func Sum256(data []byte) (ret [Size]byte) {
openssl.SHA256Bytes(data, &ret[0])