Skip to content

Commit 295fa7e

Browse files
authored
Revert "feat(enhancement): Use crypto/sha256 instead of crypto/md5 for FIPS compliance (#1056)"
This reverts commit da8d2ee.
1 parent d943b9a commit 295fa7e

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

util.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ package resty
77

88
import (
99
"bytes"
10+
"crypto/md5"
1011
"crypto/rand"
11-
"crypto/sha256"
1212
"encoding/binary"
1313
"encoding/hex"
1414
"errors"
@@ -371,7 +371,7 @@ func newGUID() string {
371371
// Timestamp, 4 bytes, big endian
372372
binary.BigEndian.PutUint32(b[:], uint32(time.Now().Unix()))
373373

374-
// Machine, first 3 bytes of sha256.Sum256([]byte(hostname))
374+
// Machine, first 3 bytes of md5(hostname)
375375
b[4], b[5], b[6] = machineID[0], machineID[1], machineID[2]
376376

377377
// Pid, 2 bytes, specs don't specify endianness, but we use big endian.
@@ -403,12 +403,13 @@ var osHostname = os.Hostname
403403
// readMachineID generates and returns a machine id.
404404
// If this function fails to get the hostname it will cause a runtime error.
405405
func readMachineID() []byte {
406-
const idSize = 3
407-
id := make([]byte, idSize)
406+
var sum [3]byte
407+
id := sum[:]
408408

409409
if hostname, err := osHostname(); err == nil {
410-
hash := sha256.Sum256([]byte(hostname))
411-
copy(id, hash[:idSize])
410+
hw := md5.New()
411+
_, _ = hw.Write([]byte(hostname))
412+
copy(id, hw.Sum(nil))
412413
return id
413414
}
414415

0 commit comments

Comments
 (0)