chovy-3012 commented on issue #13377: URL: https://github.com/apache/seatunnel/issues/13377#issuecomment-7064423774
Thanks for the review and the precise gating points. Here is the contract proposal for discussion before any implementation PR. **Naming and exposure** - Functions: `SM4_ENCRYPT(value, key[, iv])` / `SM4_DECRYPT(value, key[, iv])`, mirroring `AES_ENCRYPT` / `AES_DECRYPT`. - Exposure: Zeta SQL transform built-ins (`ZetaSQLFunction` dispatch), same as the existing crypto functions. The Calcite SQL path loads UDFs via the `CalciteUdf` SPI; I would treat a Calcite-side UDF as a follow-up rather than expanding this PR's scope, and will document that availability boundary explicitly either way. **Cryptographic contract (deliberately aligned with our `AES_ENCRYPT`, not with Doris's wire format)** - Mode/padding: `SM4/CBC/PKCS5Padding`. The issue cites Doris only as a naming/parameter-scheme precedent; I do not propose adopting its default ECB with a built-in fixed IV, which is replayable across rows. CBC with a per-call random IV keeps one uniform contract with the existing AES functions. - IV layout: identical to `AES_ENCRYPT` — when no IV argument is supplied, a random 16-byte IV is generated per call and the result is `Base64(IV || ciphertext)`; when an explicit 16-byte IV is supplied, the result is `Base64(ciphertext)` and the caller owns the IV. - Key-input rule: identical to `AES_ENCRYPT` — a `base64:`-prefixed key decodes to a raw key (SM4 is 128-bit, so exactly 16 bytes; no 24/32-byte variants); any other key is treated as a passphrase and derived via a single unsalted SHA-256, using the first 16 bytes. - Failure semantics: null input → null; invalid Base64, too-short ciphertext, or padding failure → explicit error with context (consistent with our existing crypto functions, which throw rather than silently returning null like Doris). As with any unauthenticated CBC, a wrong key can occasionally decrypt to garbage instead of throwing (~1/256); the docs will state this caveat, as the AES docs do. **Provider / packaging plan** - Pure Java, zero new dependencies: a self-contained SM4 implementation (on the order of a few hundred lines) validated against the published GB/T 32907-2016 standard test vectors. No BouncyCastle, no shading or licensing impact — this is deliberately preferred over adding a crypto dependency, since the standard JDK has no SM4 provider. **Secrets handling** - Same convention as `CryptoFunction`: error paths carry only non-sensitive metadata (argument count, byte length, type name); keys, plaintext, ciphertext, and IV never appear in exception messages or logs. **Acceptance (once the contract is agreed)** - Fixed-IV tests against the published GB/T 32907 vectors; generated-IV encrypt/decrypt round trips; raw and `base64:` 16-byte-key validation; null handling; malformed/tampered ciphertext; wrong-key failure; EN/ZH documentation alongside the unit tests. If this contract looks right, I'll open the implementation PR against it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
