Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Dec 10, 2024
1 parent 38b2750 commit c95cd73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion hash/hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"golang.org/x/crypto/sha3"
"golang.org/x/crypto/ripemd160"
"github.com/deatil/go-hash/md2"
"github.com/deatil/go-hash/sm3"
)

var (
Expand All @@ -39,9 +40,10 @@ func init() {
RegisterHmacHash(HmacSHA3_384, sha3.New384)
RegisterHmacHash(HmacSHA3_512, sha3.New512)
RegisterHmacHash(HmacRIPEMD160, ripemd160.New)
RegisterHmacHash(HmacSM3, sm3.New)
}

// hmac 用到的 hash
// hmac hash type
type HmacHash uint

const (
Expand All @@ -61,6 +63,7 @@ const (
HmacSHA3_384
HmacSHA3_512
HmacRIPEMD160
HmacSM3
)

var hmacHashes = make(map[HmacHash]func() hash.Hash)
Expand Down
5 changes: 3 additions & 2 deletions hash/hmac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var hmacTests = []struct {
{"SHA512", HmacSHA512, "sdf,gsdgfsdfg123156", "pass123", "aaf38f79d73a28a02c8ae26635e90a5b716f84d3365a1aa4333f86a99d8a85774ec3eb3c1e4d8e05df393ae7c60dd024feacafbd3564395fee52874902e54a93"},
{"RIPEMD160", HmacRIPEMD160, "sdf,gsdgfsdfg123156", "pass123", "a6fde50583758876022d48f90db93bcfedfe9615"},
{"SHA3_256", HmacSHA3_256, "sdffgsdgfsdfg123156rt5", "pass123", "6d9504b686faeeac4eb66f96603c55f4033181da671644357b7f40cd838311ac"},
{"HmacSM3", HmacSM3, "sdffgsdgfsdfg123156rt5", "pass123", "997f778d1ecbd92845c0061b4d1d658ef84170bb57efbabc7cd4ef5c953f8446"},
}

func Test_Hmac(t *testing.T) {
Expand All @@ -31,7 +32,7 @@ func Test_Hmac(t *testing.T) {

t.Run(fmt.Sprintf("Hmac_test_%d", index), func(t *testing.T) {
assertError(e.Error, "Hmac-" + test.name)
assert(test.output, e.ToHexString(), "Hmac-" + test.name)
assert(e.ToHexString(), test.output, "Hmac-" + test.name)
})
}
}
Expand All @@ -46,7 +47,7 @@ func Test_NewHmac(t *testing.T) {

t.Run(fmt.Sprintf("NewHmac_test_%d", index), func(t *testing.T) {
assertError(e.Error, "NewHmac" + test.name)
assert(test.output, e.ToHexString(), "NewHmac" + test.name)
assert(e.ToHexString(), test.output, "NewHmac" + test.name)
})
}
}

0 comments on commit c95cd73

Please sign in to comment.