Skip to content

Add noescape and nocallback directive to EVP_PKEY_derive #113

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

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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
13 changes: 13 additions & 0 deletions cgo_go122.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build go1.22 && !cmd_go_bootstrap

package openssl

/*
// The following noescape and nocallback directives are used to
// prevent the Go compiler from allocating function parameters on the
// heap. This is just a performance optimization. Only add those
// functions that are known to allocate.
#cgo noescape go_openssl_EVP_PKEY_derive
#cgo nocallback go_openssl_EVP_PKEY_derive
*/
import "C"
25 changes: 25 additions & 0 deletions ecdh_test.go
Original file line number Diff line number Diff line change
@@ -146,3 +146,28 @@ func hexDecode(t *testing.T, s string) []byte {
}
return b
}

func BenchmarkECDH(b *testing.B) {
const curve = "P-256"
aliceKey, _, err := openssl.GenerateKeyECDH(curve)
if err != nil {
b.Fatal(err)
}
bobKey, _, err := openssl.GenerateKeyECDH(curve)
if err != nil {
b.Fatal(err)
}

alicePubKey, err := aliceKey.PublicKey()
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err := openssl.ECDH(bobKey, alicePubKey)
if err != nil {
b.Fatal(err)
}
}
}