Use cryptg when available

This commit is contained in:
Lonami Exo 2023-09-17 22:48:17 +02:00
parent 495de58925
commit 6f6618f251
2 changed files with 15 additions and 0 deletions

View File

@ -51,3 +51,16 @@ def ige_decrypt(ciphertext: bytes, key: bytes, iv: bytes) -> bytes:
plaintext += plaintext_block
return bytes(plaintext)
try:
import cryptg
ige_encrypt = lambda t, k, i: cryptg.encrypt_ige(
bytes(t) if not isinstance(t, bytes) else t, k, i
)
ige_decrypt = lambda t, k, i: cryptg.decrypt_ige(
bytes(t) if not isinstance(t, bytes) else t, k, i
)
except ImportError:
pass

2
stubs/cryptg.pyi Normal file
View File

@ -0,0 +1,2 @@
def encrypt_ige(plaintext: bytes, key: bytes, iv: bytes, /) -> bytes: ...
def decrypt_ige(ciphertext: bytes, key: bytes, iv: bytes, /) -> bytes: ...