views:

134

answers:

1

The documentation for Openssl memory BIO sinks is here.

I am creating a BIO chain to turn binary strings into base64 strings. The source/sink is always a memory location, and this enables me to just keep the same chain arround. However the data (should) go into a memory buffer managed by OpenSSL when I write to it, and it should come from a user supplied memory buffer when read from the chain.

BIO_set_mem_buf() is the function used to set a user supplied buffer, and I will set the BIO_NOCLOSE property as I manage my memory using new. Now in order to use the same chain for writing I need to change the memory bio into managing its own memory. My question is: " Will BIO_reset() change it back to managing its own memory after a user has supplied a custom buffer ? Are there any performance consequences of using a single chain for what I want to do ?"

+1  A: 

I'm not sure to get you right but here is how I usually proceed with OpenSSL:

I consider OpenSSL's BIO structures to be some kind of opaque streams.

Whatever data I have to pass to (or get from) OpenSSL, it is usually stored in a custom data structure of my own, then copied to/from an OpenSSL BIO for processing.

As you stated, the documentation of OpenSSL is not really clear on some points. Since we cannot reasonably make an assumption of its internal behavior, I believe this way of doing things to be safer.

However, in case you need high performance and want to avoid the useless copy (this would be legitimate), you better ask the OpenSSL Users mailing-list. Their answers will be acurate and I believe that only them can answer things which aren't precisely described into the documentation.

ereOn
I went about the problem by keeping a copy of the BIO mem sink and the bio base64 filter around in thread local memory. When it came to decoding I created a new bio mem with a buffer managed by my application.
Hassan Syed