MCPcopy
hub / github.com/OpenNHP/opennhp / TestECCSharedKey

Function TestECCSharedKey

nhp/core/benchmark/ecc_rsa_test.go:42–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestECCSharedKey(t *testing.T) {
43 now := time.Now()
44
45 msg := "Qt for Windows - Building from Source" +
46 "This page describes the process of configuring and building Qt for Windows. To download" +
47 " and install a pre-built Qt for Windows, follow the instructions on the Getting Started with Qt page."
48
49 for i := 0; i < 10; i++ {
50 ecdh := core.NewECDH(core.ECC_CURVE25519)
51 ecdhr := core.NewECDH(core.ECC_CURVE25519)
52
53 ssc := ecdh.SharedSecret(ecdhr.PublicKey())
54 sss := ecdhr.SharedSecret(ecdh.PublicKey())
55
56 //if !bytes.Equal(ssc[:], sss[:]) {
57 // fmt.Printf("shared key is not identical, quit")
58 // return
59 //}
60
61 var sscKey, sssKey [core.SymmetricKeySize]byte
62 copy(sscKey[:], ssc[:])
63 copy(sssKey[:], sss[:])
64
65 hashc := sha256.New()
66 hashc.Write(ssc[:])
67 hashedc := hashc.Sum(nil)
68
69 hashs := sha256.New()
70 hashs.Write(ssc[:])
71 hasheds := hashs.Sum(nil)
72
73 aeadc, err := core.AeadFromKey(core.GCM_AES256, &sscKey)
74 if err != nil {
75 fmt.Printf("aead creation error: %v", err)
76 return
77 }
78 aeads, err := core.AeadFromKey(core.GCM_AES256, &sssKey)
79 if err != nil {
80 fmt.Printf("aead creation error: %v", err)
81 return
82 }
83
84 var nonceBytes [12]byte
85 aeadCount++
86 binary.BigEndian.PutUint64(nonceBytes[:], aeadCount)
87
88 encrypted := aeadc.Seal(nil, nonceBytes[:], []byte(msg), hashedc)
89 decrypted, err := aeads.Open(nil, nonceBytes[:], encrypted, hasheds)
90 _ = decrypted
91 if err != nil {
92 fmt.Printf("aead decrypt error: %v", err)
93 return
94 }
95 }
96
97 d := time.Since(now)
98 //fmt.Printf("Decrypted message:\n%s\n", string(decrypted))
99 fmt.Printf("ECC verify success with %d microseconds.\n", d.Microseconds())

Callers

nothing calls this directly

Calls 3

SharedSecretMethod · 0.65
PublicKeyMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected