Skip to content

Commit 0ed28d5

Browse files
committed
code review suggestions
1 parent f8d3e82 commit 0ed28d5

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

evp.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func cryptoHashToMD(ch crypto.Hash) (md C.GO_EVP_MD_PTR) {
7070
return C.go_openssl_EVP_md5_sha1()
7171
}
7272
}
73-
sha3Defined := vMajor > 1 || (vMajor >= 1 && vMinor > 1) || (vMajor >= 1 && vMinor >= 1 && vPatch >= 1)
7473
switch ch {
7574
case crypto.MD4:
7675
return C.go_openssl_EVP_md4()
@@ -86,20 +85,20 @@ func cryptoHashToMD(ch crypto.Hash) (md C.GO_EVP_MD_PTR) {
8685
return C.go_openssl_EVP_sha384()
8786
case crypto.SHA512:
8887
return C.go_openssl_EVP_sha512()
89-
case crypto.SHA3_224:
90-
if sha3Defined {
88+
case crypto.SHA3_224, crypto.SHA3_256, crypto.SHA3_384, crypto.SHA3_512:
89+
if version1_1_1_or_above() {
9190
return C.go_openssl_EVP_sha3_224()
9291
}
9392
case crypto.SHA3_256:
94-
if sha3Defined {
93+
if version1_1_1_or_above() {
9594
return C.go_openssl_EVP_sha3_256()
9695
}
9796
case crypto.SHA3_384:
98-
if sha3Defined {
97+
if version1_1_1_or_above() {
9998
return C.go_openssl_EVP_sha3_384()
10099
}
101100
case crypto.SHA3_512:
102-
if sha3Defined {
101+
if version1_1_1_or_above() {
103102
return C.go_openssl_EVP_sha3_512()
104103
}
105104
}

hkdf.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313
)
1414

1515
func SupportsHKDF() bool {
16-
return vMajor > 1 ||
17-
(vMajor >= 1 && vMinor > 1) ||
18-
(vMajor >= 1 && vMinor >= 1 && vPatch >= 1)
16+
return version1_1_1_or_above()
1917
}
2018

2119
func newHKDF(h func() hash.Hash, mode C.int) (*hkdf, error) {

openssl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,7 @@ func bnToBig(bn C.GO_BIGNUM_PTR) BigInt {
271271
func CheckLeaks() {
272272
C.go_openssl_do_leak_check()
273273
}
274+
275+
func version1_1_1_or_above() bool {
276+
return vMajor > 1 || (vMajor >= 1 && vMinor > 1) || (vMajor >= 1 && vMinor >= 1 && vPatch >= 1)
277+
}

sha.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,17 @@ func (h *md5Hash) Sum(in []byte) []byte {
269269
}
270270

271271
const (
272-
sha5Magic = "md5\x01"
273-
sha5MarshaledSize = len(sha5Magic) + 4*4 + 64 + 8
272+
md5Magic = "md5\x01"
273+
md5MarshaledSize = len(md5Magic) + 4*4 + 64 + 8
274274
)
275275

276276
func (h *md5Hash) MarshalBinary() ([]byte, error) {
277277
d := (*md5State)(h.shaState())
278278
if d == nil {
279-
return nil, errors.New("crypto/sha1: can't retrieve hash state")
279+
return nil, errors.New("crypto/md5: can't retrieve hash state")
280280
}
281-
b := make([]byte, 0, sha5MarshaledSize)
282-
b = append(b, sha5Magic...)
281+
b := make([]byte, 0, md5MarshaledSize)
282+
b = append(b, md5Magic...)
283283
b = appendUint32(b, d.h[0])
284284
b = appendUint32(b, d.h[1])
285285
b = appendUint32(b, d.h[2])
@@ -291,17 +291,17 @@ func (h *md5Hash) MarshalBinary() ([]byte, error) {
291291
}
292292

293293
func (h *md5Hash) UnmarshalBinary(b []byte) error {
294-
if len(b) < len(sha5Magic) || string(b[:len(sha5Magic)]) != sha5Magic {
295-
return errors.New("crypto/sha1: invalid hash state identifier")
294+
if len(b) < len(md5Magic) || string(b[:len(md5Magic)]) != md5Magic {
295+
return errors.New("crypto/md5: invalid hash state identifier")
296296
}
297-
if len(b) != sha5MarshaledSize {
298-
return errors.New("crypto/sha1: invalid hash state size")
297+
if len(b) != md5MarshaledSize {
298+
return errors.New("crypto/md5: invalid hash state size")
299299
}
300300
d := (*md5State)(h.shaState())
301301
if d == nil {
302-
return errors.New("crypto/sha1: can't retrieve hash state")
302+
return errors.New("crypto/md5: can't retrieve hash state")
303303
}
304-
b = b[len(sha5Magic):]
304+
b = b[len(md5Magic):]
305305
b, d.h[0] = consumeUint32(b)
306306
b, d.h[1] = consumeUint32(b)
307307
b, d.h[2] = consumeUint32(b)

0 commit comments

Comments
 (0)