Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small test #1569

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions go/enclave/crypto/data_enc_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package crypto

import (
"fmt"

Check failure on line 4 in go/enclave/crypto/data_enc_service_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"github.com/obscuronet/go-obscuro/integration/common/testlog"
"golang.org/x/exp/rand"
"golang.org/x/exp/slices"
"testing"

Check failure on line 8 in go/enclave/crypto/data_enc_service_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
)

const N = 1000

func Test_dataEncryptionServiceImpl_Encrypt(t1 *testing.T) {

Check warning on line 13 in go/enclave/crypto/data_enc_service_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 't1' seems to be unused, consider removing or renaming it as _ (revive)
d := NewDataEncryptionService(testlog.Logger())

plaintext := make([]byte, 512*1024)
_, err := rand.Read(plaintext)
if err != nil {
panic(err)
}

var gains = float64(0)

Check failure on line 22 in go/enclave/crypto/data_enc_service_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
for i := 0; i < N; i++ {
encryptedBlob, err := d.Encrypt(plaintext)
if err != nil {
panic(err)
}

byteFrequency := make(map[byte]int)
for _, b := range encryptedBlob {
byteFrequency[b] = byteFrequency[b] + 1
}

freqs := make([]int, 0)
for _, v := range byteFrequency {
freqs = append(freqs, v)
}

max := slices.Max(freqs)
avg := len(encryptedBlob) / 256

// calculate the gain as the difference between the numbers of the best byte compared to 0
gain := float64(max-byteFrequency[byte(0)]) * 100 / float64(avg)
gains += gain
}

fmt.Printf("GAIN: %f", gains/N)

}
Loading