Skip to content

feat: add AES-OCB to WebCrypto subtle API#915

Merged
boorad merged 3 commits intomainfrom
fix/aes-ocb
Feb 11, 2026
Merged

feat: add AES-OCB to WebCrypto subtle API#915
boorad merged 3 commits intomainfrom
fix/aes-ocb

Conversation

@boorad
Copy link
Collaborator

@boorad boorad commented Feb 11, 2026

Summary

Adds AES-OCB (Offset Codebook Mode) support to the WebCrypto subtle API, including encrypt/decrypt, key generate/import/export, and wrap/unwrap operations.

Changes

  • AES-OCB subtle API — Wire up encrypt, decrypt, generateKey, importKey, exportKey (raw + JWK), wrapKey, and unwrapKey for AES-OCB
  • Shared AEAD cipher helper — Extract aesAeadCipher to deduplicate ~160 lines between GCM and OCB cipher implementations
  • AesOcbParams type — Add proper TypeScript type with tagLength (64 | 96 | 128) and additionalData support
  • OCB tag length fix — Relax C++ tag length validation from 12–16 bytes to 8–16 bytes (per OCB spec)
  • libsodium header collision fix — Exclude ncrypto's version.h from pod sources to prevent it from shadowing libsodium's version.h in the flattened Pods/Headers/Private directory
  • Test error message fix — Correct assertThrowsAsync expected messages to match actual C++ error strings
  • Coverage docs — Update coverage status for AES-OCB across encrypt, decrypt, importKey, exportKey, wrapKey, unwrapKey

Testing

Tested on iOS device via the example app:

  • AES-OCB basic roundtrip
  • Key sizes: 128, 192, 256-bit
  • Tag lengths: 64, 96, 128-bit
  • AAD (additional authenticated data)
  • Empty plaintext
  • Key import/export (raw)
  • Tampered ciphertext / tag / AAD detection
  • Wrap/unwrap with AES-OCB

Add AES-OCB support to subtle.encrypt/decrypt/generateKey/importKey/
exportKey/wrapKey/unwrapKey, matching Node.js WebCrypto behavior.

- Add aesOcbCipher() with OCB-specific validation (tag lengths 64/96/128,
  IV max 15 bytes)
- Fix OCBCipher.cpp tag length minimum from 12 to 8 bytes
- Add AesOcbParams type and wire AES-OCB through all subtle API paths
- Fix stale coverage docs: wrap/unwrap from #914, getCurves from #913
- Add 11 AES-OCB tests (roundtrip, key sizes, AAD, tag lengths, tampering,
  wrap/unwrap)

Closes #382
…er collision

Extract shared aesAeadCipher helper to deduplicate GCM/OCB cipher logic.
Remove as-any casts in OCB tests by using proper AesOcbParams type.
Fix OCB error assertion to match actual C++ error message.
Fix IV validation message to mention 1-byte minimum.
Fix wrap/unwrap test comment numbering.
Exclude ncrypto version.h from pod sources to avoid shadowing
libsodium's version.h in flattened Pods/Headers directory.
@boorad boorad self-assigned this Feb 11, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2026

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 21890174164

📸 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

github-actions bot commented Feb 11, 2026

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 21890174159

📸 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.

Add raw-secret format support to importKey/exportKey as a Node.js-
compatible alias for raw. Fix getAlgorithmName to produce correct JWK
alg field values (e.g. A256GCM instead of AES-GCM256). Add AES-OCB
JWK and raw-secret import/export tests. Fix existing raw-secret tests
to actually use raw-secret format. Update coverage docs to mark all
symmetric key import/export as implemented.
@boorad boorad merged commit 82cf5be into main Feb 11, 2026
5 of 6 checks passed
@boorad boorad deleted the fix/aes-ocb branch February 11, 2026 02:35
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.

1 participant