Skip to content

Error in Questa simulator when importing AES from Crypto.Cipher #19

Open
@yuzhang92

Description

I saw a similar issue w.r.t "Getting an error in Questa simulator when importing PyCrypto library from Python #16"

The python I used is python 3.6.5 and i have installed pycryptodome.

I am using linux platform and followed the setup, but it seems importing AES from Crypto.Cipher gives me errors when running it with questasim (ver 2020.4):

# do run.do
terminate called after throwing an instance of 'pybind11::error_already_set'
what(): AttributeError: module 'Crypto' has no attribute 'Cipher'

My code looks like below:
[crypto_test.py]

from Crypto.Cipher import AES
from pysv import sv, compile_lib, generate_sv_binding, DataType

@sv(msg=DataType.String,key=DataType.String,return_type=DataType.String)
def crypto_algo(msg,key):
    import hashlib
    import hmac
    import binascii
    cipher = AES.new(key, AES.MODE_ECB)  # whenever i have this line, it gives error, which blocks me from creating any AES cipher
    key = key.encode('utf-8')
    return_data = hashlib.sha256(msg.encode('utf-8')).hexdigest()
    print("msg =")
    print(msg)
    print("key =")
    print(key)
    print("return_data =")
    print(return_data)

    return return_data

lib_path = compile_lib([crypto_algo], cwd="build")
generate_sv_binding([crypto_algo], filename="crypto_algo_pkg.sv")

[top1.sv]

module top1();
    import pysv::crypto_algo;
    int check;
    string str = "";
    initial begin
        check = 0;
        str = crypto_algo("0123456789012345","1122334455667788");
        $display("res = %s", str);
    end
endmodule

[vsim.sh]

rm -rf work
vlib work

vlog crypto_algo_pkg.sv top1.sv
vopt top1 +acc -l opt.log  -o top1_opt

vsim top1_opt -sv_lib build/libpysv -batch -do run.do

[run.do]
run -all

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions