示例#1
0
    def fill(self, d):
        self._d = d
        version_d = d[0]
        self.version, idx = STN.strcalc(STN.str2int, d[0], 0)

        if self.version in [2, 3]:
            hash_len, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
            self.type, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
            self.created, idx = STN.strcalc(STN.str2int, d[idx:idx+4], idx)
            self.hashed_data = d[2:idx]
            self.keyid, idx = STN.strcalc(STN.str2hex, d[idx:idx+8], idx)
            self.alg_pubkey, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
            self.alg_hash, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
            self.hashed_subpkts = [] # dummy settings to make searches easier
            self.unhashed_subpkts = [] #

        elif 4 == self.version:
            import struct
            _type_d, idx = STN.strcalc(None, d[idx:idx+1], idx)
            self.type = STN.str2int(_type_d)
            self.alg_pubkey, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
            self.alg_hash, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
            # hashed subpackets
            subpkts_len, idx = STN.strcalc(STN.str2int, d[idx:idx+2], idx)
            self.hashed_subpkts = self.__resolve_subpkts(d[idx:idx+subpkts_len])
            # hashed data & trailer - should '>i' ever return more than 4 chars?
            hashed_data = d[0:idx+subpkts_len]
            bigend = struct.pack('>i', len(hashed_data))[-4:] 
            self.hashed_data = ''.join([hashed_data, version_d, '\xff', bigend])
            idx = idx + subpkts_len
            # unhashed subpackets
            subpkts_len, idx = STN.strcalc(STN.str2int, d[idx:idx+2], idx)
            self.unhashed_subpkts = self.__resolve_subpkts(d[idx:idx+subpkts_len])
            idx = idx + subpkts_len
            # attribute convenience
            self.keyid = self.__set_subpkt_attr(SIGSUB_SIGNERID) or ''
            self.created = self.__set_subpkt_attr(SIGSUB_CREATED) or 0

        else:
            raise PGPValueError("Unsupported signature version. Received->(%s)" % str(self.version))

        self.hash_frag, idx = STN.strcalc(None, d[idx:idx+2], idx)

        if self.alg_pubkey in [ASYM_RSA_S, ASYM_RSA_EOS]:
            self.RSA, idx = MPI.strcalc_mpi(d[idx:], idx)

        elif ASYM_DSA == self.alg_pubkey:
            self.DSA_r, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.DSA_s, idx = MPI.strcalc_mpi(d[idx:], idx)

        elif self.alg_pubkey in [ASYM_ELGAMAL_EOS]:
            self.ELGAMAL_a, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.ELGAMAL_b, idx = MPI.strcalc_mpi(d[idx:], idx)

        else:
            raise PGPValueError("Unsupported public-key algorithm (%d)." % self.alg_pubkey)
示例#2
0
    def fill(self, d):
        self._d = d
        idx = 0
        __version_d = d[idx:idx+1]
        self.version, idx = STN.strcalc(STN.str2int, __version_d, idx)

        if self.version in [2, 3, 4]:
            __created_d = d[idx:idx+4] 
            self.created, idx = STN.strcalc(STN.str2int, __created_d, idx)

            if self.version in [2, 3]:
                self.__expires_d = d[idx:idx+2]
                self.expires, idx = STN.strcalc(STN.str2int, self.__expires_d, idx)

            __alg_d = d[idx:idx+1]
            self.alg, idx = STN.strcalc(STN.str2int, __alg_d, idx)

            # resolve MPIs
            if self.alg in [ASYM_RSA_EOS, ASYM_RSA_E, ASYM_RSA_S]:
                self.RSA_n, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.RSA_e, idx = MPI.strcalc_mpi(d[idx:], idx)
                self._mpi_d = self.RSA_n._d + self.RSA_e._d
            elif ASYM_DSA == self.alg:
                self.DSA_p, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.DSA_q, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.DSA_g, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.DSA_y, idx = MPI.strcalc_mpi(d[idx:], idx)
                self._mpi_d = self.DSA_p._d + self.DSA_q._d + self.DSA_g._d + self.DSA_y._d
            elif self.alg in [ASYM_ELGAMAL_E, ASYM_ELGAMAL_EOS]:
                self.ELGAMAL_p, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.ELGAMAL_g, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.ELGAMAL_y, idx = MPI.strcalc_mpi(d[idx:], idx)
                self._mpi_d = self.ELGAMAL_p._d + self.ELGAMAL_g._d + self.ELGAMAL_y._d
            else:
                raise NotImplementedError("Unsupported key algorithm. Received alg->(%s)" % self.alg)

            # set fingerprint
            if self.version in [2, 3]:
                integer_data = self.RSA_n._int_d + self.RSA_e._int_d
                self.fingerprint = md5.new(integer_data).hexdigest().upper()
                # see fingerprint/id notes in doc/NOTES.txt
                self.id = STN.str2hex(self.RSA_n._int_d[-8:])
            elif 4 == self.version:
                f = ['\x99']
                f_data = ''.join([__version_d, __created_d, __alg_d, self._mpi_d])
                length = len(f_data)
                hi = (chr((0xffff & length) >> 8)) # high order packet length
                lo = (chr(0xff & length)) # low order packet length
                f.append(hi + lo) 
                f.append(f_data)
                self.fingerprint = sha.new(''.join(f)).hexdigest().upper()
                # see fingerprint/id notes in doc/NOTES.txt
                self.id = self.fingerprint[-16:]

        else: # unsupported packet version
            raise NotImplementedError("Unsupported key version: %s" % self.version)
        return idx
    def fill(self, d):
        self._d = d
        idx = 0
        self.version, idx = STN.strcalc(STN.str2int, d[idx:idx + 1], idx)
        self.keyid, idx = STN.strcalc(STN.str2hex, d[idx:idx + 8], idx)
        self.alg_pubkey, idx = STN.strcalc(STN.str2int, d[idx:idx + 1], idx)

        if self.alg_pubkey in [ASYM_RSA_EOS, ASYM_RSA_E, ASYM_RSA_S]:
            self.RSA_me_modn, idx = MPI.strcalc_mpi(d[idx:], idx)

        elif ASYM_ELGAMAL_E == self.alg_pubkey:
            self.ELGAMAL_gk_modp, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.ELGAMAL_myk_modp, idx = MPI.strcalc_mpi(d[idx:], idx)

        else:
            raise PGPValueError, "Unsupported public key algorithm. Received alg_pubkey->(%s)" % self.alg_pubkey
    def fill(self, d):
        self._d = d
        idx = 0
        self.version, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
        self.keyid, idx = STN.strcalc(STN.str2hex, d[idx:idx+8], idx) 
        self.alg_pubkey, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)

        if self.alg_pubkey in [ASYM_RSA_EOS, ASYM_RSA_E, ASYM_RSA_S]:
            self.RSA_me_modn, idx = MPI.strcalc_mpi(d[idx:], idx)

        elif ASYM_ELGAMAL_E == self.alg_pubkey:
            self.ELGAMAL_gk_modp, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.ELGAMAL_myk_modp, idx = MPI.strcalc_mpi(d[idx:], idx)

        else:
            raise PGPValueError, "Unsupported public key algorithm. Received alg_pubkey->(%s)" % self.alg_pubkey
示例#5
0
def test3():
    """Timeout test"""

    SLEEP_TIME = 5

    MPI.register_mpi()

    #
    # Fork the parent
    #
    fork = tfork2()
    if fork.isChild:
        #
        # In child
        #
        print("in child")
        fork.release()

        time.sleep(1.1 * SLEEP_TIME)

        print("child sending hello")
        MPI.send_mpi_message(rank=0, message='hello')
        #
        # Exit the child
        #
        fork.exit()

    #
    # In parent
    # ---------
    # Check received message
    #
    print("parent doing sync")
    fork.sync()

    t0 = time.time()
    print("parent trying to receive msg")
    print 'recieved message=%s of length=%d' % MPI.receive_mpi_message(
        rank=1, timeout=2 * SLEEP_TIME, message_size=100)
    dt = time.time() - t0
    print 'dt = %g, should be bigger than %g' % (dt, SLEEP_TIME)

    #
    # Wait for the child to terminate
    #
    fork.wait()
def create_PublicKeyEncryptedSessionKeyBody(*args, **kwords):
    """
    """
    try:
        kwords = args[0]
    except IndexError:
        pass
    version = '\x03'
    keyid = STN.hex2str(kwords['keyid'])
    algorithm = STN.int2str(kwords['alg'])[0]
    if kwords['alg'] in [ASYM_RSA_EOS, ASYM_RSA_E, ASYM_RSA_S]:
        mpi_d = MPI.create_MPI(kwords['mpis'][0])._d
    elif ASYM_ELGAMAL_E == kwords['alg']:
        a_d = MPI.create_MPI(kwords['mpis'][0])._d
        b_d = MPI.create_MPI(kwords['mpis'][1])._d
        mpi_d = ''.join([a_d, b_d])
    else:
        raise PGPValueError, "Unsupported public key algorithm. Received alg->(%s)" % alg
    _d = ''.join([version, keyid, algorithm, mpi_d])
    return PublicKeyEncryptedSessionKeyBody(_d)
def create_PublicKeyEncryptedSessionKeyBody(*args, **kwords):
    """
    """
    try:
        kwords = args[0]
    except IndexError:
        pass
    version = '\x03'
    keyid = STN.hex2str(kwords['keyid'])
    algorithm = STN.int2str(kwords['alg'])[0]
    if kwords['alg'] in [ASYM_RSA_EOS, ASYM_RSA_E, ASYM_RSA_S]:
        mpi_d = MPI.create_MPI(kwords['mpis'][0])._d
    elif ASYM_ELGAMAL_E == kwords['alg']:
        a_d = MPI.create_MPI(kwords['mpis'][0])._d
        b_d = MPI.create_MPI(kwords['mpis'][1])._d
        mpi_d = ''.join([a_d, b_d])
    else:
        raise PGPValueError, "Unsupported public key algorithm. Received alg->(%s)" % alg
    _d = ''.join([version, keyid, algorithm, mpi_d])
    return PublicKeyEncryptedSessionKeyBody(_d)
示例#8
0
def test2():
    """Multi process test"""
    

    MPI.register_mpi()
    
    #
    # Fork the parent
    #
    cpid = os.fork()
    if (cpid == 0):
        #
        # In child
        #
        MPI.send_mpi_message(rank=0, message='hello')
        
        #
        # Terminate the child process
        #
        os._exit(0)

    #
    # Wait for the child to terminate
    #
    os.wait()
    
    #
    # read the message
    #
    print MPI.receive_mpi_message(rank=1, timeout=1000, message_size=100)
示例#9
0
    def run_scatter_reduce(self):
        t0 = time()
        self.data = self.comm.scatter(
            self.chunks, root=0
        )  # Defines the data and the process that contains the data to be distributed
        print(
            'rank' + str(self.rank) + ' has data:' + str(self.data)
        )  # Print the datas available in each processes distributed by initial Processor
        self.data_gather = self.comm.gather(
            self.data, root=0)  # Gather the data for a specific processor
        for i in range(len(
                self.data)):  # Performs the calculation of the split data
            self.data[i] = self.data[i] + 1
        self.reduction_data = self.comm.reduce(
            self.data, op=MPI.SUM,
            root=0)  # Reduce data to new array with calculation
        self.comm.Barrier()
        t = (time() - t0) * 1000
        print(t)

        if self.rank == 0:
            print(self.data_gather)
            print(self.reduction_data)
            print(MPI.Get_version())
示例#10
0
文件: SecretKey.py 项目: Zaryob/wubi
    def __resolve_secmpi(self, idx):
        d = self._d
        # 1:RSA (Encrypt or Sign), 2:RSA Encrypt-Only, 3:RSA Sign-Only
        if self.alg in [1, 2, 3]:
            self.RSA_d, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.RSA_p, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.RSA_q, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.RSA_u, idx = MPI.strcalc_mpi(d[idx:], idx)
            self._secmpi_d = self.RSA_d._d + self.RSA_p._d + self.RSA_q._d + self.RSA_u._d
        # 17:DSA (Digital Signature Algorithm)
        elif 17 == self.alg:
            self.DSA_x, idx = MPI.strcalc_mpi(d[idx:], idx)
            self._secmpi_d = self.DSA_x._d
        # 16:Elgamal (Encrypt-Only), 20:Elgamal (Encrypt or Sign)
        elif self.alg in [16, 20]:
            self.ELGAMAL_x, idx = MPI.strcalc_mpi(d[idx:], idx)
            self._secmpi_d = self.ELGAMAL_x._d
        else:
            self.err = (ValueError, "Unsupported key algorithm. Received alg->(%s)" % (str(self.alg)))

        if 255 == self.s2k_usg:
            self.chksum, idx = STN.strcalc(STN.str2int, d[idx:idx+2], idx)
        else:
            self.chksum = None
示例#11
0
    def fill(self, d):
        self._d = d
        idx = 0
        __version_d = d[idx:idx + 1]
        self.version, idx = STN.strcalc(STN.str2int, __version_d, idx)

        if self.version in [2, 3, 4]:
            __created_d = d[idx:idx + 4]
            self.created, idx = STN.strcalc(STN.str2int, __created_d, idx)

            if self.version in [2, 3]:
                self.__expires_d = d[idx:idx + 2]
                self.expires, idx = STN.strcalc(STN.str2int, self.__expires_d,
                                                idx)

            __alg_d = d[idx:idx + 1]
            self.alg, idx = STN.strcalc(STN.str2int, __alg_d, idx)

            # resolve MPIs
            if self.alg in [ASYM_RSA_EOS, ASYM_RSA_E, ASYM_RSA_S]:
                self.RSA_n, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.RSA_e, idx = MPI.strcalc_mpi(d[idx:], idx)
                self._mpi_d = self.RSA_n._d + self.RSA_e._d
            elif ASYM_DSA == self.alg:
                self.DSA_p, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.DSA_q, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.DSA_g, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.DSA_y, idx = MPI.strcalc_mpi(d[idx:], idx)
                self._mpi_d = self.DSA_p._d + self.DSA_q._d + self.DSA_g._d + self.DSA_y._d
            elif self.alg in [ASYM_ELGAMAL_E, ASYM_ELGAMAL_EOS]:
                self.ELGAMAL_p, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.ELGAMAL_g, idx = MPI.strcalc_mpi(d[idx:], idx)
                self.ELGAMAL_y, idx = MPI.strcalc_mpi(d[idx:], idx)
                self._mpi_d = self.ELGAMAL_p._d + self.ELGAMAL_g._d + self.ELGAMAL_y._d
            else:
                raise NotImplementedError(
                    "Unsupported key algorithm. Received alg->(%s)" % self.alg)

            # set fingerprint
            if self.version in [2, 3]:
                integer_data = self.RSA_n._int_d + self.RSA_e._int_d
                self.fingerprint = md5.new(integer_data).hexdigest().upper()
                # see fingerprint/id notes in doc/NOTES.txt
                self.id = STN.str2hex(self.RSA_n._int_d[-8:])
            elif 4 == self.version:
                f = ['\x99']
                f_data = ''.join(
                    [__version_d, __created_d, __alg_d, self._mpi_d])
                length = len(f_data)
                hi = (chr((0xffff & length) >> 8))  # high order packet length
                lo = (chr(0xff & length))  # low order packet length
                f.append(hi + lo)
                f.append(f_data)
                self.fingerprint = sha.new(''.join(f)).hexdigest().upper()
                # see fingerprint/id notes in doc/NOTES.txt
                self.id = self.fingerprint[-16:]

        else:  # unsupported packet version
            raise NotImplementedError("Unsupported key version: %s" %
                                      self.version)
        return idx
示例#12
0
文件: main.py 项目: Semen-kisliy/chm
    razmer = [c for c in range(3,14)]
    for i in razmer:
        A = matrix_generate(i)
        b = vector_b_generate(i)

        t1 = t.clock()
        res,step,acc = MNS(A,b,eps)
        t2 = t.clock()

        time_mns.append(t2-t1)
        result_mns.append(res)
        steps_mns.append(step)
        accuracy_mns.append(acc)

        t1 = t.clock()
        res,step,acc = MPI(A,b,eps)
        t2 = t.clock()

        time_mpi.append(t2-t1)
        result_mpi.append(res)
        steps_mpi.append(step)
        accuracy_mpi.append(acc)
        
        
    
    file_output(result_mpi,steps_mpi,time_mpi,accuracy_mpi,
                result_mns,steps_mns,time_mns,accuracy_mns,params['output'])

    if params['graph'] == 'yes' or  params['graph'] == 'y':
      start_plot(steps_mpi,time_mpi,steps_mns,time_mns,razmer)
示例#13
0
文件: Signature.py 项目: Zaryob/wubi
    def fill(self, d):
        self._d = d
        version_d = d[0]
        self.version, idx = STN.strcalc(STN.str2int, d[0], 0)

        if self.version in [2, 3]:
            hash_len, idx = STN.strcalc(STN.str2int, d[idx:idx + 1], idx)
            self.type, idx = STN.strcalc(STN.str2int, d[idx:idx + 1], idx)
            self.created, idx = STN.strcalc(STN.str2int, d[idx:idx + 4], idx)
            self.hashed_data = d[2:idx]
            self.keyid, idx = STN.strcalc(STN.str2hex, d[idx:idx + 8], idx)
            self.alg_pubkey, idx = STN.strcalc(STN.str2int, d[idx:idx + 1],
                                               idx)
            self.alg_hash, idx = STN.strcalc(STN.str2int, d[idx:idx + 1], idx)
            self.hashed_subpkts = []  # dummy settings to make searches easier
            self.unhashed_subpkts = []  #

        elif 4 == self.version:
            import struct
            _type_d, idx = STN.strcalc(None, d[idx:idx + 1], idx)
            self.type = STN.str2int(_type_d)
            self.alg_pubkey, idx = STN.strcalc(STN.str2int, d[idx:idx + 1],
                                               idx)
            self.alg_hash, idx = STN.strcalc(STN.str2int, d[idx:idx + 1], idx)
            # hashed subpackets
            subpkts_len, idx = STN.strcalc(STN.str2int, d[idx:idx + 2], idx)
            self.hashed_subpkts = self.__resolve_subpkts(d[idx:idx +
                                                           subpkts_len])
            # hashed data & trailer - should '>i' ever return more than 4 chars?
            hashed_data = d[0:idx + subpkts_len]
            bigend = struct.pack('>i', len(hashed_data))[-4:]
            self.hashed_data = ''.join(
                [hashed_data, version_d, '\xff', bigend])
            idx = idx + subpkts_len
            # unhashed subpackets
            subpkts_len, idx = STN.strcalc(STN.str2int, d[idx:idx + 2], idx)
            self.unhashed_subpkts = self.__resolve_subpkts(d[idx:idx +
                                                             subpkts_len])
            idx = idx + subpkts_len
            # attribute convenience
            self.keyid = self.__set_subpkt_attr(SIGSUB_SIGNERID) or ''
            self.created = self.__set_subpkt_attr(SIGSUB_CREATED) or 0

        else:
            raise PGPValueError(
                "Unsupported signature version. Received->(%s)" %
                str(self.version))

        self.hash_frag, idx = STN.strcalc(None, d[idx:idx + 2], idx)

        if self.alg_pubkey in [ASYM_RSA_S, ASYM_RSA_EOS]:
            self.RSA, idx = MPI.strcalc_mpi(d[idx:], idx)

        elif ASYM_DSA == self.alg_pubkey:
            self.DSA_r, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.DSA_s, idx = MPI.strcalc_mpi(d[idx:], idx)

        elif self.alg_pubkey in [ASYM_ELGAMAL_EOS]:
            self.ELGAMAL_a, idx = MPI.strcalc_mpi(d[idx:], idx)
            self.ELGAMAL_b, idx = MPI.strcalc_mpi(d[idx:], idx)

        else:
            raise PGPValueError("Unsupported public-key algorithm (%d)." %
                                self.alg_pubkey)
示例#14
0
文件: mpiBall.py 项目: yuw446/OpenCV
import cv2
import numpy as np
from collections import deque

import os
import sys
import numpy as np
import mpi4py import MPI
import time

comm = MPI.COMM_WORLD
size - comm.Get_size()
rank - comm.Get_rank()
name - MPI.Get_processor_name()

os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0"
os.environ['DISPLAY'] = '0, 0'

comm.Barrier

width = 640
height = 480

cap = cv2.VideoCapture(0)
cap.set(3, width)
cap.set(4, height)

video = cv2.VideoCapture("roadV.mov")
video1 = cv2.VideoCapture("roadO.mov")

示例#15
0
import sys
import System
import clr
clr.AddReference("MPI")
import MPI

args = System.Environment.GetCommandLineArgs()
argsref = clr.Reference[System.Array[str]](args)
env = MPI.Environment(argsref)

destHostname = ""
comm = MPI.Communicator.world
if comm.Rank == 0:
    print "Rank 0 is alive and running on " + MPI.Environment.ProcessorName
    for dest in range(1, comm.Size):
        print "Pinging process with rank " + str(dest) + "..."
        comm.Send[str]("Ping!", dest, 0)
        destHostname = comm.Receive[str].Overloads[(int, int)](dest, 1)
        print " Pong!"
        print "  Rank " + str(dest) + " is alive and running on " + str(
            destHostname)
else:
    destHostname = comm.Receive[str].Overloads[(int, int)](0, 0)
    comm.Send[str](str(MPI.Environment.ProcessorName), 0, 1)

env.Dispose()
示例#16
0
def test1():
    """Basic Test"""
    
    MPI.register_mpi()
    MPI.send_mpi_message(rank=0, message='hello')
    print MPI.receive_mpi_message(rank=0, timeout=1000, message_size=100)