1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:44:43 -07:00

crypto/md5: always test the portable block function too

So it doesn't bitrot.

Like the sha1 version (https://golang.org/cl/62270043)

LGTM=agl
R=agl
CC=golang-codereviews
https://golang.org/cl/62420043
This commit is contained in:
Brad Fitzpatrick 2014-02-12 13:31:05 -08:00
parent 73a304356b
commit 72f0ed42fa
4 changed files with 24 additions and 6 deletions

View File

@ -167,8 +167,6 @@ var program = `// Copyright 2013 The Go Authors. All rights reserved.
// DO NOT EDIT.
// Generate with: go run gen.go{{if .Full}} -full{{end}} | gofmt >md5block.go
// +build !amd64,!386,!arm
package md5
import (
@ -204,7 +202,7 @@ func init() {
littleEndian = *(*[4]byte)(unsafe.Pointer(&x)) == y
}
func block(dig *digest, p []byte) {
func blockGeneric(dig *digest, p []byte) {
a := dig.s[0]
b := dig.s[1]
c := dig.s[2]

View File

@ -5,6 +5,7 @@
package md5
import (
"crypto/rand"
"fmt"
"io"
"testing"
@ -105,6 +106,18 @@ func TestLarge(t *testing.T) {
}
}
// Tests that blockGeneric (pure Go) and block (in assembly for amd64, 386, arm) match.
func TestBlockGeneric(t *testing.T) {
gen, asm := New().(*digest), New().(*digest)
buf := make([]byte, BlockSize*20) // arbitrary factor
rand.Read(buf)
blockGeneric(gen, buf)
block(asm, buf)
if *gen != *asm {
t.Error("block and blockGeneric resulted in different states")
}
}
var bench = New()
var buf = make([]byte, 8192+1)
var sum = make([]byte, bench.Size())

View File

@ -5,8 +5,6 @@
// DO NOT EDIT.
// Generate with: go run gen.go -full | gofmt >md5block.go
// +build !amd64,!386,!arm
package md5
import (
@ -24,7 +22,7 @@ func init() {
littleEndian = *(*[4]byte)(unsafe.Pointer(&x)) == y
}
func block(dig *digest, p []byte) {
func blockGeneric(dig *digest, p []byte) {
a := dig.s[0]
b := dig.s[1]
c := dig.s[2]

View File

@ -0,0 +1,9 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !amd64,!386,!arm
package md5
var block = blockGeneric