Conversation
crypto/params.c
Outdated
There was a problem hiding this comment.
I think this is a bit over the top. Presumably, the calling code knows or can easily check the data type, and deduce that if it passed a reference to NULL and the passed pointer is non-NULL after the call to this function, it needs to free what that pointer points to. This should not be hard to document.
There was a problem hiding this comment.
Not quite. A UTF8_STRING_PTR will replace a NULL with a pointer that can't be freed.
Either an extra return argument is required to indicate free the pointer or the params code has to keep track of which ones need freeing.
There was a problem hiding this comment.
But surely, the code that constructed the OSSL_PARAM to begin with knows if that OSSL_PARAM has the data type OSSL_PARAM_UTF8_STRING or OSSL_PARAM_UTF8_STRING_PTR? It's not like those data types find themselves there randomly by magic. That should be very easy to code. Do you want an example?
There was a problem hiding this comment.
Okay, I'm fine delegating the free management to the caller :)
No need for an example.
There was a problem hiding this comment.
Remember to document the requirements
There was a problem hiding this comment.
While I'm not religiously opposed to leaving free management to the caller, it is something that should be pretty rare, as it's easy for the caller to mess it up. As much as possible, we should stick to simple API contracts, where (e.g.) "you should always free() this parameter after calling this function" lets the calling code be simpler.
There was a problem hiding this comment.
You cannot allocate something in a DLL and free it in main because that won't work on Windows for example.
There was a problem hiding this comment.
The allocations are not across provider boundaries. The provider calls get to extract information that has already passed the boundary. The provider is required to call free.
There was a problem hiding this comment.
@kaduk is "you must free if you didn't provide the space" sufficiently simple?
There was a problem hiding this comment.
It is tolerably simple, yes. May or may not be the best solution in any given case, though.
|
Should the string get functions use the |
I'm afraid I only confused matters with the See, there's really no reason whatsoever for a For the setters and responders, i.e. those who use the data from a passed Herein lies a lot of the confusion I'm seeing, that there are two sides to the use of `OSSL_PARAM:
These are at opposite ends and need different functionality, so in designing your API (and that goes for @richsalz as well), it's really important to understand and specify which side is expected to use what function. |
|
What worries me is that if we're getting confused, others without the background won't have a change. I.e. something is wrong with the API. |
doc/man3/OSSL_PARAM.pod
Outdated
There was a problem hiding this comment.
I think I sometimes forget this... would you mind telling me when I do?
There was a problem hiding this comment.
I'll try to remember :)
5822bce to
d544bb2
Compare
I'm not entirely convinced:
|
Why? If the
Why should the |
With a const OSSL_PARAM, how large should the BIGNUM buffer be for an RSA signature?
I'd prefer to call them
This works unless the OSSL_PARAM is const and the variable/string is allocated. |
|
I'm noticing a happy CI 😉 |
Provide a number of functions to allow parameters to be set and retrieved in a type safe manner. Functions are provided for many integral types plus double, BIGNUM, UTF8 strings and OCTET strings. All of the integer functions will widen the parameter data as required. This permits a degree of malleability in the parameter definition. For example a type can be changed from a thirty two bit integer to a sixty four bit one without changing application code. Only four and eight byte integral sizes are supported here. A pair of real functions, a get and a set, that will accept all real and integer types and automaticly convert to/from double as required. There could be some loss of precision when converting wide integral types to reals and reals to any integer type. A pair of functions is available for BIGNUMs. These accept any sized unsigned integer input and convert to/from a BIGNUM. For each OCTET and UTF8 strings, four functions are defined. This provide get and set functionality for string and for pointers to strings. The latter avoiding copies but have other inherent risks. Finally, some utility macros and functions are defined to allow OSSL_PARAM definition arrays to be more simplify specified. There are two macro and one function for most types. The exception being BIGNUM, for which there is one macro and one function.
| The size used by the parameter value, in bytes, is written to B<return_size>. | ||
|
|
||
| OSSL_PARAM_END provides an end of parameter list marker. | ||
| This should terminate all OSSL_PARAM arrays. |
There was a problem hiding this comment.
Some examples of the usage of the above macros would be helpful
There was a problem hiding this comment.
I reused the examples from OSSL_PARAM.pod converting them to the macros and functions defined here.
|
I am still working on my alterantive proposal, the day job has kept me busy. I hope this can wait until after I'm "finished" |
demacro the get/set/construct for the standard integral types
|
I think that's all the comments addressed. I'm out of action for several weeks starting Monday. |
|
This was finalized in #8451, so closing |
Add helper routines to make dealing with UTF8 and octet strings easier.