mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2026-08-29 13:18:14 +00:00
Completely refactored unit tests, removed unused code
This commit is contained in:
@@ -35,7 +35,7 @@ class AES:
|
||||
@staticmethod
|
||||
def encrypt_ige(plain_text, key, iv):
|
||||
"""Encrypts the given text in 16-bytes blocks by using the given key and 32-bytes initialization vector"""
|
||||
# TODO: Random padding
|
||||
# TODO: Random padding?
|
||||
if len(plain_text) % 16 != 0: # Add padding if and only if it's not evenly divisible by 16 already
|
||||
padding = bytes(16 - len(plain_text) % 16)
|
||||
plain_text += padding
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
# This file is based on TLSharp
|
||||
# https://github.com/sochix/TLSharp/blob/master/TLSharp.Core/MTProto/Crypto/AuthKey.cs
|
||||
import utils
|
||||
from errors import *
|
||||
from utils import BinaryWriter, BinaryReader
|
||||
import utils
|
||||
|
||||
|
||||
class AuthKey:
|
||||
def __init__(self, gab=None, data=None):
|
||||
if gab:
|
||||
self.key = utils.get_byte_array(gab, signed=False)
|
||||
elif data:
|
||||
self.key = data
|
||||
else:
|
||||
raise InvalidParameterError('Either a gab integer or data bytes array must be provided')
|
||||
def __init__(self, data):
|
||||
self.key = data
|
||||
|
||||
with BinaryReader(utils.sha1(self.key)) as reader:
|
||||
self.aux_hash = reader.read_long(signed=False)
|
||||
@@ -26,5 +21,5 @@ class AuthKey:
|
||||
writer.write_byte(number)
|
||||
writer.write_long(self.aux_hash, signed=False)
|
||||
|
||||
new_nonce_hash = utils.sha1(writer.get_bytes())[4:20]
|
||||
new_nonce_hash = utils.calc_msg_key(writer.get_bytes())
|
||||
return new_nonce_hash
|
||||
|
||||
@@ -26,16 +26,13 @@ class RSAServerKey:
|
||||
if length < 235:
|
||||
writer.write(utils.generate_random_bytes(235 - length))
|
||||
|
||||
cipher_text = utils.get_byte_array(
|
||||
pow(int.from_bytes(writer.get_bytes(), byteorder='big'), self.e, self.m),
|
||||
signed=False)
|
||||
result = int.from_bytes(writer.get_bytes(), byteorder='big')
|
||||
result = pow(result, self.e, self.m)
|
||||
|
||||
if len(cipher_text) == 256:
|
||||
return cipher_text
|
||||
|
||||
else:
|
||||
padding = bytes(256 - len(cipher_text))
|
||||
return padding + cipher_text
|
||||
# If the result byte count is less than 256, since the byte order is big,
|
||||
# the non-used bytes on the left will be 0 and act as padding,
|
||||
# without need of any additional checks
|
||||
return int.to_bytes(result, length=256, byteorder='big', signed=False)
|
||||
|
||||
|
||||
class RSA:
|
||||
|
||||
Reference in New Issue
Block a user