File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ //go:build go1.22 && !cmd_go_bootstrap
2
+
3
+ package openssl
4
+
5
+ /*
6
+ // The following noescape and nocallback directives are used to
7
+ // prevent the Go compiler from allocating function parameters on the
8
+ // heap. This is just a performance optimization. Only add those
9
+ // functions that are known to allocate.
10
+ #cgo noescape go_openssl_EVP_PKEY_derive
11
+ #cgo nocallback go_openssl_EVP_PKEY_derive
12
+ */
13
+ import "C"
Original file line number Diff line number Diff line change @@ -146,3 +146,28 @@ func hexDecode(t *testing.T, s string) []byte {
146
146
}
147
147
return b
148
148
}
149
+
150
+ func BenchmarkECDH (b * testing.B ) {
151
+ const curve = "P-256"
152
+ aliceKey , _ , err := openssl .GenerateKeyECDH (curve )
153
+ if err != nil {
154
+ b .Fatal (err )
155
+ }
156
+ bobKey , _ , err := openssl .GenerateKeyECDH (curve )
157
+ if err != nil {
158
+ b .Fatal (err )
159
+ }
160
+
161
+ alicePubKey , err := aliceKey .PublicKey ()
162
+ if err != nil {
163
+ b .Fatal (err )
164
+ }
165
+ b .ResetTimer ()
166
+ b .ReportAllocs ()
167
+ for i := 0 ; i < b .N ; i ++ {
168
+ _ , err := openssl .ECDH (bobKey , alicePubKey )
169
+ if err != nil {
170
+ b .Fatal (err )
171
+ }
172
+ }
173
+ }
You can’t perform that action at this time.
0 commit comments