From patchwork Thu Sep 5 15:12:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13792575 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (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 7BE7AF507 for ; Thu, 5 Sep 2024 15:12:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549134; cv=none; b=cz66NR5SNlTmM8D3wXnQvkMixU4E9d+FTNCRlOpN8fV1LYcWZAHMMDiR4CJmW5B8nF62T2JguyHZi1JW5BSiJH/tuCMhbkOJUKEKVhy8DZ5gN/33fB9Xh0i+aID0hfvEi2m6n8wBvktuile4gc4aJRB9BOECwuJ/AHGfTlkT/yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549134; c=relaxed/simple; bh=OPd54Shw5KgWOzQQ17KuWTJpavIibVeHYPzfHSEuXAY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hL1Y2R4RVQgAUeaJDsGr3U2CQQXS6tuHg6iOOvQIgqSPDlAOX8Sgkfx10ASRVMPhEmM2OY/aTNaOCEeb2k395IHI7q3SAk7c9ysKX5dmuCTjy0uDowExf5ZtB15MUpjlNiNy+5Nv/aKLejGpPPZ4atjRVKD20TvuaUhhPcCWOpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none 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=rh2AqkHF; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none 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="rh2AqkHF" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6bada443ffeso7239587b3.0 for ; Thu, 05 Sep 2024 08:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1725549131; x=1726153931; 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=b6voiSCHT2M9BzZNk+KaZ2KNwGbL9u6Ib6pBhPxkuIc=; b=rh2AqkHFFIhUh1tU9LFea7d6qm3GET+JGjEKlqGlThgHwooddmCu5Rn7PhhFrRfikn 9bxu5eHIHzlpPBmJl9MxDLRj6l94hau9TgWYBZMfKSnOXEQ5sQc5U8JLMwM0WFGQjwQz cIJzoopTFCD6c7Rn1W59gwyqO5qcvOTMLB2GKt/fKwuOFAQeZ6Tr7ykDYhReNuDuTi/G 7kpCeJ8an69D94oOhFIh9dGzPhIh6C2jLjGsxanm4AZdEL7/ZEYr9qM5D5Dmalch1Osu 5hn6XY889eODdYvlKgSrQGBqZuDGAag62IVeibfZHBW6/qHh9Pv1x9feJEYs6hI9waXZ HvqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725549131; x=1726153931; 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=b6voiSCHT2M9BzZNk+KaZ2KNwGbL9u6Ib6pBhPxkuIc=; b=BcS73PMW4akBBd6u1N1la+8kKEmoiNXTkNVZz9CaJvQYyXav3T02HdXfWgRraR0OQP Oq/unGjb648re++nqXYxrn5CRvKlWoVIq85AHfte/RREzHJ1BYV8479fctpu3HBqaPzs ngyJoS4s+wAgd6gC42JaOg6nkHW4etcdzEJZYtRP24dfyJKjDutsz92dAuvnekad8qKC +BS+0+kzGqCX9MNiKc/kCwII9Aw1IpjeDXe7sc8PoezikO/dlKsM7j1+o82LboJ6Vlq4 S7oQNPvFtM3E/LGDDMDvg59Mnt7YYn/As7ISOIydBl/Tt4ILJp9C4TE9bU/Z8dwcFPdw fYeA== X-Gm-Message-State: AOJu0YyFwC4fFfn+H8zqBk7U6AXe/JFLhazpoxivw9JnxOf6HIpMRqQh 4wGR5IQ8298w8FXtTQ4YKJbm9IvUCOsCyY4GKBpJs4ts3z/aB+ou0nz1TzyJ66kkvCGCwwznzTx 8yxs= X-Google-Smtp-Source: AGHT+IEWTQg2g8OreXOqp8t06qpttWherRITN5zETfXAA8mr9qOHmiS5sgr7YaGoO1p/uKuSJRS2Pw== X-Received: by 2002:a05:690c:458a:b0:6d5:7617:950e with SMTP id 00721157ae682-6db25fce581mr41076147b3.18.1725549131052; Thu, 05 Sep 2024 08:12:11 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6d6f637ca5csm17908807b3.55.2024.09.05.08.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 08:12:10 -0700 (PDT) Date: Thu, 5 Sep 2024 11:12:09 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , "brian m. carlson" , Elijah Newren , Patrick Steinhardt , Junio C Hamano Subject: [PATCH v2 1/4] sha1: do not redefine `platform_SHA_CTX` and friends 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: Our in-tree SHA-1 wrappers all define platform_SHA_CTX and related macros to point at the opaque "context" type, init, update, and similar functions for each specific implementation. In hash.h, we use these platform_ variables to set up the function pointers for, e.g., the_hash_algo->init_fn(), etc. But while these header files have a header-specific macro that prevents them declaring their structs / functions multiple times, they unconditionally define the platform variables, making it impossible to load multiple SHA-1 implementations at once. As a prerequisite for loading a separate SHA-1 implementation for non-cryptographic uses, only define the platform_ variables if they have not already been defined. Signed-off-by: Taylor Blau --- block-sha1/sha1.h | 2 ++ sha1/openssl.h | 2 ++ sha1dc_git.h | 3 +++ 3 files changed, 7 insertions(+) diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h index 9fb0441b988..47bb9166368 100644 --- a/block-sha1/sha1.h +++ b/block-sha1/sha1.h @@ -16,7 +16,9 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx); void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, size_t len); void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); +#ifndef platform_SHA_CTX #define platform_SHA_CTX blk_SHA_CTX #define platform_SHA1_Init blk_SHA1_Init #define platform_SHA1_Update blk_SHA1_Update #define platform_SHA1_Final blk_SHA1_Final +#endif diff --git a/sha1/openssl.h b/sha1/openssl.h index 006c1f4ba54..1038af47daf 100644 --- a/sha1/openssl.h +++ b/sha1/openssl.h @@ -40,10 +40,12 @@ static inline void openssl_SHA1_Clone(struct openssl_SHA1_CTX *dst, EVP_MD_CTX_copy_ex(dst->ectx, src->ectx); } +#ifndef platform_SHA_CTX #define platform_SHA_CTX openssl_SHA1_CTX #define platform_SHA1_Init openssl_SHA1_Init #define platform_SHA1_Clone openssl_SHA1_Clone #define platform_SHA1_Update openssl_SHA1_Update #define platform_SHA1_Final openssl_SHA1_Final +#endif #endif /* SHA1_OPENSSL_H */ diff --git a/sha1dc_git.h b/sha1dc_git.h index 60e3ce84395..f6f880cabea 100644 --- a/sha1dc_git.h +++ b/sha1dc_git.h @@ -18,7 +18,10 @@ void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *); void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len); #define platform_SHA_IS_SHA1DC /* used by "test-tool sha1-is-sha1dc" */ + +#ifndef platform_SHA_CTX #define platform_SHA_CTX SHA1_CTX #define platform_SHA1_Init git_SHA1DCInit #define platform_SHA1_Update git_SHA1DCUpdate #define platform_SHA1_Final git_SHA1DCFinal +#endif From patchwork Thu Sep 5 15:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13792576 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 88903F507 for ; Thu, 5 Sep 2024 15:12:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549137; cv=none; b=AmRDVv7812FJjmYKO2xRW4254US+PXY6zd2OByRVLmhaEBpXtHV4ypzD2kvpR4oOx01vGWGbgurli6KZQg3kdXv++8yyIJb/hyhpSDrXZymNVklZbYTDwVR9o7ddtF8DmuThfWDknBkngCW1oscRon8EsrVGXQNQNa3Y9mbnTA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549137; c=relaxed/simple; bh=Q6nzMN5LrLvPA9g8I5i12FxfpkL8Dx0PFLaqc+yN/mU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NJKWWsx+bZtJuDH3P6AFV/lxOzKsTZCM5IEX+MnQKoIOKGbSEATUB3APq5IKtor7WdbAzE2BXaepHAU5xVs/dsrMnbc/Y4+fj80Gjt44hnQTVU19KN8y9mHhk1HE91n8AHmOypJOF0frz3UjeB9SwM5Nbm7nHd3jp23qeKF5vp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none 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=UwnAxzCh; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none 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="UwnAxzCh" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-6d3f4218081so9416097b3.1 for ; Thu, 05 Sep 2024 08:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1725549134; x=1726153934; 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=YGLpK2lL9DeOAPxAqXCUA/Mgj4cQ1apZWdMXIW9lqJI=; b=UwnAxzChV256UlBH1dtFEq8JOpronQGlcsp4wiZPQ0y+WhTsLaAE66/dZuZV59AWo5 84NSJ6aU60L0oUFLChrcXa5wDRmMuUldhWUCDRqcmMHvwFuuUGsXIn7bCVG/3rX4EtRk p+pb7sgxxjifvXleKADgfQ7Mf8SGEdkLghATDawJQ+ACcjJ7gNRRvuzMOqhMuaFX0JiU vuRfR2/61jzkNbzgUgCQqCJYzr/D8P9EtwocKMFVXmpELIKuvhbZJraWdUbRNogehHGH FAE91muwvfJlCNUUrwoCX9bLx550WQYTCBUusttKeGb3r7nYz0HQn+Mx4O/an7zAOVM+ KalQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725549134; x=1726153934; 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=YGLpK2lL9DeOAPxAqXCUA/Mgj4cQ1apZWdMXIW9lqJI=; b=rjbmam8ewtoSr69ST2jHPYEGhhpeydmFoROSb8Is9Srm2FmwTrLxl12pXm2J4RVRWN DhX6TR00JqbrjM3eq8EzyOTSvY+BSKoufHCOo0+oYsmZwJIBhe52dfJO6coiqODcRRfw i6ocUoPPVpqIHpCeO8it8f1vUlKb1Vq0YmlZtldaphv7PwZw4XyYOGpqkinWyC8vBTSt Wzg/OpPVgpusTlKvqA8BacvUPnbIw+jndQyKXTmegkWycRyABFE2IxqFyQll4DK6OJXb b/bea4wcHJc8BVUqArMxZbCE06f6wUozeHQhl8CafyA3pNMCogaa2FuYBFaidxce7Pa1 HX8g== X-Gm-Message-State: AOJu0Yy48GsLcXqORzLCZEVRjuPh8VLCFBia30c4bVJWV/uM3SYS8mGa ZtfkfgiGZUHU9M9M0USNFmCCVCCI8mLtgKAB86sMiuYue0kVa5gHKFqAZ4X7QaKInPt0CDzJ0RE pMw0= X-Google-Smtp-Source: AGHT+IFra3/rK7RWmGTrnsU94LvirclMPUOuCqwcBQO0ee+wqr7BS+cs3GV/FpkfFuPf5dH6xSj26A== X-Received: by 2002:a05:690c:f90:b0:6d6:27af:ef73 with SMTP id 00721157ae682-6db23a39ae7mr85407567b3.37.1725549134062; Thu, 05 Sep 2024 08:12:14 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6d78d1e6901sm16700867b3.7.2024.09.05.08.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 08:12:13 -0700 (PDT) Date: Thu, 5 Sep 2024 11:12:12 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , "brian m. carlson" , Elijah Newren , Patrick Steinhardt , Junio C Hamano Subject: [PATCH v2 2/4] hash.h: scaffolding for _fast hashing variants Message-ID: <3b5f21e4a620b0afd706ec3a3fbb71918f96198f.1725549065.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: Git's default SHA-1 implementation is collision-detecting, which hardens us against known SHA-1 attacks against Git objects. This makes Git object writes safer at the expense of some speed when hashing through the collision-detecting implementation, which is slower than non-collision detecting alternatives. Prepare for loading a separate "fast" SHA-1 implementation that can be used for non-cryptographic purposes, like computing the checksum of files that use the hashwrite() API. This commit does not actually introduce any new compile-time knobs to control which implementation is used as the fast SHA-1 variant, but does add scaffolding so that the "git_hash_algo" structure has five new function pointers which are "fast" variants of the five existing hashing-related function pointers: - git_hash_init_fn fast_init_fn - git_hash_clone_fn fast_clone_fn - git_hash_update_fn fast_update_fn - git_hash_final_fn fast_final_fn - git_hash_final_oid_fn fast_final_oid_fn The following commit will introduce compile-time knobs to specify which SHA-1 implementation is used for non-cryptographic uses. Signed-off-by: Taylor Blau --- hash.h | 42 ++++++++++++++++++++++++++++++++++++++++++ object-file.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/hash.h b/hash.h index 72ffbc862e5..5e5b8205b58 100644 --- a/hash.h +++ b/hash.h @@ -44,14 +44,32 @@ #define platform_SHA1_Final SHA1_Final #endif +#ifndef platform_SHA_CTX_fast +# define platform_SHA_CTX_fast platform_SHA_CTX +# define platform_SHA1_Init_fast platform_SHA1_Init +# define platform_SHA1_Update_fast platform_SHA1_Update +# define platform_SHA1_Final_fast platform_SHA1_Final +# ifdef platform_SHA1_Clone +# define platform_SHA1_Clone_fast platform_SHA1_Clone +# endif +#endif + #define git_SHA_CTX platform_SHA_CTX #define git_SHA1_Init platform_SHA1_Init #define git_SHA1_Update platform_SHA1_Update #define git_SHA1_Final platform_SHA1_Final +#define git_SHA_CTX_fast platform_SHA_CTX_fast +#define git_SHA1_Init_fast platform_SHA1_Init_fast +#define git_SHA1_Update_fast platform_SHA1_Update_fast +#define git_SHA1_Final_fast platform_SHA1_Final_fast + #ifdef platform_SHA1_Clone #define git_SHA1_Clone platform_SHA1_Clone #endif +#ifdef platform_SHA1_Clone_fast +# define git_SHA1_Clone_fast platform_SHA1_Clone_fast +#endif #ifndef platform_SHA256_CTX #define platform_SHA256_CTX SHA256_CTX @@ -81,6 +99,13 @@ static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src) memcpy(dst, src, sizeof(*dst)); } #endif +#ifndef SHA1_NEEDS_CLONE_HELPER_FAST +static inline void git_SHA1_Clone_fast(git_SHA_CTX_fast *dst, + const git_SHA_CTX_fast *src) +{ + memcpy(dst, src, sizeof(*dst)); +} +#endif #ifndef SHA256_NEEDS_CLONE_HELPER static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src) @@ -178,6 +203,8 @@ enum get_oid_result { /* A suitably aligned type for stack allocations of hash contexts. */ union git_hash_ctx { git_SHA_CTX sha1; + git_SHA_CTX_fast sha1_fast; + git_SHA256_CTX sha256; }; typedef union git_hash_ctx git_hash_ctx; @@ -222,6 +249,21 @@ struct git_hash_algo { /* The hash finalization function for object IDs. */ git_hash_final_oid_fn final_oid_fn; + /* The fast / non-cryptographic hash initialization function. */ + git_hash_init_fn fast_init_fn; + + /* The fast / non-cryptographic hash context cloning function. */ + git_hash_clone_fn fast_clone_fn; + + /* The fast / non-cryptographic hash update function. */ + git_hash_update_fn fast_update_fn; + + /* The fast / non-cryptographic hash finalization function. */ + git_hash_final_fn fast_final_fn; + + /* The fast / non-cryptographic hash finalization function. */ + git_hash_final_oid_fn fast_final_oid_fn; + /* The OID of the empty tree. */ const struct object_id *empty_tree; diff --git a/object-file.c b/object-file.c index c5994202ba0..9691292ef5a 100644 --- a/object-file.c +++ b/object-file.c @@ -115,6 +115,33 @@ static void git_hash_sha1_final_oid(struct object_id *oid, git_hash_ctx *ctx) oid->algo = GIT_HASH_SHA1; } +static void git_hash_sha1_init_fast(git_hash_ctx *ctx) +{ + git_SHA1_Init_fast(&ctx->sha1_fast); +} + +static void git_hash_sha1_clone_fast(git_hash_ctx *dst, const git_hash_ctx *src) +{ + git_SHA1_Clone_fast(&dst->sha1_fast, &src->sha1_fast); +} + +static void git_hash_sha1_update_fast(git_hash_ctx *ctx, const void *data, + size_t len) +{ + git_SHA1_Update_fast(&ctx->sha1_fast, data, len); +} + +static void git_hash_sha1_final_fast(unsigned char *hash, git_hash_ctx *ctx) +{ + git_SHA1_Final_fast(hash, &ctx->sha1_fast); +} + +static void git_hash_sha1_final_oid_fast(struct object_id *oid, git_hash_ctx *ctx) +{ + git_SHA1_Final_fast(oid->hash, &ctx->sha1_fast); + memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); + oid->algo = GIT_HASH_SHA1; +} static void git_hash_sha256_init(git_hash_ctx *ctx) { @@ -189,6 +216,11 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = { .update_fn = git_hash_unknown_update, .final_fn = git_hash_unknown_final, .final_oid_fn = git_hash_unknown_final_oid, + .fast_init_fn = git_hash_unknown_init, + .fast_clone_fn = git_hash_unknown_clone, + .fast_update_fn = git_hash_unknown_update, + .fast_final_fn = git_hash_unknown_final, + .fast_final_oid_fn = git_hash_unknown_final_oid, .empty_tree = NULL, .empty_blob = NULL, .null_oid = NULL, @@ -204,6 +236,11 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = { .update_fn = git_hash_sha1_update, .final_fn = git_hash_sha1_final, .final_oid_fn = git_hash_sha1_final_oid, + .fast_init_fn = git_hash_sha1_init_fast, + .fast_clone_fn = git_hash_sha1_clone_fast, + .fast_update_fn = git_hash_sha1_update_fast, + .fast_final_fn = git_hash_sha1_final_fast, + .fast_final_oid_fn = git_hash_sha1_final_oid_fast, .empty_tree = &empty_tree_oid, .empty_blob = &empty_blob_oid, .null_oid = &null_oid_sha1, @@ -219,6 +256,11 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = { .update_fn = git_hash_sha256_update, .final_fn = git_hash_sha256_final, .final_oid_fn = git_hash_sha256_final_oid, + .fast_init_fn = git_hash_sha256_init, + .fast_clone_fn = git_hash_sha256_clone, + .fast_update_fn = git_hash_sha256_update, + .fast_final_fn = git_hash_sha256_final, + .fast_final_oid_fn = git_hash_sha256_final_oid, .empty_tree = &empty_tree_oid_sha256, .empty_blob = &empty_blob_oid_sha256, .null_oid = &null_oid_sha256, From patchwork Thu Sep 5 15:12:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13792577 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 A59B019FA72 for ; Thu, 5 Sep 2024 15:12:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549140; cv=none; b=hRRXZ/mImkMlN9rRnlMlFx4UPTgt7majHU3uft3kZHFBgO9oRmrjflplMWy34jCeTjJuHOGshYdyE4H9I9Ql/0w9AZ7vyJ/njZMgZge2W4uo2rzjvqhwe7gGQGPSeHjNbTtFroRMGu4SoaMA/S0EzqI4voADLIQKrc7bBy+icxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549140; c=relaxed/simple; bh=/r+sR5pvO4mhhQr1616Pgev0fd99VxVkgoljb+Gv/zo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=djt7ru86Y49lkq1cbGkY63YqvNMClKo9lMx8ToFEH2uEcJyiibK8/VHwfTZV1xoxwwfkOTClvPU9f/gHOg49rQXKttlQYppzUeoOqE3JawEKrszddJjABvpfHfUCXDz7d2u6Ch8rRKNky3vpsy57AlZPsIBYsCk8aj/30YzRpRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none 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=mW9BLsgB; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none 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="mW9BLsgB" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e17c1881a52so1563503276.0 for ; Thu, 05 Sep 2024 08:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1725549137; x=1726153937; 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=Yt6Qkv+2crSADqLclNY+cpxXEIf233JOFhbBsMDk64I=; b=mW9BLsgBKm1Vk/QkBSM/J6JweI7vfZb2Kf6zZc8lVH5+YvjAOxTkKV+IQRRvLiEZAw FfV62WqDyGMm1Q7ZRoEFSNZnhqcdKhFIs4xbB9vlIbTsUTGNZb4ruj/S0JAxJzQtfeM8 JwWjOMeZ1fyhi2Na8Nm2VIgwoF7zmCKe4RptW+pCrmczCzh+w+xJp6yidi0YOUGHbTO7 Ry4aee3kL+JRa4CizQsEmqr0OZgORosSBxCf5QvWYQZMg7FV3lnbDnONaFHy72CwjceA /Oe+AnY/+UlTewyeLEva8oSpvB/jw3LL9c1mbK/OSz/1gnv4OUue6IL5QEtp8TII1qFd jUdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725549137; x=1726153937; 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=Yt6Qkv+2crSADqLclNY+cpxXEIf233JOFhbBsMDk64I=; b=RqQYD614vOwP85bRkWRErzEzkzlHiYafmi/TmlOeFKKBKtbLUxyIhpxhZ0z+PEgmm8 VQBY6TtThbl75S9JGA6AnWyhR+uAdWdmx5tKSy1hKEPNyvXlECLKtdwF0j6ZaswsoA1M wZEBM9EM5iUejAkPoGDC2R+X+ceYQZfrGqBNl90RzgHhEN8aJCi8zypH5qKqM5et2own TfHndzVc+nNxG3EUiyM5pOuKmEWsafHuToS9AsaLFfaVo1JWtF9EcFFvPRBw3FIS5cyA o+3WC+1STN47/PEHuku0bWhpW03J/Jlk0bIy1SRmyFEULzULxsSrHRl44wAXMMr77nZX WNxw== X-Gm-Message-State: AOJu0YwZORSX06cmzAixCD3Dyy1ziAH6hoJyrB1UG6q/5X3GDXAg+u1I 1avBy+ejk491C9Qw408qGEUoWXrqjY5uUceF/A9H5DRgjNHQaSCYb/dIQgtVQvfP4ZphMIbxFEz 73bI= X-Google-Smtp-Source: AGHT+IHcqOC+KPA1zlN5QjNBMVGRmH+cq1bv2kkuPVH1tS2M09SSuN20W+88KBp0Nfts/nOtq3kz9Q== X-Received: by 2002:a05:690c:9e:b0:6ac:3043:168a with SMTP id 00721157ae682-6db25f90cccmr60278867b3.10.1725549137247; Thu, 05 Sep 2024 08:12:17 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6d2d3e990e9sm29837097b3.34.2024.09.05.08.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 08:12:16 -0700 (PDT) Date: Thu, 5 Sep 2024 11:12:15 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , "brian m. carlson" , Elijah Newren , Patrick Steinhardt , Junio C Hamano Subject: [PATCH v2 3/4] Makefile: allow specifying a SHA-1 for non-cryptographic uses Message-ID: <02764de1395119490b4705d27e3f9153d9403dc1.1725549065.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: Introduce _FAST variants of the OPENSSL_SHA1, BLK_SHA1, and APPLE_COMMON_CRYPTO_SHA1 compile-time knobs which indicate which SHA-1 implementation is to be used for non-cryptographic uses. There are a couple of small implementation notes worth mentioning: - There is no way to select the collision detecting SHA-1 as the "fast" fallback, since the fast fallback is only for non-cryptographic uses, and is meant to be faster than our collision-detecting implementation. - There are no similar knobs for SHA-256, since no collision attacks are presently known and thus no collision-detecting implementations actually exist. Signed-off-by: Taylor Blau --- Makefile | 25 +++++++++++++++++++++++++ hash.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Makefile b/Makefile index e298c8b55ec..d24f9088802 100644 --- a/Makefile +++ b/Makefile @@ -517,6 +517,10 @@ include shared.mak # Define APPLE_COMMON_CRYPTO_SHA1 to use Apple's CommonCrypto for # SHA-1. # +# Define the same Makefile knobs as above, but suffixed with _FAST to +# use the corresponding implementations for "fast" SHA-1 hashing for +# non-cryptographic purposes. +# # If don't enable any of the *_SHA1 settings in this section, Git will # default to its built-in sha1collisiondetection library, which is a # collision-detecting sha1 This is slower, but may detect attempted @@ -1982,6 +1986,27 @@ endif endif endif +ifdef OPENSSL_SHA1_FAST +ifndef OPENSSL_SHA1 + EXTLIBS += $(LIB_4_CRYPTO) + BASIC_CFLAGS += -DSHA1_OPENSSL_FAST +endif +else +ifdef BLK_SHA1_FAST +ifndef BLK_SHA1 + LIB_OBJS += block-sha1/sha1.o + BASIC_CFLAGS += -DSHA1_BLK_FAST +endif +else +ifdef APPLE_COMMON_CRYPTO_SHA1_FAST +ifndef APPLE_COMMON_CRYPTO_SHA1 + COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL + BASIC_CFLAGS += -DSHA1_APPLE_FAST +endif +endif +endif +endif + ifdef OPENSSL_SHA256 EXTLIBS += $(LIB_4_CRYPTO) BASIC_CFLAGS += -DSHA256_OPENSSL diff --git a/hash.h b/hash.h index 5e5b8205b58..6ea0d968017 100644 --- a/hash.h +++ b/hash.h @@ -15,6 +15,36 @@ #include "block-sha1/sha1.h" #endif +#if defined(SHA1_APPLE_FAST) +# include +# define platform_SHA_CTX_fast CC_SHA1_CTX +# define platform_SHA1_Init_fast CC_SHA1_Init +# define platform_SHA1_Update_fast CC_SHA1_Update +# define platform_SHA1_Final_fast CC_SHA1_Final +#elif defined(SHA1_OPENSSL_FAST) +# include +# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3 +# define SHA1_NEEDS_CLONE_HELPER_FAST +# include "sha1/openssl.h" +# define platform_SHA_CTX_fast openssl_SHA1_CTX +# define platform_SHA1_Init_fast openssl_SHA1_Init +# define platform_SHA1_Clone_fast openssl_SHA1_Clone +# define platform_SHA1_Update_fast openssl_SHA1_Update +# define platform_SHA1_Final_fast openssl_SHA1_Final +# else +# define platform_SHA_CTX_fast SHA_CTX +# define platform_SHA1_Init_fast SHA1_Init +# define platform_SHA1_Update_fast SHA1_Update +# define platform_SHA1_Final_fast SHA1_Final +# endif +#elif defined(SHA1_BLK_FAST) +# include "block-sha1/sha1.h" +# define platform_SHA_CTX_fast blk_SHA_CTX +# define platform_SHA1_Init_fast blk_SHA1_Init +# define platform_SHA1_Update_fast blk_SHA1_Update +# define platform_SHA1_Final_fast blk_SHA1_Final +#endif + #if defined(SHA256_NETTLE) #include "sha256/nettle.h" #elif defined(SHA256_GCRYPT) From patchwork Thu Sep 5 15:12:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13792578 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 2399F19F410 for ; Thu, 5 Sep 2024 15:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549143; cv=none; b=Lfpltsoxh8/v2vShAMrxtqZ3BevV+0ujC2o/kkQcb49xU4+y5ueSn7uRF/d7d7EDJ0MczTwzFn1h2UcKvzZJOix72jZgStgW9cOXscFhLUkSFoFZdRQ1jIR2YcoIl+FG2RgiCWcteEbU9nsVcTFsN+nj4zVTHts00faEoM2VEbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725549143; c=relaxed/simple; bh=+v5OILyR1nbXGMAhyA8e1HI6+7BmIO0GsD6M4zRnO8k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D12NqW+PqDnuisikUAExCL4JztmhAVJHNR1XptcCIUKMlcenroTBogWc83QENR/JjWzvkZaOvno4F0tX1mCbYrd7M5P9dRJLiI3dw67M3s6MR0AVvjtqHQsnA2d+a/8+ChJQgsVge5MJadJ6LmiTCgcGEKR4JzlUZa6G9zrT0JU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com; spf=none 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=H1mIAs9X; arc=none smtp.client-ip=209.85.219.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ttaylorr.com Authentication-Results: smtp.subspace.kernel.org; spf=none 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="H1mIAs9X" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e1a7d43a226so1040503276.3 for ; Thu, 05 Sep 2024 08:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20230601.gappssmtp.com; s=20230601; t=1725549141; x=1726153941; 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=ntnVsOdFVlYlD36fmabeFc4pLf2muLBYQlVWcydQW14=; b=H1mIAs9Xfdndefxs7Rew42RTc9zL4Ac8HCj5k8OcGNrRBVX5Hc4w9xZr/7dOl19mX5 IOuICRnK9Neq2KvjfMBRAHvtVhWw+FUkQ7Gp8p7E3bYM8n6hgZJriYCdvNIubwT1U5mb nhREbNroJroN86mhq34JnGZZJmbUIQIqQRhRWwYb8FSid+uhSisd25BjAOEldg9RdJQN mIOQu20DKtN7gr2uhGZ6mI6+NlhmHwEEVt4/WArcOXkQKHBVDf4IcAa1AUTxPhFFuW6o UJqNZOLVfkc73zH4twhqQzgGMMhHq8iKg8G0EI4inbNKBF89ISV/NbsTHGTQkQUZUy+k 6Hdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725549141; x=1726153941; 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=ntnVsOdFVlYlD36fmabeFc4pLf2muLBYQlVWcydQW14=; b=Mc68hYJ0I6+TdKtWyVqqrddSNM1+1gY1t2kgiPoHpJJpTAnZUxDSmCJmUXr2/iwhOP fd3pxD6wFfmL/zWxnRO9csIpqNkjT+48TcKNi+HYmTIEncHd2xw0y7z2074THD0jxB/T 7JIdns3wE1Uze9WD3taNytTpkV/MhHTi3Wm5Gem9Lb6WcdVJR6L4eIG9aOGxJqViPCOJ 4gsfKKNwQXaHSYFdJwlW6fwepyN0q1VCGgNAV0PzcOxVKMj9yAv9qSnFoghYU0MdCYUY v2ecqnbs98z99uU+uFXLfrjKta4aK46ZkeB4AYte1rjGXk3cNLLyLCVubZrtSpthbLSP WHkw== X-Gm-Message-State: AOJu0YwH0R0LfnQ7sIpY/kYJ+huBSK615sCnFbMYZC51MPK41J7mia/M xiCo1iZXi1hQE3M1GFdoGXZ4ZWEkik1VefvLX132nWwHtcJQUam7NAokgZZEy9qs/yLnD1+uYv7 R3y4= X-Google-Smtp-Source: AGHT+IGXI/yTd5T0EpC6AepJ94tyBiCYzfwTK2Z812HpT2YF0rmygz8mssFDGFFI8IUKh9IzYvO8Xg== X-Received: by 2002:a05:6902:2188:b0:e0e:4abc:bbd3 with SMTP id 3f1490d57ef6-e1a7a04154amr20507893276.25.1725549140370; Thu, 05 Sep 2024 08:12:20 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e1a8e7a14a5sm2448788276.20.2024.09.05.08.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 08:12:19 -0700 (PDT) Date: Thu, 5 Sep 2024 11:12:18 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jeff King , "brian m. carlson" , Elijah Newren , Patrick Steinhardt , Junio C Hamano Subject: [PATCH v2 4/4] csum-file.c: use fast SHA-1 implementation when available Message-ID: <311fcc95960ed46d2ff01a61e554e0a2efbbe931.1725549065.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: Update hashwrite() and friends to use the fast_-variants of hashing functions, calling for e.g., "the_hash_algo->fast_update_fn()" instead of "the_hash_algo->update_fn()". These callers only use the_hash_algo to produce a checksum, which we depend on for data integrity, but not for cryptographic purposes, so these callers are safe to use the fast (and potentially non-collision detecting) SHA-1 implementation. To time this, I took a freshly packed copy of linux.git, and ran the following with and without the OPENSSL_SHA1_FAST=1 build-knob. Both versions were compiled with -O3: $ git for-each-ref --format='%(objectname)' refs/heads refs/tags >in $ valgrind --tool=callgrind ~/src/git/git-pack-objects \ --revs --stdout --all-progress --use-bitmap-index /dev/null Without OPENSSL_SHA1_FAST=1 (that is, using the collision-detecting SHA-1 implementation for both cryptographic and non-cryptographic purposes), we spend a significant amount of our instruction count in hashwrite(): $ callgrind_annotate --inclusive=yes | grep hashwrite | head -n1 159,998,868,413 (79.42%) /home/ttaylorr/src/git/csum-file.c:hashwrite [/home/ttaylorr/src/git/git-pack-objects] , and the resulting "clone" takes 19.219 seconds of wall clock time, 18.94 seconds of user time and 0.28 seconds of system time. Compiling with OPENSSL_SHA1_FAST=1, we spend ~60% fewer instructions in hashwrite(): $ callgrind_annotate --inclusive=yes | grep hashwrite | head -n1 59,164,001,176 (58.79%) /home/ttaylorr/src/git/csum-file.c:hashwrite [/home/ttaylorr/src/git/git-pack-objects] , and generate the resulting "clone" much faster, in only 11.597 seconds of wall time, 11.37 seconds of user time, and 0.23 seconds of system time, for a ~40% speed-up. Signed-off-by: Taylor Blau --- csum-file.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/csum-file.c b/csum-file.c index bf82ad8f9f5..cb8c39ecf3a 100644 --- a/csum-file.c +++ b/csum-file.c @@ -50,7 +50,7 @@ void hashflush(struct hashfile *f) if (offset) { if (!f->skip_hash) - the_hash_algo->update_fn(&f->ctx, f->buffer, offset); + the_hash_algo->fast_update_fn(&f->ctx, f->buffer, offset); flush(f, f->buffer, offset); f->offset = 0; } @@ -73,7 +73,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result, if (f->skip_hash) hashclr(f->buffer, the_repository->hash_algo); else - the_hash_algo->final_fn(f->buffer, &f->ctx); + the_hash_algo->fast_final_fn(f->buffer, &f->ctx); if (result) hashcpy(result, f->buffer, the_repository->hash_algo); @@ -128,7 +128,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count) * f->offset is necessarily zero. */ if (!f->skip_hash) - the_hash_algo->update_fn(&f->ctx, buf, nr); + the_hash_algo->fast_update_fn(&f->ctx, buf, nr); flush(f, buf, nr); } else { /* @@ -174,7 +174,7 @@ static struct hashfile *hashfd_internal(int fd, const char *name, f->name = name; f->do_crc = 0; f->skip_hash = 0; - the_hash_algo->init_fn(&f->ctx); + the_hash_algo->fast_init_fn(&f->ctx); f->buffer_len = buffer_len; f->buffer = xmalloc(buffer_len); @@ -208,7 +208,7 @@ void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpo { hashflush(f); checkpoint->offset = f->total; - the_hash_algo->clone_fn(&checkpoint->ctx, &f->ctx); + the_hash_algo->fast_clone_fn(&checkpoint->ctx, &f->ctx); } int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint) @@ -219,7 +219,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint lseek(f->fd, offset, SEEK_SET) != offset) return -1; f->total = offset; - the_hash_algo->clone_fn(&f->ctx, &checkpoint->ctx); + the_hash_algo->fast_clone_fn(&f->ctx, &checkpoint->ctx); f->offset = 0; /* hashflush() was called in checkpoint */ return 0; } @@ -245,9 +245,9 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len) if (total_len < the_hash_algo->rawsz) return 0; /* say "too short"? */ - the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, data, data_len); - the_hash_algo->final_fn(got, &ctx); + the_hash_algo->fast_init_fn(&ctx); + the_hash_algo->fast_update_fn(&ctx, data, data_len); + the_hash_algo->fast_final_fn(got, &ctx); return hasheq(got, data + data_len, the_repository->hash_algo); }