mplang-nightly 0.1.dev261__py3-none-any.whl → 0.1.dev262__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.
- mplang/v2/backends/crypto_impl.py +29 -0
- mplang/v2/dialects/crypto.py +71 -8
- {mplang_nightly-0.1.dev261.dist-info → mplang_nightly-0.1.dev262.dist-info}/METADATA +1 -1
- {mplang_nightly-0.1.dev261.dist-info → mplang_nightly-0.1.dev262.dist-info}/RECORD +7 -7
- {mplang_nightly-0.1.dev261.dist-info → mplang_nightly-0.1.dev262.dist-info}/WHEEL +0 -0
- {mplang_nightly-0.1.dev261.dist-info → mplang_nightly-0.1.dev262.dist-info}/entry_points.txt +0 -0
- {mplang_nightly-0.1.dev261.dist-info → mplang_nightly-0.1.dev262.dist-info}/licenses/LICENSE +0 -0
|
@@ -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
|
mplang/v2/dialects/crypto.py
CHANGED
|
@@ -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(
|
|
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,
|
|
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(
|
|
371
|
-
|
|
372
|
-
|
|
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,
|
|
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
|
-
|
|
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:
|
|
@@ -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
|
|
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
|
|
@@ -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=
|
|
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
|
|
@@ -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.
|
|
174
|
-
mplang_nightly-0.1.
|
|
175
|
-
mplang_nightly-0.1.
|
|
176
|
-
mplang_nightly-0.1.
|
|
177
|
-
mplang_nightly-0.1.
|
|
173
|
+
mplang_nightly-0.1.dev262.dist-info/METADATA,sha256=g46JAxaR3RENuq23Ikk_tZXex4ziETfincNrzZBe1sE,16768
|
|
174
|
+
mplang_nightly-0.1.dev262.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
175
|
+
mplang_nightly-0.1.dev262.dist-info/entry_points.txt,sha256=mG1oJT-GAjQR834a62_QIWb7litzWPPyVnwFqm-rWuY,55
|
|
176
|
+
mplang_nightly-0.1.dev262.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
177
|
+
mplang_nightly-0.1.dev262.dist-info/RECORD,,
|
|
File without changes
|
{mplang_nightly-0.1.dev261.dist-info → mplang_nightly-0.1.dev262.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{mplang_nightly-0.1.dev261.dist-info → mplang_nightly-0.1.dev262.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|