Skip to content

Commit 0f35f0b

Browse files
committed
Accommodate TgCrypto
1 parent df5379b commit 0f35f0b

2 files changed

Lines changed: 26 additions & 23 deletions

File tree

pyrogram/crypto/ige.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from pyaes import AES
19+
# from pyaes import AES
20+
import tgcrypto
2021

2122
BLOCK_SIZE = 16
2223

@@ -26,11 +27,13 @@
2627
class IGE:
2728
@classmethod
2829
def encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
29-
return cls.ige(data, key, iv, True)
30+
return tgcrypto.ige_encrypt(data, key, iv)
31+
# return cls.ige(data, key, iv, True)
3032

3133
@classmethod
3234
def decrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
33-
return cls.ige(data, key, iv, False)
35+
return tgcrypto.ige_decrypt(data, key, iv)
36+
# return cls.ige(data, key, iv, False)
3437

3538
@staticmethod
3639
def xor(a: bytes, b: bytes) -> bytes:
@@ -40,22 +43,22 @@ def xor(a: bytes, b: bytes) -> bytes:
4043
"big",
4144
)
4245

43-
@classmethod
44-
def ige(cls, data: bytes, key: bytes, iv: bytes, encrypt: bool) -> bytes:
45-
cipher = AES(key)
46-
47-
iv_1 = iv[:BLOCK_SIZE]
48-
iv_2 = iv[BLOCK_SIZE:]
49-
50-
data = [data[i: i + BLOCK_SIZE] for i in range(0, len(data), BLOCK_SIZE)]
51-
52-
if encrypt:
53-
for i, chunk in enumerate(data):
54-
iv_1 = data[i] = cls.xor(cipher.encrypt(cls.xor(chunk, iv_1)), iv_2)
55-
iv_2 = chunk
56-
else:
57-
for i, chunk in enumerate(data):
58-
iv_2 = data[i] = cls.xor(cipher.decrypt(cls.xor(chunk, iv_2)), iv_1)
59-
iv_1 = chunk
60-
61-
return b"".join(data)
46+
# @classmethod
47+
# def ige(cls, data: bytes, key: bytes, iv: bytes, encrypt: bool) -> bytes:
48+
# cipher = AES(key)
49+
#
50+
# iv_1 = iv[:BLOCK_SIZE]
51+
# iv_2 = iv[BLOCK_SIZE:]
52+
#
53+
# data = [data[i: i + BLOCK_SIZE] for i in range(0, len(data), BLOCK_SIZE)]
54+
#
55+
# if encrypt:
56+
# for i, chunk in enumerate(data):
57+
# iv_1 = data[i] = cls.xor(cipher.encrypt(cls.xor(chunk, iv_1)), iv_2)
58+
# iv_2 = chunk
59+
# else:
60+
# for i, chunk in enumerate(data):
61+
# iv_2 = data[i] = cls.xor(cipher.decrypt(cls.xor(chunk, iv_2)), iv_1)
62+
# iv_1 = chunk
63+
#
64+
# return b"".join(data)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@
6767
],
6868
packages=find_packages(),
6969
zip_safe=False,
70-
install_requires=["pyaes", "pysocks"],
70+
install_requires=["pyaes", "pysocks", "tgcrypto"],
7171
include_package_data=True,
7272
)

0 commit comments

Comments
 (0)