Skip to content

Commit

Permalink
Support SHA256, SHA384 hash algorithm
Browse files Browse the repository at this point in the history
Problem: Missing SHA256, SHA384 hash algorithm so it uses SHA1 instead

Solution: Add SHA256, SHA384 hash algorithm support
  • Loading branch information
Phat Do committed Oct 7, 2021
1 parent a161b9d commit 5aa804a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions msoffcrypto/method/ecma376_agile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hmac
import io
import logging
from hashlib import sha1, sha512
from hashlib import sha1, sha256, sha384, sha512
from struct import pack, unpack

from cryptography.hazmat.backends import default_backend
Expand All @@ -13,12 +13,15 @@
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

ALGORITHM_HASH = {
"SHA1": sha1,
"SHA256": sha256,
"SHA384": sha384,
"SHA512": sha512,
}

def _get_hash_func(algorithm):
if algorithm == "SHA512":
return sha512
else:
return sha1
return ALGORITHM_HASH.get(algorithm, sha1)


def _decrypt_aes_cbc(data, key, iv):
Expand Down

0 comments on commit 5aa804a

Please sign in to comment.