1
0
mirror of https://github.com/golang/go synced 2024-11-15 02:50:31 -07:00

crypto: use byteorder to simplify consumeUint32 and consumeUint64

A follow-up for the recent CL 585017.
This commit is contained in:
apocelipes 2024-05-16 20:38:21 +08:00
parent 722d59436b
commit 468d60c396
3 changed files with 5 additions and 18 deletions

View 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() {

View 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() {

View 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.