add crypto sha1, sha256, sha512

This commit is contained in:
tsingbx
2024-07-31 13:56:42 +08:00
parent 36072584d0
commit 2d7958f726
9 changed files with 310 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package sha256
import (
"unsafe"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/openssl"
)
type digest224 struct {
ctx openssl.SHA224_CTX
}
func (d *digest224) Size() int { return Size224 }
func (d *digest224) BlockSize() int { return BlockSize }
func (d *digest224) Reset() {
d.ctx.Init()
}
func (d *digest224) Write(p []byte) (nn int, err error) {
d.ctx.UpdateBytes(p)
return len(p), nil
}
func (d *digest224) Sum(in []byte) []byte {
hash := (*[Size]byte)(c.Alloca(Size))
d.ctx.Final((*byte)(unsafe.Pointer(hash)))
return append(in, hash[:]...)
}