]> Cypherpunks repositories - gostls13.git/commitdiff
crypto: use byteorder to simplify consumeUint32 and consumeUint64
authorapocelipes <seve3r@outlook.com>
Thu, 16 May 2024 12:58:48 +0000 (12:58 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 16 May 2024 16:50:58 +0000 (16:50 +0000)
A follow-up for the recent CL 585017.

Change-Id: I9faaff7fdf62fc931fc7f64dbe238de277280730
GitHub-Last-Rev: 468d60c3960751c1eec81c6ef1a57ab9e32f2eb8
GitHub-Pull-Request: golang/go#67425
Reviewed-on: https://go-review.googlesource.com/c/go/+/586035
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/crypto/sha1/sha1.go
src/crypto/sha256/sha256.go
src/crypto/sha512/sha512.go

index 01f16b389eacb23ecea4a8bfdaab51c40daf3de3..c0742b9d83c5278a7bc6a8b539e50f005ccd2b7b 100644 (file)
@@ -82,16 +82,11 @@ func (d *digest) UnmarshalBinary(b []byte) error {
 }
 
 func consumeUint64(b []byte) ([]byte, uint64) {
-       _ = b[7]
-       x := uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
-               uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
-       return b[8:], x
+       return b[8:], byteorder.BeUint64(b)
 }
 
 func consumeUint32(b []byte) ([]byte, uint32) {
-       _ = b[3]
-       x := uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
-       return b[4:], x
+       return b[4:], byteorder.BeUint32(b)
 }
 
 func (d *digest) Reset() {
index cad651624ca10ba6e53dd171a89e29153bd6fa9f..68244fd63b0c1ede9120d8ce7dd01983e4196cd6 100644 (file)
@@ -107,16 +107,11 @@ func (d *digest) UnmarshalBinary(b []byte) error {
 }
 
 func consumeUint64(b []byte) ([]byte, uint64) {
-       _ = b[7]
-       x := uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
-               uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
-       return b[8:], x
+       return b[8:], byteorder.BeUint64(b)
 }
 
 func consumeUint32(b []byte) ([]byte, uint32) {
-       _ = b[3]
-       x := uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
-       return b[4:], x
+       return b[4:], byteorder.BeUint32(b)
 }
 
 func (d *digest) Reset() {
index 8fbaba575eeba56d4accf05aa54162485699a35b..dde83625f7b8523faffa4e9d26a6ae6ae616a5de 100644 (file)
@@ -198,10 +198,7 @@ func (d *digest) UnmarshalBinary(b []byte) error {
 }
 
 func consumeUint64(b []byte) ([]byte, uint64) {
-       _ = b[7]
-       x := uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
-               uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
-       return b[8:], x
+       return b[8:], byteorder.BeUint64(b)
 }
 
 // New returns a new hash.Hash computing the SHA-512 checksum.