After trying to ask on openssl-users and getting no answer, I found the answer on my own.
openssl currently lacks this feature, but it is possible to implement it. I sent a patch to openssl-dev, which implements it for smime. I hope to get feedback and have the patch merged in the future.