Skip to content

Param api 2#8379

Closed
paulidale wants to merge 2 commits intoopenssl:masterfrom
paulidale:param-api-2
Closed

Param api 2#8379
paulidale wants to merge 2 commits intoopenssl:masterfrom
paulidale:param-api-2

Conversation

@paulidale
Copy link
Contributor

A leaner version of the param api.

This supports fewer types and only supports widening of types (no narrowing).
Widening is done using cases rather than memcpy.

refer to #8320 and #8377

  • documentation is added or updated
  • tests are added or updated

This was referenced Mar 1, 2019
Copy link
Member

@slontis slontis left a comment

Choose a reason for hiding this comment

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

Looks a lot cleaner than the first attempt using memcpy.
Are Strings and byte arrays still TODO?

@paulidale
Copy link
Contributor Author

Yes, strings and octets are coming in another PR.
They need to deal with the _PTR versions transparently.

@paulidale
Copy link
Contributor Author

We should also address the question as to which types exactly we want to include. I've only got the thirty two and sixty four bit ones here plus size_t. Do we need sixteen bit integers or floats?

@levitte
Copy link
Member

levitte commented Mar 1, 2019

Do we need sixteen bit integers or floats?

A point: this PR doesn't have to be feature complete. If it turns out later that we want those, it would be fairly easy to add.

@paulidale
Copy link
Contributor Author

WIthout narrowing, adding them after 3.0 could be problematic.
I'm happy to leave them out for the moment.
I'm also happy to add the narrower types in here using casts.

@levitte
Copy link
Member

levitte commented Mar 1, 2019

I'm looking at all this, and am thinking of a use case that I think will be fairly common... I'll write it raw form for now (macros lacking).

So the case here is that an application wants to use some provider that's unknown to us, offering the asymmetric algorithm "blargh", and wants to find out the public parameters for some key (i.e. the numbers, like RSA's n and e), using some EVP_PKEY function that doesn't exist yet (totally top of my mind). The type and size of these parameters are documented with the provider, so the application author know what they're dealing with.

    int32_t blargh_f = 0;
    double blargh_g = 0.0;
    unsigned char blargh_p1[4096 / 8];
    unsigned char blargh_p2[4096 / 8];
    const OSSL_PARAM params[] = {
        /* |f| is documented to be a 32-bit signed integer.  No need for a return size */
        { "f", OSSL_PARAM_INTEGER, &blargh_f, sizeof(blargh_f), NULL },
        /* |g| is documented to be a double.  No need for a return size */
        { "g", OSSL_PARAM_REAL, &blargh_g, sizeof(blargh_g), NULL),
        /* |p1| and |p2| are documented to be arbitrarily large unsigned integers, maximum 4096 bits */
        { "p1", OSSL_PARAM_UNSIGNED_INTEGER, &blargh_p1, sizeof(blargh_p1), &blargh_p1_l },
        { "p2", OSSL_PARAM_UNSIGNED_INTEGER, &blargh_p2, sizeof(blargh_p2), &blargh_p2_l },
        { 0 }
    };

    if (!EVP_PKEY_get_public_params(pkey, params))
        goto err;
    /*
     * do whatever with the parameters
     * among others, blargh_p1 and blargh_p2 should be imported into whatever MP type
     * the application writer prefers
     */

I have a hard time seeing how this is supported in this PR, which seems to be preoccupied with more dynamic aspects.

Comments?

@paulidale
Copy link
Contributor Author

I'm unsure what you're getting at. The macros will handle the first two entries fine. The final two aren't supported. At least at the moment.

@levitte
Copy link
Member

levitte commented Mar 1, 2019

The macros will handle the first two entries fine.

Cool. I was unsure how to understand this PR, so thanks for confirming.

The final two aren't supported. At least at the moment.

(emphasis mine) Ok, I'll try to be patient 😉

@paulidale
Copy link
Contributor Author

There is a fair bit more to do. Strings and octets need supporting functions and (maybe) macros. I'd like the _PTR variations to be hidden from users. BIGNUMs also need some hiding and they'll need the length passed back (which are the missing cases above).

I also need to do some BIGNUM test cases and confirm that the integer functions are adequately covered by the existing tests.

I'm running out of time...

@levitte
Copy link
Member

levitte commented Mar 1, 2019

I'd like the _PTR variations to be hidden from users.

I don't think that's a good idea. There are some very crucial differences between the _PTR and non-_PTR variations, such as having to provide a separate (larger than pointer size) buffer to transfer the value or not, especially for getting parameters.

It's possible that the _PTR variation turns out to be a bad idea, if it turns out to be too difficult to handle. Removing it means a lot more copying of constants, but I'm unsure how many of those we'll see, or rather how often such values will be retrieved, and if the optimization is worth the while.

@paulidale
Copy link
Contributor Author

Let's see if I can come up with a nice _PTR neutral flavour. I'm not sure it is possible but I'd like to at least try.

@levitte
Copy link
Member

levitte commented Mar 1, 2019

I'm not sure it is possible but I'd like to at least try.

Trying is good... I have my doubts, but please never let that stop you from trying. Worst case, we might both be pleasantly surprised 😉

Copy link
Member

@levitte levitte left a comment

Choose a reason for hiding this comment

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

Deal with this after sleep, yeah?

@richsalz
Copy link
Contributor

richsalz commented Mar 1, 2019

It is unfortunate that so much effort has been spent on re-doing this since #8377 starts from a cleaner space.

@paulidale
Copy link
Contributor Author

The bulk of the changes took about half an hour :) That's roughly the time between my comment about prototyping a middle ground approach and the first push.

@paulidale paulidale force-pushed the param-api-2 branch 7 times, most recently from 9ef8687 to bfb9499 Compare March 4, 2019 03:09
Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

For the BN test. Can you show doing this with a list of PARAMS where the BIGNUM is the second or third? And show a set and a get. I.e., how it would be used in practice.

@paulidale paulidale mentioned this pull request Mar 5, 2019
2 tasks
@paulidale
Copy link
Contributor Author

I've pulled OSSL_PARAM_locate out as a separate API and not called it from the get/set functions.
Refer to #8399 for the rationale behind this.

@paulidale
Copy link
Contributor Author

The BIGNUM test is failing. I'll fix.

@paulidale paulidale force-pushed the param-api-2 branch 3 times, most recently from 0c429e6 to 4539ebc Compare March 8, 2019 00:30
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 float and double.

All of the integer functions will widen and narrow 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.  The fast path case where
the types match is dealt with directly, so it is only when the types don't
match that there is a performance impact.

The two pairs of real functions accept all real and integer types and
automaticly convert as required.  There could be some loss of precision
when converting wide integral types to reals, but the magnitude will
remain correct.  Unlike the integer functions which accept any width input,
the real functions require standard integer widths.

A pair of functions is available for BIGNUMs.  These accept any unsigned
integer input and convert to/from a BIGNUM.

Finally, some utility macros are defined to allow OSSL_PARAM definition
arrays to be more simplify specified.  There is one macro for each native
integer type and both floating point types.
@paulidale
Copy link
Contributor Author

Closing in favour if #8400 which includes a pile more functionality.

@paulidale paulidale closed this Mar 8, 2019
@paulidale paulidale deleted the param-api-2 branch September 19, 2019 02:11
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