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
|
|
|
|
2025-03-11 14:02:47 +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.
|
2024-08-02 13:02:25 +08:00
|
|
|
const Size = 32
|
2022-01-21 11:24:10 +08:00
|
|
|
|
|
|
|
// BlockSize the blocksize of SM3 in bytes.
|
2024-08-02 13:02:25 +08:00
|
|
|
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 {
|
2025-03-11 14:02:47 +08:00
|
|
|
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 {
|
2025-03-11 14:02:47 +08:00
|
|
|
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 {
|
2025-03-11 14:02:47 +08:00
|
|
|
return sm3.Kdf(z, keyLen)
|
2024-05-17 08:40:27 +08:00
|
|
|
}
|