122 Commits
Author SHA1 Message Date
David Benjamin 208361a22e Add EVP_PKEY_ALG-based raw public/private key importers
Keeping it to X25519/Ed25519 for now, but arguably we could pick "raw"
options for most of our keys. The problem is just when there's a couple
different options. (ECPrivateKey or just the serialized scalar for EC
keys, compressed vs uncompressed points.)

Bug: 42290364
Change-Id: I1e1a0a3fa971f27a962946301091ebe11bac2725
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81667
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-08-28 12:30:53 -07:00
David Benjamin 50d8772137 bssl-crypto: Switch to new SPKI/PKCS8 parsing APIs
These work much better for what bssl-crypto wants to do because we won't
forget to check the key type.

Bug: 42290364
Change-Id: I3250258e4935700f82eb196516dd4eda1766ce95
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81652
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 10:10:34 -07:00
David Benjamin 26e8a8acb9 bssl-crypto: Fix Ed25519 SPKI parser to check key types
Otherwise it mistakenly interprets an X25519 SPKI as an Ed25519 key.
Once that is fixed, a number of these error conditions are impossible.

Change-Id: Iffd116252f1f632f8f917c56b1676069686eddbf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81587
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-22 16:07:22 -07:00
David Benjamin de186e49bf Work around a Rust problem tripped by working around a Rust problem, which in turn was tripped by working around a Rust problem
We are now several layers deep in working around problems in this
language.

Rust's bindgen cannot even bind headers that reference <stdio.h> without
tripping a Rust warning due to
https://github.com/rust-lang/rust-bindgen/issues/2807

As a result we need to manually suppress the warning. However, that
warning is not available until newer Rusts, so trying to suppress the
warning causes a different warning in older Rusts.

https://boringssl-review.googlesource.com/c/boringssl/+/80707 attempted
to work around this Rust bug by using cfg_version, but that broke the
Chromium build because it is not part of Stable Rust. Stable Rust has
not yet caught up to C89 in having some way to condition code on
version.

Instead, suppress the future lint by just suppresing unknown lints. Also
add some comments so we remember where all this nonsense came from.

This unbreaks the Chromium roll.

Change-Id: I47dcedadae5695b2edab05dfbc08a9cd8cfafdc1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80747
Commit-Queue: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-07-25 08:09:20 -07:00
Per Larsen a873ab7906 rust: Gate new lint on Rust version
The `unnecessary_transmutes` lint was added in Rust 1.88 and will warn
when used unconditionally with prior Rust releases. This can break the
build when downstream users treat warnings as errors (even if they
shouldn't). Enabling this lint on Rust versions that supports it avoids
triggering any new warnings or errors.

Test: build bssl-sys with Rust 1.87 and 1.88; verify lack of warnings
Change-Id: Id038e359a763dc608cd389a90829dc035d9232d3
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80707
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-07-24 23:14:12 -07:00
Lily Chen df6e8edbac Add a Rust workspace
Define a workspace in rust/ so that bssl-sys and bssl-crypto crates can
be built and tested at once from the rust/ directory:
  cd rust
  cargo build --workspace
  cargo test --workspace

(The --workspace arg is optional since this is a virtual manifest; the
default is the whole workspace.)

Change-Id: I88fb738a96837ce19b53fdaeabe91491fa0240fd
Bug: 42290446
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80527
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Auto-Submit: Lily Chen <chlily@google.com>
2025-07-21 08:41:26 -07:00
Lily Chen 8e5174b118 rust: Suppress unnecessary_transmutes warnings in bssl-sys
The bindgen output contains unnecessary transmutes, which produce
compiler warnings by default. They are not actionable, so suppress these
warnings to reduce noise.

All 5 of the unnecessary transmute warnings come from bindgen's handling
of bitfields in the FILE struct. Bindgen uses transmute for bitfields
even when it could instead use a cast_(un)signed, or transmutes an
integer type to itself; this is a known issue [1].

[1] https://github.com/rust-lang/rust-bindgen/issues/2807

Change-Id: I402873725ce83c0aef699339a74982a808edd713
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80467
Auto-Submit: Lily Chen <chlily@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-07-17 11:44:08 -07:00
Lily Chen 290acfa3ba Update .gitignore to check in Cargo.lock files
Cargo.lock files should be checked into version control, per the FAQ.[1]
This edits .gitignore to stop ignoring these files, and checks in the
latest Cargo.lock generated for bssl-sys and bssl-crypto crates.

Unrelatedly, start ignoring /out directories which may be used for
builds.


[1] https://doc.rust-lang.org/cargo/faq.html#why-have-cargolock-in-version-control

Change-Id: I77764645cb550b60b1fc15f6c54163da5cf7cac9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80447
Commit-Queue: Lily Chen <chlily@google.com>
Auto-Submit: Lily Chen <chlily@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-07-15 14:14:22 -07:00
David Benjamin 77f159631b Fix Rust build
Change-Id: I0ae961293e5c2151951e7eb606e7ad3d1c78517e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80347
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-07-09 15:00:43 -07:00
Adam Langley e21d41adeb Add sha2.h
Historically, sha.h included both SHA-1 and SHA-2 functions. But SHA-1
functions mostly shouldn't be used now, and it's useful to be able to
audit at the level of header names in some contexts.

Therefore move SHA-2 things into a new sha2.h. In order not to break
everything, sha.h now includes sha2.h so no changes are needed in
existing callers.

Change-Id: I68d5e991f58a1c74ca377ba017caaff356acc870
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80327
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2025-07-09 12:17:15 -07:00
David Benjamin 5ec4b35773 bssl-crypto: Test that we don't accidentally accept RSA-PSS keys
The code is currently written in a way that would accept them if we
added support for EVP_PKEY_RSA_PSS naively. Add a test so we don't
regress this.

Bug: 384818542
Change-Id: I45b78647400c8ac08e0b159b7b9ed5f2d66f8544
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80269
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-07-07 14:38:20 -07:00
Brett McLarnon 34492c89a8 Expose P1363-based ECDSA sign/verify functions
Fixed: 411427388
Change-Id: I108eb20a55ea9c9e9ac31e85d1ede05df1116c3f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78807
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-04-25 11:47:49 -07:00
Nabil Wadih fa891990d1 Fix rust build breakge, unable to find cmake artifacts
introduced in:  https://boringssl-review.googlesource.com/c/boringssl/+/78587

Change-Id: Ifb6f087aac19e6c2d47d997694b9e61bee9ba182
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78667
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-04-18 14:55:37 -07:00
Bob Beck 8d8df26fc5 Do not include asn1_mac.h from rust
This file is for old openssl and we should not use it.
We already include the correct asn1.h

Change-Id: I757b668d5d0c7b9a1e2666413566b8be582f0d3f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78267
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: Bob Beck <bbe@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-04-04 11:13:30 -07:00
Brett McLarnon 5b6b14d996 Add hpke::Kem::get_public_key
This method is useful if only the private key is known because
it came from a source other than `Kem::generate_keypair`, such
as another library or a KDF.

Change-Id: I463d494048c74cac26f5cfb8660a19b20f7d7e3a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78027
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: Brett McLarnon <bmclarnon@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: Brett McLarnon <bmclarnon@google.com>
2025-03-25 16:39:34 -07:00
David Benjamin 19a66a4fb2 Fix the link order of various dependencies
CMake expects you to provide your link lines in the right order for
platforms without rescanning linkers. When they're not in the right,
it'll preserve your order but duplicate transitive dependencies. That
is, if:

    A -> C B
    B -> C

The final link line will be:

    A C B C

Wheras if A wrote B C then there would be no duplication. Newer macOS
toolchains (which do not need the duplication) seem to warn on duplicate
libraries, which is how I noticed this.

That said, this is not actually sufficient to avoid duplication and thus
the warning. Consider:

   A -> B D
   B -> C D

CMake always lists direct dependencies before transitive ones, so the
result will be:

   A B D C D

decrepit_test triggers this because decrepit_test does not directly
depend on ssl but decrepit does. It's a bit awkward to have to list it
again, but adding it avoids this issue.

Newer CMakes (3.31) now know that:
1. macOS rescans dependencies so the dependencies don't have to be in
   order.
2. macOS has this warning so it should dedup things.

However, even updating to 3.31 isn't sufficient because CMake keys all
behavior changes on cmake_minimum_required. I didn't set the target
policy version because I figure testing it at 3.16's behavior is
probably useful for the sake of keeping 3.16 hopefully working.

Change-Id: Ibb006eefbbb23f1899ef91277465d31fa8202d2e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77747
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-03-19 23:58:23 -07:00
Cindy Lin daa03aac8d Add from/to SubjectPublicKeyInfo conversion to ed25519.
And run `cargo fmt`.

Change-Id: Iff0ad50ffc8fb02454b22b82050c605620a201f8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/76647
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-02-21 15:56:07 -08:00
Cindy Lin 0c59e9e55b Clarify bssl-sys build instructions.
Change-Id: Ic25803634289d53fd2431cdb525cfe3fe08a753a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/76607
Commit-Queue: Cindy Lin <cinlin@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-02-20 11:23:21 -08:00
Fernando Lobato Meeser 0147d7f283 HPKE DHKEM-P256 BoringSSL Rust
Change-Id: I39c8a586c85ef84d7483620bb300a7228c4050d5
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/76087
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-02-07 19:04:34 -08: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
David Benjamin d4b6eb542d Fix unwrap comment for CBB_init_fixed
Change-Id: I893930a8d23f49968883e4c9b8425ebcc5a2d23b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75007
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-01-17 13:49:03 -08:00
David Benjamin a85ef9aa6c Rename foo_extra to foo
The foo / foo_extra split will make increasingly less sense as we stop
putting public APIs in crypto/fipsmodule. Just call it crypto/foo and
crypto/fipsmodule/foo.

Bug: 42290602
Change-Id: I5143d3edfb768ed7a1aa288ff606f6f13faa9278
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75151
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2025-01-16 13:21:47 -08:00
Adam Langley d3f61eeacb Gate Rust support for ML-{KEM,DSA} on a crate feature.
These algorithms depend on `new_uninit`, which was only made stable with
Rust 1.82. To allow consumers to catch up, this change gates
ML-{KEM,DSA} support in `bssl-crypto` behind a (non-default) feature.

Change-Id: I6ffe60560a4dc0f802564c56498f6a0a073d94da
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75027
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: Adam Langley <agl@google.com>
2025-01-07 20:32:13 -08:00
Adam Langley a66e808c0f Revert "Always try and enable the new_uninit feature."
This reverts commit d678fbfb48.

The original change broke Chromium:

```
error[E0725]: the feature `new_uninit` is not in the list of allowed features
  --> ../../third_party/boringssl/src/rust/bssl-crypto/src/lib.rs:28:12
   |
28 | #![feature(new_uninit)]
   |            ^^^^^^^^^^
```

Change-Id: I6732a720a5705cfe7b0219b5d9d02a911af0f89a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74987
Auto-Submit: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-01-07 10:47:27 -08:00
Pete Bentley d678fbfb48 Always try and enable the new_uninit feature.
The crate won't build without it anyway, so unconditionally
try and enable it.

Change-Id: Ief8a7dbf8d0af3040b1832424007150987ce654d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74947
Auto-Submit: Pete Bentley <prb@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-01-07 08:12:12 -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 571c76e919 SLH-DSA: support SHA-384 as the prehash function instead.
Change-Id: I931e660d6ad8e6fae0e17b414a40bb0a0ea7e9c3
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/72967
Reviewed-by: Bob Beck <bbe@google.com>
Auto-Submit: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-11-08 22:44:00 +00:00
Adam Langley 06d5078077 Add support for prehashed SLH-DSA.
This should not be used. It adds additional complexity for no benefit.
However, sometimes compatibility with external systems is required.

Change-Id: If19e7254b91ecc665267f5efd4dd1601216fdcd1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/72367
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2024-11-01 19:35:11 +00:00
Ellen Arteca 756a322105 Adding Debug derivation for RSA PublicKey
This allows any structs that have an RSA PublicKey as a field
to derive Debug automatically.

Change-Id: Id16685b08fd7671fc118e71a68fef7b461fb5280
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68987
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2024-10-29 18:10:34 +00:00
Bob Beck 197a654639 fix indexing_slicing and unwrap warnings
since this gets a slice both by using get_mut
with unwrap, and just directly getting a reference
to a slice, make them both use get and unwrap
and fix both clippy warnings.

Change-Id: I5a7870a342ae7dd9d41fbae1afbb70cc44df98c0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/72588
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2024-10-28 21:09:22 +00:00
David Benjamin a8d55075b5 Update Cargo.toml after the cfg rename
Otherwise we get a bunch of warnings:

> unexpected cfg condition name: bindgen_rs_file

While I'm here, drop the authors field. It's no longer accurate as we've
significantly reworked this from Android's original contribution. We
could list the current maintainers, but that's redundant with the git
repo, and bssl-crypto omits it, so let's just omit it.

Change-Id: Ia1b60f1dfa4f4626b5fe2562f35a14ea0ce3aef5
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/72627
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2024-10-28 20:38:22 +00:00
danakj de6d1ca6ec Copy bindings to OUT_DIR in bssl-sys build.rs
This avoids the need for a custom environment variable in Cargo or GN
builds, including under the soong build. Then Chromium will also be able
to generate bindgen into the OUT_DIR for a sys crate via its GN rules,
as boringssl is the only crate we can find which relies on a custom
environment variable in its sys crate library's include statement.

The idea to copy from a pre-generated location comes from libsqlite3-sys
https://github.com/rusqlite/rusqlite/blob/master/libsqlite3-sys/build.rs

Bazel does not support the OUT_DIR system that is used by Cargo and
every bindgen-based crate that we could find (that didn't write to the
source dir directly). So we keep a cfg around that Bazel rules can
pass when building the bssl-sys crate.

Bug: b/373864033
Change-Id: If8a8aa8a1d8a00ead2e9935a5319bcac2aa09d1f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/72487
Reviewed-by: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-10-28 18:56:05 +00:00
Adam Langley 905c3903fd rust: add SLH-DSA support.
Change-Id: I3e21ef033b2681e203be232ecd61dc6a0c9360c2
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/71470
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2024-10-09 22:33:52 +00:00
Adam Langley f8bb652b01 rust: add wrappings for ML-KEM and ML-DSA.
Change-Id: Iff8547da5905e72648c4bf36f83fd2b5fc82ec30
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/71469
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-09-30 22:31:09 +00:00
Adam Langley dec0800988 rust: minor changes resulting from safety review.
The most important one is making `Buffer`'s members private so that
code inside the crate cannot construct an invalid `Buffer` outside
of an `unsafe` block.

Change-Id: Ic6d33ebeb5c9ce472dbbe53432b1c6fad4452734
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/71468
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Augie Fackler <augie@google.com>
2024-09-25 17:49:12 +00:00
Adam Langley fda6b549f9 rust: make bssl-sys no_std.
Change-Id: Ic567e4b777914e233d3676dd00825a734612cbd9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/71467
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-09-25 17:49:05 +00:00
Maurice Lam 6b19771490 Update deny-toml to match new version format
See https://github.com/EmbarkStudios/cargo-deny/pull/611

- Instead of using the template from deny.template.toml, just specify
  the fields that we need to be changed
- Added back comments on bans.allow, but the bssl-sys and bssl-crypto
  crates are not added to the allowlist because they are now allowed
  with `licenses.allow = ["ISC"]`.

Change-Id: I9e693780d902671444bf90b4d158d6e099e87ccb
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/70147
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-09-16 19:21:01 +00:00
Adam Langley 1e8c35af53 Add a comment showing how to update a hash generically.
This isn't obvious from the docs otherwise.

Change-Id: Id48a2cc18762a779e4834b6f6c1bea33020f6757
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69807
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Auto-Submit: Adam Langley <agl@google.com>
2024-08-05 23:50:50 +00:00
Alex Gaynor e23fe9b6ee Declare our cfg()s in Cargo.toml
Starting in Rust 1.80, rustc checks that all cfg values are expected and warns if they are not. This is intended to protect against typos and other mistakes.

Change-Id: I2d6f76536b8c585796e71ef7f65550ef8d312247
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69867
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2024-08-02 20:38:43 +00:00
Ellen Arteca 9cffd74fdb Adds functionality for instantiating and using Algorithm
This CL moves some methods that exist in every hashing algorithm
implementation to the `Algorithm` trait; namely, `new`, `update`,
and `digest`. This allows for clients to instantiate the hashing
algorithms, and to call `update` and `digest` on objects that
have this trait. It allows a generic representation of an algorithm
that can be used.
In order to avoid users of concrete instance of `Algorithm` to have
to import `Algorithm` and every time they want to
use the functions implemented, these functions are also included in
the inherent implementation of each algorithm (as it was originally
set up, except that now the methods call the equivalent method in the
Algorithm implementation'

This CL also adds the block size as a const field in the `Algorithm`
trait.

Note: this specifically supports the hashing algorithm use in the
style of what is done in AOSP's
`packages/modules/Virtualization/libs/apkverify`, which was previously
using the rust openssl `Hasher` to instantiate algorithms specified
by their `MessageDigest`.

Redoing Ic47691ee2a4303923519b246de7d9724da90f60d which has since
been reverted.

Change-Id: Ib7c02e79952491d814bb49a1ff8f23271b716414
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69387
Commit-Queue: Ellen Arteca <emarteca@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-07-22 23:57:36 +00:00
David Benjamin 2fcdd11f6d Make BoringSSL initialization-less
Now that we don't depend on external CRYPTO_library_init calls or the
static initializer to initialize CPU capabilities, we can drop a ton of
code.

This makes CRYPTO_library_init, and all its wrappers, into no-ops and
drops the (non-FIPS) static initializer. I've added an internal
OPENSSL_init_cpuid function for the places where the library actually
needs to initialize the CPU vector.

Note this slightly changes the default, previously
static-initializer-full build: previously, CRYPTO_library_init was a
no-op and we relied on the static initializer. Now we uniformly use
CRYPTO_once. This should be an atomic read in the steady state and
essentially free. We can restore the static initializer by default if
this ends up being a problem, but having only one mode is more
straightforward. This also avoids problems if an application calls into
BoringSSL during its own static initializer. Static initializers are not
coherently ordered.

Update-Note: The BORINGSSL_NO_STATIC_INITIALIZER build option and
CRYPTO_library_init are now unnecessary. Once updating past this
revision, those options can now be cleaned up from downstream projects.

Fixed: 40644931
Change-Id: Idc2e6ea7a73d6352e0360fd886c46d88dba3568c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69508
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-06-21 04:01:30 +00:00
David Benjamin 11acdc6abf Revert "Adds functionality for instantiating and using Algorithm" and friends.
This reverts the following commits:
e1a860c374
a11277e187
25cf1bb965

There were a couple nuisances caused by this change, stemming from a
Rust language deficiency. If you move a method from a type to a trait,
this is a backwards-incompatible change that is visible to the caller.
That is, Rust does not allow introducing abstractions in a
backwars-compatible way!

This meant you had to import Algorithm to use a hash. This made updating
downstream code hard, but at least par for the course with Rust. It
seems Rust just isn't a language where API stability and library
evolution are possible.

However, even after we pay the transition costs, downstream code needed
to import WithOutputLength. This is too much of an implementation detail
to leak into the public API, so revert it for now. We'll need to find
some way to do this that keeps the public API reasonable.

Change-Id: I82d00b47a77fe77b5893b1e9b15faef727ef9866
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69227
Reviewed-by: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2024-06-12 03:05:31 +00:00
Maurice Lam e1a860c374 Add missing trait "use" in doc tests
Change-Id: I27d64f8f1654ed0399c09c48b9c41e84aac1aa3a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69047
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-06-05 02:19:03 +00:00
Nabil Wadih a11277e187 remove un-needed muts which were causing build warnings/errors
These were introduced in https://boringssl-review.googlesource.com/c/boringssl/+/68748
and detected in our CI which runs against the boringssl
rust bindings at HEAD

Change-Id: I42b37e8738baadffbc0c58e0340144685dd04977
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69007
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-06-04 20:29:55 +00:00
Ellen Arteca 25cf1bb965 Adds functionality for instantiating and using Algorithm
This CL moves some methods that exist in every hashing algorithm
implementation to the `Algorithm` trait; namely, `new`, `update`,
and `digest`. This allows for clients to instantiate the hashing
algorithms, and to call `update` and `digest` on objects that
have this trait. It allows a generic representation of an algorithm
that can be used.

This CL also adds the block size as a const field in the `Algorithm`
trait.

Note: this specifically supports the hashing algorithm use in the
style of what is done in AOSP's
`packages/modules/Virtualization/libs/apkverify`, which was previously
using the rust openssl `Hasher` to instantiate algorithms specified
by their `MessageDigest`.

Change-Id: Ic47691ee2a4303923519b246de7d9724da90f60d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68748
Commit-Queue: Ellen Arteca <emarteca@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-06-04 00:40:06 +00:00
Ellen Arteca 4d50a595b4 Add re-exports for making inline functions available
This CL adds a re-export for `CBS_init` and
`CBS_len`, since these are declared as `OPENSSL_INLINE` and are
thus unavailable currently since inline support is not yet merged.
It also changes the existing wrappers for inline functions
to re-exports too.

Note: this is required to land the boringssl update in AOSP.

Test: m checkbuild
Change-Id: Ic6e2927d7a79b788a4ed0380cf27b3557b6f6f64
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68327
Reviewed-by: David Benjamin <davidben@google.com>
Reviewed-by: Matthew Maurer <mmaurer@google.com>
Commit-Queue: Ellen Arteca <emarteca@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-05-09 19:58:46 +00:00
Cindy Lin d34f540e57 Add HPKE secret export and implement Send for EvpHpkeCtx.
Change-Id: I929b31f996c8b67b77286fe9f8eb1af73d2bbc72
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68307
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-05-09 19:28:16 +00:00
Cindy Lin 8de798be4b Allow creation of HKDF using PRK bytes.
Change-Id: I34a326fb8c0e83c81380bc6608b7f0b52c63e7c0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67987
Reviewed-by: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-05-03 14:38:23 +00:00
David Benjamin 9eab28fb27 Add an OUT_DIR option for finding bindgen output for Android
Android are currently using a sed line to replace our include! to a
module import. As those don't quite behave the same, and we don't want
to carry patches (even as sed lines) downstream like this, we need to
find a convention that works for everyone.

Most of the Rust world uses environment variables to communicate between
the build system and source. However, rather than principled convention,
where each target was passed in a separate environment variable, Rust
picked an inflexible convention of setting an OUT_DIR variable, and then
hardcoding everything else relative to it. It simply assumes the build
placed everything in that directory.

This is problematic for more complex build systems, which would now take
on I/O costs to copy files around into where Rust wants. It's also less
convenient for the build file author. So, instead we went with an
environment variable that carries the entire path. This has worked out,
except that Android's build tool, Soong, cannot express this! It has no
way to specify that some build product's path should be passed in via
some environment variable.

Soong does, however, have some (less preferred, less efficient) way to
emulate the OUT_DIR behavior, by copying files around until it's in the
place that the Rust convention expects. So introduce that option too,
gated on cfg(soong).

Update-Note: When this rolls into Android, remove the sed logic from
Android.bp and instead set up the OUT_DIR cargo emulation.

Bug: b:291253039
Change-Id: Id0afe9259f15f041c953dc5ad945cb9eda24ffc7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68048
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-04-25 22:44:28 +00:00
Kenichi Ishibashi 54c956b2e6 [rust] Tell Cargo to link cpp runtime library
https://boringssl-review.googlesource.com/c/boringssl/+/66288
allowed C++ runtime in libssl. The build script of bssl-sys crate
should indicate that the crate requires a C++ runtime. Use
libc++ on MacOS and libstdc++ on other unix like systems by
default. Introduce a new environment variable to configure C++
runtime to use.

Change-Id: Ib445955012126080dd03ad7b650287ea9dde10b0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67147
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2024-03-27 16:43:10 +00:00