Esempio n. 1
0
 def new_deterministic(self, name, type, text):
     for i in range(0, 2**64, 2):
         s1 = serialize.Serializer()
         s1.str(text)
         s1.vint(i)
         sigkey = crypto.sha512(s1.data)[0:32]
         s2 = serialize.Serializer()
         s2.str(text)
         s2.vint(i + 1)
         deckey = crypto.sha512(s2.data)[0:32]
         verkey = crypto.priv_to_pub(sigkey)
         enckey = crypto.priv_to_pub(deckey)
         ripe = crypto.to_ripe(verkey, enckey)
         if ripe[0:1] == b'\x00':
             return self.new_identity(name, type, sigkey, deckey)
Esempio n. 2
0
 def new_deterministic(self, name, type, text):
     for i in range(0, 2**64, 2):
         s1 = serialize.Serializer()
         s1.str(text)
         s1.vint(i)
         sigkey = crypto.sha512(s1.data)[0:32]
         s2 = serialize.Serializer()
         s2.str(text)
         s2.vint(i + 1)
         deckey = crypto.sha512(s2.data)[0:32]
         verkey = crypto.priv_to_pub(sigkey)
         enckey = crypto.priv_to_pub(deckey)
         ripe = crypto.to_ripe(verkey, enckey)
         if ripe[0:1] == b'\x00':
             return self.new_identity(name, type, sigkey, deckey)
Esempio n. 3
0
def get(data, size=10):
    # TODO salt identicons
    if data == b'':
        hash = b''
    else:
        hash = crypto.sha512(data)
    return qidenticon.render_identicon(int.from_bytes(hash, 'big'), size, True, 0, 0)
Esempio n. 4
0
 def brink(self):
     a = self.nonce.to_bytes(8, 'big')
     initial = crypto.sha512(self.data[8:])
     c = crypto.sha512d(a + initial)
     value = int.from_bytes(c[:8], 'big')
     return int(self.expires - 2**80 /
                (value * config.NETWORK_TRIALS *
                 (len(self.data) + config.NETWORK_EXTRA)) + 2**16)
Esempio n. 5
0
def check(payload, trials, extra, ttl, nonce):
    length = len(payload) + 8 + extra
    target = int(2**64/(trials*(length+ttl*length/(2**16))))
    initial = crypto.sha512(payload)
    a = nonce.to_bytes(8, 'big')
    c = crypto.sha512d(a+initial)
    value = int.from_bytes(c[:8], 'big')
    return value <= target
Esempio n. 6
0
 def send_packet(self, payload):
     magic = 0xe9beb4d9
     command = payload.command
     payloaddata = payload.data
     length = len(payloaddata)
     checksum = crypto.sha512(payloaddata)[:4]
     header = packet.Header(magic, command, length, checksum)
     self._c.send(header.to_bytes())
     self._c.send(payloaddata)
Esempio n. 7
0
 def send_packet(self, payload):
     magic = 0xe9beb4d9
     command = payload.command
     payloaddata = payload.data
     length = len(payloaddata)
     checksum = crypto.sha512(payloaddata)[:4]
     header = packet.Header(magic, command, length, checksum)
     self._c.send(header.to_bytes())
     self._c.send(payloaddata)
Esempio n. 8
0
def pow(payload, trials, extra, ttl):
    length = len(payload) + 8 + extra
    target = int(2**64/(trials*(length+max(ttl,0)*length/(2**16))))
    value = target + 1
    initial = crypto.sha512(payload)
    nonce = int.from_bytes(os.urandom(8), 'big') # Make it harder for attackers to determine how many numbers we have tried
    while value > target:
        nonce = (nonce + 1) % (2**64)
        a = nonce.to_bytes(8, 'big')
        c = crypto.sha512d(a+initial)
        value = int.from_bytes(c[:8], 'big')
    return nonce
Esempio n. 9
0
 def recv_packet(self):
     headerdata = b''
     while len(headerdata) < 24:
         buf = yield from self._c.recv(24 - len(headerdata))
         if not buf:
             return None
         headerdata += buf
     header = packet.Header.from_bytes(headerdata)
     if header.magic != 0xe9beb4d9:
         return None
     payloaddata = b''
     while len(payloaddata) < header.length:
         buf = yield from self._c.recv(header.length - len(payloaddata))
         if not buf:
             return None
         payloaddata += buf
     if header.checksum != crypto.sha512(payloaddata)[:4]:
         return None
     return packet.Generic(header.command, payloaddata)
Esempio n. 10
0
 def recv_packet(self):
     headerdata = b''
     while len(headerdata) < 24:
         buf = yield from self._c.recv(24 - len(headerdata))
         if not buf:
             return None
         headerdata += buf
     header = packet.Header.from_bytes(headerdata)
     if header.magic != 0xe9beb4d9:
         return None
     payloaddata = b''
     while len(payloaddata) < header.length:
         buf = yield from self._c.recv(header.length - len(payloaddata))
         if not buf:
             return None
         payloaddata += buf
     if header.checksum != crypto.sha512(payloaddata)[:4]:
         return None
     return packet.Generic(header.command, payloaddata)
Esempio n. 11
0
 def brink(self):
     a = self.nonce.to_bytes(8, 'big')
     initial = crypto.sha512(self.data[8:])
     c = crypto.sha512d(a+initial)
     value = int.from_bytes(c[:8], 'big')
     return int(self.expires-2**80/(value*config.NETWORK_TRIALS*(len(self.data)+config.NETWORK_EXTRA))+2**16)