From patchwork Fri Jan 31 12:55:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13955357 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCC3D1C07FC for ; Fri, 31 Jan 2025 12:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328146; cv=none; b=PgJwYg/9uUE0ArAz5bDIM4mHcRGEyK9Cn0XXjlp+b3CwA8+VkRob3aU/paGoBO+CsWlvoeif6Th66Xx/ZAp4vsNUq9wUPecm8iI6c+o65DoadGCguw968AzcKiw1hXPdbEFCOOFW1WsegzK7CaJs97vaSAL2Tp1E5wR3N5lUfXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328146; c=relaxed/simple; bh=raqOBpj+Y4rpV+41yFbt1XrCUD1pRshBdiM8kSR5P3Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GPFQhRyCOK0zoXSjfSdiklXjzAaA/uh8Fn8XREQ63zAlJjhUOVT4VovcoYQtLq6HG4bNt32/LFgvvPdfvWtIbb73me9OWpY6lxU0wdiFwXv4d2d7a8G9UK9Sn1T55hpHqzqcDjZ039WJuSxNUJtAxz1XgVhx9lL46nJrrbaUmH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=KXsB2T6A; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Itucw5gX; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="KXsB2T6A"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Itucw5gX" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 3635B13801DB; Fri, 31 Jan 2025 07:55:43 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Fri, 31 Jan 2025 07:55:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1738328143; x=1738414543; bh=OMXpzZhj0QhVkf6Af7YtejfUQHBn4VCGZEt8eNHORRI=; b= KXsB2T6AaGyhyw79P21X8ocaVHr1R3SCAH3Hh4fSx6K2YanNVzzcw8WwJtKGffsX xdkbLMzQ0uUs6TipJ+hC4473CVvf6SOVikMvXusf8rhPu+hnfvuXD/aUEKTP8BMb XL+WSbTw0KCNrycsN2kg3HdSi+z1xB5d20XibFpEVUUMQdZ7qVevU9rcKNL4XEqS /WU20FNzAgOfK4qT++lNm3mTNQ+PlYYskB134L2lIBGd/PXUOrewtlVOh2fvogRH WPNAeiGo5bOwYtqqK02aMGzTbWTCwSTRIiopRjOb3Sif4P2t5Mdc24ibICQTyfP5 2M51+P4x98t0ska58LFj0A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738328143; x= 1738414543; bh=OMXpzZhj0QhVkf6Af7YtejfUQHBn4VCGZEt8eNHORRI=; b=I tucw5gX8tQgo1NXgAzJTNR75LdtlAI2c58x/oWx25WQ2SwOlUtlRvoUjaj+stpP3 wvxYQva4bueagL2PT/KxmbkYWtNOdsi/SHWOedc5YkfdV6RwlOXzXO+1kkdf6kvj Cv5mKv5uDa7hjLzww02/CzQsHPGqShXMumnHJb0AXs1uRPCGgp9Qig/NxOzBJL5C fVWPE34YKcBhRBWT+CJwCt/EF5C57eIQNBMqOugHscFAA5+JCKBCZIuj46z/dLY7 pkrQEXw+/xHca/dgDkbNbmL4yHs00JmhWcIOyuiJHloh7dWkSnn91DPY3KLfGgQc vuB6s6RHPjd7e3PLaKNdw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdekkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithhs thgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 31 Jan 2025 07:55:42 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5decfed3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 31 Jan 2025 12:55:39 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 31 Jan 2025 13:55:28 +0100 Subject: [PATCH 1/4] hash: convert hashing context to a structure Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250131-b4-pks-hash-context-direct-v1-1-67a6d3f49d6e@pks.im> References: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> In-Reply-To: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano X-Mailer: b4 0.14.2 The `git_hash_context` is a union containing the different hash-specific states for SHA1, its unsafe variant as well as SHA256. We know that only one of these states will ever be in use at the same time because hash contexts cannot be used for multiple different hashes at the same point in time. We're about to extend the structure though to keep track of the hash algorithm used to initialize the context, which is impossible to do while the context is a union. Refactor it to instead be a structure that contains the union of context states. Signed-off-by: Patrick Steinhardt --- hash.h | 13 +++++++------ object-file.c | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/hash.h b/hash.h index ad2c919991..5b88d9b714 100644 --- a/hash.h +++ b/hash.h @@ -234,13 +234,14 @@ enum get_oid_result { #endif /* A suitably aligned type for stack allocations of hash contexts. */ -union git_hash_ctx { - git_SHA_CTX sha1; - git_SHA_CTX_unsafe sha1_unsafe; - - git_SHA256_CTX sha256; +struct git_hash_ctx { + union { + git_SHA_CTX sha1; + git_SHA_CTX_unsafe sha1_unsafe; + git_SHA256_CTX sha256; + } state; }; -typedef union git_hash_ctx git_hash_ctx; +typedef struct git_hash_ctx git_hash_ctx; typedef void (*git_hash_init_fn)(git_hash_ctx *ctx); typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src); diff --git a/object-file.c b/object-file.c index 6ce1caacae..7505aa6b60 100644 --- a/object-file.c +++ b/object-file.c @@ -88,82 +88,82 @@ static const struct object_id null_oid_sha256 = { static void git_hash_sha1_init(git_hash_ctx *ctx) { - git_SHA1_Init(&ctx->sha1); + git_SHA1_Init(&ctx->state.sha1); } static void git_hash_sha1_clone(git_hash_ctx *dst, const git_hash_ctx *src) { - git_SHA1_Clone(&dst->sha1, &src->sha1); + git_SHA1_Clone(&dst->state.sha1, &src->state.sha1); } static void git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len) { - git_SHA1_Update(&ctx->sha1, data, len); + git_SHA1_Update(&ctx->state.sha1, data, len); } static void git_hash_sha1_final(unsigned char *hash, git_hash_ctx *ctx) { - git_SHA1_Final(hash, &ctx->sha1); + git_SHA1_Final(hash, &ctx->state.sha1); } static void git_hash_sha1_final_oid(struct object_id *oid, git_hash_ctx *ctx) { - git_SHA1_Final(oid->hash, &ctx->sha1); + git_SHA1_Final(oid->hash, &ctx->state.sha1); memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); oid->algo = GIT_HASH_SHA1; } static void git_hash_sha1_init_unsafe(git_hash_ctx *ctx) { - git_SHA1_Init_unsafe(&ctx->sha1_unsafe); + git_SHA1_Init_unsafe(&ctx->state.sha1_unsafe); } static void git_hash_sha1_clone_unsafe(git_hash_ctx *dst, const git_hash_ctx *src) { - git_SHA1_Clone_unsafe(&dst->sha1_unsafe, &src->sha1_unsafe); + git_SHA1_Clone_unsafe(&dst->state.sha1_unsafe, &src->state.sha1_unsafe); } static void git_hash_sha1_update_unsafe(git_hash_ctx *ctx, const void *data, size_t len) { - git_SHA1_Update_unsafe(&ctx->sha1_unsafe, data, len); + git_SHA1_Update_unsafe(&ctx->state.sha1_unsafe, data, len); } static void git_hash_sha1_final_unsafe(unsigned char *hash, git_hash_ctx *ctx) { - git_SHA1_Final_unsafe(hash, &ctx->sha1_unsafe); + git_SHA1_Final_unsafe(hash, &ctx->state.sha1_unsafe); } static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, git_hash_ctx *ctx) { - git_SHA1_Final_unsafe(oid->hash, &ctx->sha1_unsafe); + git_SHA1_Final_unsafe(oid->hash, &ctx->state.sha1_unsafe); 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) { - git_SHA256_Init(&ctx->sha256); + git_SHA256_Init(&ctx->state.sha256); } static void git_hash_sha256_clone(git_hash_ctx *dst, const git_hash_ctx *src) { - git_SHA256_Clone(&dst->sha256, &src->sha256); + git_SHA256_Clone(&dst->state.sha256, &src->state.sha256); } static void git_hash_sha256_update(git_hash_ctx *ctx, const void *data, size_t len) { - git_SHA256_Update(&ctx->sha256, data, len); + git_SHA256_Update(&ctx->state.sha256, data, len); } static void git_hash_sha256_final(unsigned char *hash, git_hash_ctx *ctx) { - git_SHA256_Final(hash, &ctx->sha256); + git_SHA256_Final(hash, &ctx->state.sha256); } static void git_hash_sha256_final_oid(struct object_id *oid, git_hash_ctx *ctx) { - git_SHA256_Final(oid->hash, &ctx->sha256); + git_SHA256_Final(oid->hash, &ctx->state.sha256); /* * This currently does nothing, so the compiler should optimize it out, * but keep it in case we extend the hash size again. From patchwork Fri Jan 31 12:55:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13955358 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCBE219D06E for ; Fri, 31 Jan 2025 12:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328147; cv=none; b=glIGCi5hIZlNe2DibTjVCMU3rauyT9VGIRFnNYLzD0bT9O+0oHpSIS22YwawDmgC394bM15A+SAD/d1aHTLK5XApaIg5biTTVss5m0cKiLp7S2p8ipCZeoszKzteuNIIvb9tspFU2x80qYtJsmNQL7ULGhg0Mg4rG/hTl3kRzTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328147; c=relaxed/simple; bh=aPdwgG/9LSc7wU6azsnmCHsoQ4oa/XNj3dOZ+ytGS/I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WsqQlHg7CqZFTWd61pW02PJcwOfEv/+ZII5th8qLxErZFrgONO31F47wAC0+hWd2FG5xu9sr0i/VUka5/q0l9HhPyCXfyzylx0JIhzQF6lKOZqgTK5FC1AZ52XIRbNosWP5iyzwtanSZqlHhwTw7RPyo7MHkQwpOHUYSXgH1WBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=bOqrLVDc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KBnoKKph; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="bOqrLVDc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KBnoKKph" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id C7DBD13801DD; Fri, 31 Jan 2025 07:55:43 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Fri, 31 Jan 2025 07:55:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1738328143; x=1738414543; bh=TEornZQXwvz0J2oFI/PvXAICKRnuKW5ctX9i18ozfA4=; b= bOqrLVDc/o2aB8uU53K1Dsfhdjn46pGeZ+7I/OzUXZenKuy6eLWfrnL4LxCNFOMB Kqh+g3zX461h0e66RmcZJ62ZCcrH2C9yHD6ZBMni9GtVJ1r6/m5+g/D/dey45+qb HMpcDrLj2YJ0TuCd64r2w88Pc81kssxwpnGZyUn9D5p2Qahn439U4hRbT3A26Ykk oXlS2YOMYku2ecDAgacjJdeB2uyp4ymdpegmy41daGabcczl36zJItqPMzfvlBM9 Qb6hKIhQ5tXCyUzm4RJJ3v4dkw7/YPXLCD1QVeW8UXBMf29gAaxcu/5kr/8aoNnY gwd9QPkcDMTmigZaCZE+3g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738328143; x= 1738414543; bh=TEornZQXwvz0J2oFI/PvXAICKRnuKW5ctX9i18ozfA4=; b=K BnoKKphrzfQQB+hagI5YJWnXwZdJknYhOyVw61A3afDUOfuCMirw+20PquX3fjUM RXFqXjJAjF8IzLis7BnQd96j0X9wWY0HnPCnmx085h+/DJbrdFuAJlhq/l2Ygtzy ScIal1d431V6FSZiPc6RFXYB6F2AiH5paVl5aQvOr8Q1RjJ745fBhehU8RsjmPxE G4by/dPg+5wkkCqJ5BdfLJE1vruCfUSBZjqXFR3CDXkEKGUvGeWKLPXiIB+9xyj+ JHzypauF25CGRjMO6aoX4YzdGskqezXa/b/QK8qvF6YnLDq0rBCpBS25O3NtK8Rz oEccm8NA8E1pQVzJCoAXg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdekkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepmhgvseht thgrhihlohhrrhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrd horhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 31 Jan 2025 07:55:42 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 481ed8d0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 31 Jan 2025 12:55:40 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 31 Jan 2025 13:55:29 +0100 Subject: [PATCH 2/4] hash: stop typedeffing the hash context Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250131-b4-pks-hash-context-direct-v1-2-67a6d3f49d6e@pks.im> References: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> In-Reply-To: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano X-Mailer: b4 0.14.2 We generally avoid using `typedef` in the Git codebase. One exception though is the `git_hash_ctx`, likely because it used to be a union rather than a struct until the preceding commit refactored it. But now that it is a normal `struct` there isn't really a need for a typedef anymore. Drop the typedef and adapt all callers accordingly. Signed-off-by: Patrick Steinhardt --- builtin/fast-import.c | 4 +-- builtin/index-pack.c | 6 ++--- builtin/patch-id.c | 2 +- builtin/receive-pack.c | 2 +- builtin/unpack-objects.c | 4 +-- bulk-checkin.c | 4 +-- csum-file.c | 2 +- csum-file.h | 4 +-- diff.c | 10 ++++---- diff.h | 2 +- hash.h | 11 ++++---- http-push.c | 2 +- http.h | 2 +- object-file.c | 62 +++++++++++++++++++++++----------------------- pack-check.c | 2 +- pack-write.c | 2 +- read-cache.c | 12 ++++----- rerere.c | 4 +-- t/helper/test-hash-speed.c | 4 +-- t/helper/test-hash.c | 2 +- t/unit-tests/u-hash.c | 2 +- trace2/tr2_sid.c | 2 +- 22 files changed, 73 insertions(+), 74 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index ccdada1810..9862704c62 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -953,7 +953,7 @@ static int store_object( unsigned char hdr[96]; struct object_id oid; unsigned long hdrlen, deltalen; - git_hash_ctx c; + struct git_hash_ctx c; git_zstream s; hdrlen = format_object_header((char *)hdr, sizeof(hdr), type, @@ -1095,7 +1095,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) struct object_id oid; unsigned long hdrlen; off_t offset; - git_hash_ctx c; + struct git_hash_ctx c; git_zstream s; struct hashfile_checkpoint checkpoint; int status = Z_OK; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 6ffbb7ce35..40e49868b1 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -151,7 +151,7 @@ static unsigned int input_offset, input_len; static off_t consumed_bytes; static off_t max_input_size; static unsigned deepest_delta; -static git_hash_ctx input_ctx; +static struct git_hash_ctx input_ctx; static uint32_t input_crc32; static int input_fd, output_fd; static const char *curr_pack; @@ -475,7 +475,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size, int status; git_zstream stream; void *buf; - git_hash_ctx c; + struct git_hash_ctx c; char hdr[32]; int hdrlen; @@ -1248,7 +1248,7 @@ static void parse_pack_objects(unsigned char *hash) struct ofs_delta_entry *ofs_delta = ofs_deltas; struct object_id ref_delta_oid; struct stat st; - git_hash_ctx tmp_ctx; + struct git_hash_ctx tmp_ctx; if (verbose) progress = start_progress( diff --git a/builtin/patch-id.c b/builtin/patch-id.c index f540d8daa7..923ff2bb77 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -70,7 +70,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu int before = -1, after = -1; int diff_is_binary = 0; char pre_oid_str[GIT_MAX_HEXSZ + 1], post_oid_str[GIT_MAX_HEXSZ + 1]; - git_hash_ctx ctx; + struct git_hash_ctx ctx; the_hash_algo->init_fn(&ctx); oidclr(result, the_repository->hash_algo); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 0fb0266cfd..d2360c453c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -566,7 +566,7 @@ static void hmac_hash(unsigned char *out, unsigned char k_ipad[GIT_MAX_BLKSZ]; unsigned char k_opad[GIT_MAX_BLKSZ]; int i; - git_hash_ctx ctx; + struct git_hash_ctx ctx; /* RFC 2104 2. (1) */ memset(key, '\0', GIT_MAX_BLKSZ); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index f6b9825fb0..d72885510c 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -28,7 +28,7 @@ static unsigned char buffer[4096]; static unsigned int offset, len; static off_t consumed_bytes; static off_t max_input_size; -static git_hash_ctx ctx; +static struct git_hash_ctx ctx; static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; static struct progress *progress; @@ -614,7 +614,7 @@ int cmd_unpack_objects(int argc, { int i; struct object_id oid; - git_hash_ctx tmp_ctx; + struct git_hash_ctx tmp_ctx; disable_replace_refs(); diff --git a/bulk-checkin.c b/bulk-checkin.c index f889fce734..db1958b525 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -161,7 +161,7 @@ static int already_written(struct bulk_checkin_packfile *state, struct object_id * with a new pack. */ static int stream_blob_to_pack(struct bulk_checkin_packfile *state, - git_hash_ctx *ctx, off_t *already_hashed_to, + struct git_hash_ctx *ctx, off_t *already_hashed_to, int fd, size_t size, const char *path, unsigned flags) { @@ -258,7 +258,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state, const char *path, unsigned flags) { off_t seekback, already_hashed_to; - git_hash_ctx ctx; + struct git_hash_ctx ctx; unsigned char obuf[16384]; unsigned header_len; struct hashfile_checkpoint checkpoint; diff --git a/csum-file.c b/csum-file.c index 232121f415..3383515669 100644 --- a/csum-file.c +++ b/csum-file.c @@ -248,7 +248,7 @@ uint32_t crc32_end(struct hashfile *f) int hashfile_checksum_valid(const unsigned char *data, size_t total_len) { unsigned char got[GIT_MAX_RAWSZ]; - git_hash_ctx ctx; + struct git_hash_ctx ctx; const struct git_hash_algo *algop = unsafe_hash_algo(the_hash_algo); size_t data_len = total_len - algop->rawsz; diff --git a/csum-file.h b/csum-file.h index b7475f16c2..ffccbf0996 100644 --- a/csum-file.h +++ b/csum-file.h @@ -11,7 +11,7 @@ struct hashfile { int fd; int check_fd; unsigned int offset; - git_hash_ctx ctx; + struct git_hash_ctx ctx; off_t total; struct progress *tp; const char *name; @@ -33,7 +33,7 @@ struct hashfile { /* Checkpoint */ struct hashfile_checkpoint { off_t offset; - git_hash_ctx ctx; + struct git_hash_ctx ctx; }; void hashfile_checkpoint_init(struct hashfile *, struct hashfile_checkpoint *); diff --git a/diff.c b/diff.c index 0822ae4433..7f570ebdf9 100644 --- a/diff.c +++ b/diff.c @@ -6392,7 +6392,7 @@ static void diff_summary(struct diff_options *opt, struct diff_filepair *p) } struct patch_id_t { - git_hash_ctx *ctx; + struct git_hash_ctx *ctx; int patchlen; }; @@ -6409,7 +6409,7 @@ static int remove_space(char *line, int len) return dst - line; } -void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx) +void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx) { unsigned char hash[GIT_MAX_RAWSZ]; unsigned short carry = 0; @@ -6439,12 +6439,12 @@ static int patch_id_consume(void *priv, char *line, unsigned long len) return 0; } -static void patch_id_add_string(git_hash_ctx *ctx, const char *str) +static void patch_id_add_string(struct git_hash_ctx *ctx, const char *str) { the_hash_algo->update_fn(ctx, str, strlen(str)); } -static void patch_id_add_mode(git_hash_ctx *ctx, unsigned mode) +static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode) { /* large enough for 2^32 in octal */ char buf[12]; @@ -6457,7 +6457,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid { struct diff_queue_struct *q = &diff_queued_diff; int i; - git_hash_ctx ctx; + struct git_hash_ctx ctx; struct patch_id_t data; the_hash_algo->init_fn(&ctx); diff --git a/diff.h b/diff.h index 6e6007c17b..d56296dd21 100644 --- a/diff.h +++ b/diff.h @@ -644,7 +644,7 @@ void run_diff_index(struct rev_info *revs, unsigned int option); int do_diff_cache(const struct object_id *, struct diff_options *); int diff_flush_patch_id(struct diff_options *, struct object_id *, int); -void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx); +void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx); int diff_result_code(struct rev_info *); diff --git a/hash.h b/hash.h index 5b88d9b714..42b52c6dae 100644 --- a/hash.h +++ b/hash.h @@ -241,13 +241,12 @@ struct git_hash_ctx { git_SHA256_CTX sha256; } state; }; -typedef struct git_hash_ctx git_hash_ctx; -typedef void (*git_hash_init_fn)(git_hash_ctx *ctx); -typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src); -typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len); -typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx); -typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx); +typedef void (*git_hash_init_fn)(struct git_hash_ctx *ctx); +typedef void (*git_hash_clone_fn)(struct git_hash_ctx *dst, const struct git_hash_ctx *src); +typedef void (*git_hash_update_fn)(struct git_hash_ctx *ctx, const void *in, size_t len); +typedef void (*git_hash_final_fn)(unsigned char *hash, struct git_hash_ctx *ctx); +typedef void (*git_hash_final_oid_fn)(struct object_id *oid, struct git_hash_ctx *ctx); struct git_hash_algo { /* diff --git a/http-push.c b/http-push.c index 43da1c7cd3..36867af2f8 100644 --- a/http-push.c +++ b/http-push.c @@ -760,7 +760,7 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed) static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) { struct remote_lock *lock = (struct remote_lock *)ctx->userData; - git_hash_ctx hash_ctx; + struct git_hash_ctx hash_ctx; unsigned char lock_token_hash[GIT_MAX_RAWSZ]; if (tag_closed && ctx->cdata) { diff --git a/http.h b/http.h index 46e334c2c2..36202139f4 100644 --- a/http.h +++ b/http.h @@ -228,7 +228,7 @@ struct http_object_request { long http_code; struct object_id oid; struct object_id real_oid; - git_hash_ctx c; + struct git_hash_ctx c; git_zstream stream; int zret; int rename; diff --git a/object-file.c b/object-file.c index 7505aa6b60..154bcfce78 100644 --- a/object-file.c +++ b/object-file.c @@ -86,82 +86,82 @@ static const struct object_id null_oid_sha256 = { .algo = GIT_HASH_SHA256, }; -static void git_hash_sha1_init(git_hash_ctx *ctx) +static void git_hash_sha1_init(struct git_hash_ctx *ctx) { git_SHA1_Init(&ctx->state.sha1); } -static void git_hash_sha1_clone(git_hash_ctx *dst, const git_hash_ctx *src) +static void git_hash_sha1_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { git_SHA1_Clone(&dst->state.sha1, &src->state.sha1); } -static void git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len) +static void git_hash_sha1_update(struct git_hash_ctx *ctx, const void *data, size_t len) { git_SHA1_Update(&ctx->state.sha1, data, len); } -static void git_hash_sha1_final(unsigned char *hash, git_hash_ctx *ctx) +static void git_hash_sha1_final(unsigned char *hash, struct git_hash_ctx *ctx) { git_SHA1_Final(hash, &ctx->state.sha1); } -static void git_hash_sha1_final_oid(struct object_id *oid, git_hash_ctx *ctx) +static void git_hash_sha1_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) { git_SHA1_Final(oid->hash, &ctx->state.sha1); memset(oid->hash + GIT_SHA1_RAWSZ, 0, GIT_MAX_RAWSZ - GIT_SHA1_RAWSZ); oid->algo = GIT_HASH_SHA1; } -static void git_hash_sha1_init_unsafe(git_hash_ctx *ctx) +static void git_hash_sha1_init_unsafe(struct git_hash_ctx *ctx) { git_SHA1_Init_unsafe(&ctx->state.sha1_unsafe); } -static void git_hash_sha1_clone_unsafe(git_hash_ctx *dst, const git_hash_ctx *src) +static void git_hash_sha1_clone_unsafe(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { git_SHA1_Clone_unsafe(&dst->state.sha1_unsafe, &src->state.sha1_unsafe); } -static void git_hash_sha1_update_unsafe(git_hash_ctx *ctx, const void *data, +static void git_hash_sha1_update_unsafe(struct git_hash_ctx *ctx, const void *data, size_t len) { git_SHA1_Update_unsafe(&ctx->state.sha1_unsafe, data, len); } -static void git_hash_sha1_final_unsafe(unsigned char *hash, git_hash_ctx *ctx) +static void git_hash_sha1_final_unsafe(unsigned char *hash, struct git_hash_ctx *ctx) { git_SHA1_Final_unsafe(hash, &ctx->state.sha1_unsafe); } -static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, git_hash_ctx *ctx) +static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, struct git_hash_ctx *ctx) { git_SHA1_Final_unsafe(oid->hash, &ctx->state.sha1_unsafe); 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) +static void git_hash_sha256_init(struct git_hash_ctx *ctx) { git_SHA256_Init(&ctx->state.sha256); } -static void git_hash_sha256_clone(git_hash_ctx *dst, const git_hash_ctx *src) +static void git_hash_sha256_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { git_SHA256_Clone(&dst->state.sha256, &src->state.sha256); } -static void git_hash_sha256_update(git_hash_ctx *ctx, const void *data, size_t len) +static void git_hash_sha256_update(struct git_hash_ctx *ctx, const void *data, size_t len) { git_SHA256_Update(&ctx->state.sha256, data, len); } -static void git_hash_sha256_final(unsigned char *hash, git_hash_ctx *ctx) +static void git_hash_sha256_final(unsigned char *hash, struct git_hash_ctx *ctx) { git_SHA256_Final(hash, &ctx->state.sha256); } -static void git_hash_sha256_final_oid(struct object_id *oid, git_hash_ctx *ctx) +static void git_hash_sha256_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) { git_SHA256_Final(oid->hash, &ctx->state.sha256); /* @@ -172,18 +172,18 @@ static void git_hash_sha256_final_oid(struct object_id *oid, git_hash_ctx *ctx) oid->algo = GIT_HASH_SHA256; } -static void git_hash_unknown_init(git_hash_ctx *ctx UNUSED) +static void git_hash_unknown_init(struct git_hash_ctx *ctx UNUSED) { BUG("trying to init unknown hash"); } -static void git_hash_unknown_clone(git_hash_ctx *dst UNUSED, - const git_hash_ctx *src UNUSED) +static void git_hash_unknown_clone(struct git_hash_ctx *dst UNUSED, + const struct git_hash_ctx *src UNUSED) { BUG("trying to clone unknown hash"); } -static void git_hash_unknown_update(git_hash_ctx *ctx UNUSED, +static void git_hash_unknown_update(struct git_hash_ctx *ctx UNUSED, const void *data UNUSED, size_t len UNUSED) { @@ -191,13 +191,13 @@ static void git_hash_unknown_update(git_hash_ctx *ctx UNUSED, } static void git_hash_unknown_final(unsigned char *hash UNUSED, - git_hash_ctx *ctx UNUSED) + struct git_hash_ctx *ctx UNUSED) { BUG("trying to finalize unknown hash"); } static void git_hash_unknown_final_oid(struct object_id *oid UNUSED, - git_hash_ctx *ctx UNUSED) + struct git_hash_ctx *ctx UNUSED) { BUG("trying to finalize unknown hash"); } @@ -1180,7 +1180,7 @@ int stream_object_signature(struct repository *r, const struct object_id *oid) unsigned long size; enum object_type obj_type; struct git_istream *st; - git_hash_ctx c; + struct git_hash_ctx c; char hdr[MAX_HEADER_LEN]; int hdrlen; @@ -1945,7 +1945,7 @@ void *read_object_with_reference(struct repository *r, } } -static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c, +static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c, const void *buf, unsigned long len, struct object_id *oid, char *hdr, int *hdrlen) @@ -1961,7 +1961,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo, enum object_type type, struct object_id *oid, char *hdr, int *hdrlen) { - git_hash_ctx c; + struct git_hash_ctx c; /* Generate the header */ *hdrlen = format_object_header(hdr, *hdrlen, type, len); @@ -1975,7 +1975,7 @@ static void write_object_file_prepare_literally(const struct git_hash_algo *algo const char *type, struct object_id *oid, char *hdr, int *hdrlen) { - git_hash_ctx c; + struct git_hash_ctx c; *hdrlen = format_object_header_literally(hdr, *hdrlen, type, len); hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen); @@ -2206,7 +2206,7 @@ static int start_loose_object_common(struct strbuf *tmp_file, const char *filename, unsigned flags, git_zstream *stream, unsigned char *buf, size_t buflen, - git_hash_ctx *c, git_hash_ctx *compat_c, + struct git_hash_ctx *c, struct git_hash_ctx *compat_c, char *hdr, int hdrlen) { struct repository *repo = the_repository; @@ -2251,7 +2251,7 @@ static int start_loose_object_common(struct strbuf *tmp_file, * Common steps for the inner git_deflate() loop for writing loose * objects. Returns what git_deflate() returns. */ -static int write_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, +static int write_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *compat_c, git_zstream *stream, const int flush, unsigned char *in0, const int fd, unsigned char *compressed, @@ -2280,7 +2280,7 @@ static int write_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, * - End the compression of zlib stream. * - Get the calculated oid to "oid". */ -static int end_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, +static int end_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx *compat_c, git_zstream *stream, struct object_id *oid, struct object_id *compat_oid) { @@ -2306,7 +2306,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr, int fd, ret; unsigned char compressed[4096]; git_zstream stream; - git_hash_ctx c; + struct git_hash_ctx c; struct object_id parano_oid; static struct strbuf tmp_file = STRBUF_INIT; static struct strbuf filename = STRBUF_INIT; @@ -2386,7 +2386,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len, int fd, ret, err = 0, flush = 0; unsigned char compressed[4096]; git_zstream stream; - git_hash_ctx c, compat_c; + struct git_hash_ctx c, compat_c; struct strbuf tmp_file = STRBUF_INIT; struct strbuf filename = STRBUF_INIT; int dirlen; @@ -3046,7 +3046,7 @@ static int check_stream_oid(git_zstream *stream, const char *path, const struct object_id *expected_oid) { - git_hash_ctx c; + struct git_hash_ctx c; struct object_id real_oid; unsigned char buf[4096]; unsigned long total_read; diff --git a/pack-check.c b/pack-check.c index 8d9f6da7ce..f20209fccb 100644 --- a/pack-check.c +++ b/pack-check.c @@ -58,7 +58,7 @@ static int verify_packfile(struct repository *r, { off_t index_size = p->index_size; const unsigned char *index_base = p->index_data; - git_hash_ctx ctx; + struct git_hash_ctx ctx; unsigned char hash[GIT_MAX_RAWSZ], *pack_sig; off_t offset = 0, pack_sig_ofs = 0; uint32_t nr_objects, i; diff --git a/pack-write.c b/pack-write.c index 98a8c0e785..9004d1d095 100644 --- a/pack-write.c +++ b/pack-write.c @@ -388,7 +388,7 @@ void fixup_pack_header_footer(int pack_fd, off_t partial_pack_offset) { int aligned_sz, buf_sz = 8 * 1024; - git_hash_ctx old_hash_ctx, new_hash_ctx; + struct git_hash_ctx old_hash_ctx, new_hash_ctx; struct pack_header hdr; char *buf; ssize_t read_result; diff --git a/read-cache.c b/read-cache.c index d54be2c172..5e765d9af5 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1717,7 +1717,7 @@ int verify_ce_order; static int verify_hdr(const struct cache_header *hdr, unsigned long size) { - git_hash_ctx c; + struct git_hash_ctx c; unsigned char hash[GIT_MAX_RAWSZ]; int hdr_version; unsigned char *start, *end; @@ -2002,7 +2002,7 @@ static struct index_entry_offset_table *read_ieot_extension(const char *mmap, si static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_table *ieot); static size_t read_eoie_extension(const char *mmap, size_t mmap_size); -static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset); +static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_context, size_t offset); struct load_index_extensions { @@ -2566,7 +2566,7 @@ int repo_index_has_changes(struct repository *repo, } static int write_index_ext_header(struct hashfile *f, - git_hash_ctx *eoie_f, + struct git_hash_ctx *eoie_f, unsigned int ext, unsigned int sz) { @@ -2831,7 +2831,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, { uint64_t start = getnanotime(); struct hashfile *f; - git_hash_ctx *eoie_c = NULL; + struct git_hash_ctx *eoie_c = NULL; struct cache_header hdr; int i, err = 0, removed, extended, hdr_version; struct cache_entry **cache = istate->cache; @@ -3579,7 +3579,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size) uint32_t extsize; size_t offset, src_offset; unsigned char hash[GIT_MAX_RAWSZ]; - git_hash_ctx c; + struct git_hash_ctx c; /* ensure we have an index big enough to contain an EOIE extension */ if (mmap_size < sizeof(struct cache_header) + EOIE_SIZE_WITH_HEADER + the_hash_algo->rawsz) @@ -3650,7 +3650,7 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size) return offset; } -static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset) +static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_context, size_t offset) { uint32_t buffer; unsigned char hash[GIT_MAX_RAWSZ]; diff --git a/rerere.c b/rerere.c index e7fa6426b3..5ff9624b57 100644 --- a/rerere.c +++ b/rerere.c @@ -358,7 +358,7 @@ static void rerere_strbuf_putconflict(struct strbuf *buf, int ch, size_t size) } static int handle_conflict(struct strbuf *out, struct rerere_io *io, - int marker_size, git_hash_ctx *ctx) + int marker_size, struct git_hash_ctx *ctx) { enum { RR_SIDE_1 = 0, RR_SIDE_2, RR_ORIGINAL @@ -432,7 +432,7 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, */ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_size) { - git_hash_ctx ctx; + struct git_hash_ctx ctx; struct strbuf buf = STRBUF_INIT, out = STRBUF_INIT; int has_conflicts = 0; if (hash) diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c index 80df1aae66..803f41c89d 100644 --- a/t/helper/test-hash-speed.c +++ b/t/helper/test-hash-speed.c @@ -3,7 +3,7 @@ #define NUM_SECONDS 3 -static inline void compute_hash(const struct git_hash_algo *algo, git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len) +static inline void compute_hash(const struct git_hash_algo *algo, struct git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len) { algo->init_fn(ctx); algo->update_fn(ctx, p, len); @@ -12,7 +12,7 @@ static inline void compute_hash(const struct git_hash_algo *algo, git_hash_ctx * int cmd__hash_speed(int ac, const char **av) { - git_hash_ctx ctx; + struct git_hash_ctx ctx; unsigned char hash[GIT_MAX_RAWSZ]; clock_t initial, start, end; unsigned bufsizes[] = { 64, 256, 1024, 8192, 16384 }; diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index aa82638c62..f9a3db487a 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -3,7 +3,7 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe) { - git_hash_ctx ctx; + struct git_hash_ctx ctx; unsigned char hash[GIT_MAX_HEXSZ]; unsigned bufsz = 8192; int binary = 0; diff --git a/t/unit-tests/u-hash.c b/t/unit-tests/u-hash.c index a0320efe4b..05204e7b6c 100644 --- a/t/unit-tests/u-hash.c +++ b/t/unit-tests/u-hash.c @@ -8,7 +8,7 @@ static void check_hash_data(const void *data, size_t data_length, cl_assert(data != NULL); for (size_t i = 1; i < ARRAY_SIZE(hash_algos); i++) { - git_hash_ctx ctx; + struct git_hash_ctx ctx; unsigned char hash[GIT_MAX_HEXSZ]; const struct git_hash_algo *algop = &hash_algos[i]; diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c index 09c4ef0d17..c42696ef52 100644 --- a/trace2/tr2_sid.c +++ b/trace2/tr2_sid.c @@ -32,7 +32,7 @@ static void tr2_sid_append_my_sid_component(void) { const struct git_hash_algo *algo = &hash_algos[GIT_HASH_SHA1]; struct tr2_tbuf tb_now; - git_hash_ctx ctx; + struct git_hash_ctx ctx; pid_t pid = getpid(); unsigned char hash[GIT_MAX_RAWSZ + 1]; char hex[GIT_MAX_HEXSZ + 1]; From patchwork Fri Jan 31 12:55:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13955359 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAEAF1C2443 for ; Fri, 31 Jan 2025 12:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328147; cv=none; b=js4qYDv+GlH1rvAOsgcEoZLjZRttAzxHWDepAb9XZbw4RZt3DKd0mzcbnNGb5wQB7i82AL2fiz4BDUvVy7qxheC7JA/yt+JMgED22sgmLijDoy8G22HdbiZq4+8cALWJTtH5HuXPcAB0U1HZOytphH4zv9KDz3Zzl7EQQX3tjow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328147; c=relaxed/simple; bh=GU1YwqBCy0wsFcfNWFSTUKIeMoXCt8EaINVTSZI0fz4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ikoJFx5/+nlOllKbSyWD873DPIwhBypKXzGozRsgcLQETkKHjv21ZH1XupvWtAs07vNUkCXd8TSxGpcjqEqC54rHtoCLOcddEyn0kGO306SOLa9MaJD9ZLD+1DwUlA1DVRbRh2teParnPlBriulnAA+NeVL/qGCj7it932uBaRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=qV/DoKh4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TQNs09C4; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="qV/DoKh4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TQNs09C4" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5B47211401B4; Fri, 31 Jan 2025 07:55:44 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 31 Jan 2025 07:55:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1738328144; x=1738414544; bh=mLnx0aNDlusFFIlIhkd/B5+WvAqXYvZawDPf4g+VYDQ=; b= qV/DoKh4rTXz5PvfNctiHGRcs+KFf18DABFX02ubRxvoU+kIlgWjByTDx3z3sRFU aFLODQnLRg1vpkYNpEfcLZCkOm56PWeApNIKm9aEgBPOqBDIZmyrqCO3g5dnvMD7 VuhlDfB4LGS7f3PoyaMEbaLMLhA79dAhN32CEM0mdXGem5BdZ1FEiOt0Kcs8adCN 57JraD0sdrjS3Vj3jF5no467AKkh4uXc7+yRkrl540A6jPskNLYw9fw0SB/f+EfV 9q6pPdqlJPDjP+LxlEnoihVBr3hoTXkR+MEHtJHj8C/nwcaKjUq8wXDtx5BAbOBw ZailwvApDBADahfzDx12kQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738328144; x= 1738414544; bh=mLnx0aNDlusFFIlIhkd/B5+WvAqXYvZawDPf4g+VYDQ=; b=T QNs09C4sHD8ORp47TzMyfzvHs65aXqtMV13Ka6aH1lWRJTT/TYgIwZzUB5uc55lS bLcm+PELE1DeoKPOdab1406entozFQjBewckPmxT24lCo1YeYds6E+nLVrKFdSXx SZLhlAaT3iHVDVrPaaOuoXP5LmZZwrmNcvNXHPnoIo3xH5V5tXllgGVoAqBopA5l +gysAk9SvujC3HRDEaCkCkJft9FBjOMLrbFbfyFh9FKkt4UCKo5pffEU0sJjyFDx GQ7qwQ4U+v+oCsFupCuPZxq8sTGfz7mZry13Ju4A/KU3c1u6IV+yJMXAPRZg6vWb xL6m2CYXx38Tvk48ncj2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdekkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepmhgvseht thgrhihlohhrrhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtoh hmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 31 Jan 2025 07:55:43 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ccf41404 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 31 Jan 2025 12:55:40 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 31 Jan 2025 13:55:30 +0100 Subject: [PATCH 3/4] hash: provide generic wrappers to update hash contexts Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250131-b4-pks-hash-context-direct-v1-3-67a6d3f49d6e@pks.im> References: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> In-Reply-To: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano X-Mailer: b4 0.14.2 The hash context is supposed to be updated via the `git_hash_algo` structure, which contains a list of function pointers to update, clone or finalize a hashing context. This requires the callers to track which algorithm was used to initialize the context and continue to use the exact same algorithm. If they fail to do that correctly, it can happen that we start to access context state of one hash algorithm with functions of a different hash algorithm. The result would typically be a segfault, as could be seen e.g. in the patches part of 98422943f0 (Merge branch 'ps/weak-sha1-for-tail-sum-fix', 2025-01-01). The situation was significantly improved starting with 04292c3796 (hash.h: drop unsafe_ function variants, 2025-01-23) and its parent commits. These refactorings ensure that it is not possible to mix up safe and unsafe variants of the same hash algorithm anymore. But in theory, it is still possible to mix up different hash algorithms with each other, even though this is a lot less likely to happen. But still, we can do better: instead of asking the caller to remember the hash algorithm used to initialize a context, we can instead make the context itself remember which algorithm it has been initialized with. If we do so, callers can use a set of generic helpers to update the context and don't need to be aware of the hash algorithm at all anymore. Adapt the context initialization functions to store the hash algorithm in the hashing context and introduce these generic helpers. Callers will be adapted in the subsequent commit. Signed-off-by: Patrick Steinhardt --- hash.h | 21 +++++++++++++++++++++ object-file.c | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/hash.h b/hash.h index 42b52c6dae..4367acfec5 100644 --- a/hash.h +++ b/hash.h @@ -235,6 +235,7 @@ enum get_oid_result { /* A suitably aligned type for stack allocations of hash contexts. */ struct git_hash_ctx { + const struct git_hash_algo *algop; union { git_SHA_CTX sha1; git_SHA_CTX_unsafe sha1_unsafe; @@ -296,6 +297,26 @@ struct git_hash_algo { }; extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS]; +static inline void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) +{ + src->algop->clone_fn(dst, src); +} + +static inline void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len) +{ + ctx->algop->update_fn(ctx, in, len); +} + +static inline void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx) +{ + ctx->algop->final_fn(hash, ctx); +} + +static inline void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) +{ + ctx->algop->final_oid_fn(oid, ctx); +} + /* * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if * the name doesn't match a known algorithm. diff --git a/object-file.c b/object-file.c index 154bcfce78..b7f2af515f 100644 --- a/object-file.c +++ b/object-file.c @@ -88,11 +88,13 @@ static const struct object_id null_oid_sha256 = { static void git_hash_sha1_init(struct git_hash_ctx *ctx) { + ctx->algop = &hash_algos[GIT_HASH_SHA1]; git_SHA1_Init(&ctx->state.sha1); } static void git_hash_sha1_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { + dst->algop = src->algop; git_SHA1_Clone(&dst->state.sha1, &src->state.sha1); } @@ -115,11 +117,13 @@ static void git_hash_sha1_final_oid(struct object_id *oid, struct git_hash_ctx * static void git_hash_sha1_init_unsafe(struct git_hash_ctx *ctx) { + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA1]); git_SHA1_Init_unsafe(&ctx->state.sha1_unsafe); } static void git_hash_sha1_clone_unsafe(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { + dst->algop = src->algop; git_SHA1_Clone_unsafe(&dst->state.sha1_unsafe, &src->state.sha1_unsafe); } @@ -143,11 +147,13 @@ static void git_hash_sha1_final_oid_unsafe(struct object_id *oid, struct git_has static void git_hash_sha256_init(struct git_hash_ctx *ctx) { + ctx->algop = unsafe_hash_algo(&hash_algos[GIT_HASH_SHA256]); git_SHA256_Init(&ctx->state.sha256); } static void git_hash_sha256_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) { + dst->algop = src->algop; git_SHA256_Clone(&dst->state.sha256, &src->state.sha256); } From patchwork Fri Jan 31 12:55:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13955360 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAF071C3BF9 for ; Fri, 31 Jan 2025 12:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328148; cv=none; b=sRymLZxzaoPRkMn97pYJ3u/97PeMOX9i+MJbhgvh4dNdjT6/SMnoPmLpHryuy51vTu3ywNwvWhhhed6BynMx/6n7us0RQVzap17W1ZQ2C+hZHKOOxZEbR3qqLNry+FqtYUY4KZs+u/lVxvwcP7B4B32WAM+7JVAz7LRjPKnjYZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738328148; c=relaxed/simple; bh=MUmoo9D81s+fpxwV20tsjVQatVHvEQBI0/L/uN7u0hs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r3rSw3nEfQNgXKwkTyKNnwb0qL1y7894/lplh8pA3+X/c9ByTcWjwmRDi1WUlvZjsMkA+ajcj59oghoM2vpuq/kcSQBrQ6VWATfjYJIabY/cp3yKftFoxeCb5u2ah3WeTsjzuEAv2CEh5s0H88HK60oLKfxYJ4uLHqZrMFyTqjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=ei38dLfv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OApF9OPj; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="ei38dLfv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OApF9OPj" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 038BF1140198; Fri, 31 Jan 2025 07:55:45 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Fri, 31 Jan 2025 07:55:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1738328144; x=1738414544; bh=EKb6EBgbHdoOYXDWWXZ9hP71nn6G4ttmlGyvxA19wlY=; b= ei38dLfvOVJbRNeu7MP8ibaisBJatVJlrhrZGVoZdP9D1rw+67+b/ATr67a5YVty r7NbX0LBSpkM6cZDsUj7kWfittdH8pPFMmcLYYBuDxwhFei5DYIMpvpJTGtyxB9n SzT/LrkFuzEjWVeGRoZBzmGXKIfdHnegvAo2q0ge/GoCicGnIgchUe4+u0PbCe1H /RT5H+tuNcOcWVLWvRYVuY3ncvZaVKtjRYo77Py1Q4/LfS5nfFCdACRH4H+vS0S0 lyvsQcG8V9bdvgrfWZJFqISdi6RcwtId3RTuoaChnpfWY/RbtOka+oN2LIoVXrWv +Rr/r46o/WCuPcZN37CWuQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738328144; x= 1738414544; bh=EKb6EBgbHdoOYXDWWXZ9hP71nn6G4ttmlGyvxA19wlY=; b=O ApF9OPjhknpfkc3Y08TiuP6TJ5e8Jt8qdx6JJp0FZsp57vGVUITVahIupl0ZlrnY jpXoxQAv+khx0UXYDX//XdnmmIeIba7CRpwJGWxaxhpmQwVbL+5Eesyzmolm7CAF 4kKkkUP/YG8UNPYRvhBn0MwDZm0LRwYzLRG39/occlvK5tsxhAK3jcfnqJhYDiGx 99/jF1eCYTYYAS1w4+FT7HLQEiwPDyrRG1jlpGER9b4h9HojKjddkwOUsAFnw09a +b/DAj8bUUunLoHaonPnIDFqd+DfaTcfLTTYdkJ/WN/EN+AZv/5ANS09Se8B3p0j 4z/WndoAU4vezaT5gJ3Yg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdekkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithhs thgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepmhgvsehtthgrhihlohhrrhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 31 Jan 2025 07:55:43 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 32480738 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 31 Jan 2025 12:55:41 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 31 Jan 2025 13:55:31 +0100 Subject: [PATCH 4/4] global: adapt callers to use generic hash context helpers Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250131-b4-pks-hash-context-direct-v1-4-67a6d3f49d6e@pks.im> References: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> In-Reply-To: <20250131-b4-pks-hash-context-direct-v1-0-67a6d3f49d6e@pks.im> To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano X-Mailer: b4 0.14.2 Adapt callers to use generic hash context helpers instead of using the hash algorithm to update them. This makes the callsites easier to reason about and removes the possibility that the wrong hash algorithm is used to update the hash context's state. And as a nice side effect this also gets rid of a bunch of users of `the_hash_algo`. Signed-off-by: Patrick Steinhardt --- builtin/fast-import.c | 12 ++++++------ builtin/index-pack.c | 13 ++++++------- builtin/patch-id.c | 12 ++++++------ builtin/receive-pack.c | 16 ++++++++-------- builtin/unpack-objects.c | 9 ++++----- bulk-checkin.c | 6 +++--- csum-file.c | 14 +++++++------- diff.c | 24 ++++++++++++------------ http-push.c | 4 ++-- http.c | 6 +++--- object-file.c | 32 +++++++++++++++----------------- pack-check.c | 4 ++-- pack-write.c | 14 +++++++------- read-cache.c | 14 +++++++------- rerere.c | 14 +++++++------- t/helper/test-hash-speed.c | 4 ++-- t/helper/test-hash.c | 4 ++-- t/unit-tests/u-hash.c | 4 ++-- trace2/tr2_sid.c | 4 ++-- 19 files changed, 103 insertions(+), 107 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 9862704c62..91f88c467f 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -959,9 +959,9 @@ static int store_object( hdrlen = format_object_header((char *)hdr, sizeof(hdr), type, dat->len); the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, hdrlen); - the_hash_algo->update_fn(&c, dat->buf, dat->len); - the_hash_algo->final_oid_fn(&oid, &c); + git_hash_update(&c, hdr, hdrlen); + git_hash_update(&c, dat->buf, dat->len); + git_hash_final_oid(&oid, &c); if (oidout) oidcpy(oidout, &oid); @@ -1113,7 +1113,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) hdrlen = format_object_header((char *)out_buf, out_sz, OBJ_BLOB, len); the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, out_buf, hdrlen); + git_hash_update(&c, out_buf, hdrlen); crc32_begin(pack_file); @@ -1131,7 +1131,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) if (!n && feof(stdin)) die("EOF in data (%" PRIuMAX " bytes remaining)", len); - the_hash_algo->update_fn(&c, in_buf, n); + git_hash_update(&c, in_buf, n); s.next_in = in_buf; s.avail_in = n; len -= n; @@ -1157,7 +1157,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) } } git_deflate_end(&s); - the_hash_algo->final_oid_fn(&oid, &c); + git_hash_final_oid(&oid, &c); if (oidout) oidcpy(oidout, &oid); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 40e49868b1..5ee13661a1 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -301,7 +301,7 @@ static void flush(void) if (input_offset) { if (output_fd >= 0) write_or_die(output_fd, input_buffer, input_offset); - the_hash_algo->update_fn(&input_ctx, input_buffer, input_offset); + git_hash_update(&input_ctx, input_buffer, input_offset); memmove(input_buffer, input_buffer + input_offset, input_len); input_offset = 0; } @@ -482,7 +482,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size, if (!is_delta_type(type)) { hdrlen = format_object_header(hdr, sizeof(hdr), type, size); the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, hdrlen); + git_hash_update(&c, hdr, hdrlen); } else oid = NULL; if (type == OBJ_BLOB && size > big_file_threshold) @@ -502,7 +502,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size, status = git_inflate(&stream, 0); use(input_len - stream.avail_in); if (oid) - the_hash_algo->update_fn(&c, last_out, stream.next_out - last_out); + git_hash_update(&c, last_out, stream.next_out - last_out); if (buf == fixed_buf) { stream.next_out = buf; stream.avail_out = sizeof(fixed_buf); @@ -512,7 +512,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size, bad_object(offset, _("inflate returned %d"), status); git_inflate_end(&stream); if (oid) - the_hash_algo->final_oid_fn(oid, &c); + git_hash_final_oid(oid, &c); return buf == fixed_buf ? NULL : buf; } @@ -1286,9 +1286,8 @@ static void parse_pack_objects(unsigned char *hash) /* Check pack integrity */ flush(); - the_hash_algo->init_fn(&tmp_ctx); - the_hash_algo->clone_fn(&tmp_ctx, &input_ctx); - the_hash_algo->final_fn(hash, &tmp_ctx); + git_hash_clone(&tmp_ctx, &input_ctx); + git_hash_final(hash, &tmp_ctx); if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo)) die(_("pack is corrupted (SHA1 mismatch)")); use(the_hash_algo->rawsz); diff --git a/builtin/patch-id.c b/builtin/patch-id.c index 923ff2bb77..cdef2ec10a 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -85,7 +85,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu !skip_prefix(line, "From ", &p) && starts_with(line, "\\ ") && 12 < strlen(line)) { if (verbatim) - the_hash_algo->update_fn(&ctx, line, strlen(line)); + git_hash_update(&ctx, line, strlen(line)); continue; } @@ -104,10 +104,10 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu starts_with(line, "Binary files")) { diff_is_binary = 1; before = 0; - the_hash_algo->update_fn(&ctx, pre_oid_str, - strlen(pre_oid_str)); - the_hash_algo->update_fn(&ctx, post_oid_str, - strlen(post_oid_str)); + git_hash_update(&ctx, pre_oid_str, + strlen(pre_oid_str)); + git_hash_update(&ctx, post_oid_str, + strlen(post_oid_str)); if (stable) flush_one_hunk(result, &ctx); continue; @@ -165,7 +165,7 @@ static size_t get_one_patchid(struct object_id *next_oid, struct object_id *resu /* Add line to hash algo (possibly removing whitespace) */ len = verbatim ? strlen(line) : remove_space(line); patchlen += len; - the_hash_algo->update_fn(&ctx, line, len); + git_hash_update(&ctx, line, len); } if (!found_next) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d2360c453c..cc358600ca 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -572,8 +572,8 @@ static void hmac_hash(unsigned char *out, memset(key, '\0', GIT_MAX_BLKSZ); if (the_hash_algo->blksz < key_len) { the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, key_in, key_len); - the_hash_algo->final_fn(key, &ctx); + git_hash_update(&ctx, key_in, key_len); + git_hash_final(key, &ctx); } else { memcpy(key, key_in, key_len); } @@ -586,15 +586,15 @@ static void hmac_hash(unsigned char *out, /* RFC 2104 2. (3) & (4) */ the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, k_ipad, sizeof(k_ipad)); - the_hash_algo->update_fn(&ctx, text, text_len); - the_hash_algo->final_fn(out, &ctx); + git_hash_update(&ctx, k_ipad, sizeof(k_ipad)); + git_hash_update(&ctx, text, text_len); + git_hash_final(out, &ctx); /* RFC 2104 2. (6) & (7) */ the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, k_opad, sizeof(k_opad)); - the_hash_algo->update_fn(&ctx, out, the_hash_algo->rawsz); - the_hash_algo->final_fn(out, &ctx); + git_hash_update(&ctx, k_opad, sizeof(k_opad)); + git_hash_update(&ctx, out, the_hash_algo->rawsz); + git_hash_final(out, &ctx); } static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp) diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index d72885510c..8383bcf404 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -70,7 +70,7 @@ static void *fill(int min) if (min > sizeof(buffer)) die("cannot fill %d bytes", min); if (offset) { - the_hash_algo->update_fn(&ctx, buffer, offset); + git_hash_update(&ctx, buffer, offset); memmove(buffer, buffer + offset, len); offset = 0; } @@ -667,10 +667,9 @@ int cmd_unpack_objects(int argc, } the_hash_algo->init_fn(&ctx); unpack_all(); - the_hash_algo->update_fn(&ctx, buffer, offset); - the_hash_algo->init_fn(&tmp_ctx); - the_hash_algo->clone_fn(&tmp_ctx, &ctx); - the_hash_algo->final_oid_fn(&oid, &tmp_ctx); + git_hash_update(&ctx, buffer, offset); + git_hash_clone(&tmp_ctx, &ctx); + git_hash_final_oid(&oid, &tmp_ctx); if (strict) { write_rest(); if (fsck_finish(&fsck_options)) diff --git a/bulk-checkin.c b/bulk-checkin.c index db1958b525..0f40c5dac9 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -194,7 +194,7 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state, if (rsize < hsize) hsize = rsize; if (hsize) - the_hash_algo->update_fn(ctx, ibuf, hsize); + git_hash_update(ctx, ibuf, hsize); *already_hashed_to = offset; } s.next_in = ibuf; @@ -271,7 +271,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state, header_len = format_object_header((char *)obuf, sizeof(obuf), OBJ_BLOB, size); the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, obuf, header_len); + git_hash_update(&ctx, obuf, header_len); /* Note: idx is non-NULL when we are writing */ if ((flags & HASH_WRITE_OBJECT) != 0) { @@ -306,7 +306,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state, if (lseek(fd, seekback, SEEK_SET) == (off_t) -1) return error("cannot seek back"); } - the_hash_algo->final_oid_fn(result_oid, &ctx); + git_hash_final_oid(result_oid, &ctx); if (!idx) return 0; diff --git a/csum-file.c b/csum-file.c index 3383515669..5c54b3a0b9 100644 --- a/csum-file.c +++ b/csum-file.c @@ -50,7 +50,7 @@ void hashflush(struct hashfile *f) if (offset) { if (!f->skip_hash) - f->algop->update_fn(&f->ctx, f->buffer, offset); + git_hash_update(&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, f->algop); else - f->algop->final_fn(f->buffer, &f->ctx); + git_hash_final(f->buffer, &f->ctx); if (result) hashcpy(result, f->buffer, f->algop); @@ -128,7 +128,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count) * f->offset is necessarily zero. */ if (!f->skip_hash) - f->algop->update_fn(&f->ctx, buf, nr); + git_hash_update(&f->ctx, buf, nr); flush(f, buf, nr); } else { /* @@ -217,7 +217,7 @@ void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpo { hashflush(f); checkpoint->offset = f->total; - f->algop->clone_fn(&checkpoint->ctx, &f->ctx); + git_hash_clone(&checkpoint->ctx, &f->ctx); } int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint) @@ -228,7 +228,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint lseek(f->fd, offset, SEEK_SET) != offset) return -1; f->total = offset; - f->algop->clone_fn(&f->ctx, &checkpoint->ctx); + git_hash_clone(&f->ctx, &checkpoint->ctx); f->offset = 0; /* hashflush() was called in checkpoint */ return 0; } @@ -256,8 +256,8 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len) return 0; /* say "too short"? */ algop->init_fn(&ctx); - algop->update_fn(&ctx, data, data_len); - algop->final_fn(got, &ctx); + git_hash_update(&ctx, data, data_len); + git_hash_final(got, &ctx); return hasheq(got, data + data_len, algop); } diff --git a/diff.c b/diff.c index 7f570ebdf9..019fb893a7 100644 --- a/diff.c +++ b/diff.c @@ -6415,7 +6415,7 @@ void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx) unsigned short carry = 0; int i; - the_hash_algo->final_fn(hash, ctx); + git_hash_final(hash, ctx); the_hash_algo->init_fn(ctx); /* 20-byte sum, with carry */ for (i = 0; i < the_hash_algo->rawsz; ++i) { @@ -6434,14 +6434,14 @@ static int patch_id_consume(void *priv, char *line, unsigned long len) return 0; new_len = remove_space(line, len); - the_hash_algo->update_fn(data->ctx, line, new_len); + git_hash_update(data->ctx, line, new_len); data->patchlen += new_len; return 0; } static void patch_id_add_string(struct git_hash_ctx *ctx, const char *str) { - the_hash_algo->update_fn(ctx, str, strlen(str)); + git_hash_update(ctx, str, strlen(str)); } static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode) @@ -6449,7 +6449,7 @@ static void patch_id_add_mode(struct git_hash_ctx *ctx, unsigned mode) /* large enough for 2^32 in octal */ char buf[12]; int len = xsnprintf(buf, sizeof(buf), "%06o", mode); - the_hash_algo->update_fn(ctx, buf, len); + git_hash_update(ctx, buf, len); } /* returns 0 upon success, and writes result into oid */ @@ -6493,9 +6493,9 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid len2 = remove_space(p->two->path, strlen(p->two->path)); patch_id_add_string(&ctx, "diff--git"); patch_id_add_string(&ctx, "a/"); - the_hash_algo->update_fn(&ctx, p->one->path, len1); + git_hash_update(&ctx, p->one->path, len1); patch_id_add_string(&ctx, "b/"); - the_hash_algo->update_fn(&ctx, p->two->path, len2); + git_hash_update(&ctx, p->two->path, len2); if (p->one->mode == 0) { patch_id_add_string(&ctx, "newfilemode"); @@ -6514,24 +6514,24 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid /* don't do anything since we're only populating header info */ } else if (diff_filespec_is_binary(options->repo, p->one) || diff_filespec_is_binary(options->repo, p->two)) { - the_hash_algo->update_fn(&ctx, oid_to_hex(&p->one->oid), + git_hash_update(&ctx, oid_to_hex(&p->one->oid), the_hash_algo->hexsz); - the_hash_algo->update_fn(&ctx, oid_to_hex(&p->two->oid), + git_hash_update(&ctx, oid_to_hex(&p->two->oid), the_hash_algo->hexsz); } else { if (p->one->mode == 0) { patch_id_add_string(&ctx, "---/dev/null"); patch_id_add_string(&ctx, "+++b/"); - the_hash_algo->update_fn(&ctx, p->two->path, len2); + git_hash_update(&ctx, p->two->path, len2); } else if (p->two->mode == 0) { patch_id_add_string(&ctx, "---a/"); - the_hash_algo->update_fn(&ctx, p->one->path, len1); + git_hash_update(&ctx, p->one->path, len1); patch_id_add_string(&ctx, "+++/dev/null"); } else { patch_id_add_string(&ctx, "---a/"); - the_hash_algo->update_fn(&ctx, p->one->path, len1); + git_hash_update(&ctx, p->one->path, len1); patch_id_add_string(&ctx, "+++b/"); - the_hash_algo->update_fn(&ctx, p->two->path, len2); + git_hash_update(&ctx, p->two->path, len2); } if (fill_mmfile(options->repo, &mf1, p->one) < 0 || diff --git a/http-push.c b/http-push.c index 36867af2f8..1b030d96f4 100644 --- a/http-push.c +++ b/http-push.c @@ -774,8 +774,8 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) lock->token = xstrdup(ctx->cdata); the_hash_algo->init_fn(&hash_ctx); - the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token)); - the_hash_algo->final_fn(lock_token_hash, &hash_ctx); + git_hash_update(&hash_ctx, lock->token, strlen(lock->token)); + git_hash_final(lock_token_hash, &hash_ctx); lock->tmpfile_suffix[0] = '_'; memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz); diff --git a/http.c b/http.c index f08b2ae474..f4504133e8 100644 --- a/http.c +++ b/http.c @@ -2597,8 +2597,8 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb, freq->stream.next_out = expn; freq->stream.avail_out = sizeof(expn); freq->zret = git_inflate(&freq->stream, Z_SYNC_FLUSH); - the_hash_algo->update_fn(&freq->c, expn, - sizeof(expn) - freq->stream.avail_out); + git_hash_update(&freq->c, expn, + sizeof(expn) - freq->stream.avail_out); } while (freq->stream.avail_in && freq->zret == Z_OK); return nmemb; } @@ -2763,7 +2763,7 @@ int finish_http_object_request(struct http_object_request *freq) return -1; } - the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c); + git_hash_final_oid(&freq->real_oid, &freq->c); if (freq->zret != Z_STREAM_END) { unlink_or_warn(freq->tmpfile.buf); return -1; diff --git a/object-file.c b/object-file.c index b7f2af515f..00c3a4b910 100644 --- a/object-file.c +++ b/object-file.c @@ -1199,7 +1199,7 @@ int stream_object_signature(struct repository *r, const struct object_id *oid) /* Sha1.. */ r->hash_algo->init_fn(&c); - r->hash_algo->update_fn(&c, hdr, hdrlen); + git_hash_update(&c, hdr, hdrlen); for (;;) { char buf[1024 * 16]; ssize_t readlen = read_istream(st, buf, sizeof(buf)); @@ -1210,9 +1210,9 @@ int stream_object_signature(struct repository *r, const struct object_id *oid) } if (!readlen) break; - r->hash_algo->update_fn(&c, buf, readlen); + git_hash_update(&c, buf, readlen); } - r->hash_algo->final_oid_fn(&real_oid, &c); + git_hash_final_oid(&real_oid, &c); close_istream(st); return !oideq(oid, &real_oid) ? -1 : 0; } @@ -1957,9 +1957,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c char *hdr, int *hdrlen) { algo->init_fn(c); - algo->update_fn(c, hdr, *hdrlen); - algo->update_fn(c, buf, len); - algo->final_oid_fn(oid, c); + git_hash_update(c, hdr, *hdrlen); + git_hash_update(c, buf, len); + git_hash_final_oid(oid, c); } static void write_object_file_prepare(const struct git_hash_algo *algo, @@ -2246,9 +2246,9 @@ static int start_loose_object_common(struct strbuf *tmp_file, stream->avail_in = hdrlen; while (git_deflate(stream, 0) == Z_OK) ; /* nothing */ - algo->update_fn(c, hdr, hdrlen); + git_hash_update(c, hdr, hdrlen); if (compat && compat_c) - compat->update_fn(compat_c, hdr, hdrlen); + git_hash_update(compat_c, hdr, hdrlen); return fd; } @@ -2264,14 +2264,13 @@ static int write_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx const size_t compressed_len) { struct repository *repo = the_repository; - const struct git_hash_algo *algo = repo->hash_algo; const struct git_hash_algo *compat = repo->compat_hash_algo; int ret; ret = git_deflate(stream, flush ? Z_FINISH : 0); - algo->update_fn(c, in0, stream->next_in - in0); + git_hash_update(c, in0, stream->next_in - in0); if (compat && compat_c) - compat->update_fn(compat_c, in0, stream->next_in - in0); + git_hash_update(compat_c, in0, stream->next_in - in0); if (write_in_full(fd, compressed, stream->next_out - compressed) < 0) die_errno(_("unable to write loose object file")); stream->next_out = compressed; @@ -2291,16 +2290,15 @@ static int end_loose_object_common(struct git_hash_ctx *c, struct git_hash_ctx * struct object_id *compat_oid) { struct repository *repo = the_repository; - const struct git_hash_algo *algo = repo->hash_algo; const struct git_hash_algo *compat = repo->compat_hash_algo; int ret; ret = git_deflate_end_gently(stream); if (ret != Z_OK) return ret; - algo->final_oid_fn(oid, c); + git_hash_final_oid(oid, c); if (compat && compat_c) - compat->final_oid_fn(compat_oid, compat_c); + git_hash_final_oid(compat_oid, compat_c); return Z_OK; } @@ -3059,7 +3057,7 @@ static int check_stream_oid(git_zstream *stream, int status = Z_OK; the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, stream->total_out); + git_hash_update(&c, hdr, stream->total_out); /* * We already read some bytes into hdr, but the ones up to the NUL @@ -3079,7 +3077,7 @@ static int check_stream_oid(git_zstream *stream, if (size - total_read < stream->avail_out) stream->avail_out = size - total_read; status = git_inflate(stream, Z_FINISH); - the_hash_algo->update_fn(&c, buf, stream->next_out - buf); + git_hash_update(&c, buf, stream->next_out - buf); total_read += stream->next_out - buf; } git_inflate_end(stream); @@ -3094,7 +3092,7 @@ static int check_stream_oid(git_zstream *stream, return -1; } - the_hash_algo->final_oid_fn(&real_oid, &c); + git_hash_final_oid(&real_oid, &c); if (!oideq(expected_oid, &real_oid)) { error(_("hash mismatch for %s (expected %s)"), path, oid_to_hex(expected_oid)); diff --git a/pack-check.c b/pack-check.c index f20209fccb..d0aeb5ec41 100644 --- a/pack-check.c +++ b/pack-check.c @@ -77,9 +77,9 @@ static int verify_packfile(struct repository *r, pack_sig_ofs = p->pack_size - r->hash_algo->rawsz; if (offset > pack_sig_ofs) remaining -= (unsigned int)(offset - pack_sig_ofs); - r->hash_algo->update_fn(&ctx, in, remaining); + git_hash_update(&ctx, in, remaining); } while (offset < pack_sig_ofs); - r->hash_algo->final_fn(hash, &ctx); + git_hash_final(hash, &ctx); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); if (!hasheq(hash, pack_sig, the_repository->hash_algo)) err = error("%s pack checksum mismatch", diff --git a/pack-write.c b/pack-write.c index 9004d1d095..cfcb7297b8 100644 --- a/pack-write.c +++ b/pack-write.c @@ -406,9 +406,9 @@ void fixup_pack_header_footer(int pack_fd, pack_name); if (lseek(pack_fd, 0, SEEK_SET) != 0) die_errno("Failed seeking to start of '%s'", pack_name); - the_hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr)); + git_hash_update(&old_hash_ctx, &hdr, sizeof(hdr)); hdr.hdr_entries = htonl(object_count); - the_hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr)); + git_hash_update(&new_hash_ctx, &hdr, sizeof(hdr)); write_or_die(pack_fd, &hdr, sizeof(hdr)); partial_pack_offset -= sizeof(hdr); @@ -423,7 +423,7 @@ void fixup_pack_header_footer(int pack_fd, break; if (n < 0) die_errno("Failed to checksum '%s'", pack_name); - the_hash_algo->update_fn(&new_hash_ctx, buf, n); + git_hash_update(&new_hash_ctx, buf, n); aligned_sz -= n; if (!aligned_sz) @@ -432,11 +432,11 @@ void fixup_pack_header_footer(int pack_fd, if (!partial_pack_hash) continue; - the_hash_algo->update_fn(&old_hash_ctx, buf, n); + git_hash_update(&old_hash_ctx, buf, n); partial_pack_offset -= n; if (partial_pack_offset == 0) { unsigned char hash[GIT_MAX_RAWSZ]; - the_hash_algo->final_fn(hash, &old_hash_ctx); + git_hash_final(hash, &old_hash_ctx); if (!hasheq(hash, partial_pack_hash, the_repository->hash_algo)) die("Unexpected checksum for %s " @@ -454,8 +454,8 @@ void fixup_pack_header_footer(int pack_fd, free(buf); if (partial_pack_hash) - the_hash_algo->final_fn(partial_pack_hash, &old_hash_ctx); - the_hash_algo->final_fn(new_pack_hash, &new_hash_ctx); + git_hash_final(partial_pack_hash, &old_hash_ctx); + git_hash_final(new_pack_hash, &new_hash_ctx); write_or_die(pack_fd, new_pack_hash, the_hash_algo->rawsz); fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name); } diff --git a/read-cache.c b/read-cache.c index 5e765d9af5..7ef01c3806 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1739,8 +1739,8 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) return 0; the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz); - the_hash_algo->final_fn(hash, &c); + git_hash_update(&c, hdr, size - the_hash_algo->rawsz); + git_hash_final(hash, &c); if (!hasheq(hash, start, the_repository->hash_algo)) return error(_("bad index file sha1 signature")); return 0; @@ -2576,8 +2576,8 @@ static int write_index_ext_header(struct hashfile *f, if (eoie_f) { ext = htonl(ext); sz = htonl(sz); - the_hash_algo->update_fn(eoie_f, &ext, sizeof(ext)); - the_hash_algo->update_fn(eoie_f, &sz, sizeof(sz)); + git_hash_update(eoie_f, &ext, sizeof(ext)); + git_hash_update(eoie_f, &sz, sizeof(sz)); } return 0; } @@ -3634,12 +3634,12 @@ static size_t read_eoie_extension(const char *mmap, size_t mmap_size) if (src_offset + 8 + extsize < src_offset) return 0; - the_hash_algo->update_fn(&c, mmap + src_offset, 8); + git_hash_update(&c, mmap + src_offset, 8); src_offset += 8; src_offset += extsize; } - the_hash_algo->final_fn(hash, &c); + git_hash_final(hash, &c); if (!hasheq(hash, (const unsigned char *)index, the_repository->hash_algo)) return 0; @@ -3660,7 +3660,7 @@ static void write_eoie_extension(struct strbuf *sb, struct git_hash_ctx *eoie_co strbuf_add(sb, &buffer, sizeof(uint32_t)); /* hash */ - the_hash_algo->final_fn(hash, eoie_context); + git_hash_final(hash, eoie_context); strbuf_add(sb, hash, the_hash_algo->rawsz); } diff --git a/rerere.c b/rerere.c index 5ff9624b57..c42cee618b 100644 --- a/rerere.c +++ b/rerere.c @@ -396,12 +396,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, strbuf_addbuf(out, &two); rerere_strbuf_putconflict(out, '>', marker_size); if (ctx) { - the_hash_algo->update_fn(ctx, one.buf ? - one.buf : "", - one.len + 1); - the_hash_algo->update_fn(ctx, two.buf ? - two.buf : "", - two.len + 1); + git_hash_update(ctx, one.buf ? + one.buf : "", + one.len + 1); + git_hash_update(ctx, two.buf ? + two.buf : "", + two.len + 1); } break; } else if (hunk == RR_SIDE_1) @@ -453,7 +453,7 @@ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_siz strbuf_release(&out); if (hash) - the_hash_algo->final_fn(hash, &ctx); + git_hash_final(hash, &ctx); return has_conflicts; } diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c index 803f41c89d..fbf67fe6bd 100644 --- a/t/helper/test-hash-speed.c +++ b/t/helper/test-hash-speed.c @@ -6,8 +6,8 @@ static inline void compute_hash(const struct git_hash_algo *algo, struct git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len) { algo->init_fn(ctx); - algo->update_fn(ctx, p, len); - algo->final_fn(final, ctx); + git_hash_update(ctx, p, len); + git_hash_final(final, ctx); } int cmd__hash_speed(int ac, const char **av) diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index f9a3db487a..f0ee61c8b4 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -48,9 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe) } if (this_sz == 0) break; - algop->update_fn(&ctx, buffer, this_sz); + git_hash_update(&ctx, buffer, this_sz); } - algop->final_fn(hash, &ctx); + git_hash_final(hash, &ctx); if (binary) fwrite(hash, 1, algop->rawsz, stdout); diff --git a/t/unit-tests/u-hash.c b/t/unit-tests/u-hash.c index 05204e7b6c..bd4ac6a6e1 100644 --- a/t/unit-tests/u-hash.c +++ b/t/unit-tests/u-hash.c @@ -13,8 +13,8 @@ static void check_hash_data(const void *data, size_t data_length, const struct git_hash_algo *algop = &hash_algos[i]; algop->init_fn(&ctx); - algop->update_fn(&ctx, data, data_length); - algop->final_fn(hash, &ctx); + git_hash_update(&ctx, data, data_length); + git_hash_final(hash, &ctx); cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]); } diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c index c42696ef52..1c1d27b0ee 100644 --- a/trace2/tr2_sid.c +++ b/trace2/tr2_sid.c @@ -46,8 +46,8 @@ static void tr2_sid_append_my_sid_component(void) strbuf_add(&tr2sid_buf, "Localhost", 9); else { algo->init_fn(&ctx); - algo->update_fn(&ctx, hostname, strlen(hostname)); - algo->final_fn(hash, &ctx); + git_hash_update(&ctx, hostname, strlen(hostname)); + git_hash_final(hash, &ctx); hash_to_hex_algop_r(hex, hash, algo); strbuf_addch(&tr2sid_buf, 'H'); strbuf_add(&tr2sid_buf, hex, 8);