You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
878 B
Go
53 lines
878 B
Go
package gnutls
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"crypto/sha512"
|
|
"encoding/hex"
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestHashSHA(t *testing.T) {
|
|
h := NewHash(GNUTLS_HASH_SHA512)
|
|
//defer h.Close()
|
|
|
|
data := []byte("1234")
|
|
|
|
h1 := h.Sum(data)
|
|
|
|
h3 := sha512.New()
|
|
h3.Write(data)
|
|
h4 := h3.Sum(nil)
|
|
if !bytes.Equal(h4[:], h1) {
|
|
t.Logf("\n%s\n%s", hex.EncodeToString(h4[:]), hex.EncodeToString(h1))
|
|
t.Fatal("hash not equal")
|
|
}
|
|
runtime.GC()
|
|
time.Sleep(1 * time.Second)
|
|
}
|
|
|
|
func BenchmarkHashSHA512(b *testing.B) {
|
|
buf := make([]byte, 1000*1024)
|
|
rand.Reader.Read(buf)
|
|
for i := 0; i < b.N; i++ {
|
|
h := NewHash(GNUTLS_HASH_SHA512)
|
|
h.Write(buf)
|
|
h.Sum(nil)
|
|
h.Close()
|
|
}
|
|
}
|
|
|
|
func BenchmarkHashSHA512s(b *testing.B) {
|
|
buf := make([]byte, 1000*1024)
|
|
rand.Reader.Read(buf)
|
|
for i := 0; i < b.N; i++ {
|
|
h := sha512.New()
|
|
h.Write(buf)
|
|
h.Sum(nil)
|
|
//h.Close()
|
|
}
|
|
}
|