OSDN Git Service

feat: add processIssuing (#152)
[bytom/vapor.git] / vendor / github.com / bytom / crypto / sm3 / sm3_test.go
1 /*
2 Copyright Suzhou Tongji Fintech Research Institute 2017 All Rights Reserved.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7                  http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 */
15
16 package sm3
17
18 import (
19         "fmt"
20         "io/ioutil"
21         "log"
22         "os"
23         "testing"
24 )
25
26 func byteToString(b []byte) string {
27         ret := ""
28         for i := 0; i < len(b); i++ {
29                 ret += fmt.Sprintf("%02x", b[i])
30         }
31         fmt.Println("ret = ", ret)
32         return ret
33 }
34 func TestSm3(t *testing.T) {
35         msg := []byte("test")
36         err := ioutil.WriteFile("ifile", msg, os.FileMode(0644)) // 生成测试文件
37         if err != nil {
38                 log.Fatal(err)
39         }
40         msg, err = ioutil.ReadFile("ifile")
41         if err != nil {
42                 log.Fatal(err)
43         }
44         hw := New()
45         hw.Write(msg)
46         hash := hw.Sum(nil)
47         fmt.Println(hash)
48         fmt.Printf("hash = %d\n", len(hash))
49         fmt.Printf("%s\n", byteToString(hash))
50         hash1 := Sm3Sum(msg)
51         fmt.Println(hash1)
52         fmt.Printf("%s\n", byteToString(hash1))
53
54 }
55
56 func BenchmarkSm3(t *testing.B) {
57         t.ReportAllocs()
58         msg := []byte("test")
59         hw := New()
60         for i := 0; i < t.N; i++ {
61
62                 hw.Sum(nil)
63                 Sm3Sum(msg)
64         }
65 }