From OpenBSD:

https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/lang/ruby/3.1/patches/patch-ext_openssl_ossl_pkey_c

LibreSSL 3.5 and later provide and need to use
PEM_write_bio_PrivateKey_traditional()

Index: ext/openssl/ossl_pkey.c
--- a/ext/openssl/ossl_pkey.c.orig
+++ b/ext/openssl/ossl_pkey.c
@@ -670,7 +670,7 @@ ossl_pkey_export_traditional(int argc, VALUE *argv, VA
 	}
     }
     else {
-#if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER)
+#if OPENSSL_VERSION_NUMBER >= 0x10100000
 	if (!PEM_write_bio_PrivateKey_traditional(bio, pkey, enc, NULL, 0,
 						  ossl_pem_passwd_cb,
 						  (void *)pass)) {
