From 00c15a5906ff357fb08b78f29f895f33486bbd36 Mon Sep 17 00:00:00 2001 From: dev <> Date: Fri, 19 Jan 2024 09:27:21 +0000 Subject: [PATCH] mac: Add poly1305 --- mac/mac_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mac/mac_test.go b/mac/mac_test.go index ad168d0..5c04659 100644 --- a/mac/mac_test.go +++ b/mac/mac_test.go @@ -11,6 +11,7 @@ import ( zeeboblake3 "github.com/zeebo/blake3" "golang.org/x/crypto/blake2b" "golang.org/x/crypto/blake2s" + "golang.org/x/crypto/poly1305" "golang.org/x/crypto/sha3" lukechampineblake3 "lukechampine.com/blake3" ) @@ -31,6 +32,7 @@ func BenchmarkMac(b *testing.B) { 1024 * 1024 * 1024, } + output128 := make([]byte, 16, 256) output256 := make([]byte, 32, 256) output512 := make([]byte, 64, 256) @@ -42,6 +44,7 @@ func BenchmarkMac(b *testing.B) { benchmarkMac(size, "blake2s_256", blake2sMac{}, output256, b) // benchmarkMac("sha512/256", sha512_256Hasher{}, b) benchmarkMac(size, "sha3", sha3Mac{}, output256, b) + benchmarkMac(size, "poly1305", poly1305Mac{}, output128, b) benchmarkMac(size, "sha2_512", sha512Hasher{}, output512, b) benchmarkMac(size, "zeebo_blake3_512", zeeboBlake3_512Mac{}, output512, b) @@ -113,6 +116,15 @@ func (blake2bMac) Mac(key, input, output []byte) { hasher.Sum(output) } +type poly1305Mac struct{} + +func (poly1305Mac) Mac(key, input, output []byte) { + polyKey := [32]byte(key[0:32]) + hasher := poly1305.New(&polyKey) + hasher.Write(input) + hasher.Sum(output) +} + // type blake2b512Hasher struct{} // func (blake2b512Hasher) Hash(input []byte) {