Skip to content

feat: add KMAC128/KMAC256 support to subtle API#944

Merged
boorad merged 3 commits intomainfrom
feat/kmac
Feb 17, 2026
Merged

feat: add KMAC128/KMAC256 support to subtle API#944
boorad merged 3 commits intomainfrom
feat/kmac

Conversation

@boorad
Copy link
Collaborator

@boorad boorad commented Feb 17, 2026

Summary

Adds KMAC128 and KMAC256 (Keccak Message Authentication Code, NIST SP 800-185) to the WebCrypto subtle API, with review fixes and test reorganization.

Changes

KMAC Implementation (490e1da)

  • subtle.sign() / subtle.verify() with KMAC128/KMAC256
  • subtle.generateKey() for KMAC symmetric keys
  • subtle.importKey() / subtle.exportKey() (raw + JWK formats)
  • C++ HybridKmac Nitro Module using OpenSSL 3.6+ EVP_MAC API
  • Customization string support via algorithm.customization
  • Configurable output length via algorithm.length (in bits)

Review Fixes (b260212)

  • Replace JS XOR loop with native timingSafeEqual (CRYPTO_memcmp) in both kmacSignVerify and hmacSignVerify for constant-time MAC comparison
  • Add output length % 8 validation in kmacSignVerify
  • Convert raw EVP_MAC_CTX* to unique_ptr with custom deleter (RAII)
  • Reset context after EVP_MAC_final to prevent use-after-finalize UB
  • Consolidate Subtle.sign() / Subtle.verify() — remove ~50 lines of inline HMAC/KMAC interception, route all algorithms through the signVerify() dispatcher (also fixes pre-existing HMAC timing-unsafe comparison)

Test Reorganization (a613f66)

  • Move KMAC tests from standalone kmac.ts into operation-based files (sign_verify.ts, import_export.ts)
  • Delete kmac.ts

Testing

  • 6 NIST SP 800-185 test vectors (sign + verify) for both KMAC128 and KMAC256
  • generateKey + sign/verify round-trips
  • Corrupted signature verification (returns false)
  • Customization string differentiation
  • Raw and JWK import/export round-trips
  • All existing HMAC tests continue to pass (routing change is transparent)

Closes #938

Implement KMAC (Keccak Message Authentication Code) per NIST SP 800-185,
completing WebCrypto subtle coverage for generateKey, sign, and verify.

- Add HybridKmac C++ native module using OpenSSL EVP_MAC API
- Support KMAC128 and KMAC256 algorithms with optional customization string
- Wire into subtle.generateKey(), sign(), verify(), importKey(), exportKey()
- Support raw, raw-secret, and JWK key formats (K128/K256 alg identifiers)
- Add NIST SP 800-185 test vectors (6 vectors) plus round-trip tests
- Update coverage tracking
… sign/verify

- Replace JS XOR loop with native timingSafeEqual (CRYPTO_memcmp) in
  kmacSignVerify and hmacSignVerify for constant-time MAC comparison
- Add output length % 8 validation in kmacSignVerify
- Convert raw EVP_MAC_CTX* to unique_ptr with custom deleter (RAII)
- Reset context after EVP_MAC_final to prevent use-after-finalize UB
- Remove ~50 lines of inline HMAC/KMAC handling from Subtle.sign/verify,
  route all algorithms through the signVerify() dispatcher
- hmacSignVerify() is now reachable (was dead code due to inline intercept)
Move tests from standalone kmac.ts into sign_verify.ts and
import_export.ts, organized by WebCrypto operation rather than
algorithm. Delete kmac.ts and remove its import.
@boorad boorad self-assigned this Feb 17, 2026
@github-actions
Copy link
Contributor

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 22085909985

📸 Final Test Screenshot

Maestro Test Results - android

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@github-actions
Copy link
Contributor

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 22085909986

📸 Final Test Screenshot

Maestro Test Results - ios

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@boorad boorad merged commit 3e06617 into main Feb 17, 2026
7 checks passed
@boorad boorad deleted the feat/kmac branch February 17, 2026 04:37
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.

✨ add KMAC implementations

1 participant