<div dir="ltr"><div dir="ltr"><div>I'm not very familiar with the new providers system, but I would discourage introducing new special return values. In my experience, callers don't do a good job of handling this sort of thing. The more APIs diverge from a straightforward success/failure return, the more error-prone they are. So a 1 vs 2 return value for "success" vs "success, but..." seems likely to confuse things.<br></div><div><br></div><div>It also seems safer for unexpected parameters to be an error. While sometimes they can be ignored, sometimes they cannot. For example, looking at the RSA provider interface, suppose a caller passed in rsa-factor3, rsa-factor4, etc. A provider that didn't implement multi-prime keys, or supported a different number of coefficients would not notice at the parameter level. The object wouldn't be in a consistent state. (Relatedly, I think this example is another reason that providers should validate inputs on key import. See <a href="https://github.com/openssl/openssl/issues/13615" target="_blank">https://github.com/openssl/openssl/issues/13615</a>.)</div><div><a href="https://www.openssl.org/docs/manmaster/man7/EVP_PKEY-RSA.html" target="_blank">https://www.openssl.org/docs/manmaster/man7/EVP_PKEY-RSA.html</a></div><div><br></div><div>Or consider a caller that thought they were configuring a private key, but got the parameter name wrong. That would likely result in a public key. While self-consistent, it's the wrong type of object, compared to what the caller was expecting, and may result in strange errors further down the program flow.<br></div><div><br></div><div>In the other direction, the DRBG example does not seem very compelling to me. At the point the application picks the broad family of algorithm, it should also pick the parameters to instantiate the actual algorithm. They're typically a unit. The convenience of passing arguments that won't be used seems not especially valuable, especially compared against the safety and correctness cost in silently misinterpreting the caller's request. An RSA provider which does not implement CRT is a little more plausible, but I think optional parameters are more the exception rather than the rule. RSA-CRT is well-established and standard (RFC8017, Appendix A.1.2), so that provider can simply know to ignore CRT parameters, possibly still validating them. (If less well-established, the caller may need to query capabilities anyway, in which case it'd know the provider implements a smaller interface. Though see below about how likely this is.)</div><div><br></div><div><div>We can also look to programming languages. While languages sometimes do drop unused and undeclared parameters (e.g. Python **kwargs), that's usually not the default story.<br></div><div></div></div><div><br></div><div>Finally, these are cryptographic primitives, not a general-purpose plugin system. Cryptographic primitives aren't introduced frequently. They especially aren't extended frequently, and typically have well-defined serializations and structures. They're also security-sensitive. That suggests leaning towards safety and structure rather than ad-hoc extensibility.</div><div><br></div><div>David</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 14, 2020 at 4:10 PM Kurt Roeckx <<a href="mailto:kurt@roeckx.be" target="_blank">kurt@roeckx.be</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Dec 14, 2020 at 08:20:29PM +0100, Dmitry Belyavsky wrote:<br>
> Dear Kurt,<br>
> <br>
> <br>
> On Mon, Dec 14, 2020 at 3:59 PM Kurt Roeckx <<a href="mailto:kurt@roeckx.be" target="_blank">kurt@roeckx.be</a>> wrote:<br>
> <br>
> > Hi,<br>
> ><br>
> > doc/man3/OSSL_PARAM.pod current says:<br>
> > Keys that a I<setter> or I<responder> doesn't recognise should<br>
> > simply be ignored. That in itself isn't an error.<br>
> ><br>
> > The intention of that seems to be that you just pass all the data<br>
> > you have, and that it takes data it needs. So you can pass it data<br>
> > that it doesn't need because it's only used in case some other parameter<br>
> > has some specific value. For example, depending on the DRBG mode<br>
> > (HMAC, CTR, HASH) you have different parameters, and you can just<br>
> > pass all the parameters for all the modes.<br>
> ><br>
> > I think for behaviour for a setter is not something that we want,<br>
> > it makes it complicated for applications to check that it will<br>
> > behave properly. I think that in general, if the applications<br>
> > wants to set something and you don't understand it, you should<br>
> > return an error. This is about future proofing the API. For<br>
> > instance, a new version supports a new mode to work in and that<br>
> > needs a new parameter. If it's build against a version that knows<br>
> > about it, but then runs against a version that doesn't know about<br>
> > it, everything will appear to work, but be broken. If we return<br>
> > an error, it will be clear that it's not supported.<br>
> ><br>
> > An alternative method of working is that the application first<br>
> > needs to query that it's supported. And only if it's supported<br>
> > it should call the function. But we don't have an API to query for<br>
> > that. You might be able to ask for which keys you can set, but it<br>
> > doesn't cover which values you can set. I hope we at least return<br>
> > an error for a known key with an unknown value. But it's my<br>
> > understanding that we currently don't always return all supported<br>
> > keys, and that the supported keys can depend on one of the set<br>
> > parameters.<br>
> ><br>
> > I suggest that we change the return value to indicate that all<br>
> > parameters have been used or not. For instance return 1 in case<br>
> > all used, return 2 in case not all used.<br>
> ><br>
> ><br>
> From my GOST implementor's experience, the provider can get a lot of<br>
> parameters.<br>
> Some of them are supported, some of them are not.<br>
> <br>
> The particular provider is the only subsystem that knows which parameters<br>
> are supported and which are necessary for the operations.<br>
> <br>
> So the caller can provide some unsupported parameters, some supported and<br>
> some totally wrong for the provider.<br>
> These are the cases that must be distinguishable on the caller side.<br>
<br>
If I understand you correctly, what you're saying is that it's<br>
sometimes ok to ignore some parameters. For instance, if you try<br>
to create an RSA object, and you pass it CRT parameters, and the<br>
implementation doesn't do anything with them, it can ignore them<br>
if it wants to.<br>
<br>
I would say that the provider should know what those parameters<br>
mean, so that it's not an "unknown key", it just ignores them,<br>
at which points it can say that it understands all the parameters.<br>
<br>
Some might argue that they don't want to use something that<br>
doesn't make use of the CRT parameters, but then they probably<br>
shouldn't be using that provider to begin with.<br>
<br>
> After that the provided EVP object should be either in a consistent state<br>
> or not, assuming the upcoming operation.<br>
<br>
The object should always be in a consistent state. I would prefer<br>
that in case of failure the object is not created (or modified).<br>
Which brings us to some other open points about the API we have. We<br>
should not introduce new APIs where you can modify the state of the<br>
object, so it can not be in a non-consistent state. It's much more<br>
simple to get things correct in that case. But as long as we have<br>
to support old APIs where it can be modified, the prefered<br>
consistent state is to not mofify the object on error. Some APIs make<br>
this very hard, so the other acceptable state is that you can free<br>
the object. With an API that doesn't allow modification, either<br>
you get a complete object, or you get no object.<br>
<br>
<br>
Kurt<br>
<br>
</blockquote></div></div></div>