From d25b686e4182c2c64e45016c05db707ed7b50f9a Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Mon, 15 Apr 2024 20:52:35 -0400 Subject: [PATCH 1/3] bet --- export_test.go | 4 ++-- hash.go | 6 +++--- sha256_1_generic.go | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/export_test.go b/export_test.go index 59f2edf..7b44c93 100644 --- a/export_test.go +++ b/export_test.go @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2021 Prysmatic Labs +# Copyright (c) 2021 Prysmatic Labs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,4 +25,4 @@ package gohashtree // Export internal functions for testing. -var Sha256_1_generic = sha256_1_generic +var Sha256_1_generic = sha256_1_generic[[32]byte, [32]byte] diff --git a/hash.go b/hash.go index b9675e4..b4927d2 100644 --- a/hash.go +++ b/hash.go @@ -28,11 +28,11 @@ import ( "unsafe" ) -func _hash(digests *byte, p [][32]byte, count uint32) +func _hash[B ~[32]byte](digests *byte, p []B, count uint32) // Hash hashes the chunks two at the time and outputs the digests on the first // argument. It does check for lengths on the inputs. -func Hash(digests [][32]byte, chunks [][32]byte) error { +func Hash[D, C ~[32]byte](digests []D, chunks []C) error { if len(chunks) == 0 { return nil } @@ -52,7 +52,7 @@ func Hash(digests [][32]byte, chunks [][32]byte) error { } // HashChunks is the same as Hash, but does not do error checking on the lengths of the slices -func HashChunks(digests [][32]byte, chunks [][32]byte) { +func HashChunks[D, C ~[32]byte](digests []D, chunks []C) { if supportedCPU { _hash(&digests[0][0], chunks, uint32(len(chunks)/2)) } else { diff --git a/sha256_1_generic.go b/sha256_1_generic.go index 89ed2d5..66b2fa7 100644 --- a/sha256_1_generic.go +++ b/sha256_1_generic.go @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2021-2022 Prysmatic Labs +# Copyright (c) 2021-2022 Prysmatic Labs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -125,7 +125,7 @@ var _K = []uint32{ 0xc67178f2, } -func sha256_1_generic(digests [][32]byte, p [][32]byte) { +func sha256_1_generic[D, P ~[32]byte](digests []D, p []P) { var w [16]uint32 for k := 0; k < len(p)/2; k++ { // First 16 rounds @@ -217,7 +217,7 @@ func sha256_1_generic(digests [][32]byte, p [][32]byte) { h6 += g h7 += h - var dig [32]byte + var dig D binary.BigEndian.PutUint32(dig[0:4], h0) binary.BigEndian.PutUint32(dig[4:8], h1) binary.BigEndian.PutUint32(dig[8:12], h2) From 57a9a29628a9153b82a2a15ba056392415ea5d06 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Mon, 15 Apr 2024 20:53:55 -0400 Subject: [PATCH 2/3] bet --- hash.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hash.go b/hash.go index b4927d2..63dc511 100644 --- a/hash.go +++ b/hash.go @@ -28,7 +28,7 @@ import ( "unsafe" ) -func _hash[B ~[32]byte](digests *byte, p []B, count uint32) +func _hash[P ~[32]byte](digests *byte, p []P, count uint32) {} // Hash hashes the chunks two at the time and outputs the digests on the first // argument. It does check for lengths on the inputs. From af9d2573b6475a529986af5b5d1ea24331aacc63 Mon Sep 17 00:00:00 2001 From: itsdevbear Date: Mon, 15 Apr 2024 20:55:05 -0400 Subject: [PATCH 3/3] bet --- hash.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hash.go b/hash.go index 63dc511..e9fd3b6 100644 --- a/hash.go +++ b/hash.go @@ -28,7 +28,7 @@ import ( "unsafe" ) -func _hash[P ~[32]byte](digests *byte, p []P, count uint32) {} +func _hash(digests *byte, p [][32]byte, count uint32) // Hash hashes the chunks two at the time and outputs the digests on the first // argument. It does check for lengths on the inputs. @@ -44,7 +44,7 @@ func Hash[D, C ~[32]byte](digests []D, chunks []C) error { return fmt.Errorf("not enough digest length, need at least %v, got %v", len(chunks)/2, len(digests)) } if supportedCPU { - _hash(&digests[0][0], chunks, uint32(len(chunks)/2)) + _hash(&digests[0][0], *(*[][32]byte)(unsafe.Pointer(&chunks)), uint32(len(chunks)/2)) } else { sha256_1_generic(digests, chunks) } @@ -54,7 +54,7 @@ func Hash[D, C ~[32]byte](digests []D, chunks []C) error { // HashChunks is the same as Hash, but does not do error checking on the lengths of the slices func HashChunks[D, C ~[32]byte](digests []D, chunks []C) { if supportedCPU { - _hash(&digests[0][0], chunks, uint32(len(chunks)/2)) + _hash(&digests[0][0], *(*[][32]byte)(unsafe.Pointer(&chunks[0])), uint32(len(chunks)/2)) } else { sha256_1_generic(digests, chunks) }