summaryrefslogtreecommitdiff
path: root/lib/libcrypto/ec
AgeCommit message (Collapse)Author
2023-11-09Convert ecx_item_sign() to X509_ALGOR_set0_by_nid()Theo Buehler
ok jca
2023-09-24Break two ridiculously long lines in ec_pub_cmp() and ec_cmp_parameters()Theo Buehler
2023-09-24Refactor eckey_{param2type,type2param}()Theo Buehler
EC key parameters can be determined by an OID or they can be explicitly encoded. The confusingly named eckey_{param2type,type2param}() decode a new EC key from either form of parameters, or they encode a given key's parameters in the proper way. Signature and semantics are all over the place. It also features an inlined version of EC_KEY_new_by_curve_name(). This commit brings some order into this mess. Parameters are given by a pair (ptype, pval), where the ptype is either V_ASN1_OBJECT for OID encoding or V_ASN1_SEQUENCE for explicit encoding. Accordingly, the void pointer pval is an ASN1_OBJECT or an ASN1_STRING. These pairs are abstracted away in the X509_ALGOR object. The library decides whether a given EC key uses OID or explicit parameter encoding using the asn1_flag on the EC key's internal EC_GROUP, i.e., the object representing its curve. If this flag is set, the OID is determined by the nid returned by EC_GROUP_get_curve_name(). Add 'mutually inverse' pairs of functions eckey_{to,from}_params() which wrap eckey_{to,from}_object() and eckey_{to,from}_explicit_params(). This way the EC ameth pub and priv key de/encoding functions can transparently translate from/to an X509_ALGOR object. Of course, this is just an intermediate step and if you look closely you notice const weirdness (due to the fact that the carefully planned and executed const rampage missed the ECParameters API) and all sorts of other things that need to be fixed. Who would bat an eye lid? It wouldn't be visible amid all the twitching anyway. ok jsing
2023-08-21ec_ameth: clean up eckey_{pub,priv}_encode()Theo Buehler
Factor eckey_param_free() out of eckey_pub_encode(). ASN1_OBJECT_free() is not actually needed. This will be addressed later. i2o_ECPublicKey() allocates internally if *out == NULL, so no need to do the two-call dance. Its return value is documented to be <= 0 on error, which is wrong in the sense that only 0 is returned. Keep using the same check for <= 0 as everywhere else. Set of EC_PKEY_NO_PARAMETERS after the poorly named eckey_param2type() to avoid potential underhanded side effects. In eckey_priv_encode(), error exits would leak pval was leaked a few times. Avoid this and simplify using i2d's internal allocation. Reinstate the flags in a single error path. ok jsing
2023-08-12The int_ prefix also leaves the ec_ameth messTheo Buehler
The prefixes in here are all over the place... This removes one variety.
2023-08-11Move EC_KEY and EC_KEY_METHOD typedefs to ossl_typ.hTheo Buehler
ok jsing
2023-08-03Make the bn_rand_interval() API a bit more ergonomicTheo Buehler
Provide bn_rand_in_range() which is a slightly tweaked version of what was previously called bn_rand_range(). The way bn_rand_range() is called in libcrypto, the lower bound is always expressible as a word. In fact, most of the time it is 1, the DH code uses a 2, the MR tests in BPSW use 3 and an exceptinally high number appears in the Tonelli-Shanks implementation where we use 32. Converting these lower bounds to BIGNUMs on the call site is annoying so let bn_rand_interval() do that internally and route that through bn_rand_in_range(). This way we can avoid using BN_sub_word(). Adjust the bn_isqrt() test to use bn_rand_in_range() since that's the only caller that uses actual BIGNUMs as lower bounds. ok jsing
2023-07-28Stop including ecdsa.h and ecdh.h internallyTheo Buehler
These headers are now reduced to #include <openssl/ec.h> and are provided for compatiblity only. There's no point in using them. At the same time garbage collect the last uses of OPENSSL_NO_{ECDSA,ECDH} in our tree. ok jsing
2023-07-28Move KDF handling to ECDH_compute_key()Theo Buehler
In OpenSSL e2285d87, the KDF handling was moved from the compute_key() method into the public API. A consequence of this change is that the ECDH_compute_key() API no longer returns -1 for some errors. Existing checks for <= 0 are safe as are those checking for the exact length as return value, which is all what the ecosystem seems to be doing. ok jsing
2023-07-28Merge ecdh.h into ec.hTheo Buehler
The remaining two ECDH interfaces are relocated into ec.h. ecdh.h remains. It does nothing but include ec.h. ok jsing
2023-07-28Merge ecdsa.h into ec.hTheo Buehler
Move the remaining ECDSA API into ec.h to match OpenSSL 1.1's interface better. In particular, the EC_KEY sign and verify method accessors are moved to the right header. Whether the rest of the ECDSA stuff belongs there is debatable, but that was upstream's choice. ok jsing
2023-07-26Tweak EC_GROUP_check_discriminant()Theo Buehler
Make the logic and control flow a bit more explicit and use a single extra variable for computing the discriminant. Call it discriminant, not tmp, tmp_1 or tmp_2. ok jsing
2023-07-26Unindent a big block in EC_GROUP_get_affine_coordinates()Theo Buehler
2023-07-26Introduce and use ec_encode_scalar()Theo Buehler
This introduces two "inverses" of the ec_decode_scalar() function that take a BIGNUM, reduce it modulo p and then encodes it into the curve's field representation. For setting projective coordinates, we need a specialized helper that deals with the Z_is_one optimization that is used to optimize for calculations in standard affine coordinates of the projective plane. This is used for simplifying EC_POINT_set_Jprojective_coordinates() and for cleaning up and streamlining EC_GROUP_set_curve(). ok jsing
2023-07-26Garbage collect the unused order in check_discriminant()Theo Buehler
ok jsing
2023-07-26Streamline check_discriminant()Theo Buehler
Instead of inlining EC_GROUP_get_curve(), we can simply call it... ok jsing
2023-07-26Introduce ec_decode_scalar()Theo Buehler
This is a helper that decodes a scalar from field-internal representation to a representation as a BIGNUM in the interval [0, p). This simplifies EC_GROUP_get_curve() and EC_POINT_get_Jprojective_coordinates() to a few obvious lines and prepares cleanup in EC_POINT_get_affine_coordinates(). ok jsing
2023-07-26Use EC_POINT_set_to_infinity() rather than inlining itTheo Buehler
2023-07-25Fix a few more 0/NULL misspellingsTheo Buehler
2023-07-25Use [a,b), not [a,b-1] in a commentTheo Buehler
2023-07-25EC_POINT_is_on_curve() error is -1, not 0.Theo Buehler
ok miod
2023-07-22Tweak previous. Should have been 60 instead of 64Theo Buehler
2023-07-22Adapt bn_print() for EdDSA key printingTheo Buehler
This is essentially a reimplementation of ASN1_buf_print(). The latter was only added for these printing purposes and it will be removed again since nothing uses it. We can then simply remove t_pkey.c in the upcoming bump. ok jsing
2023-07-07Unbreak the namespace build after a broken mk.conf and tool misfire hadBob Beck
me aliasing symbols not in the headers I was procesing. This unbreaks the namespace build so it will pass again ok tb@
2023-07-07Hide symbols in hkdf, evp, err, ecdsa, and ecBob Beck
(part 2 of commit) ok jsing@
2023-07-07Mop up remaining uses of ASN1_bn_print()Theo Buehler
This removes lots of silly buffers and will allow us to make this API go away. ok jsing
2023-07-06Convert ecpk_print_explicit_parameters() to bn_printf()Theo Buehler
This eliminates a few stupid dances the horrible ASN1_bn_print() API required. ok jsing
2023-07-05don't return in a void functionBrent Cook
ok tb@
2023-07-05Mop up last uses of ECDHerror() and ECDSAerror()Theo Buehler
ok jsing
2023-07-05Rename ecs_local.h into ecdsa_local.hTheo Buehler
2023-07-05Drop useless ossl_ prefixesTheo Buehler
discussed with jsing
2023-07-03Explicit parameter printing can also use get0_order()Theo Buehler
ok beck jsing
2023-07-03Convert ossl_ec_key_gen() and EC_KEY_check_key()Theo Buehler
These also get the EC_GROUP_get0_order() treatment ok beck jsing
2023-07-03Convert EC_GROUP_check() to EC_GROUP_get0_order()Theo Buehler
ok beck jsing
2023-07-03Inline two copies of EC_GROUP_order_bits()Theo Buehler
This code is way more complicated than it needs to be. Simplify. ec_bits() was particularly stupid. ok beck jsing
2023-07-03Provide internal-only EC_GROUP_get0_order()Theo Buehler
ok jsing
2023-07-02Fix return values of ecx methodsTheo Buehler
It is hard to get your return values right if you choose them to be a random subset of {-2, ..., 3}. The item_verify() and the digestverify() methods don't return 0 on error, but -1. Here 0 means "failed to verify", obviously. ok jsing
2023-07-02Fix typo in previousTheo Buehler
2023-07-02Use asprintf() to avoid repetition in string constantsTheo Buehler
... since ASN1_bn_print() is stupid. ok jsing
2023-07-02Split ECPKParameters_print()Theo Buehler
This function has two entirely independent parts, so instead of a huge if/else just use two functions. In ecpk_print_explicity parameters() do some additional boring cleanup such as switching to actually using the local BN_CTX and shuffling things into a slightly more sensible order. ok jsing
2023-07-01Simplify ASN1_bn_print() usage in ec/Theo Buehler
ASN1_bn_print() doesn't print anything if the BIGNUM passed in is NULL. Also simplify the handling of the point conversion form of the generator. ok jsing
2023-06-30whitespaceTheo Buehler
2023-06-27Remove some dead code from ECPKParameters_print()Theo Buehler
This code is unreachable since binary curve support was removed. There is a lot more to clean up in here... ok jsing
2023-06-27Remove the now unused poly[] from EC_GROUPTheo Buehler
This was needed for defining the multiplication over binary fields. Since that code is gone, this is no longer needed. ok jsing
2023-06-27Simplify EC_GROUP_get_basis_type()Theo Buehler
The remaining EC_METHODs in libcrypto all have a field type of NID_X9_62_prime_field, so this function always returns 0. Make that more obvious. ok jsing
2023-06-25Stop including ech_local.hTheo Buehler
2023-06-25Remove prototypes for EC_KEY_{get,insert}_key_method_data()Theo Buehler
These were accidentally left behind in a previous commit.
2023-06-25Move ecdh_KDF_X9_63() to ec_local.hTheo Buehler
In anticipation of merging ecdh/ and ecdsa/ into ec/, move the last remaining thing in ech_local.h where it will soon belong.
2023-06-25Remove EC_EXTRA_DATATheo Buehler
With the ecdh_check() and ecdsa_check() abominations gone, we can finally get rid of EC_EXTRA_DATA and EC_KEY_{get,insert}_key_method_data(). The EC_EX_DATA_*() handlers, (which fortunately have always had "'package' level visibility") join the ride to the great bit bucket in the sky. Thanks to op for making this possible. ok jsing
2023-06-25ec_local.h: move ec_group_simple_order_bits down a bitTheo Buehler