diff --git a/signer/storage/aes_gcm_storage.go b/signer/storage/aes_gcm_storage.go index 39eedd88fd..6c303ee6d9 100644 --- a/signer/storage/aes_gcm_storage.go +++ b/signer/storage/aes_gcm_storage.go @@ -22,6 +22,7 @@ import ( "crypto/rand" "encoding/json" "errors" + "io" "os" "github.com/ethereum/go-ethereum/log" diff --git a/signer/storage/aes_gcm_storage_test.go b/signer/storage/aes_gcm_storage_test.go index 00f2f21900..d89b4a6711 100644 --- a/signer/storage/aes_gcm_storage_test.go +++ b/signer/storage/aes_gcm_storage_test.go @@ -160,3 +160,31 @@ func TestSwappedKeys(t *testing.T) { t.Errorf("double-swapped value should work fine") } } + +func BenchmarkEncryption(b *testing.B) { + storage := NewAESEncryptedStorage("test.json", []byte("x?^0^fIhNpSkTKbN")) + + // Generate plaintext and additional data + plaintext := []byte("example plaintext") + additionalData := []byte("additional data") + + b.ResetTimer() + for i := 0; i < b.N; i++ { + // Encrypt plaintext + ciphertext, _, err := storage.encrypt(plaintext, additionalData) + if err != nil { + b.Fatalf("Encryption failed: %v", err) + } + + // Decrypt ciphertext + decryptedPlaintext, err := storage.decrypt(ciphertext, additionalData) + if err != nil { + b.Fatalf("Decryption failed: %v", err) + } + + // Verify decryption + if string(decryptedPlaintext) != string(plaintext) { + b.Fatalf("Decryption failed: plaintext mismatch") + } + } +}