Skip to content

test(crypto): add C2SP/Wycheproof test vectors for HMAC - #993

Merged
auto-submit[bot] merged 6 commits into
mainfrom
crypto-wycheproof
Sep 11, 2026
Merged

auto-submit[bot] merged 6 commits into
mainfrom
crypto-wycheproof

Conversation

@kevmoo

@kevmoo kevmoo commented Aug 19, 2026

Copy link
Copy Markdown
Member

Integrates HMAC test vectors from Project Wycheproof, maintained by the
Community Cryptography Specification Project (C2SP, originally developed
at Google).

Provenance & Cryptographic Value

Project Wycheproof provides test vectors that specifically stress-test
cryptographic edge cases, boundary conditions, and known attack vectors
rather than just basic happy-path conformance. For HMAC, this includes:

  • Key-length boundary transitions: keys shorter than, equal to, and
    longer than hash block sizes (triggering RFC 2104 pre-hashing).
  • Edge-case message inputs (zero-length and boundary chunks).
  • Tag truncation testing matrices down to sub-byte boundaries.
  • Corrupted tags (single-bit flips, all-0/all-1 substitutions).

Summary of Changes

  • Added tool/pull_wycheproof.dart to fetch and pin the HMAC test vector
    JSON suites from C2SP/wycheproof.
  • Generated inlined lookup data in test/wycheproof_data.dart with base64
    encoding to enable zero-IO execution on browser (--platform chrome) and
    WebAssembly (--compiler dart2wasm) CI test runners while avoiding false
    positive secret scanner triggers.
  • Added test/wycheproof_hmac_test.dart asserting 1,212 test cases across
    SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256.

Integrates HMAC test vectors from Project Wycheproof, maintained by the
Community Cryptography Specification Project (C2SP, originally developed
at Google).

### Provenance & Cryptographic Value
Project Wycheproof provides test vectors that specifically stress-test
cryptographic edge cases, boundary conditions, and known attack vectors
rather than just basic happy-path conformance. For HMAC, this includes:
- Key-length boundary transitions: keys shorter than, equal to, and
  longer than hash block sizes (triggering RFC 2104 pre-hashing).
- Edge-case message inputs (zero-length and boundary chunks).
- Tag truncation testing matrices down to sub-byte boundaries.
- Corrupted tags (single-bit flips, all-0/all-1 substitutions).

### Summary of Changes
- Added tool/pull_wycheproof.dart to fetch and pin the HMAC test vector
  JSON suites from C2SP/wycheproof.
- Generated inlined lookup data in test/wycheproof_data.dart with base64
  encoding to enable zero-IO execution on browser (--platform chrome) and
  WebAssembly (--compiler dart2wasm) CI test runners while avoiding false
  positive secret scanner triggers.
- Added test/wycheproof_hmac_test.dart asserting 1,212 test cases across
  SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256.
@kevmoo
kevmoo requested a review from a team as a code owner August 19, 2026 05:42
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

PR Health

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/collection/benchmark/legacy_quicksort.dart

This check can be disabled by tagging the PR with skip-license-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
crypto Non-Breaking 3.0.7 3.0.8-wip 3.0.8-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Unused Dependencies ✔️
Package Status
crypto ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

Coverage ⚠️
File Coverage
pkgs/crypto/tool/pull_wycheproof.dart 💔 Not covered

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

kevmoo added 2 commits August 19, 2026 05:46
Wraps base64 string literals into 70-character chunks using adjacent
Dart string literals, matching the asset inlining pattern in pubviz.
Guarantees clean formatting under dart format and satisfies 80-column
line limits.

@natebosch natebosch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any licensing we need to worry about?

Comment thread pkgs/crypto/tool/pull_wycheproof.dart Resolved
Comment thread pkgs/crypto/.gitignore Resolved
@kevmoo

kevmoo commented Aug 19, 2026 •

Copy link
Copy Markdown
Member Author

Project Wycheproof is licensed under Apache 2.0 (originally created and open-sourced by Google security researchers, currently maintained under C2SP).

Because it is a permissive license and only used in test/ and tool/ (with zero code entering lib/), it is fully compatible with package:crypto's BSD 3-Clause license and does not affect the published package's runtime licensing.

I've added an explicit Apache 2.0 attribution notice in the generated test data and tool headers to satisfy Apache § 4 attribution.

@kevmoo

kevmoo commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

Friendly ping CC @jonasfj @brianquinlan

Comment thread pkgs/crypto/tool/pull_wycheproof.dart Resolved
@brianquinlan

Copy link
Copy Markdown
Contributor

@natebosch are you OK with the licensing?

Comment thread pkgs/crypto/test/wycheproof_data.dart Resolved
Comment thread pkgs/crypto/test/wycheproof_data.dart Resolved
Comment thread pkgs/crypto/tool/pull_wycheproof.dart Resolved
@natebosch

Copy link
Copy Markdown
Member

I'm fairly confident we need a full copy of the APACHE license next to this file somewhere, but I'm not confident on the details of where it should be. I think maybe something like a licenses/LICENSE-wycheproof.txt file is sufficient if we update the generated file to reference it.

- Add Project Wycheproof Apache 2.0 license to pkgs/crypto/third_party/wycheproof/LICENSE
- Remove Dart BSD header from generated wycheproof_data.dart and reference the Apache license
- Add doc comment explaining pkgs/crypto/tool/pull_wycheproof.dart
- Configure .gitattributes to mark wycheproof_data.dart as linguist-generated
@kevmoo

kevmoo commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Regarding the license location:

Because test/ is not excluded in .gitignore or pubspec.yaml, test/wycheproof_data.dart is packaged and distributed in the package:crypto archive on pub.dev. To comply with Apache 2.0 § 4(a) (requiring recipients of the Work or Derivative Works to be given a copy of the License), the license file must accompany the distributed package rather than living at the monorepo root (which pub publishing ignores).

Following the existing convention in this monorepo (pkgs/characters/third_party/Unicode_Consortium/):

  • Placed the full Apache 2.0 license at pkgs/crypto/third_party/wycheproof/LICENSE.
  • Removed the Dart BSD license header from wycheproof_data.dart and pull_wycheproof.dart, pointing instead to third_party/wycheproof/LICENSE.
  • Added .gitattributes to mark pkgs/crypto/test/wycheproof_data.dart as linguist-generated=true so GitHub automatically collapses it in PR diffs.
  • Added a doc comment to pkgs/crypto/tool/pull_wycheproof.dart.

@kevmoo
kevmoo requested a review from natebosch September 10, 2026 23:55
@auto-submit
auto-submit Bot merged commit 51cf766 into main Sep 11, 2026
31 checks passed
@auto-submit
auto-submit Bot deleted the crypto-wycheproof branch September 11, 2026 00:49
copybara-service Bot pushed a commit to dart-lang/sdk that referenced this pull request Sep 11, 2026
Revisions updated by `dart tools/rev_sdk_deps.dart`.

core (https://github.com/dart-lang/core/compare/7e8caaf..51cf766):
  51cf7664  Thu Sep 10 17:49:25 2026 -0700  Kevin Moore  test(crypto): add C2SP/Wycheproof test vectors for HMAC (dart-lang/core#993)

native (https://github.com/dart-lang/native/compare/84d7eda..f2b4942):
  f2b4942cc  Fri Sep 11 07:59:55 2026 +0530  Sivapriya  [jnigen] Relax binding verification test (dart-lang/native#3627)

protobuf (https://github.com/dart-lang/protobuf/compare/cde8e28..a73edc9):
  a73edc9  Fri Sep 11 12:54:45 2026 +0100  Martin Kustermann  Remove legacy interop use (conditional import on dart.library.html) (google/protobuf.dart#1102)

webdriver (https://github.com/google/webdriver.dart/compare/9b2e87d..8e5c611):
  8e5c611  Fri Sep 11 01:32:05 2026 -0400  Nate Biggs  Refactor matchState initialization to use untyped literal (google/webdriver.dart#349)

TAG=agy
CONV=688fe3c8-47b5-4273-96f1-b13470d355b6
[email protected]

Change-Id: I3c2cb3870ccc229206da7d27a3b8ece7a1492842
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/548981
Reviewed-by: Brian Quinlan <[email protected]>
Commit-Queue: Nate Bosch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants