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.

50 lines
874 B
Go

7 years ago
package gnutls
import (
"bytes"
"crypto/rand"
7 years ago
"crypto/sha512"
"encoding/hex"
"log"
"testing"
)
func TestHashSHA(t *testing.T) {
h := NewHash(GNUTLS_HASH_SHA512)
7 years ago
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) {
log.Printf("\n%s\n%s", hex.EncodeToString(h4[:]), hex.EncodeToString(h1))
7 years ago
t.Fatal("hash not equal")
}
}
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()
}
}