117 Commits
Author SHA1 Message Date
David Benjamin f84e4e8c6a Remove unused bputs hook
Bug: 412269080
Change-Id: Iab4951efc53005d9aa5e02067da65561bcffcf1c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79568
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-05-27 13:00:47 -07:00
David Benjamin 8edfd1b30c Make BIO and BIO_METHOD opaque
This does not switch our internal BIOs to the public APIs yet. The
tricky aspects are:

- We need a CRYPTO_once to fill in the BIO_METHOD, which is a little
  tedious without __cxa_guard_acquire.

- bio->num is not exposed. External BIOs are expected to just make their
  BIO_get_data structure more involved.

Update-Note: Callers should switch to public APIs.

Bug: 412269080
Change-Id: I09a2f61c653cf7a48412d9088e437b2bbbea3bb2
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79567
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-05-27 13:00:42 -07:00
David Benjamin e88e506969 Rewrite crypto_md32_* with templates instead of function pointers
Speculative improvement for b/413675390, but there is insufficient
information in the bug to really be sure, and benchmarking does not seem
to give consistent results.

It seems that crypto_md32_* are not getting inlined when being built
with the NDK, which means we're not specializing by block size and we're
calling the block data functions indirectly. It's unclear what changed
here, as this code has been the same for a while. The root cause might
have been a compiler change.

Either way, switching to templates avoids tempting the compiler into
doing this, without the mess of macros that we had a while ago.
Inspecting the assembly, this seems to fix the codegen, but benchmarking
performance on my test device is very inconsistent.

Change-Id: Ib7c1e97d4d7a3e3b82a8cc5f0418b8b1100c330d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78989
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2025-05-01 12:19:04 -07:00
David Benjamin 3718975696 Make LHASH a completely internal type
The one remaining external reference was in an unused parameter where it
was impossible to obtain a non-null value. Remove the last of that
machinery from the public API. This leaves us free to completely rework
LHASH_OF(T) internally, including making it a template that understands
whether it owns its values.

(If we end up needing to revert it, we can still make the real
LHASH_OF(T) into a template. It just won't be called LHASH_OF(T)
anymore.)

Update-Note: Calling code which references LHASH_OF(T) will no longer
compile. We have had no public APIs that allow a caller to usefully
construct an LHASH_OF(T) for some time, so this only ever came up in odd
cases around bindings APIs.

Change-Id: I5a44310b04d8f8f3599f0f356b64786e62db5fbf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78787
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-04-22 12:29:02 -07:00
David Benjamin 690261bafd Align bio_info_cb with upstream OpenSSL
A few things got lost in translation here:

OpenSSL has two (well, three with BIO_set_callback_ex) BIO callback
signatures: BIO_callback_fn and BIO_info_cb. BIO_info_cb was formerly
known as bio_info_cb.

    typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi,
                                    long argl, long ret);
    typedef int BIO_info_cb(BIO *, int, int);

Note that BIO_info_cb is a typedef for the function type, not the
pointer type.

BIO_callback_fn is used with BIO_set_callback, which is some callback
that hooks into every BIO operation, using BIO_CB_* constants.

BIO_info_cb* is used in two places. First, it is the type-erased
function pointer type for BIO_callback_ctrl, a separate control type for
BIO_CTRL_* that needs to pass in function pointers. Second, it is the
actual function pointer type for BIO_set_info_callback, which is the
only thing that uses BIO_callback_ctrl.

In the initial fork, we somehow got bio_info_cb defined as
BIO_callback_fn and passed into BIO_set_callback.
https://boringssl-review.googlesource.com/c/boringssl/+/19184 removed
BIO_set_callback, but forgot to remove the now outdated documentation
for bio_info_cb and the unusable BIO_CB_* constants.

This CL does the following:

1. Finish removing the remants of BIO_set_callback.

2. Introduce BIO_info_cb, OpenSSL's new preferred name for bio_info_cb,
   and make it match OpenSSL.

3. Redefine bio_info_cb as a deprecated alias for BIO_info_cb.

4. Update all the callback_ctrl implementations to reflect the new
   types (function pointer vs function). Although since function
   arguments decay to function pointer arguments, it's actually moot.

5. Make the connect BIO's callback type match upstream OpenSSL and
   BIO_info_cb and non-const.

This whole machinery is kinda pointless and we should probably unwind it
all, but this CL just fixes it for now.

Change-Id: I1972c62c638b96f45189d733067aa59602d9b18f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78830
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-04-22 12:20:59 -07:00
David Benjamin ea482ed0e7 Switch a bit more of libcrypto to scopers
There was no real organization to which files I looked at here. Mostly
just bounced around. At some point we'll probably need to set up some
more infrastructure though:

- For functions to return UniquePtr, they need to stop being C linkage,
  which is something we want to do anyway.

- For types to use UniquePtr, we need to get them out of malloc/free and
  into the realm of constructors and destructors. That probably means
  moving some of the helpers from ssl/internal.h to crypto/internal.h.

- UniquePtr is not very good at buffers. We should probably move Array
  Vector, and InPlaceVector to crypto/internal.h.

Change-Id: I90ebc917051d354c0e447598f382db6b22eb8813
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78687
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-04-17 20:07:10 -07:00
David Benjamin 126de11fc1 Remove MSVC warning suppressions around Windows system headers
These seem to no longer be needed? Over time we have gotten a bit more
measured about enabling all of MSVC's warnings (MSVC is just not
designed to be used with -Wall), so I'm guessing that's what changed.

Change-Id: If71850136fb83841a423b63bdf65c2d546ba0223
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77887
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2025-03-20 21:40:35 -07:00
David Benjamin 33d1049b1f Switch the license to Apache 2.0, matching OpenSSL upstream
We use the standard Apache 2.0 file header, described in "APPENDIX: How
to apply the Apache License to your work."

This was primarily automated by running:

  git ls-tree -r --name-only HEAD | xargs go run ./util/relicense.go

See go/boringssl-relicensing-triage for the results of triaging the
output of the tool.

As part of this, switch from taking fiat-crypto under MIT license to
Apache 2.0. (It is licensed under MIT OR Apache-2.0 OR BSD-1-Clause.)

The copyright_summary tool can also be used to confirm we didn't
accidentally drop any copyright lines:

  # Run before the CL
  git grep -l Copyright | xargs go run ./util/copyright_summary.go  -out /tmp/old.json
  # Run after the CL
  git grep -l Copyright | xargs go run ./util/copyright_summary.go  -compare /tmp/old.json

Bug: 364634028
Change-Id: I17c50e761e9d077a1f92e25969e50ed35e320c59
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75852
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-02-03 15:05:16 -08:00
Bob Beck 817ab07ebb Collapse the modes directory into aes
Before further surgery on aes for BCM purposes.

Bug: 392625968
Change-Id: If87ef7c391ef46b09d2b68ddd1065810a71f0bf9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75787
Auto-Submit: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2025-01-28 15:16:50 -08:00
David Benjamin 4854ec106f Apply OpenSSL's "copyright consolidation" changes
This applies the OpenSSL "copyright consolidation" process from the
following upstream changes:

* https://github.com/openssl/openssl/commit/e0a651945cb5a70a2abd9902c0fd3e9759d35867
* https://github.com/openssl/openssl/commit/3fb2cf1ad19feaf6f7c571b49bd9e320eb4daf31
* https://github.com/openssl/openssl/commit/ac3d0e13777a0f0533792ed8fdd7de485675a3a2
* https://github.com/openssl/openssl/commit/c2f312f5c2379e1dcb6b3678bda27f7544508ee6
* https://github.com/openssl/openssl/commit/596d6b7e1ca5aa24700098e262cb1625f256343f
* https://github.com/openssl/openssl/commit/e18cf66aaf44b4d476625b2416386b051007d495
* https://github.com/openssl/openssl/commit/846e33c729311169d9c988ceba29484b3783f244
* https://github.com/openssl/openssl/commit/440e5d805f449d662520313b33fd90aeee86980b
* https://github.com/openssl/openssl/commit/21dcbebc6e35419f1842f39a125374ea1ba45693
* https://github.com/openssl/openssl/commit/6286757141a8c6e14d647ec733634ae0c83d9887
* https://github.com/openssl/openssl/commit/4f22f40507fea3f272637eb8e00cadf1f34b10d9
* https://github.com/openssl/openssl/commit/d2e9e320186f0917cc940f46bdf1a7e4120da9b0
* https://github.com/openssl/openssl/commit/2039c421b0e5b75ffcf6a88e39cc09089b4303dc
* https://github.com/openssl/openssl/commit/b1322259d93cf6b6286f9febcd468b6a9f577d91
* https://github.com/openssl/openssl/commit/aa6bb1352b1026b20a23b49da4efdcf171926eb0
* https://github.com/openssl/openssl/commit/b6cff313cbb1d0381b329fe4f6a8f009cdb270e4
* https://github.com/openssl/openssl/commit/9e20068958b8c1772067299dda7df0b8a82283b4
* https://github.com/openssl/openssl/commit/6aa36e8e5a062e31543e7796f0351ff9628832ce
* https://github.com/openssl/openssl/commit/44c8a5e2b9af8909844cc002c53049311634b314

This was mostly automated, but partially manual. The automated portion
can be reproduced by checking OpenSSL to commit
44c8a5e2b9af8909844cc002c53049311634b314, and running the following:

  git grep -l -E 'Copyright remains Eric Young|Copyright.*The OpenSSL Project\.|Written by.*for the OpenSSL Project' crypto/ decrepit/ include/ ssl/ | grep -v objects.go > files.txt
  cat files.txt | xargs -n1 perl -i ./util/copyright.pl

From there, some years were fixed up manually according to
go/openssl-copyright-consolidation-comparison (internal-only).

Three files required additional manual fixing:

- crypto/ecdh_extra/ecdh_extra.cc
- crypto/fipsmodule/ecdh/ecdh.cc.inc
- include/openssl/ecdh.h

These files have an OpenSSL header, but *after* a different header, so
the script does not correctly detect the now redundant OpenSSL header.
They were manually modified to remove it. This matches what seems to
have been done to crypto/ec/ecdh_ossl.c in OpenSSL's
4f22f40507fea3f272637eb8e00cadf1f34b10d9.

Bug: 364634028
Change-Id: I79a559a409ebe2476f2cb8a48a488ac5dd77c90a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74710
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-01-03 13:56:35 -08:00
David Benjamin 3c5b9b30d5 Replace OPENSSL_FALLTHROUGH with [[fallthrough]]
Bug: 42290600
Change-Id: I0c6fec6f33ff03ac2f60276920eb6b878751478d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74468
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-12-17 10:14:25 -08:00
David Benjamin 6f4159567d Start maintaining an AUTHORS file
Following the guidance in
https://opensource.google/documentation/reference/releasing/authors,
start maintaining an AUTHORS file.

Update all existing Google copyright lines to 'The BoringSSL Authors'
per the document. This CL also changes the styling to match the new
guidance: removed the '(c)' and the comma.

All other existing copyright lines are left unmodified. Going forward,
our preference will be that new contributions to BoringSSL use 'The
BoringSSL Authors', optionally adding to the AUTHORS file if the
contributor desires.

To avoid being presumptuous, this CL does *not* proactively list every
past contributor in the BoringSSL half of the AUTHORS file. Past
contributors are welcome to send us a patch to be added, or request that
we add you. (Listed or not, the commit log continues to be a more
accurate record, and any existing non-Google copyright lines were left
unmodified.)

The OpenSSL half of the AUTHORS file is seeded with the contents of the
current OpenSSL AUTHORS file, as of writing. The current contents in the
latest revision of the 1.1.1 branch
(b372b1f76450acdfed1e2301a39810146e28b02c) and master
(d992e8729ee38b082482dc010e090bb20d1c7bd5) are identical, just formatted
in text vs Markdown.

Note when reviewing: CONTRIBUTING.md and AUTHORS contain non-mechanical
changes.

Bug: 364634028
Change-Id: I319d0ee63ec021ad85e248e8e3304b9cf9566681
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74149
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-12-11 13:52:41 -08:00
Adam Langley 5813c2c10c crypto: switch to C++
This change switches nearly all of BoringSSL to use C++. The public
functions still use the C ABI, and so code written in C can still use
BoringSSL. Also the use of the C++ standard library is minimal and no
run-time requirement for it is intended.

Change-Id: I902d2f51a3c8d6bd0dc4aabe1b192a15d7b788e8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/72747
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2024-11-26 21:10:44 +00:00
David Benjamin b171749734 Switch EVP_CIPHERs to C99 initializers
We're using it in parts of EVP already and this is much more readable.

Change-Id: I42f30b83331cafdabd4f5d995b61176458e906bc
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67567
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-03-29 21:48:32 +00:00
David Benjamin 0cb032aa4c Move ssl and decrepit sources to sources.cmake
Bug: 542
Change-Id: Iec0348555b988f8eb8eb24394a867e015b125c20
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67227
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-03-20 01:08:24 +00:00
Theo Buehler f57a11ae56 Remove unused app_data from EVP_CIPHER
This field makes no sense for static const structures. It was added
early on but never used as far as I can tell.

Change-Id: Ie0272c5f498ad777cb3b114589248d8b403ae457
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67047
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-03-16 22:48:54 +00:00
David Benjamin 48dce6d686 Import upstream's tests for DES_ede3_cfb_encrypt
Upstream does not actually have any tests for DES-EDE3-CFB, with the
exception of a single DES-EDE3-CFB1 test vector, only the single-DES
version. But we can gain some coverage by turning 3DES back into single
DES with a repeated key. That's good enough for DES.

The DES-EDE3-CFB1 test vector is unusable because that tests
EVP_des_ede3_cfb1, the real DES-EDE3-CFB1. OpenSSL's low-level APIs do
not actually implement CFB correctly for a non-whole-number of bytes!
See discussion in the test. I've added coverage for that case by just
fabricating a test vector.

Change-Id: I9f69cab4d8d1d3accecbeb09f8c1661ce2ecb4ee
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/65689
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-01-26 00:22:38 +00:00
David Benjamin 58906eab92 Merge <openssl/x509v3.h> into <openssl/x509.h>
Change-Id: I53147d1f96d1f99909f5c8bda00cefb088677a0e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64138
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-11-30 16:22:48 +00:00
David Benjamin dd68e4bb4d Add OPENSSL_zalloc
OpenSSL added a similar helper function. It's very, very common for us
to malloc something an then zero it. This saves some effort. Also
replace some more malloc + memcpy pairs with memdup.

Change-Id: I1e765c8774a0d15742827c39a1f16df9748ef247
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63345
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-10-05 18:38:27 +00:00
David Benjamin 5ba5db1a29 Support Android's "baremetal" target
This corresponds to the libcrypto_baremetal build target in Android,
which is an embedded-style platform that uses a subset of the bionic
libc. It will also, eventually, use getentropy for its PRNG.

As part of this, generalize the OPENSSL_TRUSTY exclusion for file BIOs
to OPENSSL_NO_FILESYSTEM. Upstream OpenSSL uses OPENSSL_NO_STDIO, but
that excludes all of FILE entirely. We already require FILE in quite a
few places (urandom.c, self_test.c) for writing to stderr, and FILE is
part of C standard library. So, let's tentatively say that we require
you have FILE and stderr.

Instead, OPENSSL_NO_FILESYSTEM is saying you don't have fopen. You're
still required to have the three std{in,out,err} FILEs, and given a
FILE, you need to allow the standard operations on it. (Possibly in
forms that always fail.)

To keep us honest, whenever a function is excluded, I've dropped it from
the header too, and followed callers up the chain. I have not attempted
to make the tests work when these are excluded. Later CLs in this series
will do the same for NO_SOCK and NO_POSIX_IO. This was a little tedious,
but not too bad.

(I assume we'll end up changing our minds on this a lot. For now, let's
try this.)

I haven't yet restored OPENSSL_RAND_TRUSTY or removed the OPENSSL_TRUSTY
ifdef on file.c. Having a separate CL makes it a bit easier to revert if
something goes wrong.

This depends on
https://android-review.googlesource.com/c/platform/bionic/+/2659335,
which fixes the header bionic uses for getentropy.

Bug: 629, b:291102972
Change-Id: Idd839cd3fa4253128de54bd1be7da261dbcdeb7c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61726
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2023-07-18 19:46:50 +00:00
David Benjamin 23d6e4cce9 Replace BIO_snprintf with snprintf within the library
Our BIO_snprintf is just a thin wrapper over the libc one, and we
already call it directly in other places. Just call the libc one
consistently.

Change-Id: Ia7daf26b9789ddcecab67118c4ec4a077aad5a22
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61685
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-07-16 19:42:57 +00:00
David Benjamin a36ac0a2e7 Use std::make_unique when possible
We've required C++14 for a while now. As we're mostly C with a little
C++, this is less helpful, but may as well avoid bare new where
possible.

Change-Id: Icf3386e3f3b6f2092bb0089ed874cc50985f1a40
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61429
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-07-11 19:22:41 +00:00
David Benjamin 197b57154f Use sources.cmake for test binaries
CMake and the generate builds now broadly share a source of truth for
the test files.

Update-Note: In the standalone CMake build, build/crypto/crypto_test is
now build/crypto_test, etc. For now, the build still copies the outputs
to the subdirectories (it's cheap and avoids some workflow turbulence),
but I'm thinking we keep that for six months or so and then remove it.

Bug: 542
Change-Id: I8f97e1fcedea1375d48567dfd2da01a6e66ec4e8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61286
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2023-07-05 19:25:42 +00:00
David Benjamin 987dff1a9f Make boringssl_gtest_main a STATIC library
Prior to 3.12 (which we won't be requiring until July), OBJECT libraries
cannot be used with target_link_libraries. That means they cannot pick
up INTERFACE_INCLUDE_DIRECTORIES, which makes them pretty unusable in
the "modern CMake" style.

Just switch it to a static library to unbreak the build in CMake 3.10.

For some link ordering reason I don't understand, this also requires
explicitly linking boringssl_gtest to libcxx when we USE_CUSTOM_LIBCXX
is set.

Change-Id: Ia9d8351551f5da060248aa3ca73fe04473bf62aa
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/57345
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-02-15 19:50:04 +00:00
David Benjamin 8c75ed046f Remove global_target from build.
This was added with the generated symbol-prefixing header. But it
seems to be sufficient for crypto to have a dependency on the
generated header, along with some of the stray bits of delocate.

It's a little unclear from CMake documentation how these are processed;
normally .o files can be built before libraries are built or linked,
only the link step depends on.

But, empirically, if A links B, and B has a dependency on C, then CMake
seems to run C before building any of A. I tested this by making a small
project where the generation step slept for three seconds and running
with enough parallelism that we'd have tripped.

Interestingly, in the Makefile output, the individual object file
targets didn't have that dependency, but the target itself did. But this
was true on both A and B, so I think that just might not work.

Also fix the dependency in the custom target. The old formulation broke
when using an absolute path to the symbols file.

Change-Id: I2053d44949f907d465da403a5ec69c191740268f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/56928
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2023-02-14 21:00:31 +00:00
David Benjamin 0e68520eb2 Specify -Iinclude with the crypto target.
It's unclear to me whether doing it target-by-target is an improvement
in crypto/fipsmodule, but this otherwise does seem a bit tidier. This
aligns with CMake's documentation and "modern CMake" which prefers this
pattern.

Change-Id: I36c81842bff8b36eeaaf5dd3e0695fb45f3376c9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/56585
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2023-02-14 20:26:56 +00:00
David Benjamin 0586618453 Trim unnecessary -lrt and ws2_32 deps in the build.
The ws2_32 dependency comes from BIO, which is in libcrypto. Once it's
added there, it should get inherited by anything downstream, so we don't
need to keep listing it.

We also no longer need -lrt. We tried to remove it in
https://boringssl-review.googlesource.com/4622, but had to revert it in
https://boringssl-review.googlesource.com/4894 because of clock_gettime.

clock_gettime, per the Linux man page, is now in libc, not librt, as of
glibc 2.17. THat was released December 2012, well past our five year
watermark, so clean this part of the build up.

Change-Id: Ie6a07434b0cb02fe916b32ab8c326ec33d40bcb6
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/56606
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-02-07 18:53:21 +00:00
David Benjamin 4ed497f0c5 Fix stray */s in // line comment license headers
I assume this came from a bad conversion and then got copy-and-pasted
everywhere.

Change-Id: Id596623608266ce6350d70dff413f38e9fdf13b3
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/56526
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2023-01-31 19:19:37 +00:00
David Benjamin 44b3a28317 Further const-correct config-based extension creation.
Constructing extensions from a config file should not modify the config
file or input certificates, so everything here should be const.

While I'm here, fix various missing sk_FOO_push malloc failure checks.

Change-Id: Ic29b21248a9d9243050c771fd0ce1e1d77f7ce7f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/56027
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-01-17 17:06:11 +00:00
David Benjamin faac9aa334 Finish porting dh_test.cc and ripemd_test.cc to GTest.
They're the only two half-finished ports left, so we may as well finish
that up and trim them down a little.

Change-Id: Ic058124a44086161ab5d2d6fa24448492c3ba219
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55506
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2022-12-09 02:23:13 +00:00
David Benjamin 7ac94aa279 More -Wshorten-64-to-32 fixes.
I had a rewrite of the decrepit ciphers (CAST and Blowfish) to use
CRYPTO_{load,store}_u32_be and drop the old macros, but this is probably
not worth the effort to review. Instead, just fix the type in the macro.

Bug: 516
Change-Id: I1cdecc16f6108a6235f90cf9c2198bc797c6716e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/54985
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2022-11-14 20:24:08 +00:00
David Benjamin 58f728eaec Switch RSA_sign to size_t.
While I'm here, use a fixed-size uint64_t in RSA_generate_key, rather
than unsigned long. This code also assumes unsigned long fits in
BN_ULONG, which is probably true on all platforms we care about, but
unnecessarily fussy.

The RSA_sign -> RSA_METHOD transition does require a cast. Go ahead and
check length/hash_nid consistency so we know it fits in the cast. This
does mean RSA_METHOD-backed keys are restricted to implementing digests
that we support, but that's probably fine. If anything, I think we
should try to shift away from RSA_METHOD as a story for custom keys.

Bug: 516
Change-Id: I3969da67d1daeff882279a534eb48ca831eb16cd
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/54465
Commit-Queue: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2022-10-13 23:38:03 +00:00
David Benjamin cf506f17d0 Make EVP_CIPHER opaque.
If we're to have any hope of fixing EVP_CIPHER_CTX's calling convention, we
need to be able to change the shape of its method table.

Looking back, it looks like we exported this in
https://boringssl-review.googlesource.com/4330, for OpenSSH. I don't
remember exactly what OpenSSH was doing, but I see in this commit, they
removed a bunch of custom EVP_CIPHERs which would definitely have
required an exported EVP_CIPHER struct:
https://github.com/openssh/openssh-portable/commit/cdccebdf85204bf7542b7fcc1aa2ea3f36661833

That's been gone for a while now, so hopefully we can hide it again. (If
a project needs a cipher not implemented by OpenSSL, it's not strictly
necessarily to make a custom EVP_CIPHER. It might be convenient to reuse
the abstraction, but you can always just call your own APIs directly.)

Update-Note: EVP_CIPHER is now opaque. Use accessors instead.
Bug: 494
Change-Id: I9344690c3cfe7d19d6ca12fb66484ced57dbe869
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52725
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2022-05-26 21:52:12 +00:00
Adam Langley a919539777 Move DES out of the FIPS module.
FIPS no longer likes it.

Change-Id: I32a4ba93a5849927ff75aa72b816cdc669e8a0af
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/51325
Reviewed-by: David Benjamin <davidben@google.com>
2022-02-14 21:01:14 +00:00
David Benjamin fa6ced9512 Extract common rotl/rotr functions.
We have a ton of per-file rotation functions, often with generic names
that do not tell you whether they are uint32_t vs uint64_t, or rotl vs
rotr.

Additionally, (x >> r) | (x << (32 - r)) is UB at r = 0.
(x >> r) | (x << ((-r) & 31)) works for 0 <= r < 32, which is what
cast.c does. GCC and Clang recognize this pattern as a rotate, but MSVC
doesn't. MSVC does, however, provide functions for this.

We usually rotate by a non-zero constant, which makes this moot, but
rotation comes up often enough that it's worth extracting out. Some
particular changes to call out:

- I've switched sha256.c from rotl to rotr. There was a comment
  explaining why it differed from the specification. Now that we have
  both functions, it's simpler to just match the specification.

- I've dropped all the inline assembly from sha512.c. Compilers should
  be able to recognize rotations in 2021.

Change-Id: Ia1030e8bfe94dad92514ed1c28777447c48b82f9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/49765
Reviewed-by: Adam Langley <agl@google.com>
2021-10-05 17:46:51 +00:00
David Benjamin 03cae7a2b3 Keep EVP_CIPHER/EVP_MD lookup and do_all functions in sync
Node seems uncommonly sensitive to this, so let's write these functions
in a way that stays in sync and test this. See also
https://boringssl-review.googlesource.com/c/boringssl/+/49585

This does incur a cost across all BoringSSL consumers that use these
functions: as a result of Node indiscriminately exposing every cipher,
we end up pulling more and more ciphers into these getters. But that
ship sailed long ago, so, instead, document that EVP_get_cipherby*
should not be used by size-conscious callers.

EVP_get_digestby* probably should have the same warning, but I've left
it alone for now because we don't quite have the same proliferation of
digests as ciphers. (Though there are things in there, like MD4, that
ought to be better disconnected.)

Change-Id: I61ca406c146279bd05a52bed6c57200d1619c5da
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/49625
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2021-09-24 17:18:39 +00:00
David Benjamin 31f462a1ef Include SHA512-256 in EVP_get_digestbyname and EVP_MD_do_all.
Change-Id: I25a1a58589ec8843da4d1955d8fec38561f13ec9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/49125
Reviewed-by: Adam Langley <agl@google.com>
2021-08-30 18:17:38 +00:00
David Benjamin ae7c178689 Add some OpenSSL compatibility aliases.
EVP_MD_nid, in OpenSSL, is the same as EVP_MD_type. EVP_MD_type seems to
be the preferred spelling, so put EVP_MD_nid in the deprecated bucket.
Also add an EVP_MD_do_all alias to EVP_MD_do_all_sorted.

Change-Id: I4e7b800902459ac5cb9ef0df65d73da94afdf927
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/48365
Reviewed-by: Adam Langley <agl@google.com>
2021-07-01 16:20:47 +00:00
David Benjamin 597ffef971 Make md32_common.h single-included and use an unsized helper for SHA-256.
Similar to
https://boringssl-review.googlesource.com/c/boringssl/+/46405,
SHA256_Final and SHA224_Final hit array size warnings in the new GCC.
The array sizes are, strictly speaking, purely decoration, but this is a
good warning so we should be clean with it on.

That same change is difficult to apply to md32_common.h because
md32_common.h generates the functions for us. md32_common.h is already
strange in that it is multiply-included and changes behavior based on
macros defined by the caller.

Instead, replace it with inline functions, which are a bit more
conventional and typesafe. This allows each hash function to define the
function prototype. Use this to add an unsized helper for SHA-256.

Bug: 402
Change-Id: I61bc30fb58c54dd40a55c9b1ebf3fb9adde5e038
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/47807
Reviewed-by: Adam Langley <agl@google.com>
Reviewed-by: Peter Foley <pefoley@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2021-06-01 18:53:05 +00:00
David Benjamin 4320bc4761 Pull HASH_TRANSFORM out of md32_common.h.
The macro isn't doing any work here.

Change-Id: Id97dfa4b027407c5e4b3e7eb1586c3c2a2d977d8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/47806
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2021-06-01 17:47:35 +00:00
David Benjamin 15e0f6784b Fold ripemd/internal.h into ripemd.c.
It's only used from that file and, given the names defined by it,
probably isn't usable by other files anyway.

Change-Id: Ice205408962ade00c1dcb51406da3ef2fd7f0393
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/46426
Reviewed-by: Adam Langley <agl@google.com>
2021-04-02 16:33:50 +00:00
David Benjamin ca4598781a Move load/store helpers to crypto/internal.h.
We have loads of variations of these. Align them in one set. This avoids
the HOST_* macros defined by md32_common.h, so it'll be a little easier
to make it a more conventional header.

Change-Id: Id47fe7b51a8f961bd87839f8146d8a5aa8027aa6
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/46425
Reviewed-by: Adam Langley <agl@google.com>
2021-04-02 16:33:15 +00:00
Adam Langley 5dd18d017d A handful more compatibility functions.
Change-Id: I814f55742910c519e9b64aca1b15a4d754adc541
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/44944
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2021-01-07 22:41:58 +00:00
Adam Langley 76164b1bc9 Add some OpenSSL-compatibility aliases
Change-Id: I808f37c2980e36843b5b5d29174b4f27a030738a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/44924
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2021-01-07 16:44:54 +00:00
David Benjamin a93545c2e0 Const-correct various X509 string parameters.
Change-Id: Iceaed077d072a51b67b8cda8f363d2d8f8d1762d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/43886
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2020-11-06 21:51:18 +00:00
Pete Bentley d1d8eee76b Remove uneeded switch statement.
Warnings for switch statements with just a default case are
now fatal with the latest Windows toolchain used by Github
workflows. So indirectly this was breaking Conscrypt's
continuous integration and possibly other projects using
BoringSSL which run CI on Windows.

Example: https://github.com/google/conscrypt/runs/793502854?check_suite_focus=true

Change-Id: Ia09b86f3292299089c6536862a170677a8024984
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/41844
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2020-06-22 14:06:04 +00:00
David Benjamin aaa1a84d63 Add some XTS tests.
For some reason, these also fail with the reverted aes_nohw on 32-bit
Android. (Still trying to figure out why that happens.)

Change-Id: Ia9ef34e97b473585424120620b1d937220cd2c31
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39305
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2020-01-03 23:14:49 +00:00
Shelley Vohr 012a444265 Add AES-256 CFB to libdecrepit.
Electron builds Node.js with BoringSSL. They want to match OpenSSL as
much as possible and thus have a patch[1] that adds AES-256 CFB mode.
However, that patch makes libcrypto depend on libdecrepit, which can't
be done in general. This change lands the AES-256 CFB support in
libdecrepit without the libcrypto bit and, in order for BoringSSL to
remain consistent, without advertising support in
EVP_CIPHER_do_all_sorted. This will let Electron reduce the size of
their patch a bit.

[1] https://github.com/electron/electron/blob/master/patches/boringssl/expose_aes-cfb.patch

Change-Id: If628d22a595b354623439c587542e414e43e4045
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37264
Reviewed-by: Adam Langley <agl@google.com>
2019-09-16 18:11:40 +00:00
Julien Desgats 20d43e2fa5 Fix name clash in test structures
Revealed by -lfto linking. Creating multiple classes with the same name
but different contents is illegal.

Change-Id: I184c34235f4f11e94d47dee1ca2d1a97de55d6ba
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36304
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-06-04 13:40:07 +00:00
David Benjamin 387b07b78d Rename 'md' output parameter to 'out' and add bounds.
We usually name output parameters 'out'. (Someone made a C++ templating
change in Chromium which messed up const-ness, saw the compile error,
and thought it was in MD5_Final.) Also tag the parameters with the
sizes.

Sadly, there's a bit of goofiness around SHA224_Final/SHA256_Final and
SHA384_Final/SHA512_Final, but they're just documentation anyway.
(Though it does touch on the mess that is sha->md_len which would be
nice to clear through somehow.)

Change-Id: I1918b7eecfe13f13b217d01d4414ac2358802354
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/35484
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-04-08 18:19:01 +00:00