library: crypto/{sha1, sha256, sha512}
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user