コード例 #1
0
ファイル: aes_ecb_dec.py プロジェクト: hbhbts/pyvpi_example
def aes_ecb_dec():
    """
    ECB EXAMPLE:
    -------------
    NIST Special Publication 800-38A http://cryptome.org/bcm/sp800-38a.htm#F
    >>> decipher = AES.new('2b7e151628aed2a6abf7158809cf4f3c'.decode('hex'))
    >>> decipher.decrypt(crypted).encode('hex')
    '6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51'
    """

    dec = pyvpi.handleByName("top.u_pyAESECBdec.dec")
    key = pyvpi.handleByName("top.u_pyAESECBdec.key")
    text = pyvpi.handleByName("top.u_pyAESECBdec.text")

    # if val > 32 use HexStr as string type
    val_key  = pyvpi.Value(cons.vpiHexStrVal)
    val_dec  = pyvpi.Value(cons.vpiHexStrVal)
    val_text = pyvpi.Value(cons.vpiHexStrVal)

    pyvpi.getValue(text,val_text)
    pyvpi.getValue(key, val_key)
    pyvpi.getValue(dec, val_dec)

    try:
        decipher = AES.new(str(val_key.value).decode('hex'))
        decrypted = decipher.decrypt(str(val_dec.value).decode('hex'))
        val_text.value = str(decrypted.encode('hex'))
        pyvpi.putValue(text, val_text)
        pyvpi.printf("py key:{} + dec:{} = text:{}\n".format(val_key.value, val_dec.value, val_text.value))
    except:
        print traceback.print_exc()
        # skip if value is unknown
        pass
コード例 #2
0
def aes_ecb_enc():
    """
    >>> cipher = AES.new('2b7e151628aed2a6abf7158809cf4f3c'.decode('hex'))
    >>> crypted = cipher.encrypt('6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51'.decode('hex'))
    >>> crypted.encode('hex')
    '3ad77bb40d7a3660a89ecaf32466ef97f5d3d58503b9699de785895a96fdbaaf'
    """

    text = pyvpi.handleByName("top.u_pyAESECBenc.text")
    key = pyvpi.handleByName("top.u_pyAESECBenc.key")
    enc = pyvpi.handleByName("top.u_pyAESECBenc.enc")

    # if val > 32 use HexStr as string type
    val_text = pyvpi.Value(cons.vpiHexStrVal)
    val_key = pyvpi.Value(cons.vpiHexStrVal)
    val_enc = pyvpi.Value(cons.vpiHexStrVal)

    pyvpi.getValue(text, val_text)
    pyvpi.getValue(key, val_key)
    pyvpi.getValue(enc, val_enc)

    try:
        cipher = AES.new(bytes.fromhex(val_key.value))
        crypted = cipher.encrypt(bytes.fromhex(val_text.value))
        val_enc.value = crypted.hex()
        pyvpi.putValue(enc, val_enc)
        pyvpi.printf("py key:{} + text:{} = enc:{}\n".format(
            val_key.value, val_text.value, val_enc.value))
    except:
        #        print(traceback.print_exc())
        # skip if value is unknown
        pass
コード例 #3
0
def test():
    """
    c = a+b;
    """

    a = pyvpi.handleByName("top.u_pyadaptor.a")
    b = pyvpi.handleByName("top.u_pyadaptor.b")
    c = pyvpi.handleByName("top.u_pyadaptor.c")
    p = pyvpi.handleByName("top.p")
    s = pyvpi.getStr(cons.vpiName, p)
    pyvpi.printf('p is {}\n'.format(s))
    st = pyvpi.getStr(cons.vpiType, p)
    pyvpi.printf('p type = {}\n'.format(st))

    it = pyvpi.iterate(cons.vpiMember, p)
    xt = pyvpi.scan(it)
    while (xt):
        st = pyvpi.getStr(cons.vpiFullName, xt)
        pyvpi.printf('P Member name = {} \n'.format(st))
        xt = pyvpi.scan(it)

    ph = pyvpi.handle(cons.vpiTypespec, p)
    p_name = pyvpi.getStr(cons.vpiName, ph)
    pyvpi.printf('p type name = {}\n'.format(p_name))

    val_a = pyvpi.Value(cons.vpiIntVal)
    val_b = pyvpi.Value(cons.vpiIntVal)
    val_c = pyvpi.Value(cons.vpiIntVal)

    pyvpi.getValue(a, val_a)
    pyvpi.getValue(b, val_b)
    pyvpi.getValue(c, val_c)

    try:
        val_c.value = val_a.value + val_b.value
        pyvpi.putValue(c, val_c)
        pyvpi.printf("py a:{} + b:{} = c:{}\n".format(val_a.value, val_b.value,
                                                      val_c.value))
    except:
        # skip if value is unknown
        pass
コード例 #4
0
ファイル: hello.py プロジェクト: PDFxy/my_pyvpi
def test():
    """
    c = a+b;
    """
    handle_a = pyvpi.handleByName("top.a")
    val_a = pyvpi.Value(cons.vpiIntVal)
    val_a.value = 5
    pyvpi.putValue(handle_a, val_a)
    time = pyvpi.Time()

    pyvpi.getTime(time)
    print('py: hello world at %d'%time.time)
コード例 #5
0
ファイル: test.py プロジェクト: burt0927/pyvpi
def test_pyeda():
    #print "???"
    pyvpi.printf("1\n")
    pyvpi.handleByName("test")
    pyvpi.printf("2\n")
    a = pyvpi.handleByName("o")
    pyvpi.printf("3\n")
    pyvpi.printf(
        "module name : %s\n" %
        pyvpi.getStr(cons.vpiFullName, pyvpi.handle(cons.vpiModule, a)))
    pyvpi.printf("4\n")
    val = pyvpi.Value(cons.vpiVectorVal)
    vec = pyvpi.Vector(9, [(0, 0)])
    val.value = vec
    #pyvpi.putValue(a,val)
    pyvpi.printf("%s %s\n" % (val.value.vec, val.value.size))
コード例 #6
0
 def __init__(self, s):
     self._handle = pyvpi.handleByName(s)
     self._type = pyvpi.get(cons.vpiType, self._handle)
     if self._type in INT_VAL:
         self._format = cons.vpiIntVal
         self._f = int
     elif self._type in REAL_VAL:
         self._format = cons.vpiRealVal
         self._f = float
     elif self._type in STR_VAL:
         self._format = cons.vpiStringVal
         self._f = str
     else:
         self._format = cons.vpiIntVal
         self._f = int
     self._value = pyvpi.Value(self._format)
     self._signed = pyvpi.get(cons.vpiSigned, self._handle)
     self._size = pyvpi.get(cons.vpiSize, self._handle)
     self.forced = 0
コード例 #7
0
def test():
    """
    c = a+b;
    """
    time = pyvpi.Time()
    pyvpi.getTime(time)
    pyvpi.printf('py: hello world at %d\n' % time.time)

    handle_a = pyvpi.handleByName("top.a")
    val_a = pyvpi.Value(cons.vpiIntVal)

    pyvpi.getValue(handle_a, val_a)
    print(val_a.format)
    try:
        val_a.value += 1
        pyvpi.putValue(handle_a, val_a)
        print('py:      a = %d' % val_a.value)
    except:
        #
        pass
コード例 #8
0
ファイル: test.py プロジェクト: burt0927/pyvpi
def test_normal():
    """
    """
    global call
    pyvpi.printf("error start!\n")
    cb = pyvpi.CbData(cons.cbValueChange,
                      trgobj=pyvpi.handleByName("test.o", 0),
                      value=pyvpi.Value(cons.vpiBinStrVal))
    cb.user_data = 1

    def callback(arg):
        pyvpi.printf("%s : " % arg.time.low)
        pyvpi.printf("%s : " % arg.value.value)
        pyvpi.printf("%s\n" % "callback is run...")
        if cb.user_data == 3:
            pyvpi.removeCb(arg)
        cb.user_data += 1

    cb.callback = callback
    pyvpi.registerCb(cb)
コード例 #9
0
ファイル: 2.py プロジェクト: burt0927/pyvpi
#! python
import pyvpi
import pyvpi_cons as cons

pyvpi.setDebugLevel(30)
a = pyvpi.handleByName("test.a")
b = pyvpi.handleByName("test.b")
o = pyvpi.handleByName("test.o")
val_a = pyvpi.Value(cons.vpiVectorVal)
val_b = pyvpi.Value(cons.vpiVectorVal)
val_o = pyvpi.Value(cons.vpiVectorVal)
pyvpi.getValue(a, val_a)
pyvpi.getValue(b, val_b)
pyvpi.getValue(o, val_o)
pyvpi.printf("a{} + b{} = o{}\n".format(val_a.value.vec, val_b.value.vec,
                                        val_o.value.vec))
pyvpi.putValue(b, val_o)
コード例 #10
0
            # print(n)
            # Rega.value = n
            # print('Ctime2=%d'%Simtime.value)
            # Rega.value= Rega.value+1
            if(n%100==0):
                print_mem()
            #     print(sys.getrefcount(Rega))
            #     # print(sys.getrefcount(func))           
    except Exception as e:
        RT.append(e)
        print(RT)
    print("TASK DONE\n")


a = pyvpi.handleByName('top.a')
x = pyvpi.Value(cons.vpiIntVal)
y = pyvpi.Value(cons.vpiIntVal)

async def task2():
    try:
        n = 0
        k = 0
        dd = Timer(1,'us')
        # for _ in range(1000):
        while(1):
            # print('T2time1=%d'%Simtime.value)
            await Timer(1.0,'us')
            # await RWSynch(0)
            # print("HAHA")
            # Simtime.value
            # time.sleep(0.001)
コード例 #11
0
#! python
import pyvpi
import pyvpi_cons as cons
import random
import unittest
import sys
import socket
import select

host = "localhost"
port = 9999

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
trgobj=pyvpi.handleByName("test.clk",0)
cb = pyvpi.CbData(trgobj=trgobj)
val = pyvpi.Value()
cb.reason = cons.cbValueChange
cb.value  = val
cb.user_data = [s,0]
def callback(arg) :
    cb.user_data[0].send("%s\n" % cb.user_data[1])
    infds,outfds,errfds = select.select([cb.user_data[0],],[],[],0)
    if len(infds) > 0 :
        buf = cb.user_data[0].recv(8196)
        print buf
    cb.user_data[1] += 1
cb.callback = callback
cb_h = pyvpi.registerCb(cb)
コード例 #12
0
 def format(self, format):
     self._format = format
     self._value = pyvpi.Value(format)