Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dev committed Jan 27, 2024
1 parent eb487fa commit 63879d5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 81 deletions.
7 changes: 0 additions & 7 deletions chunking/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions compression/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions encryption_aead/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions encryption_aead/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

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

Expand Down Expand Up @@ -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
}
Expand Down
50 changes: 25 additions & 25 deletions encryption_unauthenticated/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions hashing/README.md

This file was deleted.

0 comments on commit 63879d5

Please sign in to comment.