mplang-nightly 0.1.dev261__py3-none-any.whl → 0.1.dev263__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -271,6 +271,27 @@ def bytes_to_point_impl(
271
271
 
272
272
  # --- Sym / Hash Impl ---
273
273
 
274
+ # Supported symmetric encryption algorithms
275
+ _SUPPORTED_ALGOS = {"aes-gcm"}
276
+
277
+
278
+ def _validate_algo(algo: str, operation: str) -> None:
279
+ """Validate that the algorithm is supported.
280
+
281
+ Args:
282
+ algo: Algorithm name to validate
283
+ operation: Operation name for error message (e.g., "encryption", "decryption")
284
+
285
+ Raises:
286
+ ValueError: If algo is not supported
287
+ """
288
+ if algo not in _SUPPORTED_ALGOS:
289
+ supported = ", ".join(sorted(_SUPPORTED_ALGOS))
290
+ raise ValueError(
291
+ f"Unsupported {operation} algorithm: {algo!r}. "
292
+ f"Supported algorithms: {supported}"
293
+ )
294
+
274
295
 
275
296
  @crypto.hash_p.def_impl
276
297
  def hash_impl(interpreter: Interpreter, op: Operation, data: Value) -> Value:
@@ -336,6 +357,10 @@ def sym_encrypt_impl(
336
357
  numpy arrays, scalars, etc.). This supports both high-level API usage
337
358
  (with TensorValue) and elementwise operations (with raw scalars).
338
359
  """
360
+ # Read and validate algo parameter (must be provided by frontend)
361
+ algo = op.attrs["algo"]
362
+ _validate_algo(algo, "encryption")
363
+
339
364
  # Get raw key bytes - strict type checking
340
365
  if isinstance(key, SymmetricKeyValue):
341
366
  k = key.key_bytes
@@ -376,6 +401,10 @@ def sym_decrypt_impl(
376
401
  on what was encrypted - could be a Value subclass (TensorValue, BytesValue),
377
402
  a numpy array, or a scalar (int, float, etc.) when used in elementwise ops.
378
403
  """
404
+ # Read and validate algo parameter (must be provided by frontend)
405
+ algo = op.attrs["algo"]
406
+ _validate_algo(algo, "decryption")
407
+
379
408
  # Get raw key bytes - strict type checking
380
409
  if isinstance(key, SymmetricKeyValue):
381
410
  k = key.key_bytes
@@ -186,10 +186,10 @@ def constant_impl(interpreter: Interpreter, op: Operation) -> TableValue:
186
186
  # If data was a DataFrame, it might have been stored as is if the IR supports it.
187
187
  # If data was a dict, it's fine.
188
188
 
189
- if isinstance(data, pd.DataFrame):
190
- return _wrap(pa.Table.from_pandas(data))
191
-
192
- return _wrap(pa.Table.from_pydict(data))
189
+ if isinstance(data, pa.Table):
190
+ return _wrap(data)
191
+ else:
192
+ return _wrap(pa.table(data))
193
193
 
194
194
 
195
195
  def _infer_format(path: str, format_hint: str) -> str:
@@ -275,15 +275,44 @@ def _hash_batch_ae(data: elt.BaseType) -> elt.TensorType:
275
275
 
276
276
 
277
277
  @sym_encrypt_p.def_abstract_eval
278
- def _sym_encrypt_ae(key: elt.BaseType, plaintext: elt.BaseType) -> elt.TensorType:
278
+ def _sym_encrypt_ae(
279
+ key: elt.BaseType, plaintext: elt.BaseType, *, algo: str = "aes-gcm"
280
+ ) -> elt.TensorType:
281
+ """Abstract evaluation for symmetric encryption.
282
+
283
+ Args:
284
+ key: Symmetric encryption key
285
+ plaintext: Data to encrypt
286
+ algo: Encryption algorithm (keyword-only, validated at runtime)
287
+
288
+ Returns:
289
+ Ciphertext as dynamic-length uint8 tensor
290
+ """
279
291
  # Dynamic shape for ciphertext
292
+ # algo validation is done at backend impl, not here
280
293
  return elt.TensorType(elt.u8, (-1,))
281
294
 
282
295
 
283
296
  @sym_decrypt_p.def_abstract_eval
284
297
  def _sym_decrypt_ae(
285
- key: elt.BaseType, ciphertext: elt.BaseType, target_type: elt.BaseType
298
+ key: elt.BaseType,
299
+ ciphertext: elt.BaseType,
300
+ *,
301
+ target_type: elt.BaseType,
302
+ algo: str = "aes-gcm",
286
303
  ) -> elt.BaseType:
304
+ """Abstract evaluation for symmetric decryption.
305
+
306
+ Args:
307
+ key: Symmetric decryption key
308
+ ciphertext: Encrypted data
309
+ target_type: Expected type of decrypted plaintext (keyword-only)
310
+ algo: Decryption algorithm (keyword-only, validated at runtime)
311
+
312
+ Returns:
313
+ Decrypted plaintext with type matching target_type
314
+ """
315
+ # algo validation is done at backend impl, not here
287
316
  return target_type
288
317
 
289
318
 
@@ -367,16 +396,50 @@ def hash_batch(data: el.Object) -> el.Object:
367
396
  return hash_batch_p.bind(data)
368
397
 
369
398
 
370
- def sym_encrypt(key: el.Object, plaintext: el.Object) -> el.Object:
371
- """Symmetric encrypt (XOR stream or AES-GCM)."""
372
- return sym_encrypt_p.bind(key, plaintext)
399
+ def sym_encrypt(
400
+ key: el.Object, plaintext: el.Object, *, algo: str = "aes-gcm"
401
+ ) -> el.Object:
402
+ """Symmetric encrypt.
403
+
404
+ Args:
405
+ key: Symmetric encryption key (SymmetricKeyType or bytes).
406
+ plaintext: Data to encrypt (any serializable object).
407
+ algo: Encryption algorithm. Currently only "aes-gcm" is supported.
408
+ Validation is performed at backend execution time.
409
+
410
+ Returns:
411
+ Ciphertext as Tensor[u8, (-1,)].
412
+
413
+ Raises:
414
+ ValueError: At runtime if algo is not supported by the backend.
415
+ """
416
+ return sym_encrypt_p.bind(key, plaintext, algo=algo)
373
417
 
374
418
 
375
419
  def sym_decrypt(
376
- key: el.Object, ciphertext: el.Object, target_type: elt.BaseType
420
+ key: el.Object,
421
+ ciphertext: el.Object,
422
+ target_type: elt.BaseType,
423
+ *,
424
+ algo: str = "aes-gcm",
377
425
  ) -> el.Object:
378
- """Symmetric decrypt."""
379
- return sym_decrypt_p.bind(key, ciphertext, target_type=target_type)
426
+ """Symmetric decrypt.
427
+
428
+ Args:
429
+ key: Symmetric decryption key (SymmetricKeyType or bytes).
430
+ ciphertext: Encrypted data.
431
+ target_type: Expected type of the decrypted plaintext (for type inference).
432
+ algo: Decryption algorithm. Must match the algorithm used for encryption.
433
+ Currently only "aes-gcm" is supported.
434
+ Validation is performed at backend execution time.
435
+
436
+ Returns:
437
+ Decrypted plaintext with type matching target_type.
438
+
439
+ Raises:
440
+ ValueError: At runtime if algo is not supported by the backend.
441
+ """
442
+ return sym_decrypt_p.bind(key, ciphertext, target_type=target_type, algo=algo)
380
443
 
381
444
 
382
445
  def select(cond: el.Object, true_val: el.Object, false_val: el.Object) -> el.Object:
@@ -236,9 +236,6 @@ def _run_jax_trace(fn: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
236
236
 
237
237
  normalized_fn, variables = normalize_fn(fn, args, kwargs, _is_trace_object)
238
238
 
239
- if not variables:
240
- raise TypeError("tensor.run_jax requires at least one Tensor argument")
241
-
242
239
  # Convert TraceObjects to JAX placeholders for compilation
243
240
  placeholders: list[ShapeDtypeStruct] = []
244
241
  for var in variables:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mplang-nightly
3
- Version: 0.1.dev261
3
+ Version: 0.1.dev263
4
4
  Summary: Multi-Party Programming Language
5
5
  Author-email: SecretFlow Team <secretflow-contact@service.alipay.com>
6
6
  License: Apache License
@@ -82,7 +82,7 @@ mplang/v2/cli.py,sha256=QtiTFG418k26opRy4GhVV8fwFqRS11xTLH3xRCIIm6M,19665
82
82
  mplang/v2/cli_guide.md,sha256=kyoCaqkvIJJ1vsvCyBu3qgOuRSb0txu9BDZoy9GU5S0,3617
83
83
  mplang/v2/backends/__init__.py,sha256=H-4-jBEPWBZl6XT7AxBShRINnruF_f_2lB4iaiQoXME,1988
84
84
  mplang/v2/backends/bfv_impl.py,sha256=cQPinze3c2xN4CmIIoXxZoIEhu9ynoGaXbdF95z_aTE,25709
85
- mplang/v2/backends/crypto_impl.py,sha256=Kf8KC_5YTZowgAPm8MLPXKrl8AORaZTmYrUNk9gnFhU,18425
85
+ mplang/v2/backends/crypto_impl.py,sha256=-4-ry7rXgPjkuM-KTFc4pG3k-O5dSNTEkcMR4W2LtJg,19327
86
86
  mplang/v2/backends/field_impl.py,sha256=50sKGOlkUiaTj_IAola86uQeoi-fxV0o7G91BdTCWZA,14788
87
87
  mplang/v2/backends/func_impl.py,sha256=R0662cC0gSSfkjuLyevJ_g4bJDJirY76LTFYqEimCkE,3585
88
88
  mplang/v2/backends/phe_impl.py,sha256=r836e_qBHGrHhfnFail5IaUDzvS7bABjdEQmJmAtBVI,4127
@@ -90,7 +90,7 @@ mplang/v2/backends/simp_design.md,sha256=CXvfxrvV1TmKlFm8IbKTbcHHwLl6AhwlY_cNqMd
90
90
  mplang/v2/backends/spu_impl.py,sha256=nDmpntXMKlFhaOUMXAOO_-RZTzqGLsgxEvwJuVA6h1g,9047
91
91
  mplang/v2/backends/spu_state.py,sha256=wj876IvNPhKyWISN6WwKBYoaDQFFJ8jemdJUVeH5IfA,4144
92
92
  mplang/v2/backends/store_impl.py,sha256=RyhADTNsnnNnwsatAMr7eeewXkVXtfNWA1oFiLXg8H0,2222
93
- mplang/v2/backends/table_impl.py,sha256=c36gyBCWLQbV3g0hkJeTnMXUqT0nxgu74k2sLondTio,8784
93
+ mplang/v2/backends/table_impl.py,sha256=7W6Zm3bYrDx-6OTHsJe_SlVjxoDDJXNw5qfBGGBbE4U,8759
94
94
  mplang/v2/backends/tee_impl.py,sha256=Gp-vqqJPtEMNqP7y68tLhL3a-EW3BQwpo_qCJOSHqKs,7044
95
95
  mplang/v2/backends/tensor_impl.py,sha256=8f9f4-_e-m4JWGZSbXLmSSHcgPykRBc1sAYrA3OIxEg,18906
96
96
  mplang/v2/backends/simp_driver/__init__.py,sha256=ahOPYYvtFVwqxiFxkpSNP8BCTao_MfCXmtt5zsMaJxg,1258
@@ -106,7 +106,7 @@ mplang/v2/backends/simp_worker/ops.py,sha256=DMQCsKeoMtemy5ozsVZt2eoF8NZlhLeHZMD
106
106
  mplang/v2/backends/simp_worker/state.py,sha256=eRUI7MP6gU8KPC9-H5fwcoAPKOsfW2ODWvpoKWbecMk,1554
107
107
  mplang/v2/dialects/__init__.py,sha256=hvzAvz6_brfFyDGgKknoPdgh5EY033YNYwotuJK_zoA,1493
108
108
  mplang/v2/dialects/bfv.py,sha256=XrE3FX9DHWqNzUVzY0tuwPvNVVRZYpD51JZIZF-q-l4,22350
109
- mplang/v2/dialects/crypto.py,sha256=DzRpHAJ9T42KH5GqA6IkKD2KrzLkyxPHNUYUXoRhbRU,15612
109
+ mplang/v2/dialects/crypto.py,sha256=rgJh_VO971MR-0D5jryz8osItF0Q4aGYhlEYjV_hBEE,17503
110
110
  mplang/v2/dialects/dtypes.py,sha256=bGM3Jna3BnvE4MPOurWrEmQegGPxd26z1HIWox1rj0U,12104
111
111
  mplang/v2/dialects/field.py,sha256=6nBJg08k5WHb2o5msr8XAnxMQLpoTej55VQ7iSRnC4o,6380
112
112
  mplang/v2/dialects/func.py,sha256=UlaMof4NEG28VOtiRL7zBRYgFbIX74YTqqgvozbils0,4375
@@ -116,7 +116,7 @@ mplang/v2/dialects/spu.py,sha256=3JO-D394TKNH2VdFDRp5ohmG0uOcOHEs_ivFHbMZIgA,113
116
116
  mplang/v2/dialects/store.py,sha256=RqUBzMAgtEMBmdT8axV5lVCv1hp5w0ZZM0Tu4iOZt-c,2114
117
117
  mplang/v2/dialects/table.py,sha256=ax9Yjvcb8jJ8fqNJodMQ_mrS8tf-xECHQFvUKUWPp70,12714
118
118
  mplang/v2/dialects/tee.py,sha256=oj_G8ebhtuz9_HarK8rKoaJNJ9ZkRbqcIxhp3m0xsjQ,10129
119
- mplang/v2/dialects/tensor.py,sha256=FxPKsiNi2vFb-R2hqRgR7zYYO5LdRu_rdDHfjE3_2Lw,40003
119
+ mplang/v2/dialects/tensor.py,sha256=VVIlWtSHpeYFwGuKw7yWxwMQ_a35XJ-2ardeBed2HL8,39900
120
120
  mplang/v2/edsl/README.md,sha256=viflvdRojOa6Xk_UMRPqpuPGXcPGmdlv2-XR6LO7B58,7592
121
121
  mplang/v2/edsl/__init__.py,sha256=YqmtrJXD1NLKS-_Ofnxtiv77muokTZnrAiV7dXUZVyo,2607
122
122
  mplang/v2/edsl/context.py,sha256=0RgQAt7cbPudt9kyBb7wjZ31HzGMnq81Ah5sgs_qU2U,10093
@@ -170,8 +170,8 @@ mplang/v2/runtime/dialect_state.py,sha256=HxO1i4kSOujS2tQzAF9-WmI3nChSaGgupf2_07
170
170
  mplang/v2/runtime/interpreter.py,sha256=UzrM5oepka6H0YKRZncNXhsuwKVm4pliG5J92fFRZMI,32300
171
171
  mplang/v2/runtime/object_store.py,sha256=yT6jtKG2GUEJVmpq3gnQ8mCMvUFYzgBciC5A-J5KRdk,5998
172
172
  mplang/v2/runtime/value.py,sha256=CMOxElJP78v7pjasPhEpbxWbSgB2KsLbpPmzz0mQX0E,4317
173
- mplang_nightly-0.1.dev261.dist-info/METADATA,sha256=EkSyGD2BFHVs3xgCBWs-acFBbRiFJZWUsM0doPIDWmg,16768
174
- mplang_nightly-0.1.dev261.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
175
- mplang_nightly-0.1.dev261.dist-info/entry_points.txt,sha256=mG1oJT-GAjQR834a62_QIWb7litzWPPyVnwFqm-rWuY,55
176
- mplang_nightly-0.1.dev261.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
177
- mplang_nightly-0.1.dev261.dist-info/RECORD,,
173
+ mplang_nightly-0.1.dev263.dist-info/METADATA,sha256=8dpzKpue2cMj5yUJ7WMNf6NnUkUSiPFVAQ1k3Sjhj2g,16768
174
+ mplang_nightly-0.1.dev263.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
175
+ mplang_nightly-0.1.dev263.dist-info/entry_points.txt,sha256=mG1oJT-GAjQR834a62_QIWb7litzWPPyVnwFqm-rWuY,55
176
+ mplang_nightly-0.1.dev263.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
177
+ mplang_nightly-0.1.dev263.dist-info/RECORD,,