Skip to content

Commit

Permalink
mac: Add poly1305
Browse files Browse the repository at this point in the history
  • Loading branch information
dev committed Jan 19, 2024
1 parent 178d5ed commit 00c15a5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mac/mac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 00c15a5

Please sign in to comment.