Skip to content

Commit

Permalink
sm3: ppc64x, test more
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Sep 6, 2024
1 parent 7a84c6f commit b95cbab
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions sm3/sm3blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package sm3

import (
"bytes"
"encoding/binary"
"fmt"
"testing"
Expand Down Expand Up @@ -34,6 +35,24 @@ func createOneBlockBy4() [4]*byte {
return [4]*byte{&p1[0], &p2[0], &p3[0], &p4[0]}
}

func createOneRandomBlockBy4() [4]*byte {
var p1 = [64]byte{
0x49, 0xcf, 0x14, 0x64, 0x9f, 0x32, 0x4a, 0x07,
0xe0, 0xd5, 0xbb, 0x2a, 0x00, 0xf7, 0xf0, 0x5d,
0x5f, 0x5b, 0xdd, 0x6d, 0x14, 0xdf, 0xf0, 0x28,
0xe0, 0x71, 0x32, 0x7e, 0xc0, 0x31, 0x10, 0x45,
0x90, 0xed, 0xdb, 0x18, 0xf9, 0x8b, 0x76, 0x3e,
0x18, 0xbf, 0x38, 0x2f, 0xf7, 0xc3, 0x87, 0x5f,
0x30, 0x27, 0x7f, 0x31, 0x79, 0xba, 0xeb, 0xd7,
0x95, 0xe7, 0x85, 0x3f, 0xa6, 0x43, 0xfd, 0xf2,
}

var p2 = p1
var p3 = p1
var p4 = p1
return [4]*byte{&p1[0], &p2[0], &p3[0], &p4[0]}
}

func createTwoBlocksBy4() [4]*byte {
var p1 [128]byte
p1[0] = 0x61
Expand Down Expand Up @@ -65,6 +84,17 @@ func TestBlockMultBy4(t *testing.T) {
}
}

digs = initState4()
p = createOneRandomBlockBy4()
blockMultBy4(&digs[0], &p[0], &buffer[0], 1)
expected = "[8c2b6dd5 cc894103 6ec67d69 6154d5fd 62f48fd 984112e3 9e63659e 542709af]"
for i := 0; i < 4; i++ {
s := fmt.Sprintf("%x", digs[i][:])
if s != expected {
t.Errorf("digs[%d] got %s", i, s)
}
}

digs = initState4()
p = createTwoBlocksBy4()
blockMultBy4(&digs[0], &p[0], &buffer[0], 2)
Expand All @@ -85,9 +115,7 @@ func TestCopyResultsBy4(t *testing.T) {
for j := 0; j < 8; j++ {
m[i][j] = k
k++
fmt.Printf("%08x ", m[i][j])
}
fmt.Println()
}
copyResultsBy4(&m[0][0], &ret[0])

Expand All @@ -96,7 +124,9 @@ func TestCopyResultsBy4(t *testing.T) {
binary.BigEndian.PutUint32(expected[i*32+j*4:], m[i][j])
}
}
t.Errorf("got %x, expected %x\n", ret[:], expected[:])
if !bytes.Equal(ret[:], expected[:]) {
t.Errorf("got %x, expected %x\n", ret[:], expected[:])
}
}

func BenchmarkOneBlockBy4(b *testing.B) {
Expand Down

0 comments on commit b95cbab

Please sign in to comment.