Skip to content

Remove dead P-256 nistz asm under OPENSSL_SMALL and extend the size-check harness - #3350

Merged
justsmth merged 3 commits into
aws:mainfrom
justsmth:openssl-small-nistz-asm-and-size-harness
Jul 20, 2026
Merged

justsmth merged 3 commits into
aws:mainfrom
justsmth:openssl-small-nistz-asm-and-size-harness

Conversation

@justsmth

@justsmth justsmth commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Issues:

Addresses: aws/aws-lc-rs#745, P353434599
Related: #3319, #3320

Description of changes:

Follow-up to the OPENSSL_SMALL size work in #3319/#3320. Two independent changes, one per commit:

  1. Drop P-256 nistz assembly under OPENSSL_SMALL. p256-nistz.c is compiled out entirely in this configuration (ec.c dispatches P-256 to the fiat-crypto implementation), so the nistz assembly -- p256-{x86_64,armv8}-asm and p256_beeu-{x86_64,armv8}-asm -- is fully unreferenced on both architectures. This removes it from the build using the same if(OPENSSL_SMALL) list-removal pattern established for s2n-bignum in Gate s2n-bignum _alt variants under OPENSSL_SMALLย #3320. Like the EC removal there, this is pure dead-code elimination: it shrinks shared-library artifacts, but static consumers were already dropping these unreferenced objects at link time. The non-OPENSSL_SMALL build is unchanged.

  2. Extend the binary-size CI harness (from Gate s2n-bignum _alt variants under OPENSSL_SMALLย #3320) to measure GC-enabled consumers and the key-parsing anchor. The most important chunk a static consumer inherits from libcrypto is the ML-KEM/ML-DSA code retained by asn1_evp_pkey_methods[]: any consumer that parses an EVP key pulls it in, and no linker or OPENSSL_SMALL-style change can drop it -- only a future API-reduction build option can. This adds a second, section-GC library build (matching how aws-lc-rs/CcBuilder compiles the library) and a variant of the consumer that calls EVP_parse_public_key, so CI reports the anchor cost on every run. This makes the motivation for that future work concrete and quantifiable, and gives subsequent size PRs a realistic consumer-impact number rather than just an archive-size delta.

Call-outs:

  • The two commits are unrelated and could be reviewed independently; they are bundled because commit 1 is ~20 lines.
  • The default-compiled size harness is behaviorally unchanged, so the size-reduction thresholds calibrated in Gate s2n-bignum _alt variants under OPENSSL_SMALLย #3320 remain valid. The new anchor measurement is advisory (not thresholded).
  • The section-GC library build in the harness is deliberate: without -ffunction-sections -fdata-sections, any reference into bcm.c.o retains the whole object and masks the anchor.

Testing:

  • Covered by the existing openssl-small.yml matrix (full test suite, x86_64 + aarch64, gcc + clang) and the shared-library link (which proves no removed object is still referenced).
  • Locally (arm64 macOS): OPENSSL_SMALL shared-lib links cleanly, nm confirms the previously-dead ecp_nistz256_*/beeu_* symbols are gone, and the full crypto_test suite passes.
  • The harness self-checks run in CI (both consumer variants execute before their sizes are compared). On Linux/GNU ld, a base consumer retains zero ML-KEM/ML-DSA code, while adding a single EVP_parse_public_key call pulls in ~574 KB (x86_64) / ~634 KB (aarch64), per the CI runs of this PR -- confirming the anchor the harness is meant to track.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@justsmth
justsmth requested a review from a team as a code owner July 16, 2026 11:55
@justsmth
justsmth requested review from nebeid and sgmenda July 16, 2026 11:55
@github-actions

Copy link
Copy Markdown
Contributor

๐Ÿ”’ Security Review โ€” View Report

Please review before merging.

@codecov-commenter

codecov-commenter commented Jul 16, 2026 •

Copy link
Copy Markdown

Codecov Report

โœ… All modified and coverable lines are covered by tests.
โœ… Project coverage is 78.19%. Comparing base (aba09cb) to head (d905ec1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3350      +/-   ##
==========================================
- Coverage   78.20%   78.19%   -0.02%     
==========================================
  Files         695      695              
  Lines      124086   124086              
  Branches    17232    17231       -1     
==========================================
- Hits        97044    97025      -19     
- Misses      26121    26141      +20     
+ Partials      921      920       -1     

โ˜” View full report in Codecov by Harness.
๐Ÿ“ข Have feedback on the report? Share it here.

๐Ÿš€ New features to boost your workflow:
  • โ„๏ธ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nebeid nebeid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message and the PR description are reporting delta sizes smaller than what the summary is showing.

Comment thread .github/workflows/openssl-small.yml Resolved
@justsmth
justsmth requested review from manastasova and removed request for sgmenda July 17, 2026 16:08
justsmth added 3 commits July 20, 2026 08:27
Under OPENSSL_SMALL, p256-nistz.c is compiled out entirely (ec.c
dispatches P-256 to the fiat-crypto implementation), leaving the nistz
assembly (p256-{x86_64,armv8}-asm, p256_beeu-{x86_64,armv8}-asm) fully
unreferenced on both x86_64 and aarch64. Remove it from the build using
the same conditional-exclusion pattern as the s2n-bignum removal
(aws#3320).

Verified on arm64 macOS: the shared-library OPENSSL_SMALL build links
cleanly, nm shows the 21 previously-dead ecp_nistz256_*/beeu_* symbols
are gone (~5.7 KB of __text), and the full crypto_test suite passes.
Non-OPENSSL_SMALL builds are unchanged. This mainly shrinks
shared-library artifacts; static consumers never pulled these
unreferenced objects.
Extend the binary-size CI harness from aws#3320 to measure what
GC-enabled static consumers actually inherit, and to make the
key-parsing reachability anchor visible in every run.

- tests/binary-size/main.c gains an AWSLC_SIZE_CHECK_EVP_PARSE variant
  that marshals and parses an EVP public key. EVP_parse_public_key
  anchors asn1_evp_pkey_methods[] (crypto/evp_extra/p_methods.c), which
  transitively retains every key type's ASN.1 machinery -- currently
  including all of ML-KEM and ML-DSA -- even under full section GC. The
  default-compiled harness behavior is unchanged, so the existing
  calibrated thresholds remain valid.
- openssl-small.yml adds libcrypto.a sizes to the report, plus an
  advisory step that builds the OPENSSL_SMALL library with
  -ffunction-sections/-fdata-sections (the aws-lc-rs CcBuilder-like
  configuration), links base and EVP-parse consumers with
  --gc-sections, and reports the key-parsing anchor cost and the
  largest retained symbols. The section-GC library build is required
  for this measurement: without it, any reference into bcm.c.o retains
  the whole object and masks the anchor. Measured locally: the single
  EVP_parse_public_key call grows the dead-stripped consumer by
  ~418 KB.
@justsmth
justsmth force-pushed the openssl-small-nistz-asm-and-size-harness branch from 7ed868e to d905ec1 Compare July 20, 2026 12:27
@justsmth
justsmth enabled auto-merge (squash) July 20, 2026 18:27
@justsmth
justsmth merged commit 3c49fe7 into aws:main Jul 20, 2026
515 of 519 checks passed
@justsmth
justsmth deleted the openssl-small-nistz-asm-and-size-harness branch August 3, 2026 20:20
justsmth added a commit to justsmth/aws-lc that referenced this pull request Aug 4, 2026
Two things were inaccurate, both found while auditing the OPENSSL_SMALL
build after aws#3319, aws#3320, aws#3350 and aws#3368.

MY_ASSEMBLER_IS_TOO_OLD_FOR_ADX_AVX2 was documented as gating the
"ADX/AVX2/BMI2" code paths, but it does not gate BMI1/BMI2 at all. A
mnemonic census of the generated x86_64 assembly shows the real dividing
line is adcx/adox: every file this flag gates emits them, and the files
left in the AVX tier emit only mulx, rorx and andn. Concretely,
chacha20_poly1305_x86_64.S has mulx=92 with adcx=adox=0, sha1-x86_64.S
has rorx=320/andn=40, and aesni-sha256-x86_64.S has rorx=288/andn=48 --
all AVX-tier-gated -- while x86_64-mont.S (mulx=31, adcx=35, adox=29) and
p256-x86_64-asm.S (mulx=100, adcx=86, adox=90) are gated here. So the
existing gating is correct; only the comment was wrong.

MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX is not fully effective without Perl,
which was undocumented. The ADX and AVX-512 tiers are also expressed as
#ifndef guards inside the pre-generated assembly, so they still apply
with DISABLE_PERL=ON; the AVX tier is not. Measured with
-DDISABLE_PERL=ON -DMY_ASSEMBLER_IS_TOO_OLD_FOR_AVX=ON, the objects for
chacha-x86_64, chacha20_poly1305_x86_64, ghash-x86_64, sha1-x86_64,
aesni-sha256-x86_64, rsaz-avx2 and aes128gcmsiv-x86_64 are byte-identical
to a build without the flag, with identical ymm counts. Emitting those
guards is a larger change (nine scripts, win64 SEH .rva tables, and a
full generated-src regeneration) and is left as follow-up; document the
current contract and warn at configure time instead.

Also note in run_legacy_avx_tests.sh that its DISABLE_PERL=ON leg cannot
detect this, since it only checks that the build succeeds, and record
that chacha-x86_64.pl's unreachable $avx>2 AVX-512 blocks would need a
512AVX gate if ever enabled.

No functional change beyond the new configure-time warning.
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
aws-lc 5.4.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Add AArch64 NEON runtime fallback for ML-KEM and ML-DSA by @samuel40791765 in aws/aws-lc#3353
* Support for `EVP_AEAD_CTX_copy` by @justsmth in aws/aws-lc#3332
* ci:ctest timing summary for MacOS by @dougch in aws/aws-lc#3288
* Remove dead P-256 nistz asm under OPENSSL_SMALL and extend the size-check harness by @justsmth in aws/aws-lc#3350
* Use built-in Camellia in krb5 integration patch; fix CTS doc label by @WillChilds-Klein in aws/aws-lc#3349
* Bump to v5.4.0, add AES-KWP wrap/unwrap CASTs by @WillChilds-Klein in aws/aws-lc#3366


**Full Changelog**: https://github.com/aws/aws-lc/compare/v5.3.0...v5.4.0</pre>
  <p>View the full release notes at <a href="https://github.com/aws/aws-lc/releases/tag/v5.4.0">https://github.com/aws/aws-lc/releases/tag/v5.4.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!14833

This branch was previously deployed

1 inactive deployment
auto-approve โ€” d905ec1b Deployed Jul 20, 2026 by justsmth via android-debug-shared #1565
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants