From patchwork Tue Nov 5 19:05:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13863465 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00A451EB9FD for ; Tue, 5 Nov 2024 19:05:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730833518; cv=none; b=DiKJrP1FnHtQf2Sr2OqBPWBRbs6SeOCeuS1Fis0gIW70CTCDQpJjR3BveDNswl+pmNjIaDVrEV/rEgZhAlONHDLyAmgeTn7ik8qNylAsisU6DXz5JVfDY1/pFVizmPmr+KhktYGy4JgUmlXBVCJEwnJ+EXHPbpLK0UE4wJ/bXQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730833518; c=relaxed/simple; bh=iNZwqRx1Kklgl+nfFccwKyI+ATqwiARtSL4h65Dd3XQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IMVLFQYk1VT1y7GrN+C8tECJvoVTJcInUoLg3mAG6LrK33eIvk98z6FMzpoQwafqG0CtlWZ5I9k+2w/C2EY00dXvre1wgAEUQSwwOaL+nUesWLVB0mznVrn4gUiTcfYXEoU7X2AhjHCoD4Y+IDUkQ2M8mBIYw/iJ73D3LCcv9I0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=pass smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=HBcylbRI; arc=none smtp.client-ip=209.85.219.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="HBcylbRI" Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e2bdbdee559so5291701276.1 for ; Tue, 05 Nov 2024 11:05:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1730833515; x=1731438315; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZjNdy5CJOmhCR5goHp/Odeue4EBoAiOklBHXmOidAmI=; b=HBcylbRIktBcqffPu9EYBkMeTbPgQDYm+pTtKD9OkDRPvvqlz7f5T4sdwxlP8suA5O 1U/fMej4+fvloQqn+GLysZ9x7L5f0d6MZTHeNya1Qj1eUyMrbFpKO9nnS8UzE89Si31a koApe+j9IKaOTGeyEdDczvxFTS3lSNHYQoJlZ5Rxh/0S3wYCP7OqDf9igOjMoy9b4eHs 0wsUucue+VWCSUM0IP1jQ159gR/Z695DMnuaCZu3ZDb9M4yAorJs4TXU2Oe4C4oLnvjp /ijL7v7guhd4l8Q/ho4jRu5uyeO7wBu+uo5U9h0rhGdOhFP3McAB7vbO0pyA3ZquiyCD A5Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730833515; x=1731438315; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZjNdy5CJOmhCR5goHp/Odeue4EBoAiOklBHXmOidAmI=; b=pFO/s+T94RzO9A5cwD2Qv21VZ67TOboQMt4SShtq04MeTbISn+PmRK4O47QXIMDI0o vSA/Q7KQh+a3CSeuQoz6TVOUhDI3P9yQ1ZGCVXQahW2slCbrmmeiWN5RoBGnSWjDXkdL 5iwuBMxNZQsS3DmqsZhfgD7QYTA+YCX3oI7tL7AeiZ5Du6B1xhEoIKJl4tkNziZPXPbc PTotKzWt+4DZ+tqHblws2ADasSkR8Pgc70CgnqhBdyOcI6jXxk52RpwaHJsYy+E0kBDQ ULzfZb15JIKV0+wG1veVTU0eh8FlbySYjq5JPZMhvZJ33ddk2Y/U7W9gykgMCzacoTk5 wtNA== X-Gm-Message-State: AOJu0YzcQqVpMjsHewntsMbPp8CpJKStrZScsgLIiEK0NYM8T3nddxgW TuIYcpBOyujBxIsYt7jdKQ7uTwsowNB7f1dgl6At4INCzbHcWXIft2u8Uq4sdM6Yq39zmztqPx9 llcY= X-Google-Smtp-Source: AGHT+IGscYGzzMN5kLDsrDh3b+SO/ZB7tEvX6xfEpIIoIOfSx0i6WGalvG7eiskjLlQQO+7cT5F67A== X-Received: by 2002:a05:6902:33c8:b0:e30:c614:5c40 with SMTP id 3f1490d57ef6-e330254f899mr13502556276.2.1730833515616; Tue, 05 Nov 2024 11:05:15 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e30e8adf93csm2694062276.55.2024.11.05.11.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 11:05:15 -0800 (PST) Date: Tue, 5 Nov 2024 14:05:14 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Junio C Hamano , "brian m. carlson" Subject: [PATCH v2 1/2] t/helper/test-sha1: prepare for an unsafe mode Message-ID: <0e2fcee6894b7b16136ff09a69f199bea9f8c882.1730833507.git.me@ttaylorr.com> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: With the new "unsafe" SHA-1 build knob, it would be convenient to have a test-tool that can exercise Git's unsafe SHA-1 wrappers for testing, similar to 't/helper/test-tool sha1'. Prepare for such a helper by altering the implementation of that test-tool (in cmd_hash_impl(), which is generic and parameterized over different hash functions) to conditionally run the unsafe variants of the chosen hash function. The following commit will add a new test-tool which makes use of this new parameter. Signed-off-by: Taylor Blau Signed-off-by: Taylor Blau --- t/helper/test-hash.c | 17 +++++++++++++---- t/helper/test-sha1.c | 2 +- t/helper/test-sha256.c | 2 +- t/helper/test-tool.h | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index 45d829c908f..d0ee668df95 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -1,7 +1,7 @@ #include "test-tool.h" #include "hex.h" -int cmd_hash_impl(int ac, const char **av, int algo) +int cmd_hash_impl(int ac, const char **av, int algo, int unsafe) { git_hash_ctx ctx; unsigned char hash[GIT_MAX_HEXSZ]; @@ -27,7 +27,10 @@ int cmd_hash_impl(int ac, const char **av, int algo) die("OOPS"); } - algop->init_fn(&ctx); + if (unsafe) + algop->unsafe_init_fn(&ctx); + else + algop->init_fn(&ctx); while (1) { ssize_t sz, this_sz; @@ -46,9 +49,15 @@ int cmd_hash_impl(int ac, const char **av, int algo) } if (this_sz == 0) break; - algop->update_fn(&ctx, buffer, this_sz); + if (unsafe) + algop->unsafe_update_fn(&ctx, buffer, this_sz); + else + algop->update_fn(&ctx, buffer, this_sz); } - algop->final_fn(hash, &ctx); + if (unsafe) + algop->unsafe_final_fn(hash, &ctx); + else + algop->final_fn(hash, &ctx); if (binary) fwrite(hash, 1, algop->rawsz, stdout); diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c index e60d000c039..1c1272cc1f9 100644 --- a/t/helper/test-sha1.c +++ b/t/helper/test-sha1.c @@ -3,7 +3,7 @@ int cmd__sha1(int ac, const char **av) { - return cmd_hash_impl(ac, av, GIT_HASH_SHA1); + return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 0); } int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED) diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c index 2fb20438f3c..7fd0aa1fcd3 100644 --- a/t/helper/test-sha256.c +++ b/t/helper/test-sha256.c @@ -3,5 +3,5 @@ int cmd__sha256(int ac, const char **av) { - return cmd_hash_impl(ac, av, GIT_HASH_SHA256); + return cmd_hash_impl(ac, av, GIT_HASH_SHA256, 0); } diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 21802ac27da..f3524d9a0f6 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -81,6 +81,6 @@ int cmd__windows_named_pipe(int argc, const char **argv); #endif int cmd__write_cache(int argc, const char **argv); -int cmd_hash_impl(int ac, const char **av, int algo); +int cmd_hash_impl(int ac, const char **av, int algo, int unsafe); #endif From patchwork Tue Nov 5 19:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13863466 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2FD11EBA1C for ; Tue, 5 Nov 2024 19:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730833521; cv=none; b=UfGNGid//TmfFY0QfNYc1jm0VQtOiF15jy/STVA7hak1LxqhtfWpzuYG5asDZ8UiFbXpDsK0R87BBAKphJ8jHXLf6gGnls4EyBZMeMMQTv4naCU0KU8MzOKBaKr8e7UgUC1Szj2mj3CDCHOHJGLRUvhMGXcISEjAWxdjQML3Er4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730833521; c=relaxed/simple; bh=ppgLqom6fZaa20yMBHFdqK/uul4hFEHx2X1Gpbev8qU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OUZwfL0Ed1O2ORHUz7DMeaZ8txKnFnroeXyVMcflPRR3EKzlavvn8VcdsqSgHMSc+axZbIvSgNIvGIbk9dyvCGPmN02aPv7ViplZUTedLdHRziGVPw9GPTIyGZ2W0hSvM0v8kH16btUlbZueL7PjpUWi0CBZeiayqQqhnOgjPcg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=pass smtp.mailfrom=ttaylorr.com; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b=fth3GpYy; arc=none smtp.client-ip=209.85.219.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20230601.gappssmtp.com header.i=@ttaylorr-com.20230601.gappssmtp.com header.b="fth3GpYy" Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e2e340218daso5924365276.0 for ; Tue, 05 Nov 2024 11:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1730833519; x=1731438319; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=dAEMfY3OeGKacvFEOXWBrplyPJlIVq2Sxd4oW8g6KIQ=; b=fth3GpYyTfgdVJjSCp1ENLZX2T093sTL9BUFTSf+WGXKAx8Fxxt/3UkpQLFGvaD+c3 31KGUEm+/Ta8lpDdKwgs8F3kQhWFWc9qG85UOJVxLxcpOJIpLGSmY29tpP5aMT1RH1hS U7tOEHxLBlA+u9dKpUaz7jgGgeVa1sNN/8o9oLaxJbvszVg1wbaNJQ0KymY1CtCUIe2u u9I+Paad2zsYYJk4q2EEltkdCxn/nTv3iTihLgseM1rJ0o+qzT6ZMHsNFRdwQlVv0Ymo AclnpBZDx3NQUi0Ghkn9g6sjuexYBJueY/aqWTBqAxFmSvsQ6haRySsqB4UwymbCUA9h EqGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730833519; x=1731438319; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dAEMfY3OeGKacvFEOXWBrplyPJlIVq2Sxd4oW8g6KIQ=; b=U7Rj0gyXjgOwTYD+IxCzELHWuQ/3lC/tKVyyiu4sJkRUw8tcJpLhSXCxXjICk3oP1R fbswqb1YUZnFzA2+t6Q+9mJgy/DR/sGYS2AKKRQf8iz1dTF8J88LJDAUfB21PIlj0433 rxi0AiJ3REdWCGFI+kz+a5rKD1UUH9/u4z8wqSneZK5iq7vobQxvgnXn8vWDRcenYmce kct+aNyD1rZKfVtYYKpgCSCTSbDfX90/+hV0UN9Df5awwLzPhpXx16q1e7nD6JMFvmGl R0jWhWsphPEwy9dvqvYdlZFQchKmcWftFUORVogWwF/EMpDWDN3CREMsTlRj8u8EISgx 0wmQ== X-Gm-Message-State: AOJu0YwDEh4ZmIH0MIrUWhjUV8hzeMa9efcn6x5vhfUr+Vu97JmUzJZ/ va73Wde2FJTAGpMWcdpVklkIY6pA4lAp840A+42CngGMHcSMJx3IBWHdUpCfz6hnt2qh+cb+vIJ KxnI= X-Google-Smtp-Source: AGHT+IEK1Dfquqi50cuDR21ZZ2i3v+++GmG5lBWnrD9dM7PY5W9SDkQE2lngDs1xJaLzc6qQfOJkSQ== X-Received: by 2002:a05:6902:154b:b0:e30:d89f:1342 with SMTP id 3f1490d57ef6-e30e5affc43mr18701281276.24.1730833518618; Tue, 05 Nov 2024 11:05:18 -0800 (PST) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e30e8a61797sm2701189276.12.2024.11.05.11.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 11:05:18 -0800 (PST) Date: Tue, 5 Nov 2024 14:05:17 -0500 From: Taylor Blau To: git@vger.kernel.org Cc: Elijah Newren , Jeff King , Junio C Hamano , "brian m. carlson" Subject: [PATCH v2 2/2] t/helper/test-tool: implement sha1-unsafe helper Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add a new helper similar to 't/helper/test-tool sha1' called instead "sha1-unsafe" which uses the unsafe variant of Git's SHA-1 wrappers. While we're at it, modify the test-sha1.sh script to exercise both the sha1 and sha1-unsafe test tools to ensure that both produce the expected hash values. Signed-off-by: Taylor Blau --- t/helper/test-sha1.c | 5 +++++ t/helper/test-sha1.sh | 38 ++++++++++++++++++++++---------------- t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c index 1c1272cc1f9..349540c4df8 100644 --- a/t/helper/test-sha1.c +++ b/t/helper/test-sha1.c @@ -13,3 +13,8 @@ int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED) #endif return 1; } + +int cmd__sha1_unsafe(int ac, const char **av) +{ + return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 1); +} diff --git a/t/helper/test-sha1.sh b/t/helper/test-sha1.sh index 84594885c70..bf387d3db14 100755 --- a/t/helper/test-sha1.sh +++ b/t/helper/test-sha1.sh @@ -3,25 +3,31 @@ dd if=/dev/zero bs=1048576 count=100 2>/dev/null | /usr/bin/time t/helper/test-tool sha1 >/dev/null +dd if=/dev/zero bs=1048576 count=100 2>/dev/null | +/usr/bin/time t/helper/test-tool sha1-unsafe >/dev/null + while read expect cnt pfx do case "$expect" in '#'*) continue ;; esac - actual=$( - { - test -z "$pfx" || echo "$pfx" - dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null | - perl -pe 'y/\000/g/' - } | ./t/helper/test-tool sha1 $cnt - ) - if test "$expect" = "$actual" - then - echo "OK: $expect $cnt $pfx" - else - echo >&2 "OOPS: $cnt" - echo >&2 "expect: $expect" - echo >&2 "actual: $actual" - exit 1 - fi + for sha1 in sha1 sha1-unsafe + do + actual=$( + { + test -z "$pfx" || echo "$pfx" + dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null | + perl -pe 'y/\000/g/' + } | ./t/helper/test-tool $sha1 $cnt + ) + if test "$expect" = "$actual" + then + echo "OK ($sha1): $expect $cnt $pfx" + else + echo >&2 "OOPS ($sha1): $cnt" + echo >&2 "expect ($sha1): $expect" + echo >&2 "actual ($sha1): $actual" + exit 1 + fi + done done <