From 3c8e801b44f819aa4c7d4573bba7adbd776f3ac5 Mon Sep 17 00:00:00 2001 From: viensea1106 Date: Mon, 14 Aug 2023 20:09:21 +0700 Subject: [PATCH] move test.py to tests --- test.py | 67 --------------------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 test.py diff --git a/test.py b/test.py deleted file mode 100644 index 23afe83..0000000 --- a/test.py +++ /dev/null @@ -1,67 +0,0 @@ -import HashTools -import hashlib - -from os import urandom -from random import randint - -def test_imple(): - algorithms = [ - "md5", "sha1", "sha224", "sha256", "sha384", "sha512" - ] - - print("> Implementation test...") - for alg in algorithms: - msg = urandom(randint(0, 1024)) - - py_hash = hashlib.new(alg) - my_hash = HashTools.new(alg) - - py_hash.update(msg) - my_hash.update(msg) - - test1 = py_hash.hexdigest() - test2 = my_hash.hexdigest() - - if test1 != test2: - print(f"[!] {alg.ljust(6)} failed the validation test!") - print(test1) - print(test2) - exit(1) - else: - print(f"[+] {alg.ljust(6)} passed the validation test!") - - print("> All test passed!!!") - -def test_attack(): - algorithms = [ - "md5", "sha1", "sha256", "sha512" - ] - - print("> Implementation test...") - for alg in algorithms: - # setup context - length = randint(0, 1024) - secret = urandom(length) # idk ¯\_(ツ)_/¯ - original_data = b"admin=False" - sig = HashTools.new(algorithm=alg, raw=secret + original_data).hexdigest() - - # attack - append_data = b"admin=True;" - magic = HashTools.new(alg) - new_data, new_sig = magic.extension( - secret_length=length, original_data=original_data, - append_data=append_data, signature=sig - ) - - if new_sig != HashTools.new(algorithm=alg, raw=secret + new_data).hexdigest(): - print(f"[!] Our attack didn't work with {alg.ljust(6)}") - exit(1) - else: - print(f"[+] {alg.ljust(6)} passed") - - print("> All test passed!!!") - -if __name__ == "__main__": - test_imple() - print("="*100) - test_attack() \ No newline at end of file