1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00
Commit Graph

22872 Commits

Author SHA1 Message Date
schwarze
a63b39658a Add an EXAMPLES section.
I admit this is unusually long for a manual page.  But that's not my fault
as a documentation author.  An example in a manual page ought to be minimal
to show what needs to be demonstrated, and this example is minimal in that
sense.  Making it shorter without loosing important aspects does not seem
possible.

When an API is poorly designed, one of the consequences is that that
documentation becomes harder to understand and often longer - in this
case to the point of becoming outright intimidating.  If people dislike
that, they should design better APIs in the first place rather than
blasting the poor manual page for being too long or too complicated.

OK tb@
2024-12-21 00:27:47 +00:00
schwarze
4ac9059474 If EVP_CIPHER_CTX_ctrl(3) is called on EVP_chacha20_poly1305(3)
with an unsupported control command, return -1 rather than 0
to the caller to indicate the error because in general, these
control hooks ought to return -1 for unsupported control commands
and 0 for other errors, for example other invalid arguments.

Not a big deal because this change does not change when operations
succeed or fail, and because callers are unlikely to pass unsupported
control commands in the first place.  The only functional change is that
if a calling program inspects the ERR(3) stack after this failure,
it will now find the correct error code rather than nothing.
Even that wasn't a huge problem because for most EVP_CIPHER control
failures, getting no reason for the error is the usual situation.
Then again, giving the reason when easily possible may occasionally
be useful.  OpenSSL also returns -1 in this case, so it also helps
compatibility a tiny bit.

Found while auditing the return values of all the EVP_CIPHER
control hooks in our tree.  This was the only fishy one i found.

OK tb@
2024-12-20 20:05:29 +00:00
tb
b229b719d0 hidden mlkem.h: add comment to #endif 2024-12-20 15:10:31 +00:00
tb
abab89db3f Annotate yet another greasy stinky tentacle of xca
I'm so tired of this.
2024-12-20 09:40:29 +00:00
schwarze
ff6a185afe Move the horrific EVP_aes_128_ccm(3) API out of the important,
algorithm-independent EVP_EncryptInit(3) manual as another step
in making the latter leaner and more palatable.

As a side benefit, the new EVP_aes_128_ccm(3) manual page may provide
a better fighting chance to programmers who see themselves forced to
support CCM for whatever reason.  It documents the mandatory, but so
far undocumented EVP_CTRL_CCM_GET_TAG control command and makes the
description of the three EVP_CTRL_CCM_SET_* control commands and the
numerous related quirks more precise.
2024-12-20 01:54:03 +00:00
tb
822ced31eb Do not install mlkem.h and bytestring.h into /usr/include/openssl for now
More work in mlkem is needed and this was premature.

discussed with beck and jsing
2024-12-19 23:56:32 +00:00
tb
9c470d64a6 #ifdef out the inclusion of openssl/mlkem.h for now
discussed with beck and jsing
2024-12-19 23:53:38 +00:00
tb
ef1019e622 Do not assume mlkem.h and bytestring.h are public in libcrypto
As long as is not quite clear what we want to do about the public API
aspect of MLKEM, keep things internal for now.

discussed with beck and jsing
2024-12-19 23:52:26 +00:00
tb
3d8e7e8c72 ec_mult: use 1ULL to avoid C4334 warning on Visual Studio
The shift is between 0 and 5 bits, so it doesn't matter, but VS is short
for very st...ubborn as are its users when it comes to reporting non-issues
2024-12-19 21:05:46 +00:00
jmc
72dde9b872 received form the peer -> received from the peer 2024-12-19 06:45:21 +00:00
tb
67abc7a12c mlkem: fix whitespace 2024-12-18 10:55:21 +00:00
jsg
633da3e108 kength -> length 2024-12-18 04:15:48 +00:00
schwarze
f5255f98a5 New manual page EVP_aes_128_gcm(3).
The main benefit is moving the cumbersome and error-prone method of
using EVP_EncryptInit(3) for AES-GCM out of the important, but obese
manual page EVP_EncryptInit(3), and to create a logical place for
pointing readers to the safer and more flexible EVP_AEAD_CTX_init(3).

As a side benefit, document three control commands that were so far
undocumented and make the description of three others more precise.

Feedback and OK tb@.
2024-12-17 18:11:44 +00:00
beck
9ee6f1fe20 Avoid a reduce once that can cause Clang misoptomization.
Some versions of Clang compile this to non-constant time
code. The fix is adapted from boring. For full details see:
https://boringssl-review.googlesource.com/c/boringssl/+/74447

ok tb@
2024-12-17 17:06:10 +00:00
tb
516824a334 Plug two memory leaks in MLKEM*_generate_key_external_entropy()
This needs more thinking. These are void functions that allocate...
Left an XXX for now.

From Kenjiro Nakayama
2024-12-17 07:13:47 +00:00
tb
bee138d50b mlkem: clean up top matter in headers 2024-12-17 06:43:32 +00:00
tb
f88109403c Simplify ec_point_to_octets()
This had an extra dance to allow a NULL output buffer. The plan was to
use this in i2o_ECPublicKey() to preserve the behavior of avoiding an
allocation if out == NULL. However, when I rewrote the latter I punted
on preserving that complication, as it was already batshit crazy enough.

Thus, remove said dance and make ec_point_to_octets() cleaner.

ok jsing
2024-12-16 06:11:26 +00:00
beck
08c63c712f Add ML-KEM 1024 from BoringSSL
Changes include conversion from C++, basic KNF, then adaptation to
use our sha3 functions for sha3 and shake instead of the BorinSSL
version. This Adds units tests to run against BoringSSL and NIST test
vectors.

The future public API is the same as Boring's - but is not yet exposed
pending making bytestring.h public (which will happen separately) and
a minor bump

Currently this will just ensure we build and run regress.

ok tb@ to get it into the tree and massage from there.
2024-12-13 00:17:17 +00:00
beck
267e7b7d19 KNF nit tb wanted me to fix 2024-12-13 00:09:02 +00:00
beck
75c083a031 Add ML-KEM 768 from BoringSSL
Changes include conversion from C++, basic KNF, then adaptation to
use our sha3 functions for sha3 and shake instead of the BorinSSL
version. This Adds units tests to run against BoringSSL and NIST test
vectors.

The future public API is the same as Boring's - but is not yet exposed
pending making bytesring.h public (which will happen separately) and
a minor bump

Currently this will just ensure we build and run regress.

ok tb@ to get it into the tree and massage from there.
2024-12-13 00:03:57 +00:00
tb
823dae7d71 Rewrite a comment to use p rather than q 2024-12-12 10:02:00 +00:00
tb
3fd2f05c57 Rename group->field to group->p
Now that we only do curves over GF(p) fields, there's no need to use a
weird, confusing name for what we usually call p. Adjust some comments
in the vicinity as well.
2024-12-12 10:00:15 +00:00
tb
c18e04ad92 sm3: fix ugly whitespace 2024-12-12 09:54:44 +00:00
jsg
f76b031fdc appeared in 4.3BSD before 4.3BSD-Tahoe
ok millert@ schwarze@
2024-12-11 23:28:20 +00:00
tb
131e173293 Avoid an oob access in asn1_item_free()
As explained in a comment, this needs to loop backwards and the last tt--
ends up pointing at &it->templates[-1], which isn't ok. Use a simple way
of looping, which is also ugly and involves some type confusion as pointed
out by claudio. However, type confusion is common in libcrypto's asn1 code
and won't be fixed anytime soon anyway.

ok jsing
2024-12-11 11:22:06 +00:00
tb
497a100a3b Drop a pair of useless parentheses 2024-12-11 10:28:03 +00:00
schwarze
fe039420e7 Improve a rather misleading sentence about EVP_PKEY_new_mac_key(3).
It does *not* "work in the same way" as EVP_PKEY_new_raw_private_key(3)
but merely arrives at the same end result after doing lots of
cumbersome and unnecessary work - and on top of that, it only works
for EVP_PKEY_HMAC.
2024-12-10 15:10:26 +00:00
schwarze
a9a4d01cec Add a paragraph about HMAC because that algorithm also involves
parameters that can be controlled with EVP_PKEY_CTX_ctrl(3).
But rather than providing a detailed despription, instead
point to what application programs should use instead and explain
why using the control constant directly would be a particularly bad
idea in this case.
2024-12-10 14:54:20 +00:00
tb
5ad0d35887 Document tls_peer_cert_common_name()
ok beck
2024-12-10 08:42:12 +00:00
tb
4c4812c958 bump minor after symbol addition 2024-12-10 08:41:04 +00:00
tb
7c96010cd4 expose tls_peer_cert_common_name() 2024-12-10 08:40:45 +00:00
tb
26433cb13c Provide tls_peer_cert_common_name()
There is currently no sane way of getting your hands on the common name or
subject alternative name of the peer certificate from libtls. It is possible
to extract it from the peer cert's PEM by hand, but that way lies madness.
While the common name is close to being deprecated in the webpki, it is
still the de facto standard to identify client certs. It would be nice to
have a way to access the subject alternative names as well, but this is a
lot more difficult to expose in a clean and sane C interface due to its
multivaluedness.

Initial diff from henning, with input from beck, jsing and myself
henning and bluhm have plans of using this in syslogd.

ok beck
2024-12-10 08:40:30 +00:00
schwarze
f0955a9c84 insert a forgotten .Dv macro 2024-12-09 11:55:52 +00:00
schwarze
4594425fa5 Mark the constants EVP_PK_*, EVP_PKS_*, and EVP_PKT_* as intentionally
undocumented because they are only used by the function X509_certificate_type()
which is deprecated and will eventually be deleted.
2024-12-09 11:25:25 +00:00
schwarze
380ecedd40 Move the algorithm-specific functions EVP_rc2_*(3) out of EVP_EncryptInit(3)
and document them properly in their own manual page, including the control
commands EVP_CTRL_SET_RC2_KEY_BITS and EVP_CTRL_GET_RC2_KEY_BITS that were
so far undocumented.

Arguably, the main benefit is another small step making the important,
but still obese EVP_EncryptInit(3) manual page more palatable.
2024-12-08 17:41:23 +00:00
schwarze
60c3061599 Document the low-level rc2.h API.
Not that this would be particularly important, but i had to look
at the code anyway while completing the EVP documentation.
2024-12-07 19:22:15 +00:00
tb
4ccb460550 ec_mult: forgot to make one helper static 2024-12-07 13:49:43 +00:00
tb
08f8d31902 Move initialization of sign out of the middle of bits handling 2024-12-07 13:32:07 +00:00
tb
9d4c47a84d Rename ec_wNAF_mul() to ec_wnaf_mul()
discussed with jsing
2024-12-06 15:49:37 +00:00
tb
2380456e4c ec_mult: manage wNAF data in a struct
This refactors the wNAF multiplication further and introduces a small API
that manages the wNAF digits for bn and the multiples of digit * point in
a single struct that is initialized and freed in two API calls in the main
function, ec_wNAF_mul(). This way the main algorithm is no longer cluttered
with logic to keep various arrays in sync, helper functions calculating the
wNAF splitting of bn and multiples of the point do not need to deal with
memory management, and a pair of accessors obviates previously missing
bounds checking.

At this point we have reached a relatively clean and straightforward wNAF
implementation that fits precisely the purpose needed in libcrypto, i.e.,
ECDSA verification instead of being generalized and optimized to the max
for no good reason apart from endowing the author with an academic degree.

Popper's famous maxim "if you can't say it clearly, keep quiet, and keep
working until you can" very much applies to code as well. In other words,
shut up and hack (and don't pour too much energy into commit messages, tb).

ok jsing
2024-12-06 15:39:59 +00:00
schwarze
3f6360fc06 Adjust the return type and value of EVP_MD_CTX_init(3)
and EVP_CIPHER_CTX_init(3) after tb@ changed these to OpenSSL 1.1 semantics
in evp.h rev. 1.124 on March 2 this year.
2024-12-06 15:01:01 +00:00
schwarze
f1c41952de Delete the manual pages EVP_PKEY_meth_new(3) and EVP_PKEY_meth_get0_info(3)
because tb@ deleted almost all functions documented there from the API
in evp.h 1.127 on March 2 this year, but move the functions
EVP_PKEY_CTX_set_data(3) and EVP_PKEY_CTX_get_data(3) that we still
support to EVP_PKEY_keygen(3), because that page already documents
EVP_PKEY_CTX_set_app_data(3) and EVP_PKEY_CTX_get_app_data(3).
2024-12-06 14:27:49 +00:00
schwarze
cb0afab4d7 Delete the manual page EVP_PKEY_check(3).
All three functions documented in this page were deleted from the API
by tb@ in evp.h rev. 1.136 on August 31 this year.
2024-12-06 13:10:43 +00:00
schwarze
957fef74ea Delete the manual page EVP_PKEY_asn1_new(3).
All the functions documented in this page were deleted from the API
by tb@ in evp.h rev. 1.126 on March 2 this year.
2024-12-06 12:51:13 +00:00
jsing
90c5a28a23 Provide a SHA-1 assembly implementation for amd64 using SHA-NI.
This provides a SHA-1 assembly implementation for amd64, which uses
the Intel SHA Extensions (aka SHA New Instructions or SHA-NI). This
provides a 2-2.5x performance gain on some Intel CPUs and many AMD CPUs.

ok tb@
2024-12-06 11:57:17 +00:00
schwarze
0afdf00682 Explain what "EVP" is supposed to mean.
It's so non-obvious that even i had to do some research to find out.
Source: The file "doc/ssleay.doc" from SSLeay 0.8.1b,
see for example OpenSSL commit d02b48c6 on Dec 21, 1998.
2024-12-06 11:56:21 +00:00
tb
59c41a1786 Fix previous and thus regress failures reported by anton
Looks like I applied the diff to a dirty tree and didn't notice.
2024-12-06 07:10:20 +00:00
tb
ce5fd5cb4f ec_asn1: update a comment to match reality 2024-12-06 05:13:35 +00:00
tb
c9c3f1d69f Set nid on group decoded from EC parameters
We match curve parameters against the builtin curves and only accept
them if they're encoding a curve known to us. After getting rid of the
wtls curves, some of which used to coincide with secp curves (sometimes
the wrong ones), the nid is unambiguous. Setting the nid has no direct
implications on the encoding.

This helps ssh avoid doing ugly computations during the key exchange
for PEM keys using this encoding.

ok djm joshua jsing
2024-12-06 04:35:03 +00:00
tb
f88101f637 Zap a trailing space 2024-12-05 19:57:37 +00:00