From 3c7bb53c3ca310fc26f5bdba428c9541b4a3fdb4 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 24 Jan 2022 14:27:34 +0100 Subject: [PATCH] Use threads for factorization Closes #3162. --- telethon/_network/authenticator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/telethon/_network/authenticator.py b/telethon/_network/authenticator.py index dfd16469..2a6890d7 100644 --- a/telethon/_network/authenticator.py +++ b/telethon/_network/authenticator.py @@ -2,6 +2,8 @@ This module contains several functions that authenticate the client machine with Telegram's servers, effectively creating an authorization key. """ +import asyncio +import functools import os import time from hashlib import sha1 @@ -31,7 +33,10 @@ async def do_authentication(sender): pq = get_int(res_pq.pq) # Step 2 sending: DH Exchange - p, q = Factorization.factorize(pq) + p, q = await asyncio.get_running_loop().run_in_executor( + None, + functools.partial(Factorization.factorize, pq) + ) p, q = rsa.get_byte_array(p), rsa.get_byte_array(q) new_nonce = int.from_bytes(os.urandom(32), 'little', signed=True)