Skip to content

Add OpenSSL compat: BIO_get_new_index, i2d_PUBKEY_bio, OpenSSL_version - #11020

Open
julek-wolfssl wants to merge 9 commits into
wolfSSL:masterfrom
julek-wolfssl:feature/extra_enhancement_to_compatibility_layer
Open

Add OpenSSL compat: BIO_get_new_index, i2d_PUBKEY_bio, OpenSSL_version#11020
julek-wolfssl wants to merge 9 commits into
wolfSSL:masterfrom
julek-wolfssl:feature/extra_enhancement_to_compatibility_layer

Conversation

@julek-wolfssl

Copy link
Copy Markdown
Member

Description

As part of the continuous integration of OpenSSL to wolfSSL, this adds a few missing functions needed for OpenSSL-compat APIs: BIO_get_new_index() (unique custom BIO type IDs, 128–255), i2d_PUBKEY_bio() (write public-key DER to a BIO), and OpenSSL_version(type) handling for the six standard OPENSSL_* selector constants (plus unknown → version string). Headers/macros updated under OPENSSL_EXTRA / !NO_BIO as appropriate.

Originally authored by @Roy-Carter in #10294, which was closed. Re-opening from julek-wolfssl with the same branch and follow-up fixes applied.

Testing

Ran ./tests/unit.test with -~BIO_get_new_index, -~OpenSSL_version, and -~i2d_PUBKEY_bio (substring filters). All passed.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Roy-Carter and others added 9 commits July 30, 2026 15:02
wolfSSL_OpenSSL_version() was declared with either an int or a void
parameter list depending on OPENSSL_VERSION_NUMBER. That macro does not
evaluate the same way in the library and in the application: with
OPENSSL_COEXIST the library additionally pulls in the real OpenSSL
headers and gets their version number, while an application that turns
coexist off gets wolfSSL's default. The two builds then disagreed on the
argument list and the selector read garbage, so OpenSSL_version() always
hit the default case. Give the function a single unconditional
signature.

Also match the test guards for wolfSSL_i2d_PUBKEY_bio and
wolfSSL_OpenSSL_version to the guards on their implementations.
The Linux kernel build compiles with -Werror=date-time, so OPENSSL_BUILT_ON
broke libwolfssl.ko.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends wolfSSL’s OpenSSL-compat layer by adding missing APIs used by OpenSSL-compatible applications: BIO_get_new_index(), i2d_PUBKEY_bio(), and fuller OpenSSL_version(type) selector handling.

Changes:

  • Add wolfSSL_BIO_get_new_index() plus BIO_TYPE_START mapping for allocating custom BIO method type IDs.
  • Add wolfSSL_i2d_PUBKEY_bio() to write DER-encoded public keys to a BIO, plus unit test coverage.
  • Standardize wolfSSL_OpenSSL_version(int type) and implement selector-based strings for OPENSSL_* constants, with tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
wolfssl/ssl.h Adds BIO type range macros, declares wolfSSL_BIO_get_new_index, adds wolfSSL_i2d_PUBKEY_bio, and standardizes wolfSSL_OpenSSL_version(int).
wolfssl/openssl/ssl.h Maps i2d_PUBKEY_bio and simplifies OpenSSL_version(x) mapping to always pass the selector.
wolfssl/openssl/opensslv.h Defines OPENSSL_* selector constants (0–5) when missing.
wolfssl/openssl/bio.h Exposes BIO_TYPE_START and maps BIO_get_new_index to wolfSSL.
wolfcrypt/src/evp_pk.c Implements wolfSSL_i2d_PUBKEY_bio() for writing DER public keys to a BIO.
src/ssl.c Implements selector-based wolfSSL_OpenSSL_version(int type) and avoids signature dependence on OPENSSL_VERSION_NUMBER.
src/bio.c Implements wolfSSL_BIO_get_new_index() using a static counter (needs thread-safety fix per review comment).
tests/api/test_ossl_bio.h Adds declaration and registration for the new BIO index test.
tests/api/test_ossl_bio.c Adds BIO_get_new_index() API test for uniqueness and range.
tests/api.c Adds i2d_PUBKEY_bio round-trip tests and expands OpenSSL_version(type) selector tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bio.c
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +160 B, .text +128 B (+0.0%, 771,636 B / 1,048,576 B, total: 74% used)
  • RAM: .data +8 B (+0.0%, 136,944 B / 262,144 B, total: 52% used)

linuxkm-standard

@julek-wolfssl

Copy link
Copy Markdown
Member Author

retest this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants