mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 20:26:19 +08:00
sm3: remove duplicated code
This commit is contained in:
parent
dc1c5806c9
commit
51a003b022
39
sm3/sm3.go
39
sm3/sm3.go
@ -50,17 +50,17 @@ func (d *digest) MarshalBinary() ([]byte, error) {
|
||||
|
||||
func (d *digest) AppendBinary(b []byte) ([]byte, error) {
|
||||
b = append(b, magic...)
|
||||
b = appendUint32(b, d.h[0])
|
||||
b = appendUint32(b, d.h[1])
|
||||
b = appendUint32(b, d.h[2])
|
||||
b = appendUint32(b, d.h[3])
|
||||
b = appendUint32(b, d.h[4])
|
||||
b = appendUint32(b, d.h[5])
|
||||
b = appendUint32(b, d.h[6])
|
||||
b = appendUint32(b, d.h[7])
|
||||
b = byteorder.BEAppendUint32(b, d.h[0])
|
||||
b = byteorder.BEAppendUint32(b, d.h[1])
|
||||
b = byteorder.BEAppendUint32(b, d.h[2])
|
||||
b = byteorder.BEAppendUint32(b, d.h[3])
|
||||
b = byteorder.BEAppendUint32(b, d.h[4])
|
||||
b = byteorder.BEAppendUint32(b, d.h[5])
|
||||
b = byteorder.BEAppendUint32(b, d.h[6])
|
||||
b = byteorder.BEAppendUint32(b, d.h[7])
|
||||
b = append(b, d.x[:d.nx]...)
|
||||
b = append(b, make([]byte, len(d.x)-d.nx)...)
|
||||
b = appendUint64(b, d.len)
|
||||
b = byteorder.BEAppendUint64(b, d.len)
|
||||
return b, nil
|
||||
}
|
||||
|
||||
@ -86,29 +86,12 @@ func (d *digest) UnmarshalBinary(b []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func appendUint64(b []byte, x uint64) []byte {
|
||||
var a [8]byte
|
||||
byteorder.BEPutUint64(a[:], x)
|
||||
return append(b, a[:]...)
|
||||
}
|
||||
|
||||
func appendUint32(b []byte, x uint32) []byte {
|
||||
var a [4]byte
|
||||
byteorder.BEPutUint32(a[:], x)
|
||||
return append(b, a[:]...)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// New returns a new hash.Hash computing the SM3 checksum. The Hash
|
||||
|
Loading…
x
Reference in New Issue
Block a user