Exemple #1
0
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
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(str(val_key.value).decode('hex'))
        crypted = cipher.encrypt(str(val_text.value).decode('hex'))
        val_enc.value = str(crypted.encode('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
Exemple #3
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
Exemple #4
0
def test_iterate():
    m = pyvpi.handleByName("test")
    iter = pyvpi.iterate(cons.vpiReg,m)
    reg = pyvpi.scan(iter)
    while(reg) :
        pyvpi.printf("reg : %s\n" % pyvpi.getStr(cons.vpiName,reg))
        reg = pyvpi.scan(iter)
Exemple #5
0
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))
Exemple #6
0
def test_iterate():
    m = pyvpi.handleByName("test")
    iter = pyvpi.iterate(cons.vpiReg, m)
    reg = pyvpi.scan(iter)
    while (reg):
        pyvpi.printf("reg : %s\n" % pyvpi.getStr(cons.vpiName, reg))
        reg = pyvpi.scan(iter)
Exemple #7
0
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))
Exemple #8
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
Exemple #9
0
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)
Exemple #10
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")

    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
Exemple #11
0
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)
Exemple #12
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
Exemple #13
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
Exemple #14
0
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)
Exemple #15
0
from pyvpi import CbData,registerCb,removeCb,handleByName,Value,getValue,printf
import pyvpi_cons as cons
import traceback

c = handleByName("top.c")
a = handleByName("top.a")
b = handleByName("top.b")
def callback(self) :
    try :
        getValue(self.a,self.av)
        getValue(self.b,self.bv)
        printf("%s : %s(a) + %s(b) = %s(o)\n" % (self.time.time,
            self.av.value,
            self.bv.value,
            self.value.value.vec))
    except Exception as e :
        printf("%s\n%s\n" % (e,traceback.print_exc()))
        
cb = CbData(trgobj = c,callback = callback, value = Value(cons.vpiVectorVal))
cb.a = a
cb.b = b
cb.av = Value()
cb.bv = Value()
printf("%s\n"  % (hasattr(cb,"a")))
registerCb(cb)
Exemple #16
0
#! python
from pyvpi import CbData, registerCb, removeCb, handleByName, Value, getValue, printf
import pyvpi_cons as cons
import traceback

o = handleByName("test.o")
a = handleByName("test.a")
b = handleByName("test.b")


def callback(self):
    try:
        getValue(self.a, self.av)
        getValue(self.b, self.bv)
        printf("%s : %s(a) + %s(b) = %s(o)\n" %
               (self.time.time, self.av.value, self.bv.value,
                self.value.value.vec))
    except Exception, e:
        printf("%s\n%s\n" % (e, traceback.print_exc()))


cb = CbData(trgobj=o, callback=callback, value=Value(cons.vpiVectorVal))
cb.a = a
cb.b = b
cb.av = Value()
cb.bv = Value()
printf("%s\n" % (hasattr(cb, "a")))
registerCb(cb)
Exemple #17
0
            n+=1
            # 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
Exemple #18
0
#! python
import pyvpi
import pyvpi_cons as cons


def getAllHandles(handle, type):
    ans = []
    iter = pyvpi.iterate(type, handle)
    while True:
        h = pyvpi.scan(iter)
        if not h:
            break
        ans.append(h)
    return ans


mod = pyvpi.handleByName("test")

pyvpi.printf("All regs are blew here :\n")
for reg in getAllHandles(mod, cons.vpiReg):
    pyvpi.printf("%s\n" % (pyvpi.getStr(cons.vpiName, reg)))
pyvpi.printf("All nets are blew here :\n")
for net in getAllHandles(mod, cons.vpiNet):
    pyvpi.printf("%s\n" % (pyvpi.getStr(cons.vpiFullName, net)))

time = pyvpi.Time()
pyvpi.getTime(time)
pyvpi.printf("%s\n" % (time.low))
Exemple #19
0
def test_index():
    o = pyvpi.handleByName("test.o")
    o_0 = pyvpi.handleByIndex(o, 0)
    pyvpi.printf("index : %s\n" % o_0)
    o1 = pyvpi.handleByName("test.o[0]")
    pyvpi.printf("index : %s\n" % o1)
Exemple #20
0
def test_index():
    o = pyvpi.handleByName("test.o")
    o_0 = pyvpi.handleByIndex(o,0)
    pyvpi.printf("index : %s\n" % o_0)
    o1 = pyvpi.handleByName("test.o[0]")
    pyvpi.printf("index : %s\n" % o1)
Exemple #21
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)
Exemple #22
0
import pyvpi
import pyvpi_cons as cons
def getAllHandles(handle,type) :
    ans = []
    iter = pyvpi.iterate(type,handle)
    while True :
        h = pyvpi.scan(iter)
        if not h :
            break
        ans.append(h)
    return ans
    
mod = pyvpi.handleByName("top")

pyvpi.printf("All regs are blew here :\n")    
for reg in getAllHandles(mod,cons.vpiReg) :
    pyvpi.printf("%s\n" % (pyvpi.getStr(cons.vpiName,reg)))
pyvpi.printf("All nets are blew here :\n")    
for net in getAllHandles(mod,cons.vpiNet) :
    pyvpi.printf("%s\n" % (pyvpi.getStr(cons.vpiFullName,net)))

time = pyvpi.Time()
pyvpi.getTime(time)
pyvpi.printf("%s\n" %(time.low))
Exemple #23
0
#! 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)
Exemple #24
0
#! python
import pyvpi
import pyvpi_cons as cons
def getAllHandles(handle,type) :
    ans = []
    iter = pyvpi.iterate(type,handle)
    while True :
        h = pyvpi.scan(iter)
        if not h :
            break
        ans.append(h)
    return ans
    
mod = pyvpi.handleByName("test")

pyvpi.printf("All regs are blew here :\n")    
for reg in getAllHandles(mod,cons.vpiReg) :
    pyvpi.printf("%s\n" % (pyvpi.getStr(cons.vpiName,reg)))
pyvpi.printf("All nets are blew here :\n")    
for net in getAllHandles(mod,cons.vpiNet) :
    pyvpi.printf("%s\n" % (pyvpi.getStr(cons.vpiFullName,net)))

time = pyvpi.Time()
pyvpi.getTime(time)
pyvpi.printf("%s\n" %(time.low))
Exemple #25
0
#! python
from pyvpi import CbData,registerCb,removeCb,handleByName,Value,getValue,printf
import pyvpi_cons as cons
import traceback

o = handleByName("test.o")
a = handleByName("test.a")
b = handleByName("test.b")
def callback(self) :
    try :
        getValue(self.a,self.av)
        getValue(self.b,self.bv)
        printf("%s : %s(a) + %s(b) = %s(o)\n" % (self.time.time,
            self.av.value,
            self.bv.value,
            self.value.value.vec))
    except Exception,e :
        printf("%s\n%s\n" % (e,traceback.print_exc()))
        
cb = CbData(trgobj = o,callback = callback, value = Value(cons.vpiVectorVal))
cb.a = a
cb.b = b
cb.av = Value()
cb.bv = Value()
printf("%s\n"  % (hasattr(cb,"a")))
registerCb(cb)

Exemple #26
0
#! 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()
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,val_b.value.vec,val_o.value.vec))