summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Retire the oct2point and point2oct EC_METHOD memberstb2024-10-314-32/+10
| | | | | | | | Both our remaining EC_METHODs use the methods that used to be called ec_GFp_simple_{oct2point,point2oct}() so there's no need for the function pointer indirection. Make the public API call them directly. ok jsing
* Clean up the mess in i2d_EC_PRIVATEKEY()tb2024-10-311-16/+36
| | | | | | | | | | | | | | | | Use a few local variables to make the checks at the start slightly less unappealing. Use those to simplify the conditionals a bit and avoid a particularly silly exit code. ok is set unless ret is 0, so what do you think 'return (ok ? ret : 0);' returns? By the way, ret < 0 is an error as well. While most of the stuff in this file could use a lot more cleanup, I think the first layer of cockroaches has been exterminated and there's even some faint golden glimmer between the turds. Let's shelve the biohazard warnings for now. ok jsing
* Clean up o2i_ECPublicKey()tb2024-10-311-14/+17
| | | | | | | | | | | | | a is a stupid name for an EC_key, so is ret. Pull apart the tests at the start and check the length for negativity (long is always the wrong type). Switch to ec_point_from_octets() and let it determine the point conversion form rather than having yet another copy of the same ugly stanza. Set the form on the key using EC_KEY_set_conv_form() (which also affects the group on the key, so this is a slight change of behavior). Why on earth this function returns the EC_KEY passed in, I'll never know. ok jsing
* Rewrite i2o_ECPublicKey()tb2024-10-311-26/+25
| | | | | | | | | | | | | | | | | | | | Turn the function into single exit and use ec_point_to_octets() to avoid the point2oct dance. Ensure that the buf_len size_t doesn't get truncated by the int return. While we could avoid an allocation in case out == NULL, we don't do so. In case out != NULL and *out != NULL this API assumes *out has sufficient room, copies the result into it and advances *out past it. This is just asking for trouble (of course, i2d has the same misfeature). Don't use this if you can help it. Unfortunately, OpenSSH couldn't help it in at least one spot (that one's on BoringSSL's allocator not returning an allocated pointer that you can pass to free). We had to do it lest people run RedHat patches of dubious quality. For: FIPS the monkey must be pleased at all cost. ok jsing
* ecp_oct.c no longer needs bytestring and stdinttb2024-10-311-4/+1
|
* ec_point_to_octets: move out_len initialization up a bittb2024-10-311-3/+3
|
* Expand the introductory comment with references to X9.62 and SEC 1tb2024-10-301-1/+4
|
* Move the point2bn and point2hex API to ec_convert.ctb2024-10-303-146/+84
| | | | discussed with jsing
* Replace hardcoded 1U with EC_OCT_YBITtb2024-10-301-2/+2
|
* Move the GFp-specific point <-> octets functions to ec_convert.ctb2024-10-302-296/+296
| | | | discussed with jsing
* Move public point <-> octets API to a new ec_convert.ctb2024-10-303-131/+202
| | | | discussed with jsing
* Rewrite EC_POINT_bn2point()tb2024-10-301-28/+15
| | | | | | | | | This is slightly asymmetric with EC_POINT_point2bn() and different from the other "print" functions since it has to deal with the asymmetry between BN_bin2bn() and BN_bn2bin() and allocate itself. Still, we can make this substantially shorter than it previously was. ok jsing
* Add ec_point_from_asn1_bit_string()tb2024-10-301-16/+20
| | | | | | | This is inverse to ec_point_to_asn1_bit_string(). Use it to simplify the ec_key_set_public_key() helper. ok jsing
* Add ec_point_from_asn1_octet_string()tb2024-10-301-13/+21
| | | | | | | This is inverse to ec_point_to_asn1_octet_string() but again a lot simpler. Simplify ec_asn1_set_group_parameters() by using it. ok jsing
* Provide ec_point_from_octets()tb2024-10-302-3/+35
| | | | | | | | | This is a wrapper that is the reverse of ec_point_to_octets(). It is a bit simpler since EC_POINT_oct2point() expects the point to be allocated already. It also hands back the correctly parsed point conversion form so that we don't have to do this by hand in a few places. ok jsing
* Rewrite BN_hex2point()tb2024-10-301-11/+12
| | | | | | This can do the reverse dance: chain BN_hex2bn() with EC_POINT_bn2point(). ok jsing
* Rewrite EC_POINT_point2hex()tb2024-10-301-34/+10
| | | | | | | | | | | | Instead of doing everything by hand, this can use EC_POINT_point2bn() and chain it with BN_bn2hex(), slashing the number of lines in half. This removes one of the ten remaining "01234567890ABCDEF" strings from libcrypto. Unfortunately, none of the nine others is used in an API that could convert the octet string directly, so we use that ugly detour via a bignum. Still it's better than what was there. ok jsing
* Rewrite EC_POINT_point2bn()tb2024-10-301-17/+11
| | | | | | | | | While it makes little sens to place either one of the uncompressed, the compressed or the hybrid X9.62 octet string encoding of an elliptic curve point into a BIGNUM, it is what this API does. It's ec_point_to_octets() followed by BN_bin2bn(). ok jsing
* ec_asn1_group2parameters: some spring cleaningtb2024-10-301-14/+12
| | | | | Garbage collect the ok variable and some comments from captain obvious, wrap a long line and tidy up the exit path.
* ec_asn1_group2parameters: replace point with generatortb2024-10-301-4/+4
|
* ec_asn1_group2parameters: mechanically replace ret with parameterstb2024-10-301-15/+15
|
* Provide ec_point_to_asn1_bit_string()tb2024-10-301-30/+14
| | | | | | | | This adds a specialized helper for creating an ASN.1 bit string out of an elliptic curve point (the public key) and use it in i2d_ECPrivateKey(). ok jsing
* Provide ec_point_to_asn1_octet_string()tb2024-10-301-26/+49
| | | | | | | | This adds a specialized helper for creating an ASN.1 octet string out of an elliptic curve point (the generator). Use this to simplify ec_asn1_group2parameters(). ok jsing
* Add a convenience wrapper for EC_POINT_point2oct()tb2024-10-302-2/+48
| | | | | | | | | EC_POING_point2oct() is annoying to use since its invocation involves two calls: one to determine the space to allocate and one to pass the buffer and perform the actual conversion. Wrap this dance in a helper with the correct signature. ok jsing
* Split ec_key_test_point_encoding() into chunks of saner sizetb2024-10-291-49/+172
|
* eckey_compute_pubkey: don't leak the public keytb2024-10-291-2/+1
| | | | | EC_KEY_set_public_key() sets a copy, so it doesn't take ownership and hence pub_key must not be nulled out on success.
* ec_asn1_test: point doubling is fine, the leak is elsewheretb2024-10-291-3/+1
| | | | (will be fixed shortly).
* Disable point doubling for now, it leaks due to a doc bug.tb2024-10-291-1/+3
| | | | | Can't replace it with adding the point to itself since that also leaks (another doc bug). Who would've thought.
* ec_asn1: zap an empty linetb2024-10-291-2/+1
|
* unifdef -m -DCORRECT_PRIV_KEY_PADDING=1 ec_asn1_test.ctb2024-10-281-9/+1
|
* Enable the tests that depend on correct private key paddingtb2024-10-281-2/+2
|
* Fix private key encoding in i2d_ECPrivateKey()tb2024-10-281-31/+40
| | | | | | | | | | | | | | The private key is a random integer between 1 and order - 1. As such it requires at most as many bytes as the order to encode. SEC 1, Section C.4 is very explicit about padding it to this length: The component privateKey is the private key defined to be the octet string of length [ceil(log_2 n/8)] (where n is the order of the curve) obtained from the unsigned integer via the encoding of Section 2.3.7. Fix this by generalizing a similar fix for field elements. ok jsing
* d2i_ECPrivateKey: split public key setting into a helpertb2024-10-281-36/+41
| | | | | | | | | | | | | | | If the public key is not part of the ECPrivateKey, it needs to be computed. Rather than doing this ad hoc inline, use the function from the ameth that already does this. If it is present, decode it after checking that its unused bits octet is zero. Again use the dedicated setter API to honor an eventual EC_KEY_METHOD. There remains a gross bit reading the point point conversion form out of the first octet of the bit string. This will go away in a later commit. ok jsing
* Expose eckey_compute_key() from ec_amethtb2024-10-282-3/+4
| | | | | | This helper will be needed in a subsequent commit. ok jsing
* d2i_ECPrivateKey: split private key setting into a helpertb2024-10-281-14/+31
| | | | | | | | | Contrary to domain parameters and public key, the private key most be part of the DER. Convert that to a BIGNUM and set it on the EC_KEY. Use the dedicated setter for this (which will possibly call the handler of the EC_KEY_METHOD) rather than doing this by hand. ok jsing
* d2i_ECPrivateKey: split parameter setting into a helpertb2024-10-281-8/+26
| | | | | | | | | | | | | | | | In order to decode a private key, the group must be known in some way. Typically, the group is encoded in the EC domain parameters, preferably as a named curve (this is mandatory in PKIX per RFC 5480). However, the group could be absent because the domain parameters are OPTIONAL in the ECPrivateKey SEQUENCE. In that case the code falls back to the group that may already be set on the EC_KEY. Now there is no way to tell whether that group is the right one... In any case. Split this thing out of the body of d2i_ECPrivateKey() to make that function a bit less of an eyesore. ok jsing
* Rename the EC_KEY in i2o_ECPublicKey() to ec_keytb2024-10-281-6/+6
|
* Rename the EC_KEY in i2d_ECPrivateKey() to ec_keytb2024-10-281-14/+14
|
* ec_print.c: fix includes.tb2024-10-281-2/+6
| | | | It doesn't currently need ec_local.h, but it will soon, so leave it there.
* c2sp: run test against openssl/3.4 if it is installedtb2024-10-281-2/+2
|
* d2i_ECParameters: clean up entry and exittb2024-10-271-13/+17
|
* d2i_ECParameters: rename a to out_ec_keytb2024-10-271-7/+7
|
* d2i_ECParameters: rename ret to ec_keytb2024-10-271-9/+9
|
* i2d_ECParameters: rename a to ec_keytb2024-10-271-4/+4
|
* {d2i,i2d}_ECParameters() also want a bit of exercisingtb2024-10-261-1/+28
|
* d2i_ECPrivateKey: move the version setting where it belongstb2024-10-261-2/+2
|
* d2i_ECPrivateKey: minor cleanup for entry and exit pathtb2024-10-261-13/+13
| | | | | Reduces an upcoming diff which is hard enough to review without these distractions.
* a and ret aren't great names for EC_KEYstb2024-10-261-26/+26
|
* Mechanically rename priv_key to ec_privatekeytb2024-10-261-27/+27
|
* ec_asn1_test: play some silly games to cover a few more code pathstb2024-10-261-1/+47
|