Conversation
|
May I suggest a |
|
A |
crypto/params.c
Outdated
There was a problem hiding this comment.
I think this cleverness should be avoided, just use portable shift and or.
There was a problem hiding this comment.
That was actually cleverer than what I had in mind, which was something like this:
const union {
char digits[4];
uint32_t number;
} byteorder = { { 0x00, 0x01, 0x02, 0x03 } };And then compare with 0x00010203, 0x03020100, 0x01000302 and whatever else to figure out the byte order (one of them is PDP-11, can you see which one?).
I actually think @paulidale's cleverness is much more to the point than most variants I've seen. Of course, it demands that you know C...
There was a problem hiding this comment.
The union trick has been used by @dot-asm for crypto code. I think it is needless tricky and premature optimization to use it for parameter-passing, especially when you can do things like always promote and then cast down:
case TYPE_SHORT: {
int itemp;
memcpy(item, param->value, sizeof (int));
*val = (short)itemp;
}
There was a problem hiding this comment.
So this is not really about the clever union trick, but rather about widening and narrowing being a bit over the top... is that what you're trying to say?
There was a problem hiding this comment.
The union trick is needed only for the widening/narrowing optimization here. This code as currently proposed is a poster-child for needless optimization in my view.
There was a problem hiding this comment.
The union trick is from elsewhere in the OpenSSL code base, it isn't my creation. Yes I remember the joy of Dec's own endian scheme.
crypto/params.c
Outdated
There was a problem hiding this comment.
I think quietly ignoring NULL parameters is a bad idea.
crypto/params.c
Outdated
There was a problem hiding this comment.
same thing; this is too clever for needless efficiency.
crypto/params.c
Outdated
There was a problem hiding this comment.
I'd prefer macros that cast things up to the largest integral size; why not?
crypto/params.c
Outdated
There was a problem hiding this comment.
This assumes that little-endian uses the lebin encoding. Are you sure that's true? If so, why?
There was a problem hiding this comment.
That's actually what is specified if you read the manual on OSSL_PARAM. "Native byte order"
crypto/params.c
Outdated
There was a problem hiding this comment.
After all, the whole point of this stuff was to just use the native encoding, no? BN's are strange and things become simpler if you just use canonical, IMO.
There was a problem hiding this comment.
What do you mean with "canonical"?
There was a problem hiding this comment.
Canonical means pick one format and use it, such as always using BN_lebin2bin. As it stands right now, you have to document the format of both BN2bin functions, right?
There was a problem hiding this comment.
Or simpler, just encode it as a byte array, LSB first, and document that.
There was a problem hiding this comment.
So basically, you're suggesting that we have two types of integers, one that fits in a long and is native byte order and one that fits in a BIGNUM and always LSB first no matter what?
How does that make anything easier? 'cause then you must suddenly check the size and choose the type depending on size...
There was a problem hiding this comment.
Where do you want the public community to discuss this, if not in the PR?
There was a problem hiding this comment.
The PR?
This PR is about wrappers around OSSL_PARAM. OSSL_PARAM itself comes from #8286 (and even further back, from the design document)
There was a problem hiding this comment.
This is the first PR that presents the real developer-facing API. The design document was not public during almost all of its writing. If you don't like comments here, again I ask where you want them?
There was a problem hiding this comment.
... If it's about OSSL_PARAM itself...
crypto/params.c
Outdated
There was a problem hiding this comment.
Be like classic C and just coerce float to double, and scalers to int/long.
doc/man3/OSSL_PARAM_get_int.pod
Outdated
There was a problem hiding this comment.
OMG. Gee that is a lot of functions. Dozens of them. Just do int/long and double.
doc/man7/openssl-core.h.pod
Outdated
There was a problem hiding this comment.
This is part of #8286 too.
I'm intending to provide a wrapper for this as well.
93b8b82 to
2dc3505
Compare
|
Well, until someone makes a final review of #8286, it's effectively stalled. So the answer is, someone has to take action. |
|
Or hold on a minute and I will simply rebase #8286 |
|
Done, please rebase this on top of a fresher 300-coredef |
|
Rebased with build errors. This PR is stalled until #8286 and beyond. The BIGNUM, octet and string types will other PRs I expect. |
|
One Travis failure is relevant (ppc little endian), the other two are too |
2fd1e94 to
8552366
Compare
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.
|
Finally got the tests passing. |
|
Leaner version in #8379 |
|
Closed in favour of the other two options. |
This builds on the work by @levitte in #8286
The aim is to provide extra utility routines that make dealing the OSSL_PARAMS easier, more type safe and (at least somewhat) resilient to changes in the future.
This PR deals with the numeric types only.