Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Move TLS 1.3 KDF into the FIPS module and wire up ACVP#3247

Open
justsmth wants to merge 6 commits into
aws:main from
justsmth:acvp-tls-1.3-kdf
Open

Move TLS 1.3 KDF into the FIPS module and wire up ACVP #3247
justsmth wants to merge 6 commits into
aws:main from
justsmth:acvp-tls-1.3-kdf

Conversation

@justsmth

@justsmth justsmth commented May 12, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Issues

Addresses:

Description of changes:

Moves TLS 1.3 HKDF-Expand-Label (RFC 8446 §7.1) into the FIPS module and wires up the ACVP modulewrapper so we advertise TLS-v1.3 as a validated composite algorithm.

  1. CRYPTO_tls13_hkdf_expand_label in crypto/fipsmodule/tls/kdf.c — builds the HkdfLabel structure, calls HKDF_expand, handles the FIPS service indicator (approved for SHA2-256 / SHA2-384).

  2. Delegates both consumersssl/tls13_enc.cc::hkdf_expand_label becomes a thin wrapper; the modulewrapper's TLS13_HKDFExpandLabel handler (wire command HKDFExpandLabel/<HASH>) routes through the same code path.

  3. ACVP wiring — registers TLS-v1.3 / RFC8446 in getConfig, implements HKDFExtract/ and HKDFExpandLabel/ commands, adds 250 NIST test vectors from the ACVP-Server repo.

  4. FIPS self-test — TLS13-KDF KAT in self_check.c plus matching break-kat.go entry.

Call-outs:

  • Public API surface. CRYPTO_tls13_hkdf_expand_label is declared in include/openssl/kdf.h alongside CRYPTO_tls1_prf for consistency. BoringSSL keeps it private; happy to switch if reviewers prefer tighter scope.

  • Ported from BoringSSL. The HkdfLabel/CBB construction in CRYPTO_tls13_hkdf_expand_label, the ACVP handlers, the getConfig block, and the KAT vectors (commit 480344d4fa) are all ported from BoringSSL. The FIPS service-indicator wiring is AWS-LC-specific. Attribution comments are in-line in the diff.

  • Helper naming. The modulewrapper handlers are TLS13_HKDFExtract / TLS13_HKDFExpandLabel (diverging from BoringSSL's names) to disambiguate from the pre-existing generic HKDF / HKDF_expand helpers in the same TU.

Testing:

All existing crypto_test, ssl_test, and acvp_tests pass. New coverage: five TLS13KDF_ServiceIndicatorTest cases and the TLS13-KDF self-test KAT.

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.

@github-actions github-actions Bot 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.

clang-tidy made some suggestions

Comment thread util/fipstools/acvp/modulewrapper/modulewrapper.cc
Comment thread util/fipstools/acvp/modulewrapper/modulewrapper.cc

codecov-commenter commented May 12, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.89189% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.16%. Comparing base (c0a3c85) to head (10b9f5b).

Files with missing lines Patch % Lines
crypto/fipsmodule/tls/kdf.c 92.00% 2 Missing ⚠️
crypto/fipsmodule/self_check/self_check.c 85.71% 1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@
## main #3247 +/- ##
==========================================
- Coverage 78.17% 78.16% -0.02% 
==========================================
 Files 689 689 
 Lines 123733 123751 +18 
 Branches 17197 17204 +7 
==========================================
 Hits 96724 96724 
- Misses 26091 26108 +17 
- Partials 918 919 +1 

☔ View full report in Codecov by Sentry.
📢 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.

@justsmth justsmth changed the title (削除) [DRAFT] Add TLS v1.3 KDF to ACVP modulewrapper (削除ここまで) (追記) [DRAFT] Move TLS 1.3 KDF into the FIPS module and wire up ACVP (追記ここまで) May 13, 2026

@github-actions github-actions Bot 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.

clang-tidy made some suggestions

Comment thread crypto/fipsmodule/self_check/self_check.c
Comment thread crypto/fipsmodule/tls/kdf.c
Comment thread crypto/fipsmodule/tls/kdf.c
Comment thread crypto/fipsmodule/tls/kdf.c
Comment thread crypto/fipsmodule/tls/kdf.c
@justsmth justsmth changed the title (削除) [DRAFT] Move TLS 1.3 KDF into the FIPS module and wire up ACVP (削除ここまで) (追記) Move TLS 1.3 KDF into the FIPS module and wire up ACVP (追記ここまで) May 13, 2026
@justsmth justsmth marked this pull request as ready for review May 13, 2026 18:47
@justsmth justsmth requested a review from a team as a code owner May 13, 2026 18:47
Comment thread include/openssl/kdf.h
Comment thread crypto/fipsmodule/tls/kdf.c Outdated
justsmth added 6 commits June 3, 2026 12:13
Wire up the TLS-v1.3 (RFC 8446) KDF as an ACVP-testable algorithm in
the FIPS modulewrapper. The acvptool subprocess handler (tls13.go)
already existed but had no corresponding modulewrapper implementation.
Add HKDFExtract and HKDFExpandLabel commands to the modulewrapper,
register the TLS-v1.3 algorithm in the ACVP config (SHA2-256/384,
DHE/PSK/PSK-DHE modes), and include NIST-published test vectors from
the ACVP-Server repository.
All 250 NIST test cases pass.
Introduces CRYPTO_tls13_hkdf_expand_label in crypto/fipsmodule/tls/kdf.c,
mirroring the CRYPTO_tls1_prf pattern already in that file. The function
builds the HkdfLabel structure (RFC 8446 §7.1) via CBB and calls
HKDF_expand, bracketed by FIPS_service_indicator_lock_state /
unlock_state and a post-success TLS13_KDF_verify_service_indicator call
that approves SHA2-256 and SHA2-384 (matching what the ACVP config
registers).
Consumers now delegate:
 * ssl/tls13_enc.cc's hkdf_expand_label collapses to a thin wrapper.
 * The ACVP modulewrapper's HKDFExpandLabel delegates to the same
 function, so ACVP exercises the actual FIPS-module code path
 instead of a parallel label-construction reimplementation.
A TLS13-KDF KAT (HKDF_extract -> CRYPTO_tls13_hkdf_expand_label, using
the RFC 8448 early-secret / 'c e traffic' derivation) is added to the
FIPS self-test, along with a matching break-kat.go entry. A new
parameterised TLS13KDF_ServiceIndicatorTest covers the approval policy
across SHA-1 / SHA-224 / SHA-256 / SHA-384 / SHA-512.
The RFC 8446 Section 7.1 "opaque label<7..255>" lower bound on the HkdfLabel.label field does not match real caller behavior: SSL_export_keying_material permits a zero-length caller label, which the ssl/test/runner exerciser relies on for TLS 1.3 exporter interop tests. Neither the pre-refactor ssl/tls13_enc.cc hkdf_expand_label nor BoringSSL's CRYPTO_tls13_hkdf_expand_label enforce the lower bound, so rejecting label_len == 0 here regressed every TLS-TLS13-* and QUIC-TLS13-* runner test that uses exportKeyingMaterial.
The upper bound on out_len is already enforced implicitly by CBB_add_u16, so the explicit check is redundant. Drop the whole block and document what CBB enforces for us.
tests/ci/run_fips_callback_tests.sh::run_all_break_tests enumerates every KAT known to util/fipstools/break-kat.go, tampers the crypto_test binary for each, and runs FIPSCallback.PowerOnSelfTests expecting the AWS_LC_fips_failure_callback to be invoked with the exact failure-message sequence listed in crypto/fips_callback_test.cc::kat_failure_messages.
This PR added TLS13-KDF to break-kat.go and to boringssl_self_test_fast but forgot to teach the callback test about it, so when the broken binary runs with FIPS_CALLBACK_TEST_EXPECTED_FAILURE=TLS13-KDF the lookup misses and the test body hits FAIL("Failed to find expected message for ... TLS13-KDF"). That's what's blocking the fips-callback-amazonlinux:2023-aarch64 job.
The failure-message sequence mirrors TLS-KDF (same enclosing boringssl_self_test_fast path, so the outer "Power on self test failed" string is produced from bcm.c::BORINGSSL_bcm_power_on_self_test). The Expected/Calculated hex pair is derived by running the HKDF-Extract(SHA256, IKM=0^32, salt=kTLS13Salt) then CRYPTO_tls13_hkdf_expand_label(label="c e traffic", context=kTLS13ClientHelloHash) chain that self_check.c uses; break-kat zeroes the 32-byte kTLS13Secret in the binary image, producing the given Calculated bytes.
Address review feedback:
- Rename the new modulewrapper ACVP handlers HKDFExtract/HKDFExpandLabel
 to TLS13_HKDFExtract/TLS13_HKDFExpandLabel. The ACVP command strings
 on the wire are unchanged; only the C++ identifiers move. This matches
 the existing TLSKDF / "TLSKDF/1.2/..." convention in the same file
 and disambiguates the new helpers from the generic HKDF / HKDF_expand
 helpers (KDA/HKDF and KDF/Feedback) already defined in this TU.
- Add in-code attribution for the parts of this change that are ported
 from BoringSSL: the pair of ACVP handlers in modulewrapper.cc and the
 HkdfLabel/CBB construction in CRYPTO_tls13_hkdf_expand_label. The
 comment on the latter also calls out that the FIPS service-indicator
 lock/unlock and TLS13_KDF_verify_service_indicator call are
 AWS-LC-specific, to make the port vs. novel split explicit for future
 reviewers and for resyncs with BoringSSL upstream.
Address review comments from Nevine on PR aws#3247:
* include/openssl/kdf.h: correct the documented contract for
 CRYPTO_tls13_hkdf_expand_label to match the actual implementation
 behavior. The previous text required |label_len| in [1, 249] but
 commit 12e6a75 intentionally stopped enforcing the lower bound to
 support SSL_export_keying_material callers that pass an empty label.
* crypto/fipsmodule/tls/kdf.c: restore the explicit
 |out_len > UINT16_MAX| check that was removed in 12e6a75. CBB_add_u16
 cannot enforce the bound on its own because the size_t-to-uint16_t
 narrowing happens in the implicit conversion at the call site, before
 CBB_add_u16 ever sees the value, silently producing a spec-violating
 HkdfLabel.length on oversized requests. The empty-label allowance from
 12e6a75 stays; only the upper-bound check comes back. Comment
 clarified to explain which bounds CBB does and does not enforce.
Comment on lines +3424 to +3425
static const uint8_t kHash[32] = {0};
FIPSStatus approved = AWSLC_NOT_APPROVED;

@samuel40791765 samuel40791765 Jun 9, 2026

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.

Minor nit, but kHash[32] = {0} is fixed at 32 bytes even when the test exercises SHA-384 (output is 48 bytes). It doesn't really effect the correctness of the implementation though, just something that felt off.

Comment thread include/openssl/kdf.h
Comment on lines +33 to +35
// most 65535, |label_len| must be at most 249 so that the "tls13 "-prefixed
// label fits in the RFC 8446 |opaque label<...255>| bound, and |hash_len|
// must be at most 255. An empty |label| (|label_len == 0|) is permitted to

@samuel40791765 samuel40791765 Jun 9, 2026

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.

Should we introduce a check to bail early and enforce this?

 if (label_len > 249 || hash_len > 255) {
 OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
 return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@samuel40791765 samuel40791765 samuel40791765 left review comments

@github-actions github-actions[bot] github-actions[bot] left review comments

@nhatnghiho nhatnghiho Awaiting requested review from nhatnghiho

@nebeid nebeid Awaiting requested review from nebeid

At least 2 approving reviews are required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /