oaep finish

This commit is contained in:
Christoph J. Scherr 2023-06-02 11:14:46 +02:00
parent 396506aa7a
commit d087abd7e6
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
3 changed files with 33 additions and 2 deletions

View File

@ -0,0 +1,29 @@
"""
Common tools that may be used by many
@author: Christoph J. Scherr <software@cscherr.de>
@license: MIT
@source: https://git.cscherr.de/PlexSheep/plexcryptool/src/branch/master/plexcryptool/trash-hash.py
"""
from math import floor
def byte_xor(ba0: bytearray, ba1: bytearray) -> bytearray:
"""
helper function for bytewise xor
"""
ba2: bytearray = bytearray(0)
for (b0, b1) in zip(ba0, ba1):
ba2.append((b0 ^ b1))
#print("xored:\n%s" % ba2.hex())
return ba2
def calc_byte_len(n: int) -> int:
"""
helper function to calculate the length in bytes
"""
len = n.bit_length() / 8
if len > floor(len):
return 1 + floor(len)
else:
return floor(len)

View File

@ -0,0 +1 @@
0976f89569d94414fed4f7714cd85c840dbf338781926f5d1f6284688c97eaeef7f42b3d844c70468cfb960092235855da5d5c66107dfee4204c1a78512ee00306da957a856a085affe40b2ab32fc90a8c8e059feea9a83e753618aeae04884aa1658afe59a69c30ec5c014a5da06ff484143ca1ea884b44a3f92d063db8503f

View File

@ -79,7 +79,7 @@ def mgf1(seed: bytearray, length: int, hash_func=hashlib.sha256) -> bytearray:
# 4.Output the leading l octets of T as the octet string mask. # 4.Output the leading l octets of T as the octet string mask.
return bytearray(T[:length]) return bytearray(T[:length])
def byte_xor(ba0: bytearray, ba1: bytearray): def byte_xor(ba0: bytearray, ba1: bytearray) -> bytearray:
""" """
helper function for bytewise xor helper function for bytewise xor
""" """
@ -203,7 +203,8 @@ def main():
else: else:
ha = bytearray(0) ha = bytearray(0)
if args.message: if args.message:
m = bytearray.fromhex(args.message) m = bytearray(str.encode(args.message))
print("msg: %s" % m.hex())
else: else:
m = bytearray.fromhex("466f6f62617220313233343536373839") m = bytearray.fromhex("466f6f62617220313233343536373839")
if args.seed: if args.seed: