From 63879d57a98b4509c8d352581c9d3fdb8eec74aa Mon Sep 17 00:00:00 2001 From: dev <> Date: Sat, 27 Jan 2024 11:44:05 +0000 Subject: [PATCH] cleanup --- chunking/README.md | 7 --- compression/README.md | 6 --- encryption_aead/README.md | 7 --- encryption_aead/encryption_test.go | 26 ---------- encryption_unauthenticated/encryption_test.go | 50 +++++++++---------- hashing/README.md | 10 ---- 6 files changed, 25 insertions(+), 81 deletions(-) delete mode 100644 chunking/README.md delete mode 100644 compression/README.md delete mode 100644 encryption_aead/README.md delete mode 100644 hashing/README.md diff --git a/chunking/README.md b/chunking/README.md deleted file mode 100644 index 407eb7b..0000000 --- a/chunking/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Go Chunking Benchmarks - -Tested implementations: - -* [`github.com/jotfs/fastcdc-go`](https://github.com/jotfs/fastcdc-go) -* [`github.com/tigerwill90/fastcdc`](https://github.com/tigerwill90/fastcdc) -* [`github.com/restic/chunker`](https://github.com/restic/chunker) diff --git a/compression/README.md b/compression/README.md deleted file mode 100644 index 599b0b9..0000000 --- a/compression/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Go Compression Benchmarks - -Tested implementations: - -* [`github.com/klauspost/compress/s2`](https://github.com/klauspost/compress/s2) -* [`github.com/klauspost/compress/zstd`](https://github.com/klauspost/compress/zstd) diff --git a/encryption_aead/README.md b/encryption_aead/README.md deleted file mode 100644 index 0fd8d87..0000000 --- a/encryption_aead/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Go Encryption Benchmarks - - -Tested implementations: - -* [`golang.org/x/crypto/chacha20poly1305`](https://golang.org/x/crypto/chacha20poly1305) -* [`crypto/aes`](https://pkg.go.dev/crypto/aes) diff --git a/encryption_aead/encryption_test.go b/encryption_aead/encryption_test.go index 3f44fff..8d46164 100644 --- a/encryption_aead/encryption_test.go +++ b/encryption_aead/encryption_test.go @@ -9,7 +9,6 @@ import ( "github.com/bloom42/stdx/crypto/bchacha20blake3" "github.com/bloom42/stdx/crypto/chacha20" "github.com/bloom42/stdx/crypto/chacha20blake3" - "github.com/bloom42/stdx/crypto/xchacha20sha256" "github.com/bloom42/stdx/crypto/zchacha20blake3" "github.com/skerkour/go-benchmarks/utils" "golang.org/x/crypto/chacha20poly1305" @@ -58,7 +57,6 @@ func BenchmarkEncryptAEAD(b *testing.B) { benchmarkEncrypt(b, size, "AES_128_GCM", newAesGcmCipher(b, aes128GcmKey), aes128GcmNonce, additionalData) benchmarkEncrypt(b, size, "BChaCha20_BLAKE3", newBChaCha20Blake3Cipher(b, xChaCha20Key), bChaCha20Nonce, additionalData) benchmarkEncrypt(b, size, "ZChaCha20_BLAKE3", newZChaCha20Blake3Cipher(b, xChaCha20Key), bChaCha20Nonce, additionalData) - benchmarkEncrypt(b, size, "XChaCha20_SHA256", newXChaCha20Sha256Cipher(b, xChaCha20Key), xChaCha20Nonce, additionalData) } } @@ -87,7 +85,6 @@ func BenchmarkDecryptAEAD(b *testing.B) { benchmarkDecrypt(b, size, "AES_128_GCM", newAesGcmCipher(b, aes128GcmKey), aes128GcmNonce, additionalData) benchmarkDecrypt(b, size, "BChaCha20_BLAKE3", newBChaCha20Blake3Cipher(b, xChaCha20Key), bChaCha20Nonce, additionalData) benchmarkDecrypt(b, size, "ZChaCha20_BLAKE3", newZChaCha20Blake3Cipher(b, xChaCha20Key), bChaCha20Nonce, additionalData) - benchmarkDecrypt(b, size, "XChaCha20_SHA256", newXChaCha20Sha256Cipher(b, xChaCha20Key), xChaCha20Nonce, additionalData) } } @@ -211,29 +208,6 @@ func (cipher xChaCha20Poly1305Cipher) Decrypt(dst, nonce, ciphertext, additional _, _ = cipher.cipher.Open(dst, nonce, ciphertext, additionalData) } -type xChaCha20Sha256Cipher struct { - cipher cipher.AEAD -} - -func newXChaCha20Sha256Cipher(b *testing.B, key []byte) xChaCha20Sha256Cipher { - cipher, err := xchacha20sha256.New(key) - if err != nil { - b.Error(err) - } - - return xChaCha20Sha256Cipher{ - cipher: cipher, - } -} - -func (cipher xChaCha20Sha256Cipher) Encrypt(dst, nonce, plaintext, additionalData []byte) []byte { - return cipher.cipher.Seal(dst, nonce, plaintext, additionalData) -} - -func (cipher xChaCha20Sha256Cipher) Decrypt(dst, nonce, ciphertext, additionalData []byte) { - _, _ = cipher.cipher.Open(dst, nonce, ciphertext, additionalData) -} - type chaCha20Poly1305Cipher struct { cipher cipher.AEAD } diff --git a/encryption_unauthenticated/encryption_test.go b/encryption_unauthenticated/encryption_test.go index f302938..dcad95f 100644 --- a/encryption_unauthenticated/encryption_test.go +++ b/encryption_unauthenticated/encryption_test.go @@ -45,9 +45,9 @@ func BenchmarkEncryptUnauthenticated(b *testing.B) { aes256CfbIv := utils.RandBytes(b, 16) for _, size := range BENCHMARKS { + benchmarkEncrypt(b, size, "ChaCha20", newChaCha20Cipher(b, chaCha20Key, chaCha20Nonce), chaCha20Nonce) benchmarkEncrypt(b, size, "XChaCha20", newXChaCha20Cipher(b, xChaCha20Key, xChaCha20Nonce), xChaCha20Nonce) benchmarkEncrypt(b, size, "ChaCha12", newChaCha12Cipher(b, xChaCha20Key, chaCha20Nonce), chaCha20Nonce) - benchmarkEncrypt(b, size, "ChaCha20", newChaCha20Cipher(b, chaCha20Key, chaCha20Nonce), chaCha20Nonce) benchmarkEncrypt(b, size, "AES_256_CBC", newAesCbcCipher(b, aes256CbcKey), aes256CbcIv) benchmarkEncrypt(b, size, "AES_256_CFB", newAesCfbCipher(b, aes256CfbKey), aes256CfbIv) } @@ -67,9 +67,9 @@ func BenchmarkDecryptUnauthenticated(b *testing.B) { aes256CfbIv := utils.RandBytes(b, 16) for _, size := range BENCHMARKS { - benchmarkEncrypt(b, size, "XChaCha20", newXChaCha20Cipher(b, xChaCha20Key, xChaCha20Nonce), xChaCha20Nonce) - benchmarkEncrypt(b, size, "ChaCha12", newChaCha12Cipher(b, xChaCha20Key, chaCha20Nonce), chaCha20Nonce) benchmarkDecrypt(b, size, "ChaCha20", newChaCha20Cipher(b, chaCha20Key, chaCha20Nonce), chaCha20Nonce) + benchmarkDecrypt(b, size, "XChaCha20", newXChaCha20Cipher(b, xChaCha20Key, xChaCha20Nonce), xChaCha20Nonce) + benchmarkDecrypt(b, size, "ChaCha12", newChaCha12Cipher(b, xChaCha20Key, chaCha20Nonce), chaCha20Nonce) benchmarkDecrypt(b, size, "AES_256_CBC", newAesCbcCipher(b, aes256CbcKey), aes256CbcIv) benchmarkDecrypt(b, size, "AES_256_CFB", newAesCfbCipher(b, aes256CfbKey), aes256CfbIv) } @@ -244,28 +244,28 @@ func pkcs7Pad(b []byte, blocksize int) ([]byte, error) { // pkcs7Unpad validates and unpads data from the given bytes slice. // The returned value will be 1 to n bytes smaller depending on the // amount of padding, where n is the block size. -func pkcs7Unpad(b []byte, blocksize int) ([]byte, error) { - if blocksize <= 0 { - return nil, ErrInvalidBlockSize - } - if len(b) == 0 { - return nil, ErrInvalidPKCS7Data - } - if len(b)%blocksize != 0 { - return nil, ErrInvalidPKCS7Padding - } - c := b[len(b)-1] - n := int(c) - if n == 0 || n > len(b) { - return nil, ErrInvalidPKCS7Padding - } - for i := 0; i < n; i++ { - if b[len(b)-n+i] != c { - return nil, ErrInvalidPKCS7Padding - } - } - return b[:len(b)-n], nil -} +// func pkcs7Unpad(b []byte, blocksize int) ([]byte, error) { +// if blocksize <= 0 { +// return nil, ErrInvalidBlockSize +// } +// if len(b) == 0 { +// return nil, ErrInvalidPKCS7Data +// } +// if len(b)%blocksize != 0 { +// return nil, ErrInvalidPKCS7Padding +// } +// c := b[len(b)-1] +// n := int(c) +// if n == 0 || n > len(b) { +// return nil, ErrInvalidPKCS7Padding +// } +// for i := 0; i < n; i++ { +// if b[len(b)-n+i] != c { +// return nil, ErrInvalidPKCS7Padding +// } +// } +// return b[:len(b)-n], nil +// } type aesCfbCipher struct { aesCipher cipher.Block diff --git a/hashing/README.md b/hashing/README.md deleted file mode 100644 index 27b2740..0000000 --- a/hashing/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Go Hashing Benchmarks - -Tested implementations: - -* [`crypto/sha1`](https://pkg.go.dev/crypto/sha1) -* [`crypto/sha256`](https://pkg.go.dev/crypto/sha256) -* [`crypto/sha512`](https://pkg.go.dev/crypto/sha512) -* [`golang.org/x/crypto/blake2b`](https://pkg.go.dev/golang.org/x/crypto/blake2b) -* [`lukechampine.com/blake3`](https://github.com/lukechampine/blake3) -* [`github.com/zeebo/blake3`](https://github.com/zeebo/blake3)