From 0a18868475fd6fc80c484c5a4ebdcc5cfc694788 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Wed, 25 Jan 2023 21:07:15 +0100 Subject: [PATCH] Upgrade blst & remove sha256 patch (#85) --- .gitmodules | 1 - bindings/csharp/Makefile | 6 +----- blst | 2 +- blst_sha.patch | 31 ------------------------------- src/Makefile | 3 --- src/c_kzg_4844.c | 28 +++------------------------- 6 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 blst_sha.patch diff --git a/.gitmodules b/.gitmodules index 6f7ff08..bed358c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,3 @@ [submodule "blst"] path = blst url = https://github.com/supranational/blst - ignore = dirty # because we apply a patch diff --git a/bindings/csharp/Makefile b/bindings/csharp/Makefile index 1364efa..b94e455 100644 --- a/bindings/csharp/Makefile +++ b/bindings/csharp/Makefile @@ -27,11 +27,7 @@ CLANG_FLAGS += -DFIELD_ELEMENTS_PER_BLOB=$(FIELD_ELEMENTS_PER_BLOB) TARGETS=ckzg.c ../../src/c_kzg_4844.c ../../blst/$(BLST_OBJ) .blst: - cd ../../blst &&\ - git apply ../blst_sha.patch &&\ - $(BLST_BUILDSCRIPT) &&\ - git apply -R ../blst_sha.patch &&\ - cd ../bindings/csharp + cd ../../blst && $(BLST_BUILDSCRIPT) .ckzg: $(CLANG_EXECUTABLE) -O -Wall -shared $(CLANG_FLAGS) ${addprefix -I,${INCLUDE_DIRS}} -o $(CKZG_LIBRARY_PATH) $(TARGETS) diff --git a/blst b/blst index 6382d67..ca03e11 160000 --- a/blst +++ b/blst @@ -1 +1 @@ -Subproject commit 6382d67c72119d563975892ed49ba32e92d3d0da +Subproject commit ca03e11a3ff24d818ae390a1e7f435f15bf72aee diff --git a/blst_sha.patch b/blst_sha.patch deleted file mode 100644 index a4a975c..0000000 --- a/blst_sha.patch +++ /dev/null @@ -1,31 +0,0 @@ -diff --git a/src/sha256.h b/src/sha256.h -index 77ddb6d..67ccf7a 100644 ---- a/src/sha256.h -+++ b/src/sha256.h -@@ -49,7 +49,7 @@ static void sha256_init_h(unsigned int h[8]) - h[7] = 0x5be0cd19U; - } - --static void sha256_init(SHA256_CTX *ctx) -+void sha256_init(SHA256_CTX *ctx) - { - sha256_init_h(ctx->h); - ctx->N = 0; -@@ -57,7 +57,7 @@ static void sha256_init(SHA256_CTX *ctx) - ctx->off = 0; - } - --static void sha256_update(SHA256_CTX *ctx, const void *_inp, size_t len) -+void sha256_update(SHA256_CTX *ctx, const void *_inp, size_t len) - { - size_t n; - const unsigned char *inp = _inp; -@@ -116,7 +116,7 @@ static void sha256_emit(unsigned char md[32], const unsigned int h[8]) - } - #endif - --static void sha256_final(unsigned char md[32], SHA256_CTX *ctx) -+void sha256_final(unsigned char md[32], SHA256_CTX *ctx) - { - unsigned long long bits = ctx->N * 8; - size_t n = ctx->off; diff --git a/src/Makefile b/src/Makefile index 527dd8f..4512e0c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,11 +16,8 @@ all: c_kzg_4844.o lib c_kzg_4844.o: c_kzg_4844.c Makefile ${CLANG_EXECUTABLE} -Wall -I$(INCLUDE_DIRS) -DFIELD_ELEMENTS_PER_BLOB=$(FIELD_ELEMENTS_PER_BLOB) $(CFLAGS) -c $< -# Will fail with "patch does not apply" if it has already been patched. -# Safe to ignore. blst: cd ../blst; \ - git apply < ../blst_sha.patch; \ ${BLST_BUILD_SCRIPT} && \ cp libblst.a ../lib && \ cp bindings/*.h ../inc diff --git a/src/c_kzg_4844.c b/src/c_kzg_4844.c index 4319958..6291f96 100644 --- a/src/c_kzg_4844.c +++ b/src/c_kzg_4844.c @@ -527,28 +527,6 @@ static void bytes_of_uint64(uint8_t out[8], uint64_t n) { } } -/////////////////////////////////////////////////////////////////////////////// -// SHA-256 Hash Functions -/////////////////////////////////////////////////////////////////////////////// - -typedef struct { - unsigned int h[8]; - unsigned long long N; - unsigned char buf[64]; - size_t off; -} SHA256_CTX; - -void sha256_init(SHA256_CTX *ctx); -void sha256_update(SHA256_CTX *ctx, const void *_inp, size_t len); -void sha256_final(unsigned char md[32], SHA256_CTX *ctx); - -static void hash(uint8_t md[32], const uint8_t *input, size_t n) { - SHA256_CTX ctx; - sha256_init(&ctx); - sha256_update(&ctx, input, n); - sha256_final(md, &ctx); -} - /////////////////////////////////////////////////////////////////////////////// // Bit-reversal Permutation Functions /////////////////////////////////////////////////////////////////////////////// @@ -724,7 +702,7 @@ static C_KZG_RET compute_challenges(fr_t *eval_challenge_out, fr_t *r_powers_out /* Now let's create challenges! */ uint8_t hashed_data[32] = {0}; - hash(hashed_data, bytes, nb); + blst_sha256(hashed_data, bytes, nb); /* We will use hash_input in the computation of both challenges */ uint8_t hash_input[33]; @@ -733,7 +711,7 @@ static C_KZG_RET compute_challenges(fr_t *eval_challenge_out, fr_t *r_powers_out Bytes32 r_bytes; memcpy(hash_input, hashed_data, 32); hash_input[32] = 0x0; - hash(r_bytes.bytes, hash_input, 33); + blst_sha256(r_bytes.bytes, hash_input, 33); /* Compute r_powers */ fr_t r; @@ -743,7 +721,7 @@ static C_KZG_RET compute_challenges(fr_t *eval_challenge_out, fr_t *r_powers_out /* Compute eval_challenge */ Bytes32 eval_challenge; hash_input[32] = 0x1; - hash(eval_challenge.bytes, hash_input, 33); + blst_sha256(eval_challenge.bytes, hash_input, 33); hash_to_bls_field(eval_challenge_out, &eval_challenge); free(bytes);