コード例 #1
0
def decrypt_data(data):
    if data is None:
        return None

    key = derive_key(128, data[:0x20])[:0x20]
    iv = derive_key(128, data[0x10:0x30])[:0x10]
    cipher = AES.new(key, AES.MODE_CBC, iv)

    def pad(s):
        return s + (-len(s) % 16) * bytes([-len(s) % 16])

    data = pad(data[0x30:])
    data = cipher.decrypt(data)

    if len(data) >= 8:
        size, _ = struct.unpack_from('=II', data)
        signature = data[size+0x08:size+0x68]
        data = data[:size+0x08]
        try:
            verifier.verify(SHA384.new(data), signature)
        except ValueError:
            log.warning('[!] WARNING: Bad public key signature (incorrect bot key?)')
        data = data[0x08:]

    return data
コード例 #2
0
def rsa_verify(pubkey, received_message, signature):
    h = SHA384.new(received_message)
    verifier = pss.new(pubkey)
    try:
        verifier.verify(h, base64.b64decode(signature))
        return True
    except ValueError:
        return False
コード例 #3
0
def do_hmac(key, value):
    value = value.encode('utf-8')
    # Let's only encode if its not a byte
    try:
        key = key.encode('utf-8')
    except AttributeError:
        pass

    h = HMAC.new(key, value, digestmod=SHA384.new())
    return h.hexdigest()
コード例 #4
0
def pycrypto():
    import Crypto
    from Crypto.Hash import MD2
    from Crypto.Hash import MD4
    from Crypto.Hash import MD5
    from Crypto.Hash import SHA
    from Crypto.Hash import SHA224
    from Crypto.Hash import SHA256
    from Crypto.Hash import SHA384
    from Crypto.Hash import SHA512
    from Crypto.Hash import HMAC

    Crypto.Hash.MD2.new()  # Noncompliant
    MD2.new()  # Noncompliant
    MD4.new()  # Noncompliant
    MD5.new()  # Noncompliant
    SHA.new()  # Noncompliant
    SHA224.new()  # Noncompliant
    SHA256.new()  # Noncompliant
    SHA384.new()  # Noncompliant
    SHA512.new()  # Noncompliant
    HMAC.new(b"\x00")  # Noncompliant
コード例 #5
0
def cryptodome():
    import Cryptodome
    from Cryptodome.Hash import MD2
    from Cryptodome.Hash import MD4
    from Cryptodome.Hash import MD5
    from Cryptodome.Hash import SHA1
    from Cryptodome.Hash import SHA224
    from Cryptodome.Hash import SHA256
    from Cryptodome.Hash import SHA384
    from Cryptodome.Hash import SHA512
    from Cryptodome.Hash import HMAC

    Cryptodome.Hash.MD2.new()  # Noncompliant
    MD2.new()  # Noncompliant
    MD4.new()  # Noncompliant
    MD5.new()  # Noncompliant
    SHA1.new()  # Noncompliant
    SHA224.new()  # Noncompliant
    SHA256.new()  # OK
    SHA384.new()  # OK
    SHA512.new()  # OK
    HMAC.new(b"\x00")  # OK
コード例 #6
0
def verify(message, signature, pub_key, hash="SHA256"):
    signer = PKCS1_v1_5.new(pub_key)
    if (hash == "SHA512"):
        digest = SHA512.new()
    elif (hash == "SHA384"):
        digest = SHA384.new()
    elif (hash == "SHA256"):
        digest = SHA256.new()
    elif (hash == "SHA1"):
        digest = SHA.new()
    else:
        digest = MD5.new()
    digest.update(message)
    return signer.verify(digest, signature)
コード例 #7
0
def sign(message, priv_key, hash="SHA256"):
    priv_key = importKey(priv_key)
    signer = PKCS1_v1_5.new(priv_key)

    if (hash == "SHA512"):
        digest = SHA512.new()
    elif (hash == "SHA384"):
        digest = SHA384.new()
    elif (hash == "SHA256"):
        digest = SHA256.new()
    elif (hash == "SHA1"):
        digest = SHA.new()
    else:
        digest = MD5.new()
    digest.update(message)
    return signer.sign(digest)
コード例 #8
0
ファイル: rsa.py プロジェクト: utkuarslan5/cloud_IT_project
def sign(message, priv_key, hashAlg="SHA-256"):
    global hash_type
    hash_type = hashAlg
    signer = PKCS1_v1_5.new(priv_key)
    if (hash_type == "SHA-512"):
        digest = SHA512.new()
    elif (hash_type == "SHA-384"):
        digest = SHA384.new()
    elif (hash_type == "SHA-256"):
        digest = SHA256.new()
    elif (hash_type == "SHA-1"):
        digest = SHA.new()
    else:
        digest = MD5.new()
    digest.update(message)
    return signer.sign(digest)
コード例 #9
0
def sha2(value):
    return SHA384.new(data=value).hexdigest()
コード例 #10
0
def rsa_sign(key, message):
    h = SHA384.new(message)
    signature = pss.new(key).sign(h)
    return base64.b64encode(signature)
コード例 #11
0
ファイル: crypto.py プロジェクト: henn/python-keylime
def do_hmac(key, value):
    h = HMAC.new(key, value, digestmod=SHA384.new())
    return h.hexdigest()
コード例 #12
0
            if len(listaMsg) < 50:
                mensaje = linea.lstrip("Msg = ")
                listaMsg.append(mensaje.rstrip("\n"))
            else:
                break
    archivo.close()
    return listaMsg


#--------------------------- SHA-2 384 -----------------------------------------
#HASH
#print("\n *****************SHA2-384********************* ")
datos = leeArchivoSHA("SHA384ShortMsg.rsp") + leeArchivoSHA(
    "SHA384LongMsg.rsp")
listaTmpoSHA384 = []  #Lista de tiempos SHA-2 384
h = SHA384.new()
for i in range(0, 50):
    for dato in datos:
        timeI = time()
        h.update(bytearray.fromhex(dato))
        timeF = time()
        listaTmpoSHA384.append(timeF - timeI)
        #print(h.hexdigest())

#--------------------------- SHA-2 512 -----------------------------------------
#HASH
#print("\n *****************SHA2-512********************* ")
datos = leeArchivoSHA("SHA512ShortMsg.rsp") + leeArchivoSHA(
    "SHA512LongMsg.rsp")
listaTmpoSHA512 = []  #Lista de tiempos SHA-2 512
h = SHA512.new()