init: v1.0.0
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package pbkd
|
||||
|
||||
import (
|
||||
"xdx.jelly/xgcl/mac"
|
||||
)
|
||||
|
||||
type pbmacWithHmacSm3 struct {
|
||||
mac mac.MAC
|
||||
}
|
||||
|
||||
func NewPbmacWithHmacSm3(password, salt []byte, count int) (mac.MAC, error) {
|
||||
key, err := PbkdfWithHmacSm3(password, salt, count, 16)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mac, err := mac.NewHMacSm3(key, hmacSm3TagSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pbmacWithHmacSm3{
|
||||
mac: mac,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// func PbmacWithHmacSm3(password, salt []byte, count int, dst, src, iv []byte, op int) ([]byte, error) {
|
||||
// }
|
||||
|
||||
// ComputeMAC computes message authentication code (MAC) for code data.
|
||||
func (p *pbmacWithHmacSm3) ComputeMAC(data []byte) ([]byte, error) {
|
||||
return p.mac.ComputeMAC(data)
|
||||
}
|
||||
|
||||
// Verify returns nil if mac is a correct authentication code (MAC) for data,
|
||||
// otherwise it returns an error.
|
||||
func (p *pbmacWithHmacSm3) VerifyMAC(mac, data []byte) error {
|
||||
return p.mac.VerifyMAC(mac, data)
|
||||
}
|
||||
Reference in New Issue
Block a user