gmsm/sm3/sm3.go

38 lines
769 B
Go
Raw Normal View History

2023-01-31 13:50:14 +08:00
// Package sm3 implements ShangMi(SM) sm3 hash algorithm.
2022-01-21 11:24:10 +08:00
package sm3
2022-02-09 10:11:45 +08:00
// [GM/T] SM3 GB/T 32905-2016
2022-01-21 11:24:10 +08:00
import (
"hash"
2024-11-21 14:32:32 +08:00
"github.com/emmansun/gmsm/internal/sm3"
2022-01-21 11:24:10 +08:00
)
// Size the size of a SM3 checksum in bytes.
const Size = 32
2022-01-21 11:24:10 +08:00
// BlockSize the blocksize of SM3 in bytes.
const BlockSize = 64
2022-01-21 11:24:10 +08:00
// New returns a new hash.Hash computing the SM3 checksum. The Hash
// also implements encoding.BinaryMarshaler and
// encoding.BinaryUnmarshaler to marshal and unmarshal the internal
// state of the hash.
func New() hash.Hash {
return sm3.New()
2022-01-21 11:24:10 +08:00
}
// Sum returns the SM3 checksum of the data.
func Sum(data []byte) [Size]byte {
h := New()
h.Write(data)
var sum [Size]byte
h.Sum(sum[:0])
return sum
2024-05-15 08:28:47 +08:00
}
2024-05-17 08:40:27 +08:00
func Kdf(z []byte, keyLen int) []byte {
return sm3.Kdf(z, keyLen)
2024-05-17 08:40:27 +08:00
}