just slight update

This commit is contained in:
2024-12-01 17:29:14 +09:00
parent cd26dd8c88
commit 0d6eaf273d
2 changed files with 87 additions and 8 deletions

View File

@ -1,8 +1,9 @@
import random
import binascii
import base64
from Crypto.Cipher import AES
from Crypto.Hash import CMAC, HMAC, SHA256
# Crypto.Hash and hmac modules are forbidden so needs to replace them
KEY = b'1337133713371337'
@ -16,22 +17,21 @@ def calc_cbc_mac(message: bytes, iv: bytes, key: bytes) -> bytes:
cipher = AES.new(key, AES.MODE_CBC, iv)
message = pkcs7(message)
last_block = cipher.encrypt(message)[-16:]
last_block = base64.b64encode(last_block)
return last_block
def calc_hmac(message: bytes, key: bytes) -> bytes:
# Create HMAC object with the key and message using SHA-256
hmac = HMAC.new(KEY, msg=message, digestmod=SHA256)
# Calculate the HMAC
mac = hmac.hexdigest()
return mac
hmac = base64.b64encode(hmac.digest())
return hmac
def calc_cmac(message: bytes, key: bytes) -> bytes:
c = CMAC.new(key, ciphermod=AES)
c.update(message)
return c.digest()
cmac = base64.b64encode(c.digest())
return cmac
def check_challenge(challenge: bytes):
@ -52,4 +52,4 @@ def main():
if __name__ == "__main__":
main()
main()