[v2] builtin/receive-pack: avoid generic function name hmac()
diff mbox series

Message ID 20200505095326.36374-1-carenas@gmail.com
State New
Headers show
Series
  • [v2] builtin/receive-pack: avoid generic function name hmac()
Related show

Commit Message

Carlo Marcelo Arenas Belón May 5, 2020, 9:53 a.m. UTC
fabec2c5c3 (builtin/receive-pack: switch to use the_hash_algo, 2019-08-18)
renames hmac_sha1 to hmac, as it was updated to use the hash function used
by git (which won't be sha1 in the future).

hmac() is provided by NetBSD >= 8 libc and therefore conflicts as shown by :

builtin/receive-pack.c:421:13: error: conflicting types for 'hmac'
 static void hmac(unsigned char *out,
             ^~~~
In file included from ./git-compat-util.h:172:0,
                 from ./builtin.h:4,
                 from builtin/receive-pack.c:1:
/usr/include/stdlib.h:305:10: note: previous declaration of 'hmac' was here
 ssize_t  hmac(const char *, const void *, size_t, const void *, size_t, void *,
          ^~~~

Rename it again to hmac_hash to reflect it will use the git's defined hash
function and avoid the conflict, while at it update a comment to better
describe the HMAC function that was used.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
v2
* cleaner commit message that even has an SOB

 builtin/receive-pack.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: af6b65d45ef179ed52087e80cb089f6b2349f4ec

Comments

brian m. carlson May 5, 2020, 11:48 a.m. UTC | #1
On 2020-05-05 at 09:53:26, Carlo Marcelo Arenas Belón wrote:
> fabec2c5c3 (builtin/receive-pack: switch to use the_hash_algo, 2019-08-18)
> renames hmac_sha1 to hmac, as it was updated to use the hash function used
> by git (which won't be sha1 in the future).
> 
> hmac() is provided by NetBSD >= 8 libc and therefore conflicts as shown by :
> 
> builtin/receive-pack.c:421:13: error: conflicting types for 'hmac'
>  static void hmac(unsigned char *out,
>              ^~~~
> In file included from ./git-compat-util.h:172:0,
>                  from ./builtin.h:4,
>                  from builtin/receive-pack.c:1:
> /usr/include/stdlib.h:305:10: note: previous declaration of 'hmac' was here
>  ssize_t  hmac(const char *, const void *, size_t, const void *, size_t, void *,
>           ^~~~
> 
> Rename it again to hmac_hash to reflect it will use the git's defined hash
> function and avoid the conflict, while at it update a comment to better
> describe the HMAC function that was used.
> 
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>

Looks good.  Thanks again for the patch.

Patch
diff mbox series

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 2cc18bbffd..39b0c3d70b 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -418,7 +418,7 @@  static int copy_to_sideband(int in, int out, void *arg)
 	return 0;
 }
 
-static void hmac(unsigned char *out,
+static void hmac_hash(unsigned char *out,
 		      const char *key_in, size_t key_len,
 		      const char *text, size_t text_len)
 {
@@ -463,10 +463,10 @@  static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
 	unsigned char hash[GIT_MAX_RAWSZ];
 
 	strbuf_addf(&buf, "%s:%"PRItime, path, stamp);
-	hmac(hash, buf.buf, buf.len, cert_nonce_seed, strlen(cert_nonce_seed));
+	hmac_hash(hash, buf.buf, buf.len, cert_nonce_seed, strlen(cert_nonce_seed));
 	strbuf_release(&buf);
 
-	/* RFC 2104 5. HMAC-SHA1-80 */
+	/* RFC 2104 5. HMAC-SHA1 or HMAC-SHA256 */
 	strbuf_addf(&buf, "%"PRItime"-%.*s", stamp, (int)the_hash_algo->hexsz, hash_to_hex(hash));
 	return strbuf_detach(&buf, NULL);
 }