X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=crypto%2Fsm3%2Fsm3_test.go;fp=crypto%2Fsm3%2Fsm3_test.go;h=428bcc24b8befd235ab652454b00e9797de9fb21;hp=0000000000000000000000000000000000000000;hb=db158dcf09436b003defd333f1a665e7e051d820;hpb=d09b7a78d44dc259725902b8141cdba0d716b121 diff --git a/crypto/sm3/sm3_test.go b/crypto/sm3/sm3_test.go new file mode 100644 index 00000000..428bcc24 --- /dev/null +++ b/crypto/sm3/sm3_test.go @@ -0,0 +1,65 @@ +/* +Copyright Suzhou Tongji Fintech Research Institute 2017 All Rights Reserved. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sm3 + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "testing" +) + +func byteToString(b []byte) string { + ret := "" + for i := 0; i < len(b); i++ { + ret += fmt.Sprintf("%02x", b[i]) + } + fmt.Println("ret = ", ret) + return ret +} +func TestSm3(t *testing.T) { + msg := []byte("test") + err := ioutil.WriteFile("ifile", msg, os.FileMode(0644)) // 生成测试文件 + if err != nil { + log.Fatal(err) + } + msg, err = ioutil.ReadFile("ifile") + if err != nil { + log.Fatal(err) + } + hw := New() + hw.Write(msg) + hash := hw.Sum(nil) + fmt.Println(hash) + fmt.Printf("hash = %d\n", len(hash)) + fmt.Printf("%s\n", byteToString(hash)) + hash1 := Sm3Sum(msg) + fmt.Println(hash1) + fmt.Printf("%s\n", byteToString(hash1)) + +} + +func BenchmarkSm3(t *testing.B) { + t.ReportAllocs() + msg := []byte("test") + hw := New() + for i := 0; i < t.N; i++ { + + hw.Sum(nil) + Sm3Sum(msg) + } +}