Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Apr 3, 2024
1 parent 247f9ee commit 5ed1fb9
Showing 1 changed file with 116 additions and 6 deletions.
122 changes: 116 additions & 6 deletions cubehash/cubehash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Test_EmptyMessage(t *testing.T) {
{
check := "44c6de3ac6c73c391bf0906cb7482600ec06b216c7c54a2a8688a6a42676577d"

c := NewCubehash(256, 32, 16, 160, 160)
c := NewSH256()
c.Reset()
c.Write([]byte(msg))
dst := c.Sum(nil)
Expand All @@ -114,7 +114,7 @@ func Test_EmptyMessage(t *testing.T) {
{
check := "4a1d00bbcfcb5a9562fb981e7f7db3350fe2658639d948b9d57452c22328bb32f468b072208450bad5ee178271408be0b16e5633ac8a1e3cf9864cfbfc8e043a"

c := NewCubehash(512, 32, 16, 160, 160)
c := NewSH512()
c.Reset()
c.Write([]byte(msg))
dst := c.Sum(nil)
Expand All @@ -132,7 +132,7 @@ func Test_ShortMessage(t *testing.T) {
{
check := "e712139e3b892f2f5fe52d0f30d78a0cb16b51b217da0e4acb103dd0856f2db0"

c := NewCubehash(256, 32, 16, 160, 160)
c := NewSH256()
c.Reset()
c.Write([]byte(msg))
dst := c.Sum(nil)
Expand All @@ -145,7 +145,7 @@ func Test_ShortMessage(t *testing.T) {
{
check := "dcc0503aae279a3c8c95fa1181d37c418783204e2e3048a081392fd61bace883a1f7c4c96b16b4060c42104f1ce45a622f1a9abaeb994beb107fed53a78f588c"

c := NewCubehash(512, 32, 16, 160, 160)
c := NewSH512()
c.Reset()
c.Write([]byte(msg))
dst := c.Sum(nil)
Expand All @@ -163,7 +163,7 @@ func Test_LongerMessage(t *testing.T) {
{
check := "5151e251e348cbbfee46538651c06b138b10eeb71cf6ea6054d7ca5fec82eb79"

c := NewCubehash(256, 32, 16, 160, 160)
c := NewSH256()
c.Reset()
c.Write([]byte(msg))
dst := c.Sum(nil)
Expand All @@ -176,7 +176,7 @@ func Test_LongerMessage(t *testing.T) {
{
check := "bdba44a28cd16b774bdf3c9511def1a2baf39d4ef98b92c27cf5e37beb8990b7cdb6575dae1a548330780810618b8a5c351c1368904db7ebdf8857d596083a86"

c := NewCubehash(512, 32, 16, 160, 160)
c := NewSH512()
c.Reset()
c.Write([]byte(msg))
dst := c.Sum(nil)
Expand All @@ -188,6 +188,116 @@ func Test_LongerMessage(t *testing.T) {

}

func Test_Others(t *testing.T) {
tests := []struct{
fn func() hash.Hash
}{
{
fn: New,
},
{
fn: New512x,
},
{
fn: New384,
},
{
fn: New256,
},
{
fn: New224,
},
{
fn: New192,
},
{
fn: New160,
},
{
fn: New128,
},

{
fn: NewSH512,
},
{
fn: NewSH256,
},
{
fn: NewSH224,
},
{
fn: NewSH192,
},
}

msg := "The quick brown fox jumps over the lazy dog"
for _, test := range tests {
c := test.fn()
c.Reset()
c.Write([]byte(msg))
dst := c.Sum(nil)

if len(dst) == 0 {
t.Errorf("fail zero")
}
}

}

func Test_Sum_Others(t *testing.T) {
msg := "The quick brown fox jumps over the lazy dog"

{
sum := Sum([]byte(msg))
if len(sum) == 0 {
t.Errorf("fail zero")
}
}

{
sum := Sum384([]byte(msg))
if len(sum) == 0 {
t.Errorf("fail zero")
}
}

{
sum := Sum256([]byte(msg))
if len(sum) == 0 {
t.Errorf("fail zero")
}
}

{
sum := Sum224([]byte(msg))
if len(sum) == 0 {
t.Errorf("fail zero")
}
}

{
sum := Sum192([]byte(msg))
if len(sum) == 0 {
t.Errorf("fail zero")
}
}

{
sum := Sum160([]byte(msg))
if len(sum) == 0 {
t.Errorf("fail zero")
}
}

{
sum := Sum128([]byte(msg))
if len(sum) == 0 {
t.Errorf("fail zero")
}
}
}

func BenchmarkSum(b *testing.B) {
var buf [1 << 20]byte
c := New()
Expand Down

0 comments on commit 5ed1fb9

Please sign in to comment.