Skip to content

feat(crypto): Add PBKDF2 importKey and SubtleCrypto.deriveBits - #346

Open
draco2003 wants to merge 3 commits into
bytecodealliance:mainfrom
draco2003:devin/pbkdf2-derivebits
Open

draco2003 wants to merge 3 commits into
bytecodealliance:mainfrom
draco2003:devin/pbkdf2-derivebits

Conversation

@draco2003

Copy link
Copy Markdown

Implement the PBKDF2 slice of WebCrypto on StarlingMonkey:

  • CryptoAlgorithmPBKDF2_Import: importKey for 'raw' PBKDF2 password material, producing a non-extractable secret CryptoKey usable for deriveBits (and, once implemented, deriveKey).
  • CryptoAlgorithmDeriveBits: new base class for algorithms that support the deriveBits operation.
  • CryptoAlgorithmPBKDF2_DeriveBits: PBKDF2 deriveBits backed by OpenSSL PKCS5_PBKDF2_HMAC, supporting SHA-1/256/384/512.
  • SubtleCrypto.deriveBits entry point following the WebCrypto algorithm steps, including [EnforceRange] coercion of the optional length parameter.
  • Shared CryptoKey helpers: createSymmetric (refactored out of createHMAC), canEncrypt/canDecrypt/canDeriveBits usage checks, and canOnlyDeriveBitsOrKey. hmacKeyData is renamed to keyData.

Integration tests cover SHA-1/256/384/512 vectors (including an RFC 7914 4096-iteration vector), zero and non-multiple-of-8 lengths, empty password import, usage checks, and parameter coercion. WPT pbkdf2.https.any.js is enabled with recorded expectations; deriveKey and wrong-ECDH-key subtests are expected-fail until deriveKey and ECDH are implemented.

Implement the PBKDF2 slice of WebCrypto on StarlingMonkey:

- CryptoAlgorithmPBKDF2_Import: importKey for 'raw' PBKDF2 password
  material, producing a non-extractable secret CryptoKey usable for
  deriveBits (and, once implemented, deriveKey).
- CryptoAlgorithmDeriveBits: new base class for algorithms that
  support the deriveBits operation.
- CryptoAlgorithmPBKDF2_DeriveBits: PBKDF2 deriveBits backed by
  OpenSSL PKCS5_PBKDF2_HMAC, supporting SHA-1/256/384/512.
- SubtleCrypto.deriveBits entry point following the WebCrypto
  algorithm steps, including [EnforceRange] coercion of the optional
  length parameter.
- Shared CryptoKey helpers: createSymmetric (refactored out of
  createHMAC), canEncrypt/canDecrypt/canDeriveBits usage checks, and
  canOnlyDeriveBitsOrKey. hmacKeyData is renamed to keyData.

Enables use cases such as the HUMAN Security _px3 cookie scheme on
Fastly Compute, which requires PBKDF2-HMAC-SHA256 key derivation
before AES-256-CBC decryption.

Integration tests cover SHA-1/256/384/512 vectors (including an
RFC 7914 4096-iteration vector), zero and non-multiple-of-8 lengths,
empty password import, usage checks, and parameter coercion. WPT
pbkdf2.https.any.js is enabled with recorded expectations; deriveKey
and wrong-ECDH-key subtests are expected-fail until deriveKey and
ECDH are implemented.
@draco2003

Copy link
Copy Markdown
Author

Will create another PR to Add AES-CBC importKey and SubtleCrypto encrypt/decrypt (draco2003#2) if / when the current PR gets feedback/is acceptable.

This branch has not been deployed

No deployments
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