This is an automated email from the ASF dual-hosted git repository.

cmorris pushed a commit to branch crypto-benchmarks
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git

commit edb3abc2d55dd50424e27e8de5134abdb0ab28b8
Author: Christopher Morris <[email protected]>
AuthorDate: Tue Sep 17 12:14:16 2019 +0100

    Add Crypto Benchmark test
---
 libs/crypto/bench_test.go | 124 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)

diff --git a/libs/crypto/bench_test.go b/libs/crypto/bench_test.go
new file mode 100644
index 0000000..d4372d1
--- /dev/null
+++ b/libs/crypto/bench_test.go
@@ -0,0 +1,124 @@
+package crypto
+
+import (
+       "encoding/hex"
+       "log"
+       "testing"
+       "time"
+)
+
+//Results on I9 laptop
+// BLSKeys took 1.367643ms
+// AESCBCEncrypt took 1.831µs
+// EncapsulateEncrypt took 163.514139ms
+// DecapsulateDecrypt took 165.586105ms
+// AESCBCDecrypt took 1.791µs
+// BLSSign took 652.917µs
+// BLSVerify took 3.441072ms
+
+//Test_Bench1 Some simple benchmarks to show speeds of the different crypto 
functions
+func Test_Bench1(t *testing.T) {
+       start := time.Now()
+       elapsed := time.Since(start)
+
+       var SIKEpk []byte
+       var SIKEsk []byte
+       var BLSsk []byte
+       var BLSpk []byte
+       var C2 []byte
+       var C1 []byte
+       var EK []byte
+       var P3 []byte
+       var S []byte
+
+       SEEDHex := 
"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30"
+       SEED, _ := hex.DecodeString(SEEDHex)
+       // AES-256 Key
+       KHex := 
"af5f8452d644d131c35164fee8c8300fb29725b03b00eaef411c823293c469d8"
+
+       // AES IVs
+       IV1Hex := "de4724534df5f50160a28cf3b3caec80"
+       IV2Hex := "a08576336500e79b2593dc4c10b0f36c"
+
+       // Messsage to encrypt and sign. Note it is zero padded.
+       PHex := 
"48656c6c6f20426f622120546869732069732061206d6573736167652066726f6d20416c696365000000000000000000"
+
+       // Generate SIKE keys
+
+       start = time.Now()
+       for i := 0; i < 100; i++ {
+               _, SIKEpk, SIKEsk = SIKEKeys(SEED)
+       }
+       elapsed = time.Since(start)
+       log.Printf("SIKEKeys took %s", elapsed/100)
+
+       // Generate BLS keys
+
+       start = time.Now()
+       for i := 0; i < 1000; i++ {
+               _, BLSpk, BLSsk = BLSKeys(SEED, nil)
+       }
+       elapsed = time.Since(start)
+       log.Printf("BLSKeys took %s", elapsed/1000)
+
+       // Encrypt message
+       K, _ := hex.DecodeString(KHex)
+       IV1, _ := hex.DecodeString(IV1Hex)
+       P1, _ := hex.DecodeString(PHex)
+
+       start = time.Now()
+       for i := 0; i < 1000; i++ {
+               C1 = AESCBCEncrypt(K, IV1, P1)
+       }
+       elapsed = time.Since(start)
+       log.Printf("AESCBCEncrypt took %s", elapsed/1000)
+
+       // Encrypt AES Key, K, and returned encapsulated key used for
+       // encryption
+       IV2, _ := hex.DecodeString(IV2Hex)
+       P2 := K
+
+       start = time.Now()
+       for i := 0; i < 100; i++ {
+               _, C2, EK = EncapsulateEncrypt(P2, IV2, SIKEpk)
+       }
+       elapsed = time.Since(start)
+       log.Printf("EncapsulateEncrypt took %s", elapsed/100)
+
+       // Decapsulate the AES Key and use it to decrypt the ciphertext.
+       // P2 and P3 should be the same. This value is the AES-256 key
+       // used to encrypt the plaintext P1
+
+       start = time.Now()
+       for i := 0; i < 100; i++ {
+               _, P3 = DecapsulateDecrypt(C2, IV2, SIKEsk, EK)
+       }
+       elapsed = time.Since(start)
+       log.Printf("DecapsulateDecrypt took %s", elapsed/100)
+
+       K2 := P3
+
+       start = time.Now()
+       for i := 0; i < 1000; i++ {
+               _ = AESCBCDecrypt(K2, IV1, C1)
+       }
+       elapsed = time.Since(start)
+       log.Printf("AESCBCDecrypt took %s", elapsed/1000)
+
+       // BLS Sign a message
+       start = time.Now()
+       for i := 0; i < 1000; i++ {
+               _, S = BLSSign(P1, BLSsk)
+       }
+       elapsed = time.Since(start)
+       log.Printf("BLSSign took %s", elapsed/1000)
+
+       // BLS Verify signature
+       start = time.Now()
+       for i := 0; i < 1000; i++ {
+               _ = BLSVerify(P1, BLSpk, S)
+       }
+       elapsed = time.Since(start)
+       log.Printf("BLSVerify took %s", elapsed/1000)
+
+}

Reply via email to