Commit 72f0ed42 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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
parent 73a30435
......@@ -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]
......
......@@ -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())
......
......@@ -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]
......
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment