From 32199a418b5e5507259fa4b6715da8a9c185f90a Mon Sep 17 00:00:00 2001 From: sevki Date: Fri, 16 Nov 2018 00:37:12 +0000 Subject: [PATCH] crypto/hmac: change checkhmac to validhmac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Procedure names should reflect what they do; function names should reflect what they return. Functions are used in expressions, often in things like if's, so they need to read appropriately. if CheckHMAC(a,b, key) is unhelpful because we can't deduce whether CheckHMAC returns true on error or nonĀ­error;instead if ValidHMAC(x) https://www.lysator.liu.se/c/pikestyle.html makes the point clear and makes a future mistake in using the routine less likely. --- src/crypto/hmac/hmac.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/hmac/hmac.go b/src/crypto/hmac/hmac.go index c8c0617c47f788..801ece67ae415e 100644 --- a/src/crypto/hmac/hmac.go +++ b/src/crypto/hmac/hmac.go @@ -11,8 +11,8 @@ The receiver verifies the hash by recomputing it using the same key. Receivers should be careful to use Equal to compare MACs in order to avoid timing side-channels: - // CheckMAC reports whether messageMAC is a valid HMAC tag for message. - func CheckMAC(message, messageMAC, key []byte) bool { + // ValidMAC reports whether messageMAC is a valid HMAC tag for message. + func ValidMAC(message, messageMAC, key []byte) bool { mac := hmac.New(sha256.New, key) mac.Write(message) expectedMAC := mac.Sum(nil)