]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/md5: always test the portable block function too
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 12 Feb 2014 21:31:05 +0000 (13:31 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 12 Feb 2014 21:31:05 +0000 (13:31 -0800)
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

src/pkg/crypto/md5/gen.go
src/pkg/crypto/md5/md5_test.go
src/pkg/crypto/md5/md5block.go
src/pkg/crypto/md5/md5block_generic.go [new file with mode: 0644]

index 397e2647e4bef36c000a4c8004ec8c90b6d21358..75295e4fcb070a21ad94bb491da7e858a2db3aa5 100644 (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]
index a8b7a1a525284b3f72cb32ca3b8cf6f26312cac7..e7faf4961e43cce6c96c515bd38b39c0a874719d 100644 (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())
index c1a87e4640bb969ccab76d8ab03ce1153ca27190..e2a17677757e55ac0b07d2477513fb38734524ba 100644 (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]
diff --git a/src/pkg/crypto/md5/md5block_generic.go b/src/pkg/crypto/md5/md5block_generic.go
new file mode 100644 (file)
index 0000000..239bf4d
--- /dev/null
@@ -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