Skip to content

Stdarg based OSSL_PARAM array building.#9246

Closed
paulidale wants to merge 6 commits intoopenssl:masterfrom
paulidale:params-alloc
Closed

Stdarg based OSSL_PARAM array building.#9246
paulidale wants to merge 6 commits intoopenssl:masterfrom
paulidale:params-alloc

Conversation

@paulidale
Copy link
Contributor

@paulidale paulidale commented Jun 26, 2019

Add a function that allows an array of OSSL_PARAMs to be allocated and populated in one call.

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

@paulidale paulidale mentioned this pull request Jun 26, 2019
@richsalz
Copy link
Contributor

see #9139 (comment)

crypto/params.c Outdated

for (; name != NULL; name = va_arg(ap, const char *)) {
type = va_arg(ap, int);
#define T(type, type_name, param_type) \
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe make this be CASE instead of T

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks kind of ugly, too many leading capitals after argument reordering.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, but then it looks kinda like C code.

crypto/params.c Outdated
break; \
}
switch (type) {
T(int, int, INTEGER);
Copy link
Contributor

Choose a reason for hiding this comment

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

put the all-caps, the type_name first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change.

int setup_tests(void)
{
ADD_ALL_TESTS(test_case, OSSL_NELEM(test_cases));
ADD_TEST(test_build);
Copy link
Member

Choose a reason for hiding this comment

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

Can't it be made into a set of test cases alongside the other test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The storage for each item is allocated dynamically which means the global variables aren't being updated. This goes against the premise of the other test cases. (I tried).

params = OSSL_PARAM_build(
OSSL_PARAM_utf8_string("foo", NULL, 32),
OSSL_PARAM_int("bar", 42),
NULL
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't correspond to what's described in this manual.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In what way?

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment at line 150 says OSSL_PARAM_END structure the text of the docs say NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It also says automatically :)

I'll change.


=head1 HISTORY

These APIs were introduced in OpenSSL 3.0.0.
Copy link
Member

Choose a reason for hiding this comment

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

"APIs" should be "functions"

(using "API" as synonym for "functions" is an abomination IMNSHO)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not just functions though: it's also macros and various constants: together that makes an API.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly. An API, not a set of APIs. You made my point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, fixed.

OSSL_PARAM *OSSL_PARAM_build(const char *name, ...);
void OSSL_PARAM_build_free(OSSL_PARAM *params);

#define OSSL_PARAM_BUILD_int(name, value) \
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, the manual says "address", not "value". Please decide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Name for scalar types, address for strings and BN's.

@levitte
Copy link
Member

levitte commented Jun 26, 2019

#9139 (comment) made me wonder about use cases. OSSL_PARAM_build requires that the amount of parameters is known in compile time, so it seems to me like it's a huge waste of cycles just to save someone from having to add a local variable for immediate values...

@levitte
Copy link
Member

levitte commented Jun 26, 2019

(maybe I'm not seeing it all clearly... How often do we pass immediate values via ctrl functions today?)

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.

I remain convinced that this is a bad trade-off in complexity/usefulness.

A collection of utility functions that simplify building arrays of
OSSL_PARAM structures. The following B<TYPE> names are supported:

=over 1
Copy link
Contributor

Choose a reason for hiding this comment

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

if you indent this and just make a block of text it takes less space and looks like C code.


=item *

long int (long)
Copy link
Contributor

Choose a reason for hiding this comment

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

why "long int" and not just "long" ?
because "long int" isn't really a supported value for the TYPE is it. :)
And flip the lines so the TYPE appears first, then the native C type in parens.

Using these functions introduces additional overhead when compared to raw
OSSL_PARAM operations.

=over 1
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't doc-nits complain on anything other than 4 here?

OSSL_PARAM_BUILD_utf8_string(), OSSL_PARAM_BUILD_octet_string(),
OSSL_PARAM_BUILD_BN() are macros that provide support
for defining UTF8 strings, OCTET strings and big numbers.
A parameter with B<name> is defined, storage of length B<len> is allocated and
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the code, I don't see where any storage is allocated, also because OSSL_PARAM_build_free only free's an array structure.

OH, now I get it, you allocate a single excess space to avoid memory fragmentation. Bleaugh.

@paulidale
Copy link
Contributor Author

Closing an unrequited PR.

This won't fly and I think I favour @mattcaswell's approach in #9266 (& fleshed out in #9305).

@paulidale paulidale closed this Jul 8, 2019
@paulidale paulidale deleted the params-alloc branch July 8, 2019 22:05
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