33 lines
499 B
Go
33 lines
499 B
Go
package pbkd
|
|
|
|
import "xdx.jelly/xgcl/mac"
|
|
|
|
type prfer interface {
|
|
prf(data []byte) ([]byte, error)
|
|
hLen() int64
|
|
}
|
|
|
|
const hmacSm3TagSize = 32
|
|
|
|
type hmacSm3 struct {
|
|
m mac.MAC
|
|
}
|
|
|
|
func newPrfHmacSm3(key []byte) prfer {
|
|
for i := len(key); i < 16; i++ {
|
|
key = append(key, 0)
|
|
}
|
|
m, _ := mac.NewHMacSm3(key, hmacSm3TagSize)
|
|
return &hmacSm3{
|
|
m: m,
|
|
}
|
|
}
|
|
|
|
func (h *hmacSm3) prf(data []byte) ([]byte, error) {
|
|
return h.m.ComputeMAC(data)
|
|
}
|
|
|
|
func (h *hmacSm3) hLen() int64 {
|
|
return hmacSm3TagSize
|
|
}
|