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

@@ -1,12 +1,16 @@
package sha256
import (
"hash"
"unsafe"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/openssl"
)
// The size of a SHA224 checksum in bytes.
const Size224 = 28
type digest224 struct {
ctx openssl.SHA224_CTX
}
@@ -29,3 +33,16 @@ func (d *digest224) Sum(in []byte) []byte {
d.ctx.Final((*byte)(unsafe.Pointer(hash)))
return append(in, hash[:]...)
}
// 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
}